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-2022 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 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class triSurfaceMesh Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 class triSurfaceMesh
80 :
81  public searchableSurface,
82  public objectRegistry, // so we can store fields
83  public triSurface,
84  public triSurfaceRegionSearch
85 {
86  // Private member data
87 
88  //- Supplied fileName override
89  fileName fName_;
90 
91  //- Optional min triangle quality. Triangles below this get
92  // ignored for normal calculation
93  scalar minQuality_;
94 
95  //- Search tree for boundary edges.
96  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
97 
98  //- Names of regions
99  mutable wordList regions_;
100 
101  //- Is surface closed
102  mutable label surfaceClosed_;
103 
104 
105  // Private Member Functions
106 
107  //- Return fileName to load IOobject from
108  static fileName checkFile(const regIOobject& io, const bool isGlobal);
109 
110  //- Return fileName. If fileName is relative gets treated local to
111  // IOobject
112  static fileName relativeFilePath
113  (
114  const regIOobject&,
115  const fileName&,
116  const bool isGlobal
117  );
118 
119  //- Return fileName to load IOobject from. Optional override of fileName
120  static fileName checkFile
121  (
122  const regIOobject&,
123  const dictionary&,
124  const bool isGlobal
125  );
126 
127  //- Helper function for isSurfaceClosed
128  static bool addFaceToEdge
129  (
130  const edge&,
132  );
133 
134  //- Check whether surface is closed without calculating any permanent
135  // addressing.
136  bool isSurfaceClosed() const;
137 
138  //- Steps to next intersection. Adds smallVec and starts tracking
139  // from there.
140  static void getNextIntersections
141  (
142  const indexedOctree<treeDataTriSurface>& octree,
143  const point& start,
144  const point& end,
145  const vector& smallVec,
147  );
148 
149  void drawHitProblem
150  (
151  const label fi,
152  const point& start,
153  const point& p,
154  const point& end,
155  const pointIndexHitList& hitInfo
156  ) const;
157 
158  void processHit
159  (
160  scalar& internalCloseness,
161  scalar& externalCloseness,
162  const scalar internalToleranceCosAngle,
163  const scalar externalToleranceCosAngle,
164  const label fi,
165  const point& start,
166  const point& p,
167  const point& end,
168  const vector& normal,
169  const vectorField& normals,
170  const pointIndexHitList& hitInfo
171  ) const;
172 
173 
174 public:
175 
176  //- Runtime type information
177  TypeName("triSurfaceMesh");
178 
179 
180  // Constructors
181 
182  //- Construct from triSurface
183  triSurfaceMesh(const IOobject&, const triSurface&);
184 
185  //- Construct read
186  triSurfaceMesh(const IOobject& io);
187 
188  //- Construct from IO and dictionary (used by searchableSurface).
189  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
191  (
192  const IOobject& io,
193  const dictionary& dict
194  );
195 
196 
197  // Special constructors for use by distributedTriSurface. File search
198  // status (local/global) supplied.
199 
200  triSurfaceMesh(const IOobject& io, const bool isGlobal);
201 
203  (
204  const IOobject& io,
205  const dictionary& dict,
206  const bool isGlobal
207  );
208 
209  //- Disallow default bitwise copy construction
210  triSurfaceMesh(const triSurfaceMesh&) = delete;
211 
212 
213  //- Destructor
214  virtual ~triSurfaceMesh();
215 
216 
217  // Member Functions
218 
219  //- Clear storage
220  void clearOut();
221 
222  //- Move points
223  virtual void movePoints(const pointField&);
224 
225  //- Demand driven construction of octree for boundary edges
226  const indexedOctree<treeDataEdge>& edgeTree() const;
227 
228 
229  // searchableSurface implementation
230 
231  virtual const wordList& regions() const;
232 
233  //- Whether supports volume type below. I.e. whether is closed.
234  virtual bool hasVolumeType() const;
235 
236  //- Range of local indices that can be returned.
237  virtual label size() const
238  {
239  return triSurface::size();
240  }
241 
242  //- Get representative set of element coordinates
243  // Usually the element centres (should be of length size()).
244  virtual tmp<pointField> coordinates() const;
245 
246  //- Get bounding spheres (centre and radius squared). Any point
247  // on surface is guaranteed to be inside.
248  virtual void boundingSpheres
249  (
250  pointField& centres,
251  scalarField& radiusSqr
252  ) const;
253 
254  //- Get the points that define the surface.
255  virtual tmp<pointField> points() const;
256 
257  // Does any part of the surface overlap the supplied bound box?
258  virtual bool overlaps(const boundBox& bb) const;
259 
260  virtual void findNearest
261  (
262  const pointField& sample,
263  const scalarField& nearestDistSqr,
265  ) const;
266 
267  virtual void findNearest
268  (
269  const pointField& sample,
270  const scalarField& nearestDistSqr,
271  const labelList& regionIndices,
273  ) const;
274 
275  virtual void findLine
276  (
277  const pointField& start,
278  const pointField& end,
280  ) const;
281 
282  virtual void findLineAny
283  (
284  const pointField& start,
285  const pointField& end,
287  ) const;
288 
289  //- Get all intersections in order from start to end.
290  virtual void findLineAll
291  (
292  const pointField& start,
293  const pointField& end,
295  ) const;
296 
297  //- From a set of points and indices get the region
298  virtual void getRegion
299  (
300  const List<pointIndexHit>&,
301  labelList& region
302  ) const;
303 
304  //- From a set of points and indices get the normal
305  virtual void getNormal
306  (
307  const List<pointIndexHit>&,
308  vectorField& normal
309  ) const;
310 
311  //- Determine type (inside/outside/mixed) for point. unknown if
312  // cannot be determined (e.g. non-manifold surface)
313  virtual void getVolumeType
314  (
315  const pointField&,
317  ) const;
318 
319 
320  // Other
321 
322  //- WIP. Store element-wise field.
323  virtual void setField(const labelList& values);
324 
325  //- WIP. From a set of hits (points and
326  // indices) get the specified field. Misses do not get set.
327  virtual void getField(const List<pointIndexHit>&, labelList&) const;
328 
329  //- Return a pair of triSurfaceScalarFields representing the
330  // internal and external closeness of regions of the surface
332  (
333  const scalar internalAngleTolerance = 80,
334  const scalar externalAngleTolerance = 80
335  ) const;
336 
337  //- Return a pair of triSurfaceScalarPointFields representing the
338  // internal and external closeness of regions of the surface
340  (
341  const scalar internalAngleTolerance = 80,
342  const scalar externalAngleTolerance = 80
343  ) const;
344 
345 
346  // regIOobject implementation
347 
348  bool writeData(Ostream&) const
349  {
351  return false;
352  }
353 
354  //- Write using given format, version and compression
355  virtual bool writeObject
356  (
360  const bool write = true
361  ) const;
362 
363  //- Is object global
364  virtual bool global() const
365  {
366  return true;
367  }
368 
369 
370  // Member Operators
371 
372  //- Disallow default bitwise assignment
373  void operator=(const triSurfaceMesh&) = delete;
374 };
375 
376 
377 //- Trait for obtaining global status
378 template<>
380 {
381  static const bool global = true;
382 };
383 
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 } // End namespace Foam
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #endif
392 
393 // ************************************************************************* //
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:160
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.
Pair< tmp< triSurfacePointScalarField > > extractPointCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=80) const
Return a pair of triSurfaceScalarPointFields representing the.
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.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
TypeName("triSurfaceMesh")
Runtime type information.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual void movePoints(const pointField &)
Move points.
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.
Pair< tmp< triSurfaceScalarField > > extractCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=80) const
Return a pair of triSurfaceScalarFields representing the.
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 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:353
Namespace for OpenFOAM.
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