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-2020 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  IOoject and searching on triSurface
29 
30  Note: when constructing from dictionary has optional parameters:
31  - scale : scaling factor.
32  - tolerance : relative tolerance for doing intersections
33  (see triangle::intersection)
34  - minQuality: discard triangles with low quality when getting normal
35 
36 SourceFiles
37  triSurfaceMesh.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef triSurfaceMesh_H
42 #define triSurfaceMesh_H
43 
44 #include "treeBoundBox.H"
45 #include "searchableSurface.H"
46 #include "objectRegistry.H"
47 #include "indexedOctree.H"
48 #include "treeDataTriSurface.H"
49 #include "treeDataPrimitivePatch.H"
50 #include "treeDataEdge.H"
51 #include "EdgeMap.H"
52 #include "triSurface.H"
53 #include "triSurfaceRegionSearch.H"
54 #include "triSurfaceFieldsFwd.H"
55 #include "pointIndexHitList.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class triSurfaceMesh Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class triSurfaceMesh
67 :
68  public searchableSurface,
69  public objectRegistry, // so we can store fields
70  public triSurface,
72 {
73  // Private member data
74 
75  //- Supplied fileName override
76  fileName fName_;
77 
78  //- Optional min triangle quality. Triangles below this get
79  // ignored for normal calculation
80  scalar minQuality_;
81 
82  //- Search tree for boundary edges.
83  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
84 
85  //- Names of regions
86  mutable wordList regions_;
87 
88  //- Is surface closed
89  mutable label surfaceClosed_;
90 
91 
92  // Private Member Functions
93 
94  //- Return fileName to load IOobject from
95  static fileName checkFile(const regIOobject& io, const bool isGlobal);
96 
97  //- Return fileName. If fileName is relative gets treated local to
98  // IOobject
99  static fileName relativeFilePath
100  (
101  const regIOobject&,
102  const fileName&,
103  const bool isGlobal
104  );
105 
106  //- Return fileName to load IOobject from. Optional override of fileName
107  static fileName checkFile
108  (
109  const regIOobject&,
110  const dictionary&,
111  const bool isGlobal
112  );
113 
114  //- Helper function for isSurfaceClosed
115  static bool addFaceToEdge
116  (
117  const edge&,
119  );
120 
121  //- Check whether surface is closed without calculating any permanent
122  // addressing.
123  bool isSurfaceClosed() const;
124 
125  //- Steps to next intersection. Adds smallVec and starts tracking
126  // from there.
127  static void getNextIntersections
128  (
129  const indexedOctree<treeDataTriSurface>& octree,
130  const point& start,
131  const point& end,
132  const vector& smallVec,
134  );
135 
136  void drawHitProblem
137  (
138  const label fi,
139  const point& start,
140  const point& p,
141  const point& end,
142  const pointIndexHitList& hitInfo
143  ) const;
144 
145  void processHit
146  (
147  scalar& internalCloseness,
148  scalar& externalCloseness,
149  const scalar internalToleranceCosAngle,
150  const scalar externalToleranceCosAngle,
151  const label fi,
152  const point& start,
153  const point& p,
154  const point& end,
155  const vector& normal,
156  const vectorField& normals,
157  const pointIndexHitList& hitInfo
158  ) const;
159 
160 
161 public:
162 
163  //- Runtime type information
164  TypeName("triSurfaceMesh");
165 
166 
167  // Constructors
168 
169  //- Construct from triSurface
170  triSurfaceMesh(const IOobject&, const triSurface&);
171 
172  //- Construct read
173  triSurfaceMesh(const IOobject& io);
174 
175  //- Construct from IO and dictionary (used by searchableSurface).
176  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
178  (
179  const IOobject& io,
180  const dictionary& dict
181  );
182 
183 
184  // Special constructors for use by distributedTriSurface. File search
185  // status (local/global) supplied.
186 
187  triSurfaceMesh(const IOobject& io, const bool isGlobal);
188 
190  (
191  const IOobject& io,
192  const dictionary& dict,
193  const bool isGlobal
194  );
195 
196  //- Disallow default bitwise copy construction
197  triSurfaceMesh(const triSurfaceMesh&) = delete;
198 
199 
200  //- Destructor
201  virtual ~triSurfaceMesh();
202 
203 
204  // Member Functions
205 
206  //- Clear storage
207  void clearOut();
208 
209  //- Move points
210  virtual void movePoints(const pointField&);
211 
212  //- Demand driven construction of octree for boundary edges
213  const indexedOctree<treeDataEdge>& edgeTree() const;
214 
215 
216  // searchableSurface implementation
217 
218  virtual const wordList& regions() const;
219 
220  //- Whether supports volume type below. I.e. whether is closed.
221  virtual bool hasVolumeType() const;
222 
223  //- Range of local indices that can be returned.
224  virtual label size() const
225  {
226  return triSurface::size();
227  }
228 
229  //- Get representative set of element coordinates
230  // Usually the element centres (should be of length size()).
231  virtual tmp<pointField> coordinates() const;
232 
233  //- Get bounding spheres (centre and radius squared). Any point
234  // on surface is guaranteed to be inside.
235  virtual void boundingSpheres
236  (
237  pointField& centres,
238  scalarField& radiusSqr
239  ) const;
240 
241  //- Get the points that define the surface.
242  virtual tmp<pointField> points() const;
243 
244  // Does any part of the surface overlap the supplied bound box?
245  virtual bool overlaps(const boundBox& bb) const;
246 
247  virtual void findNearest
248  (
249  const pointField& sample,
250  const scalarField& nearestDistSqr,
252  ) const;
253 
254  virtual void findNearest
255  (
256  const pointField& sample,
257  const scalarField& nearestDistSqr,
258  const labelList& regionIndices,
260  ) const;
261 
262  virtual void findLine
263  (
264  const pointField& start,
265  const pointField& end,
267  ) const;
268 
269  virtual void findLineAny
270  (
271  const pointField& start,
272  const pointField& end,
274  ) const;
275 
276  //- Get all intersections in order from start to end.
277  virtual void findLineAll
278  (
279  const pointField& start,
280  const pointField& end,
282  ) const;
283 
284  //- From a set of points and indices get the region
285  virtual void getRegion
286  (
287  const List<pointIndexHit>&,
288  labelList& region
289  ) const;
290 
291  //- From a set of points and indices get the normal
292  virtual void getNormal
293  (
294  const List<pointIndexHit>&,
295  vectorField& normal
296  ) const;
297 
298  //- Determine type (inside/outside/mixed) for point. unknown if
299  // cannot be determined (e.g. non-manifold surface)
300  virtual void getVolumeType
301  (
302  const pointField&,
304  ) const;
305 
306 
307  // Other
308 
309  //- WIP. Store element-wise field.
310  virtual void setField(const labelList& values);
311 
312  //- WIP. From a set of hits (points and
313  // indices) get the specified field. Misses do not get set.
314  virtual void getField(const List<pointIndexHit>&, labelList&) const;
315 
316  //- Return a pair of triSurfaceScalarFields representing the
317  // internal and external closeness of regions of the surface
319  (
320  const scalar internalAngleTolerance = 80,
321  const scalar externalAngleTolerance = 80
322  ) const;
323 
324  //- Return a pair of triSurfaceScalarPointFields representing the
325  // internal and external closeness of regions of the surface
327  (
328  const scalar internalAngleTolerance = 80,
329  const scalar externalAngleTolerance = 80
330  ) const;
331 
332 
333  // regIOobject implementation
335  bool writeData(Ostream&) const
336  {
338  return false;
339  }
340 
341  //- Write using given format, version and compression
342  virtual bool writeObject
343  (
347  const bool write = true
348  ) const;
349 
350  //- Is object global
351  virtual bool global() const
352  {
353  return true;
354  }
355 
356  //- Return complete path + object name if the file exists
357  // either in the case/processor or case otherwise null
358  virtual fileName filePath() const
359  {
361  }
362 
363 
364  // Member Operators
365 
366  //- Disallow default bitwise assignment
367  void operator=(const triSurfaceMesh&) = delete;
368 };
369 
370 
371 //- Template function for obtaining global status
372 template<>
373 inline bool typeGlobal<triSurfaceMesh>()
374 {
375  return true;
376 }
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 } // End namespace Foam
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 #endif
386 
387 // ************************************************************************* //
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.
dictionary dict
Pair< tmp< triSurfacePointScalarField > > extractPointCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=80) const
Return a pair of triSurfaceScalarPointFields representing the.
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
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
A class for handling file names.
Definition: fileName.H:79
triSurfaceMesh(const IOobject &, const triSurface &)
Construct from triSurface.
void clearOut()
Clear storage.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared). Any point.
virtual fileName filePath() const
Return complete path + object name if the file exists.
virtual tmp< pointField > points() const
Get the points that define the surface.
virtual ~triSurfaceMesh()
Destructor.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
virtual void setField(const labelList &values)
WIP. Store element-wise field.
Helper class to search on triSurface. Creates an octree for each region of the surface and only searc...
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
IOoject and searching on triSurface.
virtual bool hasVolumeType() const
Whether supports volume type below. I.e. whether is closed.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
virtual bool global() const
Is object global.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
fileName globalFilePath(const word &typeName) const
Helper for filePath that searches up if in parallel.
Definition: IOobject.C:392
Pair< tmp< triSurfaceScalarField > > extractCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=80) const
Return a pair of triSurfaceScalarFields representing the.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void operator=(const triSurfaceMesh &)=delete
Disallow default bitwise assignment.
bool typeGlobal< triSurfaceMesh >()
Template function for obtaining global status.
void write(Ostream &) const
Write to Ostream in simple FOAM format.
Definition: triSurface.C:1328
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
TypeName("triSurfaceMesh")
Runtime type information.
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
virtual label size() const
Range of local indices that can be returned.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void movePoints(const pointField &)
Move points.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
Triangulated surface description with patch information.
Definition: triSurface.H:66
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
virtual const wordList & regions() const
Names of regions.
Namespace for OpenFOAM.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.