OpenLB 1.7
Loading...
Searching...
No Matches
stlReader.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2010-2015 Thomas Henn, Mathias J. Krause
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 coords = rhs.coords;
62 return *this;
63 };
65 Vertex(Vertex<T,D> const& rhs):coords(rhs.coords) {};
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
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;
142};
143
144template<typename T>
145class STLmesh {
147 T distPoints(Vertex<T,3>& p1, Vertex<T,3>& p2);
149 const std::string _fName;
151 std::vector<STLtriangle<T> > _triangles;
153 Vector<T,3> _min, _max;
155 T _maxDist2;
157 mutable OstreamManager clout;
158
159public:
165 STLmesh(std::string, T stlSize = 1.);
166
172 STLmesh(const std::vector<std::vector<T>> meshPoints, T stlSize = 1.);
173
175 inline STLtriangle<T>& getTri(unsigned int i)
176 {
177 return _triangles[i];
178 }
180 inline std::vector<STLtriangle<T> >& getTriangles()
181 {
182 return _triangles;
183 }
185 inline unsigned int triangleSize() const
186 {
187 return _triangles.size();
188 }
191 {
192 return _min;
193 };
196 {
197 return _max;
198 };
200 inline float maxDist2() const
201 {
202 return _maxDist2;
203 }
205 void print(bool full = false);
207 void write(std::string fName);
209 bool testRayIntersect(const std::set<unsigned int>& tris, const Vector<T,3>& pt,const Vector<T,3>& dir, Vector<T,3>& q, T& alpha);
210};
211
212
213template<typename T>
214class STLreader : public IndicatorF3D<T> {
215private:
216 /*
217 * Old indicate function (slower, more stable)
218 * Define three rays (X-, Y-, Z-direction) for each leaf and count intersections
219 * with STL for each ray. Odd number of intersection means inside (Majority vote).
220 */
221 void indicate1();
222 /*
223 * New indicate function (faster, less stable)
224 * Define ray in Z-direction for each Voxel in XY-layer. Indicate all nodes on the fly.
225 */
226 void indicate2();
227 /*
228 * New indicate function (faster, less stable)
229 * Define ray in X-direction for each Voxel in YZ-layer. Indicate all nodes on the fly.
230 */
231 void indicate2_Xray();
232 /*
233 * New indicate function (faster, less stable)
234 * Define ray in Y-direction for each Voxel in XZ-layer. Indicate all nodes on the fly.
235 */
236 void indicate2_Yray();
237 /*
238 * Double ray approach: two times (X-, Y-, Z-direction) for each leaf.
239 * Could be use to deal with double layer triangles and face intersections.
240 */
241
242 void indicate3();
243
247 Vector<T,3> evalNormalOnSurface(const PhysR<T,3>& pt, const Vector<T,3>& fallbackNormal);
248
250 Vector<T,3> evalSurfaceNormal(const Vector<T,3>& origin);
251
257 short evalSignForSignedDistance(const Vector<T,3>& normal, const Vector<T,3>& distance);
261 short evalSignForSignedDistance(const Vector<T,3>& pt);
262
264 T _voxelSize;
266 T _stlSize;
268 T _overlap;
270 Octree<T>* _tree;
272 const std::string _fName;
274 STLmesh<T> _mesh;
276 bool _verbose;
278 mutable OstreamManager clout;
279
280public:
292 STLreader(const std::string fName, T voxelSize, T stlSize=1, int method=2,
293 bool verbose = false, T overlap=0., T max=0.);
304 STLreader(const std::vector<std::vector<T>> meshPoints, T voxelSize, T stlSize=1, int method=2,
305 bool verbose = false, T overlap=0., T max=0.);
306
307 ~STLreader() override;
309 bool operator() (bool output[], const T input[]) override;
310
312 bool distance(T& distance,const Vector<T,3>& origin, const Vector<T,3>& direction, int iC=-1) override;
313
315 T signedDistance(const Vector<T,3>& input) override;
316
318 Vector<T,3> surfaceNormal(const Vector<T,3>& pos, const T meshSize=0) override;
319
321 void print();
322
324 void writeSTL(std::string stlName="");
325
327 void writeOctree();
328
330 void setNormalsOutside();
331
335
337 inline Octree<T>* getTree() const
338 {
339 return _tree;
340 };
341
342
345 {
346 return _mesh;
347 };
348};
349
350} // namespace olb
351
352#endif
IndicatorF3D is an application from .
virtual bool normal(Vector< T, 3 > &normal, const Vector< T, 3 > &origin, const Vector< T, 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.
Definition stlReader.hh:318
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.
Definition stlReader.hh:698
STLtriangle< T > & getTri(unsigned int i)
Returns reference to a triangle.
Definition stlReader.h:175
float maxDist2() const
Returns maxDist squared.
Definition stlReader.h:200
Vector< T, 3 > & getMin()
Returns _min.
Definition stlReader.h:190
void print(bool full=false)
Prints console output.
Definition stlReader.hh:639
std::vector< STLtriangle< T > > & getTriangles()
Returns reference to all triangles.
Definition stlReader.h:180
unsigned int triangleSize() const
Returns number of triangles.
Definition stlReader.h:185
Vector< T, 3 > & getMax()
Returns _max.
Definition stlReader.h:195
void write(std::string fName)
Writes STL mesh in Si units.
Definition stlReader.hh:663
STLreader(const std::string fName, T voxelSize, T stlSize=1, int method=2, bool verbose=false, T overlap=0., T max=0.)
Constructs a new STLreader from a file.
Definition stlReader.hh:713
T signedDistance(const Vector< T, 3 > &input) override
Computes signed distance to closest triangle in direction of the surface normal.
void print()
Prints console output.
void writeSTL(std::string stlName="")
Writes STL mesh in Si units.
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)
STLmesh< T > & getMesh()
Returns mesh.
Definition stlReader.h:344
~STLreader() override
Definition stlReader.hh:888
void setBoundaryInsideNodes()
Every octree leaf intersected by the STL will be part of the inside nodes.
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.
Octree< T > * getTree() const
Returns tree.
Definition stlReader.h:337
void writeOctree()
Writes Octree.
Plain old scalar vector.
Definition vector.h:47
The description of a vector of 3D cuboid – header file.
This file contains indicator functions.
Top level namespace for all of OpenLB.
Octree.
std::vector< T > getE0()
Returns Pt0-Pt1.
Definition stlReader.hh:106
STLtriangle(STLtriangle< T > const &tri)
CopyConstructor copies.
Definition stlReader.h:106
STLtriangle()
Constructor constructs.
Definition stlReader.h:104
std::vector< T > getE1()
Returns Pt0-Pt2.
Definition stlReader.hh:116
Vector< T, 3 > uBeta
variables explained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY....
Definition stlReader.h:99
Vector< T, 3 > normal
normal of triangle
Definition stlReader.h:95
Vector< T, 3 > uGamma
Definition stlReader.h:99
std::vector< Vertex< T, 3 > > point
A triangle contains 3 Points.
Definition stlReader.h:92
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.
Definition stlReader.hh:154
void init()
Initializes triangle and precomputes member variables.
Definition stlReader.hh:46
Vector< T, 3 > getCenter()
Returns center.
Definition stlReader.hh:91
Vector< T, 3 > & getNormal()
Return write access to normal.
Definition stlReader.h:125
Vector< T, 3 > closestPtPointTriangle(const Vector< T, 3 > &pt) const
computes closest Point in a triangle to another point.
Definition stlReader.hh:261
const Vector< T, 3 > & getNormal() const
Return read access to normal.
Definition stlReader.h:130
STLtriangle< T > & operator=(STLtriangle< T > const &tri)
Operator= equals.
Definition stlReader.h:108
bool isPointInside(const PhysR< T, 3 > &pt) const
Check whether a point is inside a triangle.
Definition stlReader.hh:126
int getDim() const
Get dimension.
Definition stlReader.h:71
Vertex()
Constructor constructs.
Definition stlReader.h:56
Vertex(Vector< T, D > coords_)
Definition stlReader.h:57
Vertex(Vertex< T, D > const &rhs)
CopyConstructor copies.
Definition stlReader.h:65
Vertex< T, D > & operator=(Vertex< T, D > const &rhs)
Operator= equals.
Definition stlReader.h:59
Vector< T, D > coords
Point coordinates in SI units.
Definition stlReader.h:68
efficient implementation of a vector class