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-2020 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  fileType | The surface format (Eg, nastran) | no |
45  scale | Scaling factor | no | 0
46  minQuality | Quality criterion | no | -1
47  \endtable
48 
49 SourceFiles
50  triSurfaceMesh.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef triSurfaceMesh_H
55 #define triSurfaceMesh_H
56 
57 #include "searchableSurface.H"
58 #include "treeBoundBox.H"
59 #include "objectRegistry.H"
60 #include "indexedOctree.H"
61 #include "treeDataTriSurface.H"
62 #include "treeDataPrimitivePatch.H"
63 #include "treeDataEdge.H"
64 #include "edgeHashes.H"
65 #include "triSurface.H"
66 #include "triSurfaceRegionSearch.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class triSurfaceMesh Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class triSurfaceMesh
78 :
79  public searchableSurface,
80  public objectRegistry, // so we can store fields
81  public triSurface,
82  public triSurfaceRegionSearch
83 {
84 protected:
85 
86  // Private member data
87 
88  //- Supplied fileName override
89  fileName fName_;
90 
91  //- Optional min triangle quality. Triangles below this get
92  // ignored for normal calculation
93  scalar minQuality_;
94 
95  //- Search tree for boundary edges.
96  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
97 
98  //- Names of regions
99  mutable wordList regions_;
100 
101  //- Is surface closed
102  mutable label surfaceClosed_;
103 
104  //- If surface is closed, what is type of outside points
105  mutable volumeType outsideVolType_;
106 
107 
108  // Private Member Functions
109 
110  //- Helper function for isSurfaceClosed
111  static bool addFaceToEdge
112  (
113  const edge&,
115  );
117  //- Check whether surface is closed without calculating any permanent
118  // addressing.
119  bool isSurfaceClosed() const;
120 
121  //- Steps to next intersection. Adds smallVec and starts tracking
122  // from there.
124  (
125  const indexedOctree<treeDataTriSurface>& octree,
126  const point& start,
127  const point& end,
128  const vector& smallVec,
130  );
131 
132  //- No copy construct
133  triSurfaceMesh(const triSurfaceMesh&) = delete;
134 
135  //- No copy assignment
136  void operator=(const triSurfaceMesh&) = delete;
137 
139 public:
140 
141  //- Runtime type information
142  TypeName("triSurfaceMesh");
144  //- Return the mesh sub-directory name (usually "triSurface")
145  static word meshSubDir;
146 
147 
148  // Constructors
149 
150  //- Construct from triSurface
151  triSurfaceMesh(const IOobject&, const triSurface&);
152 
153  //- Construct read
154  triSurfaceMesh(const IOobject& io);
155 
156  //- Construct from IO and dictionary (used by searchableSurface).
157  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
159  (
160  const IOobject& io,
161  const dictionary& dict
162  );
163 
164 
165  // Special constructors for use by distributedTriSurface. File search
166  // method supplied:
167 
168  enum readAction
169  {
170  localOnly, // load from (processor-)local file only
171  localOrGlobal, // load from (processor-)local or global file
172  masterOnly // as localOrGlobal but only load on master
173  };
174 
175  triSurfaceMesh(const IOobject& io, const readAction r);
176 
178  (
179  const IOobject& io,
180  const dictionary& dict,
181  const readAction r
182  );
183 
184 
185  //- Destructor
186  virtual ~triSurfaceMesh();
187 
188 
189  //- Clear storage
190  void clearOut();
191 
192 
193  // Member Functions
194 
195  //- Move points
196  virtual void movePoints(const pointField&);
197 
198  //- Demand driven construction of octree for boundary edges
200 
201 
202  // searchableSurface implementation
203 
204  //- Names of regions
205  virtual const wordList& regions() const;
206 
207  //- Whether supports volume type (below) - i.e. whether is closed.
208  virtual bool hasVolumeType() const;
209 
210  //- If surface is closed, what is type of points outside bounds
211  virtual volumeType outsideVolumeType() const;
212 
213  //- Range of local indices that can be returned.
214  virtual label size() const
215  {
216  return triSurface::size();
217  }
218 
219  //- Get representative set of element coordinates
220  // Usually the element centres (should be of length size()).
221  virtual tmp<pointField> coordinates() const;
222 
223  //- Get bounding spheres (centre and radius squared). Any point
224  // on surface is guaranteed to be inside.
225  virtual void boundingSpheres
226  (
227  pointField& centres,
228  scalarField& radiusSqr
229  ) const;
230 
231  //- Get the points that define the surface.
232  virtual tmp<pointField> points() const;
234  // Does any part of the surface overlap the supplied bound box?
235  virtual bool overlaps(const boundBox& bb) const;
236 
237  virtual void findNearest
238  (
239  const pointField& sample,
240  const scalarField& nearestDistSqr,
242  ) const;
243 
244  virtual void findNearest
245  (
246  const pointField& sample,
247  const scalarField& nearestDistSqr,
248  const labelList& regionIndices,
250  ) const;
251 
252  virtual void findLine
253  (
254  const pointField& start,
255  const pointField& end,
257  ) const;
258 
259  virtual void findLineAny
260  (
261  const pointField& start,
262  const pointField& end,
264  ) const;
265 
266  //- Get all intersections in order from start to end.
267  virtual void findLineAll
268  (
269  const pointField& start,
270  const pointField& end,
272  ) const;
273 
274  //- From a set of points and indices get the region
275  virtual void getRegion
276  (
277  const List<pointIndexHit>&,
278  labelList& region
279  ) const;
280 
281  //- From a set of points and indices get the normal
282  virtual void getNormal
283  (
284  const List<pointIndexHit>&,
285  vectorField& normal
286  ) const;
287 
288  //- Determine type (inside/outside/mixed) for point.
289  // Unknown if cannot be determined (e.g. non-manifold surface)
290  virtual void getVolumeType
291  (
292  const pointField& points,
293  List<volumeType>& volType
294  ) const;
295 
296 
297  // Other
298 
299  //- WIP. Store element-wise field.
300  virtual void setField(const labelList& values);
301 
302  //- WIP. From a set of hits (points and
303  // indices) get the specified field. Misses do not get set.
304  virtual void getField(const List<pointIndexHit>&, labelList&) const;
305 
306 
307  // regIOobject implementation
308 
309  bool writeData(Ostream&) const
310  {
312  return false;
313  }
314 
315  //- Write using stream options
316  virtual bool writeObject
317  (
318  IOstreamOption streamOpt,
319  const bool writeOnProc
320  ) const;
321 
322  //- Is object global
323  virtual bool global() const
324  {
325  return true;
326  }
327 
328  //- Return complete path + object name if the file exists
329  // either in the case/processor or case otherwise null
330  virtual fileName filePath() const
331  {
333  }
334 };
335 
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 //- Global file type for triSurfaceMesh
340 template<>
341 struct is_globalIOobject<triSurfaceMesh> : std::true_type {};
342 
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 } // End namespace Foam
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 #endif
351 
352 // ************************************************************************* //
bool writeData(Ostream &) const
The writeData function is 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.
void clearOut()
Clear storage.
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:547
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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.
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.
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.
static bool addFaceToEdge(const edge &, EdgeMap< label > &)
Helper function for isSurfaceClosed.
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 min/max extrema points.
Definition: boundBox.H:63
A simple container for options an IOstream can normally have.
An enumeration wrapper for classification of a location as being inside/outside of a volume...
Definition: volumeType.H:55
bool isSurfaceClosed() const
Check whether surface is closed without calculating any permanent.
iterator end() noexcept
iterator to signal the end (for any HashTable)
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
IOoject and searching on triSurface.
virtual bool hasVolumeType() const
Whether supports volume type (below) - i.e. whether is closed.
virtual bool global() const
Is object global.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
volumeType outsideVolType_
If surface is closed, what is type of outside points.
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
autoPtr< indexedOctree< treeDataEdge > > edgeTree_
Search tree for boundary edges.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void operator=(const triSurfaceMesh &)=delete
No copy assignment.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label size() const noexcept
The number of elements in the container.
Definition: UList.H:671
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.
scalar minQuality_
Optional min triangle quality. Triangles below this get.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
TypeName("triSurfaceMesh")
Runtime type information.
List< word > wordList
List of word.
Definition: fileName.H:59
Non-pointer based hierarchical recursive searching.
virtual label size() const
Range of local indices that can be returned.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
label surfaceClosed_
Is surface closed.
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual volumeType outsideVolumeType() const
If surface is closed, what is type of points outside bounds.
triSurfaceMesh(const triSurfaceMesh &)=delete
No copy construct.
Triangulated surface description with patch information.
Definition: triSurface.H:71
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
fileName fName_
Supplied fileName override.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
virtual const wordList & regions() const
Names of regions.
wordList regions_
Names of regions.
Namespace for OpenFOAM.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.