triSurfaceMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::triSurfaceMesh
26 
27 Description
28  A surface geometry formed of discrete facets, e.g. triangles and/or
29  quadrilaterals, defined in a file using formats such as Wavefront OBJ, or
30  stereolithography STL.
31 
32 Usage
33  \table
34  Property | Description | Required
35  file | Name of the geometry file | yes
36  scale | Scaling factor for surface | no
37  minQuality | Threshold triangle quality | no
38  \endtable
39 
40  Note: when calculating surface normal vectors, triangles are ignored with
41  quality < minQuality.
42 
43  Example specification in snappyHexMeshDict/geometry:
44  \verbatim
45  type triSurfaceMesh;
46  file "surfaceFile.obj";
47  \endverbatim
48 
49 SourceFiles
50  triSurfaceMesh.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef triSurfaceMesh_H
55 #define triSurfaceMesh_H
56 
57 #include "treeBoundBox.H"
58 #include "searchableSurface.H"
59 #include "objectRegistry.H"
60 #include "indexedOctree.H"
61 #include "treeDataTriSurface.H"
62 #include "treeDataPrimitivePatch.H"
63 #include "treeDataEdge.H"
64 #include "EdgeMap.H"
65 #include "triSurface.H"
66 #include "triSurfaceRegionSearch.H"
67 #include "triSurfaceFieldsFwd.H"
68 #include "pointIndexHitList.H"
69 #include "unitConversion.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class triSurfaceMesh Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 class triSurfaceMesh
81 :
82  public searchableSurface,
83  public objectRegistry, // so we can store fields
84  public triSurface,
85  public triSurfaceRegionSearch
86 {
87  // Private member data
88 
89  //- Supplied fileName override
90  fileName fName_;
91 
92  //- Optional min triangle quality. Triangles below this get
93  // ignored for normal calculation
94  scalar minQuality_;
95 
96  //- Search tree for boundary edges.
97  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
98 
99  //- Names of regions
100  mutable wordList regions_;
101 
102  //- Is surface closed
103  mutable label surfaceClosed_;
104 
105 
106  // Private Member Functions
107 
108  //- Return fileName to load IOobject from
109  static fileName checkFile(const regIOobject& io, const bool isGlobal);
110 
111  //- Return fileName. If fileName is relative gets treated local to
112  // IOobject
113  static fileName relativeFilePath
114  (
115  const regIOobject&,
116  const fileName&,
117  const bool isGlobal
118  );
119 
120  //- Return fileName to load IOobject from. Optional override of fileName
121  static fileName checkFile
122  (
123  const regIOobject&,
124  const dictionary&,
125  const bool isGlobal
126  );
127 
128  //- Helper function for isSurfaceClosed
129  static bool addFaceToEdge
130  (
131  const edge&,
133  );
134 
135  //- Check whether surface is closed without calculating any permanent
136  // addressing.
137  bool isSurfaceClosed() const;
138 
139  //- Steps to next intersection. Adds smallVec and starts tracking
140  // from there.
141  static void getNextIntersections
142  (
143  const indexedOctree<treeDataTriSurface>& octree,
144  const point& start,
145  const point& end,
146  const vector& smallVec,
148  );
149 
150  void drawHitProblem
151  (
152  const label fi,
153  const point& start,
154  const point& p,
155  const point& end,
156  const pointIndexHitList& hitInfo
157  ) const;
158 
159  void processHit
160  (
161  scalar& internalCloseness,
162  scalar& externalCloseness,
163  const scalar internalToleranceCosAngle,
164  const scalar externalToleranceCosAngle,
165  const label fi,
166  const point& start,
167  const point& p,
168  const point& end,
169  const vector& normal,
170  const vectorField& normals,
171  const pointIndexHitList& hitInfo
172  ) const;
173 
174 
175 public:
176 
177  //- Runtime type information
178  TypeName("triSurfaceMesh");
179 
180 
181  // Constructors
182 
183  //- Construct from triSurface
184  triSurfaceMesh(const IOobject&, const triSurface&);
185 
186  //- Construct read
187  triSurfaceMesh(const IOobject& io);
188 
189  //- Construct from IO and dictionary (used by searchableSurface).
190  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
192  (
193  const IOobject& io,
194  const dictionary& dict
195  );
196 
197 
198  // Special constructors for use by distributedTriSurface. File search
199  // status (local/global) supplied.
200 
201  triSurfaceMesh(const IOobject& io, const bool isGlobal);
202 
204  (
205  const IOobject& io,
206  const dictionary& dict,
207  const bool isGlobal
208  );
209 
210  //- Disallow default bitwise copy construction
211  triSurfaceMesh(const triSurfaceMesh&) = delete;
212 
213 
214  //- Destructor
215  virtual ~triSurfaceMesh();
216 
217 
218  // Member Functions
219 
220  //- Clear storage
221  void clearOut();
222 
223  //- Move points
224  virtual void setPoints(const pointField&);
225 
226  //- Demand driven construction of octree for boundary edges
227  const indexedOctree<treeDataEdge>& edgeTree() const;
228 
229 
230  // searchableSurface implementation
231 
232  virtual const wordList& regions() const;
233 
234  //- Whether supports volume type below. I.e. whether is closed.
235  virtual bool hasVolumeType() const;
236 
237  //- Range of local indices that can be returned.
238  virtual label size() const
239  {
240  return triSurface::size();
241  }
242 
243  //- Get representative set of element coordinates
244  // Usually the element centres (should be of length size()).
245  virtual tmp<pointField> coordinates() const;
246 
247  //- Get bounding spheres (centre and radius squared). Any point
248  // on surface is guaranteed to be inside.
249  virtual void boundingSpheres
250  (
251  pointField& centres,
252  scalarField& radiusSqr
253  ) const;
254 
255  //- Get the points that define the surface.
256  virtual tmp<pointField> points() const;
257 
258  // Does any part of the surface overlap the supplied bound box?
259  virtual bool overlaps(const boundBox& bb) const;
260 
261  virtual void findNearest
262  (
263  const pointField& sample,
264  const scalarField& nearestDistSqr,
266  ) const;
267 
268  virtual void findNearest
269  (
270  const pointField& sample,
271  const scalarField& nearestDistSqr,
272  const labelList& regionIndices,
274  ) const;
275 
276  virtual void findLine
277  (
278  const pointField& start,
279  const pointField& end,
281  ) const;
282 
283  virtual void findLineAny
284  (
285  const pointField& start,
286  const pointField& end,
288  ) const;
289 
290  //- Get all intersections in order from start to end.
291  virtual void findLineAll
292  (
293  const pointField& start,
294  const pointField& end,
296  ) const;
297 
298  //- From a set of points and indices get the region
299  virtual void getRegion
300  (
301  const List<pointIndexHit>&,
302  labelList& region
303  ) const;
304 
305  //- From a set of points and indices get the normal
306  virtual void getNormal
307  (
308  const List<pointIndexHit>&,
309  vectorField& normal
310  ) const;
311 
312  //- Determine type (inside/outside/mixed) for point. unknown if
313  // cannot be determined (e.g. non-manifold surface)
314  virtual void getVolumeType
315  (
316  const pointField&,
318  ) const;
319 
320 
321  // Other
322 
323  //- WIP. Store element-wise field.
324  virtual void setField(const labelList& values);
325 
326  //- WIP. From a set of hits (points and
327  // indices) get the specified field. Misses do not get set.
328  virtual void getField(const List<pointIndexHit>&, labelList&) const;
329 
330  //- Return a pair of triSurfaceScalarFields representing the
331  // internal and external closeness of regions of the surface
333  (
334  const scalar internalAngleTolerance = degToRad(80),
335  const scalar externalAngleTolerance = degToRad(80)
336  ) const;
337 
338  //- Return a pair of triSurfaceScalarPointFields representing the
339  // internal and external closeness of regions of the surface
341  (
342  const scalar internalAngleTolerance = degToRad(80),
343  const scalar externalAngleTolerance = degToRad(80)
344  ) const;
345 
346 
347  // regIOobject implementation
348 
349  bool writeData(Ostream&) const
350  {
352  return false;
353  }
354 
355  //- Write using given format, version and compression
356  virtual bool writeObject
357  (
361  const bool write = true
362  ) const;
363 
364  //- Is object global
365  virtual bool global() const
366  {
367  return true;
368  }
369 
370 
371  // Member Operators
372 
373  //- Disallow default bitwise assignment
374  void operator=(const triSurfaceMesh&) = delete;
375 };
376 
377 
378 //- Trait for obtaining global status
379 template<>
381 {
382  static const bool global = true;
383 };
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #endif
393 
394 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
A class for handling file names.
Definition: fileName.H:82
Non-pointer based hierarchical recursive searching.
Definition: indexedOctree.H:72
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
A surface geometry formed of discrete facets, e.g. triangles and/or quadrilaterals,...
virtual label size() const
Range of local indices that can be returned.
triSurfaceMesh(const IOobject &, const triSurface &)
Construct from triSurface.
void operator=(const triSurfaceMesh &)=delete
Disallow default bitwise assignment.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
virtual ~triSurfaceMesh()
Destructor.
bool writeData(Ostream &) const
writeData function required by regIOobject but not used
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared). Any point.
virtual bool global() const
Is object global.
virtual void setField(const labelList &values)
WIP. Store element-wise field.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
Pair< tmp< triSurfaceScalarField > > extractCloseness(const scalar internalAngleTolerance=degToRad(80), const scalar externalAngleTolerance=degToRad(80)) const
Return a pair of triSurfaceScalarFields representing the.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
TypeName("triSurfaceMesh")
Runtime type information.
Pair< tmp< triSurfacePointScalarField > > extractPointCloseness(const scalar internalAngleTolerance=degToRad(80), const scalar externalAngleTolerance=degToRad(80)) const
Return a pair of triSurfaceScalarPointFields representing the.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual const wordList & regions() const
Names of regions.
virtual bool hasVolumeType() const
Whether supports volume type below. I.e. whether is closed.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
void clearOut()
Clear storage.
virtual void setPoints(const pointField &)
Move points.
virtual tmp< pointField > points() const
Get the points that define the surface.
Triangulated surface description with patch information.
Definition: triSurface.H:69
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
scalar degToRad(const scalar deg)
Convert degrees to radians.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dictionary dict
volScalarField & p
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
Trait for obtaining global status.
Definition: IOobject.H:504
static const bool global
Definition: IOobject.H:505