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