extendedEdgeMesh.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-2013 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::extendedEdgeMesh
26 
27 Description
28 
29  Description of feature edges and points.
30 
31  Feature points are a sorted subset at the start of the overall points list:
32  0 .. concaveStart_-1 : convex points (w.r.t normals)
33  concaveStart_ .. mixedStart_-1 : concave points
34  mixedStart_ .. nonFeatureStart_-1 : mixed internal/external points
35  nonFeatureStart_ .. size-1 : non-feature points
36 
37  Feature edges are the edgeList of the edgeMesh and are sorted:
38  0 .. internalStart_-1 : external edges (convex w.r.t normals)
39  internalStart_ .. flatStart_-1 : internal edges (concave)
40  flatStart_ .. openStart_-1 : flat edges (neither concave or convex)
41  can arise from region interfaces on
42  flat surfaces
43  openStart_ .. multipleStart_-1 : open edges (e.g. from baffle surfaces)
44  multipleStart_ .. size-1 : multiply connected edges
45 
46  The edge direction and feature edge and feature point adjacent normals
47  are stored.
48 
49 SourceFiles
50  extendedEdgeMeshI.H
51  extendedEdgeMesh.C
52  extendedEdgeMeshNew.C
53 
54 \*---------------------------------------------------------------------------*/
55 
56 #ifndef extendedEdgeMesh_H
57 #define extendedEdgeMesh_H
58 
59 #include "edgeMesh.H"
60 #include "indexedOctree.H"
61 #include "treeDataEdge.H"
62 #include "treeDataPoint.H"
63 #include "PrimitivePatch.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 class surfaceFeatures;
71 class objectRegistry;
72 
73 // Forward declaration of friend functions and operators
74 class extendedEdgeMesh;
75 Istream& operator>>(Istream&, extendedEdgeMesh&);
76 Ostream& operator<<(Ostream&, const extendedEdgeMesh&);
77 
78 /*---------------------------------------------------------------------------*\
79  Class extendedEdgeMesh Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 class extendedEdgeMesh
83 :
84  public edgeMesh
85 {
86 
87 public:
88 
89  //- Runtime type information
90  TypeName("extendedEdgeMesh");
91 
92  enum pointStatus
93  {
94  CONVEX, // Fully convex point (w.r.t normals)
95  CONCAVE, // Fully concave point
96  MIXED, // A point surrounded by both convex and concave edges
97  NONFEATURE // Not a feature point
98  };
99 
102  enum edgeStatus
103  {
104  EXTERNAL, // "Convex" edge
105  INTERNAL, // "Concave" edge
106  FLAT, // Neither concave or convex, on a flat surface
107  OPEN, // i.e. only connected to one face
108  MULTIPLE, // Multiply connected (connected to more than two faces)
109  NONE // Not a classified feature edge (consistency with
110  // surfaceFeatures)
111  };
114 
115  //- Normals point to the outside
116  enum sideVolumeType
117  {
118  INSIDE = 0, // mesh inside
119  OUTSIDE = 1, // mesh outside
120  BOTH = 2, // e.g. a baffle
121  NEITHER = 3 // not sure when this may be used
122  };
125 
126  //- Angular closeness tolerance for treating normals as the same
127  static scalar cosNormalAngleTol_;
128 
129 
130 protected:
131 
132  // Static data
133 
134  //- Index of the start of the convex feature points - static as 0
135  static label convexStart_;
136 
137  //- Index of the start of the external feature edges - static as 0
138  static label externalStart_;
139 
140 
141  // Private data
142 
143  //- Index of the start of the concave feature points
145 
146  //- Index of the start of the mixed type feature points
148 
149  //- Index of the start of the non-feature points
151 
152  //- Index of the start of the internal feature edges
154 
155  //- Index of the start of the flat feature edges
157 
158  //- Index of the start of the open feature edges
160 
161  //- Index of the start of the multiply-connected feature edges
163 
164  //- Normals of the features, to be referred to by index by both feature
165  // points and edges, unsorted
167 
168  //- Type per normal: which side of normal to mesh
170 
171  //- Flat and open edges require the direction of the edge
173 
174  //- Starting directions for the edges.
175  // This vector points to the half of the plane defined by the first
176  // edge normal.
178 
179  //- Indices of the normals that are adjacent to the feature edges
181 
182  //- Indices of the normals that are adjacent to the feature points
183  // (only valid for 0..nonFeatureStart_-1)
185 
186  //- Indices of feature edges attached to feature points. The edges are
187  // ordered so that they can be circulated.
189 
190  //- Feature edges which are on the boundary between regions
192 
193  //- Search tree for all feature points
195 
196  //- Search tree for all edges
198 
199  //- Individual search trees for each type of edge
201 
202 
203  // Private Member Functions
204 
205  //- Classify the type of feature point. Requires valid stored member
206  // data for edges and normals.
208 
209  template<class Patch>
210  void sortPointsAndEdges
211  (
212  const Patch&,
213  const labelList& featureEdges,
214  const labelList& regionFeatureEdges,
215  const labelList& feaurePoints
216  );
217 
218 public:
219 
220  // Static data
221 
222  //- Number of possible point types (i.e. number of slices)
223  static label nPointTypes;
224 
225  //- Number of possible feature edge types (i.e. number of slices)
226  static label nEdgeTypes;
227 
228  //- Can we read this file format?
229  static bool canRead(const fileName&, const bool verbose=false);
230 
231  //- Can we read this file format?
232  static bool canReadType(const word& ext, const bool verbose=false);
233 
234  //- Can we write this file format type?
235  static bool canWriteType(const word& ext, const bool verbose=false);
236 
237  static wordHashSet readTypes();
238  static wordHashSet writeTypes();
239 
240 
241  // Constructors
242 
243  //- Construct null
245 
246  //- Construct as copy
247  explicit extendedEdgeMesh(const extendedEdgeMesh&);
248 
249  //- Construct from file name (uses extension to determine type)
250  extendedEdgeMesh(const fileName&);
251 
252  //- Construct from file name (uses extension to determine type)
253  extendedEdgeMesh(const fileName&, const word& ext);
254 
255  //- Construct from Istream
257 
258  //- Construct by transferring components (points, edges)
260  (
261  const Xfer<pointField>&,
262  const Xfer<edgeList>&
263  );
264 
265  //- Construct given a surface with selected edges,point
266  // (surfaceFeatures), an objectRegistry and a
267  // fileName to write to.
268  // Extracts, classifies and reorders the data from surfaceFeatures.
270  (
271  const surfaceFeatures& sFeat,
272  const boolList& surfBaffleRegions
273  );
274 
275  //- Construct from PrimitivePatch
277  (
279  const labelList& featureEdges,
280  const labelList& regionFeatureEdges,
281  const labelList& featurePoints
282  );
283 
284  //- Construct from all components
286  (
287  const pointField& pts,
288  const edgeList& eds,
296  const vectorField& normals,
300  const labelListList& edgeNormals,
303  const labelList& regionEdges
304  );
305 
306 
307  // Declare run-time constructor selection table
308 
310  (
311  autoPtr,
313  fileExtension,
314  (
315  const fileName& name
316  ),
317  (name)
318  );
319 
320 
321  // Selectors
322 
323  //- Select constructed from filename (explicit extension)
325  (
326  const fileName&,
327  const word& ext
328  );
329 
330  //- Select constructed from filename (implicit extension)
331  static autoPtr<extendedEdgeMesh> New(const fileName&);
332 
333 
334  //- Destructor
336 
337 
338  // Member Functions
339 
340  // Find
341 
342  //- Find nearest surface edge for the sample point.
344  (
345  const point& sample,
346  scalar searchDistSqr,
347  pointIndexHit& info
348  ) const;
349 
350  //- Find nearest surface edge for the sample point.
351  void nearestFeatureEdge
352  (
353  const point& sample,
354  scalar searchDistSqr,
355  pointIndexHit& info
356  ) const;
357 
358  //- Find nearest surface edge for each sample point.
359  void nearestFeatureEdge
360  (
361  const pointField& samples,
362  const scalarField& searchDistSqr,
363  List<pointIndexHit>& info
364  ) const;
365 
366  //- Find the nearest point on each type of feature edge
368  (
369  const point& sample,
370  const scalarField& searchDistSqr,
371  List<pointIndexHit>& info
372  ) const;
373 
374  //- Find all the feature points within searchDistSqr of sample
376  (
377  const point& sample,
378  scalar searchRadiusSqr,
379  List<pointIndexHit>& info
380  ) const;
381 
382  //- Find all the feature edges within searchDistSqr of sample
384  (
385  const point& sample,
386  const scalar searchRadiusSqr,
387  List<pointIndexHit>& info
388  ) const;
389 
390 
391  // Access
392 
393  //- Return the index of the start of the convex feature points
394  inline label convexStart() const;
395 
396  //- Return the index of the start of the concave feature points
397  inline label concaveStart() const;
398 
399  //- Return the index of the start of the mixed type feature points
400  inline label mixedStart() const;
401 
402  //- Return the index of the start of the non-feature points
403  inline label nonFeatureStart() const;
404 
405  //- Return the index of the start of the external feature edges
406  inline label externalStart() const;
407 
408  //- Return the index of the start of the internal feature edges
409  inline label internalStart() const;
410 
411  //- Return the index of the start of the flat feature edges
412  inline label flatStart() const;
413 
414  //- Return the index of the start of the open feature edges
415  inline label openStart() const;
416 
417  //- Return the index of the start of the multiply-connected feature
418  // edges
419  inline label multipleStart() const;
420 
421  //- Return whether or not the point index is a feature point
422  inline bool featurePoint(label ptI) const;
423 
424  //- Return the normals of the surfaces adjacent to the feature edges
425  // and points
426  inline const vectorField& normals() const;
427 
428  //- Return
429  inline const List<sideVolumeType>& normalVolumeTypes() const;
430 
431  //- Return the edgeDirection vectors
432  inline const vectorField& edgeDirections() const;
433 
434  //-
435  inline const labelListList& normalDirections() const;
436 
437  //- Return the direction of edgeI, pointing away from ptI
438  inline vector edgeDirection(label edgeI, label ptI) const;
439 
440  //- Return the indices of the normals that are adjacent to the
441  // feature edges
442  inline const labelListList& edgeNormals() const;
443 
444  //- Return the normal vectors for a given set of normal indices
445  inline vectorField edgeNormals(const labelList& edgeNormIs) const;
446 
447  //- Return the normal vectors for a given edge
448  inline vectorField edgeNormals(label edgeI) const;
449 
450  //- Return the indices of the normals that are adjacent to the
451  // feature points
452  inline const labelListList& featurePointNormals() const;
453 
454  //- Return the normal vectors for a given feature point
455  inline vectorField featurePointNormals(label ptI) const;
456 
457  //- Return the edge labels for a given feature point. Edges are
458  // ordered by the faces that they share. The edge labels
459  // correspond to the entry in edges().
460  inline const labelListList& featurePointEdges() const;
461 
462  //- Return the feature edges which are on the boundary between
463  // regions
464  inline const labelList& regionEdges() const;
465 
466  //- Return the pointStatus of a specified point
467  inline pointStatus getPointStatus(label ptI) const;
468 
469  //- Return the edgeStatus of a specified edge
470  inline edgeStatus getEdgeStatus(label edgeI) const;
471 
472  //- Return the baffle faces of a specified edge
473  inline PackedList<2> edgeBaffles(label edgeI) const;
474 
475  //- Demand driven construction of octree for feature points
477 
478  //- Demand driven construction of octree for boundary edges
479  const indexedOctree<treeDataEdge>& edgeTree() const;
480 
481  //- Demand driven construction of octree for boundary edges by type
483  edgeTreesByType() const;
484 
485 
486  // Edit
487 
488  //- Transfer the contents of the argument and annul the argument
489  void transfer(extendedEdgeMesh&);
490 
491  //- Transfer contents to the Xfer container
493 
494  //- Clear all storage
495  virtual void clear();
496 
497  //- Add extendedEdgeMesh. No filtering of duplicates.
498  void add(const extendedEdgeMesh&);
499 
500  //- Flip normals. All concave become convex, all internal external
501  // etc.
502  void flipNormals();
503 
504 
505  // Read
506 
507  //- Read from file. Chooses reader based on explicit extension
508  bool read(const fileName&, const word& ext);
509 
510  //- Read from file. Chooses reader based on detected extension
511  virtual bool read(const fileName&);
512 
513 
514  // Write
515 
516  //- Write all components of the extendedEdgeMesh as obj files
517  void writeObj(const fileName& prefix) const;
518 
519  //- Dump some information
520  virtual void writeStats(Ostream& os) const;
521 
522  friend Istream& operator>>(Istream& is, sideVolumeType& vt);
523  friend Ostream& operator<<(Ostream& os, const sideVolumeType& vt);
524 
525 
526  //- Classify the type of feature edge. Requires face centre 0 to face
527  // centre 1 vector to distinguish internal from external
528  static edgeStatus classifyEdge
529  (
530  const List<vector>& norms,
531  const labelList& edNorms,
532  const vector& fC0tofC1
533  );
534 
535 
536  // Ostream Operator
537 
538  friend Ostream& operator<<(Ostream&, const extendedEdgeMesh&);
540 };
541 
542 
543 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
544 
545 } // End namespace Foam
546 
547 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
548 
549 #include "extendedEdgeMeshI.H"
550 
551 #ifdef NoRepository
552 # include "extendedEdgeMeshTemplates.C"
553 #endif
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 #endif
558 
559 // ************************************************************************* //
autoPtr< indexedOctree< treeDataEdge > > edgeTree_
Search tree for all edges.
void nearestFeatureEdgeByType(const point &sample, const scalarField &searchDistSqr, List< pointIndexHit > &info) const
Find the nearest point on each type of feature edge.
label flatStart_
Index of the start of the flat feature edges.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
sideVolumeType
Normals point to the outside.
label externalStart() const
Return the index of the start of the external feature edges.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
static wordHashSet writeTypes()
vectorField edgeDirections_
Flat and open edges require the direction of the edge.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const indexedOctree< treeDataPoint > & pointTree() const
Demand driven construction of octree for feature points.
const List< sideVolumeType > & normalVolumeTypes() const
Return.
TypeName("extendedEdgeMesh")
Runtime type information.
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
label nonFeatureStart() const
Return the index of the start of the non-feature points.
autoPtr< indexedOctree< treeDataPoint > > pointTree_
Search tree for all feature points.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
PackedList< 2 > edgeBaffles(label edgeI) const
Return the baffle faces of a specified edge.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
const labelListList & featurePointEdges() const
Return the edge labels for a given feature point. Edges are.
void transfer(extendedEdgeMesh &)
Transfer the contents of the argument and annul the argument.
A class for handling words, derived from string.
Definition: word.H:59
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
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
pointStatus getPointStatus(label ptI) const
Return the pointStatus of a specified point.
friend Ostream & operator<<(Ostream &os, const sideVolumeType &vt)
const vectorField & edgeDirections() const
Return the edgeDirection vectors.
static autoPtr< extendedEdgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
const labelList & regionEdges() const
Return the feature edges which are on the boundary between.
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
void writeObj(const fileName &prefix) const
Write all components of the extendedEdgeMesh as obj files.
PtrList< indexedOctree< treeDataEdge > > edgeTreesByType_
Individual search trees for each type of edge.
Holds feature edges/points of surface.
Namespace for OpenFOAM.
const labelListList & edgeNormals() const
Return the indices of the normals that are adjacent to the.
labelListList featurePointNormals_
Indices of the normals that are adjacent to the feature points.
label multipleStart() const
Return the index of the start of the multiply-connected feature.
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
label internalStart_
Index of the start of the internal feature edges.
List< sideVolumeType > normalVolumeTypes_
Type per normal: which side of normal to mesh.
static edgeStatus classifyEdge(const List< vector > &norms, const labelList &edNorms, const vector &fC0tofC1)
Classify the type of feature edge. Requires face centre 0 to face.
const PtrList< indexedOctree< treeDataEdge > > & edgeTreesByType() const
Demand driven construction of octree for boundary edges by type.
void allNearestFeatureEdges(const point &sample, const scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature edges within searchDistSqr of sample.
extendedEdgeMesh()
Construct null.
friend Istream & operator>>(Istream &is, sideVolumeType &vt)
label nonFeatureStart_
Index of the start of the non-feature points.
pointStatus classifyFeaturePoint(label ptI) const
Classify the type of feature point. Requires valid stored member.
const vectorField & normals() const
Return the normals of the surfaces adjacent to the feature edges.
void flipNormals()
Flip normals. All concave become convex, all internal external.
label mixedStart_
Index of the start of the mixed type feature points.
vector edgeDirection(label edgeI, label ptI) const
Return the direction of edgeI, pointing away from ptI.
void nearestFeatureEdge(const point &sample, scalar searchDistSqr, pointIndexHit &info) const
Find nearest surface edge for the sample point.
void add(const extendedEdgeMesh &)
Add extendedEdgeMesh. No filtering of duplicates.
label concaveStart_
Index of the start of the concave feature points.
labelListList featurePointEdges_
Indices of feature edges attached to feature points. The edges are.
label openStart() const
Return the index of the start of the open feature edges.
static const Foam::NamedEnum< pointStatus, 4 > pointStatusNames_
static label nEdgeTypes
Number of possible feature edge types (i.e. number of slices)
labelListList normalDirections_
Starting directions for the edges.
static label convexStart_
Index of the start of the convex feature points - static as 0.
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
Xfer< extendedEdgeMesh > xfer()
Transfer contents to the Xfer container.
A list of faces which address into the list of points.
static wordHashSet readTypes()
edgeStatus getEdgeStatus(label edgeI) const
Return the edgeStatus of a specified edge.
label convexStart() const
Return the index of the start of the convex feature points.
Points connected by edges.
Definition: edgeMesh.H:69
label openStart_
Index of the start of the open feature edges.
vectorField normals_
Normals of the features, to be referred to by index by both feature.
declareRunTimeSelectionTable(autoPtr, extendedEdgeMesh, fileExtension,( const fileName &name ),(name))
A class for handling file names.
Definition: fileName.H:69
A HashTable with keys but without contents.
Definition: HashSet.H:59
label internalStart() const
Return the index of the start of the internal feature edges.
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
virtual void clear()
Clear all storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
label mixedStart() const
Return the index of the start of the mixed type feature points.
static label externalStart_
Index of the start of the external feature edges - static as 0.
static const Foam::NamedEnum< sideVolumeType, 4 > sideVolumeTypeNames_
scalarField samples(nIntervals, 0)
labelList regionEdges_
Feature edges which are on the boundary between regions.
static label nPointTypes
Number of possible point types (i.e. number of slices)
static scalar cosNormalAngleTol_
Angular closeness tolerance for treating normals as the same.
labelListList edgeNormals_
Indices of the normals that are adjacent to the feature edges.
virtual void writeStats(Ostream &os) const
Dump some information.
Description of feature edges and points.
label multipleStart_
Index of the start of the multiply-connected feature edges.
const labelListList & normalDirections() const
label concaveStart() const
Return the index of the start of the concave feature points.
~extendedEdgeMesh()
Destructor.
bool featurePoint(label ptI) const
Return whether or not the point index is a feature point.
void sortPointsAndEdges(const Patch &, const labelList &featureEdges, const labelList &regionFeatureEdges, const labelList &feaurePoints)
void nearestFeaturePoint(const point &sample, scalar searchDistSqr, pointIndexHit &info) const
Find nearest surface edge for the sample point.
label flatStart() const
Return the index of the start of the flat feature edges.
const labelListList & featurePointNormals() const
Return the indices of the normals that are adjacent to the.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
void allNearestFeaturePoints(const point &sample, scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature points within searchDistSqr of sample.
static const Foam::NamedEnum< edgeStatus, 6 > edgeStatusNames_