OpenLB 1.8.1
Loading...
Searching...
No Matches
STLreaderForSubgridParticleWallContact.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2010-2024 Thomas Henn, Mathias J. Krause, Christoph Gaul
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
28#ifndef STL_READER_H
29#define STL_READER_H
30
31#include <string>
32#include <vector>
33#include <iostream>
34#include <sstream>
35#include <set>
36#include <limits>
37
43#include "octree.h"
44#include "core/vector.h"
45
46
47// All OpenLB code is contained in this namespace.
48namespace olb {
49
50template<typename T>
51class Octree;
52
53template<typename T, unsigned D>
54struct Vertex {
56 Vertex() : coords() {};
57 Vertex( Vector<T,D> coords_ ) : coords(coords_) {};
60 {
61 = rhs;
62 return *this;
63 };
65 Vertex(Vertex<T,D> const& rhs)(rhs) {};
66
69
71 int getDim() const
72 {
73 return D;
74 }
75
76};
77
78template<typename T>
88 bool testRayIntersect(const Vector<T,3>& pt,const Vector<T,3>& dir, Vector<T,3>& q, T& alpha, const T& rad = T(), bool print = false);
90
92 std::vector<Vertex<T,3> > point;
93
96
100 T d, kBeta, kGamma;
101
102public:
104 STLtriangle():point(3, Vertex<T,3>()), normal(T()), uBeta(T()), uGamma(T()), d(T()), kBeta(T()), kGamma(T()) {};
106 STLtriangle(STLtriangle<T> const& tri):point(tri.point), normal(tri.normal), uBeta(tri.uBeta), uGamma(tri.uGamma), d(tri.d), kBeta(tri.kBeta), kGamma(tri.kGamma) {};
109 {
110 point = tri.point;
111 normal = tri.normal;
112 uBeta = tri.uBeta;
113 uGamma = tri.uGamma;
114 d = tri.d;
115 kBeta = tri.kBeta;
116 kGamma = tri.kGamma;
117 return *this;
118 };
119
121
123 void init();
126 {
127 return normal;
128 }
130 inline const Vector<T,3>& getNormal() const
131 {
132 return normal;
133 }
137 std::vector<T> getE0();
139 std::vector<T> getE1();
141 bool isPointInside(const PhysR<T,3>& pt) const;
144 bool getPointToEdgeDistances (const Vector<T,3>& input, Vector<T,3> & output, T sensitivity = 1.e-15);
146 bool isEdgePoint (const Vector<T,3> & input, Vector<T,3>& P1, Vector<T,3> & P2, T sensitivity = 1.e-15);
148 bool isVortexPoint (const Vector<T,3> & input,Vector<T,3>& P, T sensitivity = 1.e-15);
149};
150
151template<typename T>
152class STLmesh {
154 T distPoints(Vertex<T,3>& p1, Vertex<T,3>& p2);
156 const std::string _fName;
158 std::vector<STLtriangle<T> > _triangles;
160 Vector<T,3> _min, _max;
162 T _maxDist2;
164 mutable OstreamManager clout;
165
166public:
172 STLmesh(std::string, T stlSize = 1.);
173
179 STLmesh(const std::vector<std::vector<T>> meshPoints, T stlSize = 1.);
180
182 inline STLtriangle<T>& getTri(unsigned int i)
183 {
184 return _triangles[i];
185 }
187 inline std::vector<STLtriangle<T> >& getTriangles()
188 {
189 return _triangles;
190 }
192 inline unsigned int triangleSize() const
193 {
194 return _triangles.size();
195 }
198 {
199 return _min;
200 };
203 {
204 return _max;
205 };
207 inline float maxDist2() const
208 {
209 return _maxDist2;
210 }
212 void print(bool full = false);
214 void write(std::string fName);
216 bool testRayIntersect(const std::set<unsigned int>& tris, const Vector<T,3>& pt,const Vector<T,3>& dir, Vector<T,3>& q, T& alpha);
217};
218
227enum class SignMode { EXACT, CACHED };
228
229
230enum class RayMode : int {
231 FastRayZ = 1,
232 Robust = 2,
233 FastRayX = 3,
234 FastRayY = 4,
235 DoubleRay = 5
236};
237
238
239template<typename T>
240class STLreader : public IndicatorF3D<T> {
241private:
242 /*
243 * Old indicate function (slower, more stable)
244 * Define three rays (X-, Y-, Z-direction) for each leaf and count intersections
245 * with STL for each ray. Odd number of intersection means inside (Majority vote).
246 */
247 void indicate1();
248 /*
249 * New indicate function (faster, less stable)
250 * Define ray in Z-direction for each Voxel in XY-layer. Indicate all nodes on the fly.
251 */
252 void indicate2();
253 /*
254 * New indicate function (faster, less stable)
255 * Define ray in X-direction for each Voxel in YZ-layer. Indicate all nodes on the fly.
256 */
257 void indicate2_Xray();
258 /*
259 * New indicate function (faster, less stable)
260 * Define ray in Y-direction for each Voxel in XZ-layer. Indicate all nodes on the fly.
261 */
262 void indicate2_Yray();
263 /*
264 * Double ray approach: two times (X-, Y-, Z-direction) for each leaf.
265 * Could be use to deal with double layer triangles and face intersections.
266 */
267
268 void indicate3();
269
272 template <typename F>
273 void iterateOverCloseTriangles(const PhysR<T,3>& pt, F func, Octree<T>* leafNode = nullptr);
274
278 Vector<T,3> evalNormalOnSurface(const PhysR<T,3>& pt, const Vector<T,3>& fallbackNormal);
279
281 template <SignMode SIGNMODE>
282 Vector<T,3> evalSurfaceNormal(const Vector<T,3>& origin);
283
297 template <SignMode SIGNMODE>
298 short evalSignForSignedDistance(const Vector<T,3>& pt, [[maybe_unused]] const T distance, Vector<T,3> vecdist = {} , STLtriangle<T> stlT = STLtriangle<T>() );
299
300template<SignMode SIGNMODE>
301Vector<T,3> evalSurfaceNormalForPseudoNormal(const Vector<T,3>& origin, Vector<T,3> & outputPointOnSurface);
302
303
304 short evalSignForSignedDistanceFromNormal(const Vector<T,3>& normal, const Vector<T,3>& distance);
310 short evalSignForSignedDistanceFromPseudonormal(const Vector<T,3>& pseudonormal, const Vector<T,3>& distance);
314 short evalSignForSignedDistanceFromWindingNumber(const Vector<T,3>& pt);
317 short evalSignForSignedDistanceFromCache(const Vector<T,3>& pt);
318
320 T _voxelSize;
322 T _stlSize;
324 T _overlap;
326 Octree<T>* _tree;
328 const std::string _fName;
330 STLmesh<T> _mesh;
332 bool _verbose;
334 mutable OstreamManager clout;
335
336public:
348 STLreader(const std::string fName, T voxelSize, T stlSize=1, RayMode method = RayMode::FastRayZ,
349 bool verbose = false, T overlap=0., T max=0.);
360 STLreader(const std::vector<std::vector<T>> meshPoints, T voxelSize, T stlSize=1, RayMode method= RayMode::FastRayZ,
361 bool verbose = false, T overlap=0., T max=0.);
362
363 ~STLreader() override;
365 bool operator() (bool output[], const T input[]) override;
366
368 bool isInsideRootTree(const T input[]);
369
373
375 bool distance(T& distance,const Vector<T,3>& origin, const Vector<T,3>& direction, int iC=-1) override;
376
379 T signedDistance(const Vector<T,3>& input) override;
382 T signedDistanceExact(const Vector<T,3>& input) override;
384 template <SignMode SIGNMODE>
386
389 Vector<T,3> surfaceNormal(const Vector<T,3>& pos, const T meshSize=0) override;
392 Vector<T,3> surfaceNormalExact(const Vector<T,3>& pos, const T meshSize=0) override;
394 template <SignMode SIGNMODE>
395 Vector<T,3> surfaceNormal(const Vector<T,3>& pos, const T meshSize=0);
396
398 void print();
399
401 void writeSTL(std::string stlName="");
402
405
408
412
414 inline Octree<T>* getTree() const
415 {
416 return _tree;
417 };
418
419
422 {
423 return _mesh;
424 };
425
426};
427
428} // namespace olb
429
430#endif
IndicatorF3D is an application from .
Definition aliases.h:244
virtual bool normal(Vector< S, 3 > &normal, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1)
returns true and the normal if there was one found for an given origin and direction
class for marking output with some text
STLmesh(std::string, T stlSize=1.)
Constructs a new STLmesh from a file.
bool testRayIntersect(const std::set< unsigned int > &tris, const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, Vector< T, 3 > &q, T &alpha)
Compute intersection between Ray and set of triangles; returns true if intersection is found.
STLtriangle< T > & getTri(unsigned int i)
Returns reference to a triangle.
float maxDist2() const
Returns maxDist squared.
Vector< T, 3 > & getMin()
Returns _min.
void print(bool full=false)
Prints console output.
STLmesh(const std::vector< std::vector< T > > meshPoints, T stlSize=1.)
Constructs a new STLmesh from a file.
std::vector< STLtriangle< T > > & getTriangles()
Returns reference to all triangles.
unsigned int triangleSize() const
Returns number of triangles.
Vector< T, 3 > & getMax()
Returns _max.
void write(std::string fName)
Writes STL mesh in Si units.
T signedDistance(const Vector< T, 3 > &input) override
Computes signed distance to closest triangle in direction of the surface normal Using the cached info...
void print()
Prints console output.
void writeSTL(std::string stlName="")
Writes STL mesh in Si units.
bool isInsideRootTree(const T input[])
Returns whether node is inside the top-level octree or not.
void setNormalsOutside()
Rearranges normals of triangles to point outside of geometry.
Vector< T, 3 > surfaceNormal(const Vector< T, 3 > &pos, const T meshSize=0) override
Finds and returns normal of the closest surface (triangle) Using the cached information (faster,...
STLmesh< T > & getMesh()
Returns mesh.
Vector< T, 3 > closestPointInBoundingBox(const Vector< T, 3 > &input)
Returns the closest point in the bounding box If input is already inside, then it returns input.
~STLreader() override
Vector< T, 3 > surfaceNormal(const Vector< T, 3 > &pos, const T meshSize=0)
Finds and returns normal of the closest surface (triangle)
void setBoundaryInsideNodes()
Every octree leaf intersected by the STL will be part of the inside nodes.
STLreader(const std::vector< std::vector< T > > meshPoints, T voxelSize, T stlSize=1, RayMode method=RayMode::FastRayZ, bool verbose=false, T overlap=0., T max=0.)
Constructs a new STLreader from a file.
Vector< T, 3 > surfaceNormalExact(const Vector< T, 3 > &pos, const T meshSize=0) override
Finds and returns normal of the closest surface (triangle) Much slower, but more accurate.
STLreader(const std::string fName, T voxelSize, T stlSize=1, RayMode method=RayMode::FastRayZ, bool verbose=false, T overlap=0., T max=0.)
Constructs a new STLreader from a file.
bool operator()(bool output[], const T input[]) override
Returns whether node is inside or not.
bool distance(T &distance, const Vector< T, 3 > &origin, const Vector< T, 3 > &direction, int iC=-1) override
Computes distance to closest triangle intersection.
T signedDistanceExact(const Vector< T, 3 > &input) override
Computes exact signed distance to closest triangle in direction of the surface normal Much slower,...
T signedDistance(const Vector< T, 3 > &input)
Computes signed distance to closest triangle in direction of the surface normal.
Octree< T > * getTree() const
Returns tree.
void writeOctree()
Writes Octree.
Plain old scalar vector.
This file contains indicator functions.
Top level namespace for all of OpenLB.
SignMode
Enum class that specifies the mode to use for computing the sign of the signed distance.
Definition stlReader.h:206
RayMode
Definition stlReader.h:209
@ DoubleRay
Indicate function with ray in Y-direction(faster, less stable).
@ FastRayX
Old indicate function (slower, more stable)
@ FastRayY
Indicate function with ray in X-direction(faster, less stable).
@ Robust
Indicate function with ray in Z-direction(faster, less stable). Default option.
Octree.
std::vector< T > getE0()
Returns Pt0-Pt1.
STLtriangle(STLtriangle< T > const &tri)
CopyConstructor copies.
std::vector< T > getE1()
Returns Pt0-Pt2.
Vector< T, 3 > uBeta
variables explained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY....
Definition stlReader.h:74
Vector< T, 3 > normal
normal of triangle
Definition stlReader.h:70
std::vector< Vertex< T, 3 > > point
A triangle contains 3 Points.
bool testRayIntersect(const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, Vector< T, 3 > &q, T &alpha, const T &rad=T(), bool print=false)
Test intersection between ray and triangle.
bool getPointToEdgeDistances(const Vector< T, 3 > &input, Vector< T, 3 > &output, T sensitivity=1.e-15)
Returns true if the point is on a edge (smaller than sensitivity) and gives the perpendicular distanc...
void init()
Initializes triangle and precomputes member variables.
bool isVortexPoint(const Vector< T, 3 > &input, Vector< T, 3 > &P, T sensitivity=1.e-15)
Returns true if is near vortex (smaller than sensitivity) and saves in P the vortex points.
Vector< T, 3 > getCenter()
Returns center.
Vector< T, 3 > & getNormal()
Return write access to normal.
bool isEdgePoint(const Vector< T, 3 > &input, Vector< T, 3 > &P1, Vector< T, 3 > &P2, T sensitivity=1.e-15)
Returns true if is near edge (smaller than sensitivity) and not near vortex and saves in P1 and P2 th...
Vector< T, 3 > uGamma
Definition stlReader.h:74
Vector< T, 3 > closestPtPointTriangle(const Vector< T, 3 > &pt) const
const Vector< T, 3 > & getNormal() const
Return read access to normal.
STLtriangle< T > & operator=(STLtriangle< T > const &tri)
Operator= equals.
std::vector< Vector< T, 3 > > point
A triangle contains 3 Points.
Definition stlReader.h:67
bool isPointInside(const PhysR< T, 3 > &pt) const
Check whether a point is inside a triangle.
int getDim() const
Get dimension.
Vertex()
Constructor constructs.
Vertex(Vertex< T, D > const &rhs)(rhs)
CopyConstructor copies.
Vertex< T, D > & operator=(Vertex< T, D > const &rhs)
Operator= equals.
Vector< T, D > coords
Point coordinates in SI units.
efficient implementation of a vector class