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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::triSurfaceMesh
29 
30 Description
31  IOoject and searching on triSurface
32 
33  Note: when constructing from dictionary has the following parameters:
34  - scale : scaling factor.
35  - tolerance : relative tolerance for doing intersections
36  (see triangle::intersection)
37  - minQuality: discard triangles with low quality when getting normal
38 
39  \heading Dictionary parameters
40  \table
41  Property | Description | Required | Default
42  type | triSurfaceMesh | selector |
43  file | File name to locate the surface | no |
44  scale | Scaling factor | no | 0
45  minQuality | Quality criterion | no | -1
46  \endtable
47 
48 SourceFiles
49  triSurfaceMesh.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef triSurfaceMesh_H
54 #define triSurfaceMesh_H
55 
56 #include "searchableSurface.H"
57 #include "treeBoundBox.H"
58 #include "objectRegistry.H"
59 #include "indexedOctree.H"
60 #include "treeDataTriSurface.H"
61 #include "treeDataPrimitivePatch.H"
62 #include "treeDataEdge.H"
63 #include "edgeHashes.H"
64 #include "triSurface.H"
65 #include "triSurfaceRegionSearch.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 /*---------------------------------------------------------------------------*\
73  Class triSurfaceMesh Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 class triSurfaceMesh
77 :
78  public searchableSurface,
79  public objectRegistry, // so we can store fields
80  public triSurface,
81  public triSurfaceRegionSearch
82 {
83 protected:
84 
85  // Private member data
86 
87  //- Supplied fileName override
88  fileName fName_;
89 
90  //- Optional min triangle quality. Triangles below this get
91  // ignored for normal calculation
92  scalar minQuality_;
93 
94  //- Search tree for boundary edges.
95  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
96 
97  //- Names of regions
98  mutable wordList regions_;
99 
100  //- Is surface closed
101  mutable label surfaceClosed_;
102 
103  //- If surface is closed, what is type of outside points
104  mutable volumeType outsideVolType_;
105 
106 
107  // Private Member Functions
108 
109  //- Return fileName to load IOobject from
110  static fileName checkFile(const IOobject& io, const bool isGlobal);
111 
112  //- Return fileName. If fileName is relative gets treated local to
113  // IOobject
115  (
116  const IOobject&,
117  const fileName&,
118  const bool isGlobal
119  );
120 
121  //- Return fileName to load IOobject from. Optional override of fileName
123  (
124  const IOobject&,
125  const dictionary&,
126  const bool isGlobal
127  );
128 
129  //- Helper function for isSurfaceClosed
130  static bool addFaceToEdge
131  (
132  const edge&,
134  );
135 
136  //- Check whether surface is closed without calculating any permanent
137  // addressing.
138  bool isSurfaceClosed() const;
139 
140  //- Steps to next intersection. Adds smallVec and starts tracking
141  // from there.
142  static void getNextIntersections
143  (
144  const indexedOctree<treeDataTriSurface>& octree,
145  const point& start,
146  const point& end,
147  const vector& smallVec,
149  );
150 
151  //- No copy construct
152  triSurfaceMesh(const triSurfaceMesh&) = delete;
153 
154  //- No copy assignment
155  void operator=(const triSurfaceMesh&) = delete;
156 
157 
158 public:
159 
160  //- Runtime type information
161  TypeName("triSurfaceMesh");
162 
163  //- Return the mesh sub-directory name (usually "triSurface")
164  static word meshSubDir;
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  // method supplied:
186 
187  enum readAction
188  {
189  localOnly, // load from (processor-)local file only
190  localOrGlobal, // load from (processor-)local or global file
191  masterOnly // as localOrGlobal but only load on master
192  };
193 
194  triSurfaceMesh(const IOobject& io, const readAction r);
195 
197  (
198  const IOobject& io,
199  const dictionary& dict,
200  const readAction r
201  );
202 
203 
204  //- Destructor
205  virtual ~triSurfaceMesh();
206 
207 
208  //- Clear storage
209  void clearOut();
210 
211 
212  // Member Functions
213 
214  //- Move points
215  virtual void movePoints(const pointField&);
216 
217  //- Demand driven construction of octree for boundary edges
218  const indexedOctree<treeDataEdge>& edgeTree() const;
219 
220 
221  // searchableSurface implementation
222 
223  //- Names of regions
224  virtual const wordList& regions() const;
225 
226  //- Whether supports volume type (below) - i.e. whether is closed.
227  virtual bool hasVolumeType() const;
228 
229  //- If surface is closed, what is type of points outside bounds
230  virtual volumeType outsideVolumeType() const;
231 
232  //- Range of local indices that can be returned.
233  virtual label size() const
234  {
235  return triSurface::size();
236  }
237 
238  //- Get representative set of element coordinates
239  // Usually the element centres (should be of length size()).
240  virtual tmp<pointField> coordinates() const;
241 
242  //- Get bounding spheres (centre and radius squared). Any point
243  // on surface is guaranteed to be inside.
244  virtual void boundingSpheres
245  (
246  pointField& centres,
247  scalarField& radiusSqr
248  ) const;
249 
250  //- Get the points that define the surface.
251  virtual tmp<pointField> points() const;
252 
253  // Does any part of the surface overlap the supplied bound box?
254  virtual bool overlaps(const boundBox& bb) const;
255 
256  virtual void findNearest
257  (
258  const pointField& sample,
259  const scalarField& nearestDistSqr,
261  ) const;
262 
263  virtual void findNearest
264  (
265  const pointField& sample,
266  const scalarField& nearestDistSqr,
267  const labelList& regionIndices,
269  ) const;
270 
271  virtual void findLine
272  (
273  const pointField& start,
274  const pointField& end,
276  ) const;
277 
278  virtual void findLineAny
279  (
280  const pointField& start,
281  const pointField& end,
283  ) const;
284 
285  //- Get all intersections in order from start to end.
286  virtual void findLineAll
287  (
288  const pointField& start,
289  const pointField& end,
291  ) const;
292 
293  //- From a set of points and indices get the region
294  virtual void getRegion
295  (
296  const List<pointIndexHit>&,
297  labelList& region
298  ) const;
299 
300  //- From a set of points and indices get the normal
301  virtual void getNormal
302  (
303  const List<pointIndexHit>&,
304  vectorField& normal
305  ) const;
306 
307  //- Determine type (inside/outside/mixed) for point.
308  // Unknown if cannot be determined (e.g. non-manifold surface)
309  virtual void getVolumeType
310  (
311  const pointField& points,
312  List<volumeType>& volType
313  ) const;
314 
315 
316  // Other
317 
318  //- WIP. Store element-wise field.
319  virtual void setField(const labelList& values);
320 
321  //- WIP. From a set of hits (points and
322  // indices) get the specified field. Misses do not get set.
323  virtual void getField(const List<pointIndexHit>&, labelList&) const;
324 
325 
326  // regIOobject implementation
327 
328  bool writeData(Ostream&) const
329  {
331  return false;
332  }
333 
334  //- Write using given format, version and compression
335  virtual bool writeObject
336  (
340  const bool valid
341  ) const;
342 
343  //- Is object global
344  virtual bool global() const
345  {
346  return true;
347  }
348 
349  //- Return complete path + object name if the file exists
350  // either in the case/processor or case otherwise null
351  virtual fileName filePath() const
352  {
354  }
355 };
356 
357 
358 //- Template function for obtaining global status
359 template<>
360 inline bool typeGlobal<triSurfaceMesh>()
361 {
362  return true;
363 }
364 
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 } // End namespace Foam
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
372 #endif
373 
374 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::triSurfaceMesh::operator=
void operator=(const triSurfaceMesh &)=delete
No copy assignment.
Foam::triSurfaceMesh::relativeFilePath
static fileName relativeFilePath(const IOobject &, const fileName &, const bool isGlobal)
Return fileName. If fileName is relative gets treated local to.
Definition: triSurfaceMesh.C:74
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
searchableSurface.H
Foam::triSurfaceMesh::localOnly
Definition: triSurfaceMesh.H:213
Foam::triSurfaceMesh::localOrGlobal
Definition: triSurfaceMesh.H:214
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::triSurfaceMesh::minQuality_
scalar minQuality_
Optional min triangle quality. Triangles below this get.
Definition: triSurfaceMesh.H:116
Foam::triSurfaceMesh::edgeTree_
autoPtr< indexedOctree< treeDataEdge > > edgeTree_
Search tree for boundary edges.
Definition: triSurfaceMesh.H:119
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:57
Foam::triSurfaceMesh::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Definition: triSurfaceMesh.C:1035
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::triSurfaceMesh::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Definition: triSurfaceMesh.C:1002
Foam::triSurfaceMesh::edgeTree
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
Definition: triSurfaceMesh.C:726
Foam::triSurfaceMesh::TypeName
TypeName("triSurfaceMesh")
Runtime type information.
indexedOctree.H
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
objectRegistry.H
Foam::typeGlobal< triSurfaceMesh >
bool typeGlobal< triSurfaceMesh >()
Template function for obtaining global status.
Definition: triSurfaceMesh.H:384
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:100
Foam::triSurfaceRegionSearch
Helper class to search on triSurface. Creates an octree for each region of the surface and only searc...
Definition: triSurfaceRegionSearch.H:57
triSurface.H
Foam::triSurfaceMesh::readAction
readAction
Definition: triSurfaceMesh.H:211
Foam::triSurfaceMesh::size
virtual label size() const
Range of local indices that can be returned.
Definition: triSurfaceMesh.H:257
Foam::triSurfaceMesh::surfaceClosed_
label surfaceClosed_
Is surface closed.
Definition: triSurfaceMesh.H:125
Foam::triSurfaceMesh::outsideVolumeType
virtual volumeType outsideVolumeType() const
If surface is closed, what is type of points outside bounds.
Definition: triSurfaceMesh.C:841
Foam::triSurfaceMesh::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Definition: triSurfaceMesh.C:956
Foam::triSurfaceMesh::triSurfaceMesh
triSurfaceMesh(const triSurfaceMesh &)=delete
No copy construct.
Foam::triSurfaceMesh::movePoints
virtual void movePoints(const pointField &)
Move points.
Definition: triSurfaceMesh.C:693
Foam::triSurfaceMesh::checkFile
static fileName checkFile(const IOobject &io, const bool isGlobal)
Return fileName to load IOobject from.
Definition: triSurfaceMesh.C:51
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
Foam::label
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:62
Foam::volumeType
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:60
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::Field< vector >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:70
treeBoundBox.H
Foam::triSurfaceMesh::fName_
fileName fName_
Supplied fileName override.
Definition: triSurfaceMesh.H:112
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::triSurfaceMesh::findLine
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
Definition: triSurfaceMesh.C:933
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:50
treeDataPrimitivePatch.H
Foam::triSurfaceMesh::getField
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
Definition: triSurfaceMesh.C:1157
Foam::triSurfaceMesh::regions
virtual const wordList & regions() const
Names of regions.
Definition: triSurfaceMesh.C:809
Foam::triSurfaceMesh::regions_
wordList regions_
Names of regions.
Definition: triSurfaceMesh.H:122
Foam::triSurfaceMesh::writeData
bool writeData(Ostream &) const
writeData function required by regIOobject but not used.
Definition: triSurfaceMesh.H:352
Foam::triSurfaceMesh::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared). Any point.
Definition: triSurfaceMesh.C:650
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::triSurfaceMesh::clearOut
void clearOut()
Clear storage.
Definition: triSurfaceMesh.C:622
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::triSurfaceMesh::filePath
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: triSurfaceMesh.H:375
Foam::IOobject::globalFilePath
fileName globalFilePath(const word &typeName, const bool search=true) const
Helper for filePath that searches up if in parallel.
Definition: IOobject.C:493
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
treeDataEdge.H
Foam::triSurfaceMesh::points
virtual tmp< pointField > points() const
Get the points that define the surface.
Definition: triSurfaceMesh.C:677
Foam::triSurfaceMesh::coordinates
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
Definition: triSurfaceMesh.C:633
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::triSurfaceMesh::getNextIntersections
static void getNextIntersections(const indexedOctree< treeDataTriSurface > &octree, const point &start, const point &end, const vector &smallVec, DynamicList< pointIndexHit > &hits)
Steps to next intersection. Adds smallVec and starts tracking.
Foam::triSurfaceMesh::setField
virtual void setField(const labelList &values)
WIP. Store element-wise field.
Definition: triSurfaceMesh.C:1118
treeDataTriSurface.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::EdgeMap< label >
edgeHashes.H
Foam::triSurfaceMesh::~triSurfaceMesh
virtual ~triSurfaceMesh()
Destructor.
Definition: triSurfaceMesh.C:616
Foam::triSurfaceMesh::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Definition: triSurfaceMesh.C:876
Foam::Vector< scalar >
Foam::List< word >
Foam::triSurfaceMesh::addFaceToEdge
static bool addFaceToEdge(const edge &, EdgeMap< label > &)
Helper function for isSurfaceClosed.
Definition: triSurfaceMesh.C:142
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::triSurfaceMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
Definition: triSurfaceMesh.H:188
Foam::triSurfaceMesh::overlaps
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
Definition: triSurfaceMesh.C:683
Foam::triSurfaceMesh::isSurfaceClosed
bool isSurfaceClosed() const
Check whether surface is closed without calculating any permanent.
Definition: triSurfaceMesh.C:158
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::triSurfaceMesh::getVolumeType
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
Definition: triSurfaceMesh.C:1188
Foam::triSurfaceMesh::masterOnly
Definition: triSurfaceMesh.H:215
Foam::HashTable< regIOobject * >::end
const iterator & end()
iterator to signal the end for any HashTable
Definition: HashTableIterI.H:276
Foam::triSurfaceMesh::writeObject
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write using given format, version and compression.
Definition: triSurfaceMesh.C:1241
triSurfaceRegionSearch.H
Foam::triSurfaceMesh::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below) - i.e. whether is closed.
Definition: triSurfaceMesh.C:823
Foam::triSurfaceMesh::global
virtual bool global() const
Is object global.
Definition: triSurfaceMesh.H:368
Foam::triSurfaceMesh::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
Definition: triSurfaceMesh.C:979
Foam::triSurfaceMesh::outsideVolType_
volumeType outsideVolType_
If surface is closed, what is type of outside points.
Definition: triSurfaceMesh.H:128