triSurfaceMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2017 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 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 /*---------------------------------------------------------------------------*\
61  Class triSurfaceMesh Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class triSurfaceMesh
65 :
66  public searchableSurface,
67  public objectRegistry, // so we can store fields
68  public triSurface,
70 {
71  // Private member data
72 
73  //- Supplied fileName override
74  fileName fName_;
75 
76  //- Optional min triangle quality. Triangles below this get
77  // ignored for normal calculation
78  scalar minQuality_;
79 
80  //- Search tree for boundary edges.
81  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
82 
83  //- Names of regions
84  mutable wordList regions_;
85 
86  //- Is surface closed
87  mutable label surfaceClosed_;
88 
89 
90  // Private Member Functions
91 
92  //- Return fileName to load IOobject from
93  static fileName checkFile(const regIOobject& io, const bool isGlobal);
94 
95  //- Return fileName. If fileName is relative gets treated local to
96  // IOobject
97  static fileName relativeFilePath
98  (
99  const regIOobject&,
100  const fileName&,
101  const bool isGlobal
102  );
103 
104  //- Return fileName to load IOobject from. Optional override of fileName
105  static fileName checkFile
106  (
107  const regIOobject&,
108  const dictionary&,
109  const bool isGlobal
110  );
111 
112  //- Helper function for isSurfaceClosed
113  static bool addFaceToEdge
114  (
115  const edge&,
117  );
118 
119  //- Check whether surface is closed without calculating any permanent
120  // addressing.
121  bool isSurfaceClosed() const;
122 
123  //- Steps to next intersection. Adds smallVec and starts tracking
124  // from there.
125  static void getNextIntersections
126  (
127  const indexedOctree<treeDataTriSurface>& octree,
128  const point& start,
129  const point& end,
130  const vector& smallVec,
132  );
133 
134  //- Disallow default bitwise copy construct
136 
137  //- Disallow default bitwise assignment
138  void operator=(const triSurfaceMesh&);
139 
140 
141 public:
142 
143  //- Runtime type information
144  TypeName("triSurfaceMesh");
145 
146 
147  // Constructors
148 
149  //- Construct from triSurface
150  triSurfaceMesh(const IOobject&, const triSurface&);
151 
152  //- Construct read
153  triSurfaceMesh(const IOobject& io);
154 
155  //- Construct from IO and dictionary (used by searchableSurface).
156  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
158  (
159  const IOobject& io,
160  const dictionary& dict
161  );
162 
163 
164  // Special constructors for use by distributedTriSurface. File search
165  // status (local/global) supplied.
166 
167  triSurfaceMesh(const IOobject& io, const bool isGlobal);
168 
170  (
171  const IOobject& io,
172  const dictionary& dict,
173  const bool isGlobal
174  );
175 
176 
177  //- Destructor
178  virtual ~triSurfaceMesh();
179 
180  //- Clear storage
181  void clearOut();
182 
183 
184  // Member Functions
185 
186  //- Move points
187  virtual void movePoints(const pointField&);
188 
189  //- Demand driven construction of octree for boundary edges
190  const indexedOctree<treeDataEdge>& edgeTree() const;
191 
192 
193  // searchableSurface implementation
194 
195  virtual const wordList& regions() const;
196 
197  //- Whether supports volume type below. I.e. whether is closed.
198  virtual bool hasVolumeType() const;
199 
200  //- Range of local indices that can be returned.
201  virtual label size() const
202  {
203  return triSurface::size();
204  }
205 
206  //- Get representative set of element coordinates
207  // Usually the element centres (should be of length size()).
208  virtual tmp<pointField> coordinates() const;
209 
210  //- Get bounding spheres (centre and radius squared). Any point
211  // on surface is guaranteed to be inside.
212  virtual void boundingSpheres
213  (
214  pointField& centres,
215  scalarField& radiusSqr
216  ) const;
217 
218  //- Get the points that define the surface.
219  virtual tmp<pointField> points() const;
220 
221  // Does any part of the surface overlap the supplied bound box?
222  virtual bool overlaps(const boundBox& bb) const;
223 
224  virtual void findNearest
225  (
226  const pointField& sample,
227  const scalarField& nearestDistSqr,
229  ) const;
230 
231  virtual void findNearest
232  (
233  const pointField& sample,
234  const scalarField& nearestDistSqr,
235  const labelList& regionIndices,
237  ) const;
238 
239  virtual void findLine
240  (
241  const pointField& start,
242  const pointField& end,
244  ) const;
245 
246  virtual void findLineAny
247  (
248  const pointField& start,
249  const pointField& end,
251  ) const;
252 
253  //- Get all intersections in order from start to end.
254  virtual void findLineAll
255  (
256  const pointField& start,
257  const pointField& end,
259  ) const;
260 
261  //- From a set of points and indices get the region
262  virtual void getRegion
263  (
264  const List<pointIndexHit>&,
265  labelList& region
266  ) const;
267 
268  //- From a set of points and indices get the normal
269  virtual void getNormal
270  (
271  const List<pointIndexHit>&,
273  ) const;
274 
275  //- Determine type (inside/outside/mixed) for point. unknown if
276  // cannot be determined (e.g. non-manifold surface)
277  virtual void getVolumeType
278  (
279  const pointField&,
281  ) const;
282 
283 
284  // Other
285 
286  //- WIP. Store element-wise field.
287  virtual void setField(const labelList& values);
288 
289  //- WIP. From a set of hits (points and
290  // indices) get the specified field. Misses do not get set.
291  virtual void getField(const List<pointIndexHit>&, labelList&) const;
292 
293 
294  // regIOobject implementation
296  bool writeData(Ostream&) const
297  {
299  return false;
300  }
301 
302  //- Write using given format, version and compression
303  virtual bool writeObject
304  (
308  const bool valid
309  ) const;
310 
311  //- Is object global
312  virtual bool global() const
313  {
314  return true;
315  }
316 
317  //- Return complete path + object name if the file exists
318  // either in the case/processor or case otherwise null
319  virtual fileName filePath() const
320  {
322  }
323 };
324 
325 
326 //- Template function for obtaining global status
327 template<>
328 inline bool typeGlobal<triSurfaceMesh>()
329 {
330  return true;
331 }
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Foam
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #endif
341 
342 // ************************************************************************* //
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.
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:416
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
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:485
A normal distribution model.
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.
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
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
Triangulated surface description with patch information.
Definition: triSurface.H:65
#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.