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