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-2018 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  //- Disallow default bitwise copy construct
162 
163  //- Disallow default bitwise assignment
164  void operator=(const triSurfaceMesh&);
165 
166 
167 public:
168 
169  //- Runtime type information
170  TypeName("triSurfaceMesh");
171 
172 
173  // Constructors
174 
175  //- Construct from triSurface
176  triSurfaceMesh(const IOobject&, const triSurface&);
177 
178  //- Construct read
179  triSurfaceMesh(const IOobject& io);
180 
181  //- Construct from IO and dictionary (used by searchableSurface).
182  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
184  (
185  const IOobject& io,
186  const dictionary& dict
187  );
188 
189 
190  // Special constructors for use by distributedTriSurface. File search
191  // status (local/global) supplied.
192 
193  triSurfaceMesh(const IOobject& io, const bool isGlobal);
194 
196  (
197  const IOobject& io,
198  const dictionary& dict,
199  const bool isGlobal
200  );
201 
202 
203  //- Destructor
204  virtual ~triSurfaceMesh();
205 
206  //- Clear storage
207  void clearOut();
208 
209 
210  // Member Functions
211 
212  //- Move points
213  virtual void movePoints(const pointField&);
214 
215  //- Demand driven construction of octree for boundary edges
216  const indexedOctree<treeDataEdge>& edgeTree() const;
217 
218 
219  // searchableSurface implementation
220 
221  virtual const wordList& regions() const;
222 
223  //- Whether supports volume type below. I.e. whether is closed.
224  virtual bool hasVolumeType() const;
225 
226  //- Range of local indices that can be returned.
227  virtual label size() const
228  {
229  return triSurface::size();
230  }
231 
232  //- Get representative set of element coordinates
233  // Usually the element centres (should be of length size()).
234  virtual tmp<pointField> coordinates() const;
235 
236  //- Get bounding spheres (centre and radius squared). Any point
237  // on surface is guaranteed to be inside.
238  virtual void boundingSpheres
239  (
240  pointField& centres,
241  scalarField& radiusSqr
242  ) const;
243 
244  //- Get the points that define the surface.
245  virtual tmp<pointField> points() const;
246 
247  // Does any part of the surface overlap the supplied bound box?
248  virtual bool overlaps(const boundBox& bb) const;
249 
250  virtual void findNearest
251  (
252  const pointField& sample,
253  const scalarField& nearestDistSqr,
255  ) const;
256 
257  virtual void findNearest
258  (
259  const pointField& sample,
260  const scalarField& nearestDistSqr,
261  const labelList& regionIndices,
263  ) const;
264 
265  virtual void findLine
266  (
267  const pointField& start,
268  const pointField& end,
270  ) const;
271 
272  virtual void findLineAny
273  (
274  const pointField& start,
275  const pointField& end,
277  ) const;
278 
279  //- Get all intersections in order from start to end.
280  virtual void findLineAll
281  (
282  const pointField& start,
283  const pointField& end,
285  ) const;
286 
287  //- From a set of points and indices get the region
288  virtual void getRegion
289  (
290  const List<pointIndexHit>&,
291  labelList& region
292  ) const;
293 
294  //- From a set of points and indices get the normal
295  virtual void getNormal
296  (
297  const List<pointIndexHit>&,
298  vectorField& normal
299  ) const;
300 
301  //- Determine type (inside/outside/mixed) for point. unknown if
302  // cannot be determined (e.g. non-manifold surface)
303  virtual void getVolumeType
304  (
305  const pointField&,
307  ) const;
308 
309 
310  // Other
311 
312  //- WIP. Store element-wise field.
313  virtual void setField(const labelList& values);
314 
315  //- WIP. From a set of hits (points and
316  // indices) get the specified field. Misses do not get set.
317  virtual void getField(const List<pointIndexHit>&, labelList&) const;
318 
319  //- Return a pair of triSurfaceScalarFields representing the
320  // internal and external closeness of regions of the surface
322  (
323  const scalar internalAngleTolerance = 80,
324  const scalar externalAngleTolerance = 10
325  ) const;
326 
327  //- Return a pair of triSurfaceScalarPointFields representing the
328  // internal and external closeness of regions of the surface
330  (
331  const scalar internalAngleTolerance = 80,
332  const scalar externalAngleTolerance = 10
333  ) const;
334 
335 
336  // regIOobject implementation
338  bool writeData(Ostream&) const
339  {
341  return false;
342  }
343 
344  //- Write using given format, version and compression
345  virtual bool writeObject
346  (
350  const bool valid
351  ) const;
352 
353  //- Is object global
354  virtual bool global() const
355  {
356  return true;
357  }
358 
359  //- Return complete path + object name if the file exists
360  // either in the case/processor or case otherwise null
361  virtual fileName filePath() const
362  {
364  }
365 };
366 
367 
368 //- Template function for obtaining global status
369 template<>
370 inline bool typeGlobal<triSurfaceMesh>()
371 {
372  return true;
373 }
374 
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 } // End namespace Foam
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 #endif
383 
384 // ************************************************************************* //
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
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:69
void clearOut()
Clear storage.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:110
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write using given format, version and compression.
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.
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:428
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:53
Pair< tmp< triSurfacePointScalarField > > extractPointCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=10) const
Return a pair of triSurfaceScalarPointFields representing the.
bool typeGlobal< triSurfaceMesh >()
Template function for obtaining global status.
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.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
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.
Pair< tmp< triSurfaceScalarField > > extractCloseness(const scalar internalAngleTolerance=80, const scalar externalAngleTolerance=10) const
Return a pair of triSurfaceScalarFields representing the.
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.
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:65
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:366
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:170
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.