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-2025 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 "triSurfaceFieldsFwd.H"
68 #include "pointIndexHitList.H"
69 #include "unitConversion.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 member 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  //- Helper function for isSurfaceClosed
131  static bool addFaceToEdge
132  (
133  const edge&,
135  );
136 
137  //- Check whether surface is closed without calculating any permanent
138  // addressing.
139  bool isSurfaceClosed() const;
140 
141  //- Steps to next intersection. Adds smallVec and starts tracking
142  // from there.
143  static void getNextIntersections
144  (
145  const indexedOctree<treeDataTriSurface>& octree,
146  const point& start,
147  const point& end,
148  const vector& smallVec,
150  );
151 
152  void drawHitProblem
153  (
154  const label fi,
155  const point& start,
156  const point& p,
157  const point& end,
158  const pointIndexHitList& hitInfo
159  ) const;
160 
161  void processHit
162  (
163  scalar& internalCloseness,
164  scalar& externalCloseness,
165  const scalar internalToleranceCosAngle,
166  const scalar externalToleranceCosAngle,
167  const label fi,
168  const point& start,
169  const point& p,
170  const point& end,
171  const vector& normal,
172  const vectorField& normals,
173  const pointIndexHitList& hitInfo
174  ) const;
175 
176 
177 public:
178 
179  //- Runtime type information
180  TypeName("triSurface");
181 
182 
183  // Constructors
184 
185  //- Construct from triSurface
186  triSurface(const IOobject&, const Foam::triSurface&);
187 
188  //- Construct read
189  triSurface(const IOobject& io);
190 
191  //- Construct from IO and dictionary (used by searchableSurface).
192  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
193  triSurface
194  (
195  const IOobject& io,
196  const dictionary& dict
197  );
198 
199 
200  // Special constructors for use by distributedTriSurface. File search
201  // status (local/global) supplied.
202 
203  triSurface(const IOobject& io, const bool isGlobal);
204 
205  triSurface
206  (
207  const IOobject& io,
208  const dictionary& dict,
209  const bool isGlobal
210  );
211 
212  //- Disallow default bitwise copy construction
213  triSurface(const triSurface&) = delete;
214 
215 
216  //- Destructor
217  virtual ~triSurface();
218 
219 
220  // Member Functions
221 
222  //- Clear storage
223  void clearOut();
224 
225  //- Move points
226  virtual void setPoints(const pointField&);
227 
228  //- Demand driven construction of octree for boundary edges
229  const indexedOctree<treeDataEdge>& edgeTree() const;
230 
231 
232  // searchableSurface implementation
233 
234  virtual const wordList& regions() const;
235 
236  //- Whether supports volume type below. I.e. whether is closed.
237  virtual bool hasVolumeType() const;
238 
239  //- Range of local indices that can be returned.
240  virtual label size() const
241  {
242  return Foam::triSurface::size();
243  }
244 
245  //- Get representative set of element coordinates
246  // Usually the element centres (should be of length size()).
247  virtual tmp<pointField> coordinates() const;
248 
249  //- Get bounding spheres (centre and radius squared). Any point
250  // on surface is guaranteed to be inside.
251  virtual void boundingSpheres
252  (
253  pointField& centres,
254  scalarField& radiusSqr
255  ) const;
256 
257  //- Get the points that define the surface.
258  virtual tmp<pointField> points() const;
259 
260  // Does any part of the surface overlap the supplied bound box?
261  virtual bool overlaps(const boundBox& bb) const;
262 
263  virtual void findNearest
264  (
265  const pointField& sample,
266  const scalarField& nearestDistSqr,
268  ) const;
269 
270  virtual void findNearest
271  (
272  const pointField& sample,
273  const scalarField& nearestDistSqr,
274  const labelList& regionIndices,
276  ) const;
277 
278  virtual void findLine
279  (
280  const pointField& start,
281  const pointField& end,
283  ) const;
284 
285  virtual void findLineAny
286  (
287  const pointField& start,
288  const pointField& end,
290  ) const;
291 
292  //- Get all intersections in order from start to end.
293  virtual void findLineAll
294  (
295  const pointField& start,
296  const pointField& end,
298  ) const;
299 
300  //- From a set of points and indices get the region
301  virtual void getRegion
302  (
303  const List<pointIndexHit>&,
304  labelList& region
305  ) const;
306 
307  //- From a set of points and indices get the normal
308  virtual void getNormal
309  (
310  const List<pointIndexHit>&,
311  vectorField& normal
312  ) const;
313 
314  //- Determine type (inside/outside/mixed) for point. unknown if
315  // cannot be determined (e.g. non-manifold surface)
316  virtual void getVolumeType
317  (
318  const pointField&,
320  ) const;
321 
322 
323  // Other
324 
325  //- WIP. Store element-wise field.
326  virtual void setField(const labelList& values);
327 
328  //- WIP. From a set of hits (points and
329  // indices) get the specified field. Misses do not get set.
330  virtual void getField(const List<pointIndexHit>&, labelList&) const;
331 
332  //- Return a pair of triSurfaceScalarFields representing the
333  // internal and external closeness of regions of the surface
335  (
336  const scalar internalAngleTolerance = degToRad(80),
337  const scalar externalAngleTolerance = degToRad(80)
338  ) const;
339 
340  //- Return a pair of triSurfaceScalarPointFields representing the
341  // internal and external closeness of regions of the surface
343  (
344  const scalar internalAngleTolerance = degToRad(80),
345  const scalar externalAngleTolerance = degToRad(80)
346  ) const;
347 
348 
349  // regIOobject implementation
350 
351  bool writeData(Ostream&) const
352  {
354  return false;
355  }
356 
357  //- Write using given format, version and compression
358  virtual bool writeObject
359  (
363  const bool write = true
364  ) const;
365 
366  //- Is object global
367  virtual bool global() const
368  {
369  return true;
370  }
371 
372 
373  // Member Operators
374 
375  //- Disallow default bitwise assignment
376  void operator=(const triSurface&) = delete;
377 };
378 
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 } // End of namespace searchableSurfaces
383 
384 //- Trait for obtaining global status
385 template<>
386 struct typeGlobal<searchableSurfaces::triSurface>
387 {
388  static const bool global = true;
389 };
390 
391 } // End namespace Foam
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #endif
396 
397 // ************************************************************************* //
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 <Type> with first() and second() elements.
Definition: Pair.H:66
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 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.
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.
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.
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
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
Triangulated surface description with patch information.
Definition: triSurface.H:69
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.
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:503
static const bool global
Definition: IOobject.H:504