DGtal  1.2.0
SurfaceMesh.h
1 
17 #pragma once
18 
31 #if defined(SurfaceMesh_RECURSES)
32 #error Recursive header files inclusion detected in SurfaceMesh.h
33 #else // defined(SurfaceMesh_RECURSES)
35 #define SurfaceMesh_RECURSES
36 
37 #if !defined SurfaceMesh_h
39 #define SurfaceMesh_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <sstream>
45 #include <string>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/base/IntegerSequenceIterator.h"
48 #include "DGtal/helpers/StdDefs.h"
49 
50 namespace DGtal
51 {
53  // template class SurfaceMesh
90  template < typename TRealPoint, typename TRealVector >
91  struct SurfaceMesh
92  {
93  typedef TRealPoint RealPoint;
94  typedef TRealVector RealVector;
96 
97  static const Dimension dimension = RealPoint::dimension;
99 
100  typedef typename RealVector::Component Scalar;
101  typedef std::vector<Scalar> Scalars;
103  typedef std::size_t Size;
105  typedef std::size_t Index;
106  typedef Index Face;
107  typedef Index Edge;
108  typedef Index Vertex;
109  typedef std::pair< Edge, Scalar > WeightedEdge;
110  typedef std::pair< Face, Scalar > WeightedFace;
112  typedef std::vector< Vertex > Vertices;
114  typedef std::vector< Edge > Edges;
115  typedef std::vector< WeightedEdge > WeightedEdges;
116  typedef std::vector< Face > Faces;
117  typedef std::vector< WeightedFace > WeightedFaces;
118  typedef std::pair< Vertex, Vertex > VertexPair;
119 
120  // Required by CUndirectedSimpleLocalGraph
121  typedef std::set<Vertex> VertexSet;
122  template <typename Value> struct VertexMap {
123  typedef typename std::map<Vertex, Value> Type;
124  };
125 
126  // Required by CUndirectedSimpleGraph
127 
130 
131  //---------------------------------------------------------------------------
132  public:
135 
137  ~SurfaceMesh() = default;
147  SurfaceMesh() = default;
150  SurfaceMesh( const Self& other ) = default;
153  SurfaceMesh( Self&& other ) = default;
157  Self& operator=( const Self& other ) = default;
158 
178  template <typename RealPointIterator, typename VerticesIterator>
179  SurfaceMesh( RealPointIterator itPos, RealPointIterator itPosEnd,
180  VerticesIterator itVertices, VerticesIterator itVerticesEnd );
181 
203  template <typename RealPointIterator, typename VerticesIterator>
204  bool init( RealPointIterator itPos, RealPointIterator itPosEnd,
205  VerticesIterator itVertices, VerticesIterator itVerticesEnd );
206 
208  void clear();
209 
211 
212  //---------------------------------------------------------------------------
213  public:
216 
219  template <typename RealVectorIterator>
220  bool setVertexNormals( RealVectorIterator itN, RealVectorIterator itNEnd );
221 
224  template <typename RealVectorIterator>
225  bool setFaceNormals( RealVectorIterator itN, RealVectorIterator itNEnd );
226 
231 
236 
241 
247 
251  template <typename AnyRing>
253  ( const std::vector<AnyRing>& vvalues ) const;
254 
258  template <typename AnyRing>
260  ( const std::vector<AnyRing>& fvalues ) const;
261 
265  ( const std::vector<RealVector>& vuvectors ) const;
266 
270  ( const std::vector<RealVector>& fuvectors ) const;
271 
273 
274  //---------------------------------------------------------------------------
275  public:
278 
280  Size nbVertices() const
281  { return myIncidentFaces.size(); }
282 
284  Size nbEdges() const
285  { return myEdgeVertices.size(); }
286 
288  Size nbFaces() const
289  { return myIncidentVertices.size(); }
290 
294  long Euler() const
295  { return nbVertices() - nbEdges() + nbFaces(); }
296 
302  Edge makeEdge( Vertex i, Vertex j ) const;
303 
307  const Vertices& incidentVertices( Face f ) const
308  { return myIncidentVertices[ f ]; }
309 
313  const Faces& incidentFaces( Vertex v ) const
314  { return myIncidentFaces[ v ]; }
315 
318  const Faces& neighborFaces( Face f ) const
319  { return myNeighborFaces[ f ]; }
320 
323  const Vertices& neighborVertices( Vertex v ) const
324  { return myNeighborVertices[ v ]; }
325 
329  const VertexPair& edgeVertices( Edge e ) const
330  { return myEdgeVertices[ e ]; }
331 
335  const Faces& edgeFaces( Edge e ) const
336  { return myEdgeFaces[ e ]; }
337 
346  const Faces& edgeRightFaces( Edge e ) const
347  { return myEdgeRightFaces[ e ]; }
348 
357  const Faces& edgeLeftFaces( Edge e ) const
358  { return myEdgeLeftFaces[ e ]; }
359 
362  const std::vector< Vertices >& allIncidentVertices() const
363  { return myIncidentVertices; }
364 
367  const std::vector< Faces >& allIncidentFaces() const
368  { return myIncidentFaces; }
369 
371  const std::vector< Faces >& allNeighborFaces() const
372  { return myNeighborFaces; }
373 
375  const std::vector< Vertices >& allNeighborVertices() const
376  { return myNeighborVertices; }
377 
381  const std::vector< VertexPair >& allEdgeVertices() const
382  { return myEdgeVertices; }
383 
386  const std::vector< Faces >& allEdgeFaces() const
387  { return myEdgeFaces; }
388 
396  const std::vector< Faces >& allEdgeRightFaces() const
397  { return myEdgeRightFaces; }
398 
406  const std::vector< Faces >& allEdgeLeftFaces() const
407  { return myEdgeLeftFaces; }
408 
410 
411  //---------------------------------------------------------------------------
412  public:
415 
438 
440 
441  // ----------------------- Undirected simple graph services ----------------------
442  public:
445 
449  Size size() const
450  { return nbVertices(); }
451 
459  { return 8; }
460 
466  Size degree( const Vertex & v ) const
467  { return myNeighborVertices[ v ].size(); }
468 
479  template <typename OutputIterator>
480  void
481  writeNeighbors( OutputIterator &it ,
482  const Vertex & v ) const
483  {
484  for ( auto&& nv : myNeighborVertices[ v ] )
485  *it++ = nv;
486  }
487 
504  template <typename OutputIterator, typename VertexPredicate>
505  void
506  writeNeighbors( OutputIterator &it ,
507  const Vertex & v,
508  const VertexPredicate & pred) const
509  {
510  for ( auto&& nv : myNeighborVertices[ v ] )
511  if ( pred( nv ) ) *it++ = nv;
512  }
513 
516  { return ConstIterator( 0 ); }
517 
520  { return ConstIterator( nbVertices() ); }
521 
523 
524  //---------------------------------------------------------------------------
525  public:
528 
530  const std::vector< RealPoint >& positions() const
531  { return myPositions; }
532 
537  { return myPositions[ v ]; }
538 
542  const RealPoint& position( Vertex v ) const
543  { return myPositions[ v ]; }
544 
546  const std::vector< RealVector >& vertexNormals() const
547  { return myVertexNormals; }
548 
550  std::vector< RealVector >& vertexNormals()
551  { return myVertexNormals; }
552 
557  { return myVertexNormals[ v ]; }
558 
562  const RealVector& vertexNormal( Vertex v ) const
563  { return myVertexNormals[ v ]; }
564 
566  const std::vector< RealVector >& faceNormals() const
567  { return myFaceNormals; }
568 
570  std::vector< RealVector >& faceNormals()
571  { return myFaceNormals; }
572 
577  { return myFaceNormals[ f ]; }
578 
582  const RealVector& faceNormal( Face f ) const
583  { return myFaceNormals[ f ]; }
584 
587 
591  Scalar localWindow( Face f ) const;
592 
597 
602 
606 
610 
613  Scalar faceArea( Index f ) const;
614 
619 
643 
659  std::tuple< Vertices, WeightedEdges, WeightedFaces >
661 
676 
691 
702 
704 
705  // ----------------------- Interface --------------------------------------
706  public:
707 
712  void selfDisplay ( std::ostream & out ) const;
713 
718  bool isValid() const;
719 
720  // ------------------------- Protected Datas ------------------------------
721  protected:
723  std::vector< Vertices > myIncidentVertices;
725  std::vector< Faces > myIncidentFaces;
727  std::vector< RealPoint > myPositions;
729  std::vector< RealVector > myVertexNormals;
731  std::vector< RealVector > myFaceNormals;
733  std::vector< Faces > myNeighborFaces;
735  std::vector< Vertices > myNeighborVertices;
737  std::vector< VertexPair > myEdgeVertices;
739  std::vector< Faces > myEdgeFaces;
745  std::vector< Faces > myEdgeRightFaces;
751  std::vector< Faces > myEdgeLeftFaces;
752 
753  // ------------------------- Private Datas --------------------------------
754  private:
755 
756 
757  // ------------------------- Internals ------------------------------------
758  protected:
759 
763  void computeEdges();
764 
766  static Scalar rand01()
767  { return (Scalar) rand() / (Scalar) RAND_MAX; }
768 
769  }; // end of class SurfaceMesh
770 
777  template < typename TRealPoint, typename TRealVector >
778  std::ostream&
779  operator<< ( std::ostream & out,
780  const SurfaceMesh<TRealPoint, TRealVector> & object );
781 
782 } // namespace DGtal
783 
785 // Includes inline functions.
786 #include "SurfaceMesh.ih"
787 // //
789 
790 #endif // !defined SurfaceMesh_h
791 
792 #undef SurfaceMesh_RECURSES
793 #endif // else defined(SurfaceMesh_RECURSES)
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it,...
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition: Common.h:137
std::map< Vertex, Value > Type
Definition: SurfaceMesh.h:123
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:92
std::vector< WeightedEdge > WeightedEdges
Definition: SurfaceMesh.h:115
void writeNeighbors(OutputIterator &it, const Vertex &v, const VertexPredicate &pred) const
Definition: SurfaceMesh.h:506
std::vector< RealVector > & faceNormals()
Definition: SurfaceMesh.h:570
Size size() const
Definition: SurfaceMesh.h:449
const Faces & neighborFaces(Face f) const
Definition: SurfaceMesh.h:318
std::pair< Vertex, Vertex > VertexPair
Definition: SurfaceMesh.h:118
Scalar edgeInclusionRatio(RealPoint p, Scalar r, Index e) const
Edges computeManifoldInnerUnconsistentEdges() const
RealPoint & position(Vertex v)
Definition: SurfaceMesh.h:536
SurfaceMesh(RealPointIterator itPos, RealPointIterator itPosEnd, VerticesIterator itVertices, VerticesIterator itVerticesEnd)
SurfaceMesh(const Self &other)=default
std::vector< RealVector > computeVertexUnitVectorsFromFaceUnitVectors(const std::vector< RealVector > &fuvectors) const
void perturbateWithAdaptiveUniformRandomNoise(Scalar p)
bool setVertexNormals(RealVectorIterator itN, RealVectorIterator itNEnd)
std::vector< Vertex > Vertices
The type that defines a list/range of vertices (e.g. to define faces)
Definition: SurfaceMesh.h:112
Edges computeManifoldInnerEdges() const
std::vector< Faces > myNeighborFaces
For each face, its range of neighbor faces (no particular order)
Definition: SurfaceMesh.h:733
RealPoint faceCentroid(Index f) const
std::vector< Scalar > Scalars
Definition: SurfaceMesh.h:101
static Scalar rand01()
Definition: SurfaceMesh.h:766
const std::vector< Faces > & allEdgeRightFaces() const
Definition: SurfaceMesh.h:396
long Euler() const
Definition: SurfaceMesh.h:294
void computeEdges()
Computes edge information.
SurfaceMesh< RealPoint, RealVector > Self
Definition: SurfaceMesh.h:95
const std::vector< RealVector > & faceNormals() const
Definition: SurfaceMesh.h:566
static const Dimension dimension
Definition: SurfaceMesh.h:97
Scalars getMaxWeights(Index v) const
std::vector< WeightedFace > WeightedFaces
Definition: SurfaceMesh.h:117
const Faces & edgeFaces(Edge e) const
Definition: SurfaceMesh.h:335
Scalar localWindow(Face f) const
void perturbateWithUniformRandomNoise(Scalar p)
TRealPoint RealPoint
Definition: SurfaceMesh.h:93
const std::vector< RealVector > & vertexNormals() const
Definition: SurfaceMesh.h:546
Scalar faceArea(Index f) const
std::vector< Faces > myIncidentFaces
For each vertex, its range of incident faces.
Definition: SurfaceMesh.h:725
void computeFaceNormalsFromPositions()
std::vector< Faces > myEdgeRightFaces
Definition: SurfaceMesh.h:745
std::vector< AnyRing > computeFaceValuesFromVertexValues(const std::vector< AnyRing > &vvalues) const
const std::vector< RealPoint > & positions() const
Definition: SurfaceMesh.h:530
RealVector & vertexNormal(Vertex v)
Definition: SurfaceMesh.h:556
SurfaceMesh()=default
ConstIterator begin() const
Definition: SurfaceMesh.h:515
std::vector< AnyRing > computeVertexValuesFromFaceValues(const std::vector< AnyRing > &fvalues) const
void computeVertexNormalsFromFaceNormals()
RealVector & faceNormal(Face f)
Definition: SurfaceMesh.h:576
std::size_t Index
The type used for numbering vertices and faces.
Definition: SurfaceMesh.h:105
const Vertices & incidentVertices(Face f) const
Definition: SurfaceMesh.h:307
~SurfaceMesh()=default
Default destructor.
const Faces & edgeRightFaces(Edge e) const
Definition: SurfaceMesh.h:346
IntegerSequenceIterator< Vertex > ConstIterator
Non mutable iterator for visiting vertices.
Definition: SurfaceMesh.h:129
std::vector< Vertices > myNeighborVertices
For each vertex, its range of neighbor vertices (no particular order)
Definition: SurfaceMesh.h:735
BOOST_STATIC_ASSERT((dimension==3))
const std::vector< VertexPair > & allEdgeVertices() const
Definition: SurfaceMesh.h:381
std::vector< Edge > Edges
The type that defines a list/range of faces.
Definition: SurfaceMesh.h:114
std::pair< Face, Scalar > WeightedFace
Definition: SurfaceMesh.h:110
const std::vector< Faces > & allEdgeFaces() const
Definition: SurfaceMesh.h:386
const std::vector< Vertices > & allNeighborVertices() const
Definition: SurfaceMesh.h:375
const RealVector & faceNormal(Face f) const
Definition: SurfaceMesh.h:582
std::vector< Faces > myEdgeFaces
For each edge, its faces (one, two, or more if non manifold)
Definition: SurfaceMesh.h:739
void computeVertexNormalsFromFaceNormalsWithMaxWeights()
std::vector< RealVector > & vertexNormals()
Definition: SurfaceMesh.h:550
std::set< Vertex > VertexSet
Definition: SurfaceMesh.h:121
std::vector< RealVector > computeFaceUnitVectorsFromVertexUnitVectors(const std::vector< RealVector > &vuvectors) const
bool setFaceNormals(RealVectorIterator itN, RealVectorIterator itNEnd)
const RealVector & vertexNormal(Vertex v) const
Definition: SurfaceMesh.h:562
SurfaceMesh(Self &&other)=default
Scalar faceInclusionRatio(RealPoint p, Scalar r, Index f) const
std::size_t Size
The type for counting elements.
Definition: SurfaceMesh.h:103
Self & operator=(const Self &other)=default
Size nbFaces() const
Definition: SurfaceMesh.h:288
std::tuple< Vertices, WeightedEdges, WeightedFaces > computeCellsInclusionsInBall(Scalar r, Index f) const
Size nbEdges() const
Definition: SurfaceMesh.h:284
Edges computeManifoldBoundaryEdges() const
Edges computeManifoldInnerConsistentEdges() const
const std::vector< Faces > & allEdgeLeftFaces() const
Definition: SurfaceMesh.h:406
const VertexPair & edgeVertices(Edge e) const
Definition: SurfaceMesh.h:329
Size bestCapacity() const
Definition: SurfaceMesh.h:458
WeightedFaces computeFacesInclusionsInBall(Scalar r, Index f) const
const std::vector< Vertices > & allIncidentVertices() const
Definition: SurfaceMesh.h:362
const Faces & incidentFaces(Vertex v) const
Definition: SurfaceMesh.h:313
bool init(RealPointIterator itPos, RealPointIterator itPosEnd, VerticesIterator itVertices, VerticesIterator itVerticesEnd)
bool isValid() const
const Faces & edgeLeftFaces(Edge e) const
Definition: SurfaceMesh.h:357
RealVector::Component Scalar
Definition: SurfaceMesh.h:100
Edge makeEdge(Vertex i, Vertex j) const
Size degree(const Vertex &v) const
Definition: SurfaceMesh.h:466
Size nbVertices() const
Definition: SurfaceMesh.h:280
RealPoint edgeCentroid(Index e) const
void computeFaceNormalsFromVertexNormals()
std::vector< VertexPair > myEdgeVertices
For each edge, its two vertices.
Definition: SurfaceMesh.h:737
void clear()
Clears everything. The object is empty.
Edges computeNonManifoldEdges() const
const Vertices & neighborVertices(Vertex v) const
Definition: SurfaceMesh.h:323
std::vector< RealVector > myFaceNormals
For each face, its normal vector.
Definition: SurfaceMesh.h:731
ConstIterator end() const
Definition: SurfaceMesh.h:519
std::vector< Face > Faces
Definition: SurfaceMesh.h:116
std::pair< Edge, Scalar > WeightedEdge
Definition: SurfaceMesh.h:109
void computeNeighbors()
Computes neighboring information.
std::vector< Vertices > myIncidentVertices
For each face, its range of incident vertices.
Definition: SurfaceMesh.h:723
std::vector< Faces > myEdgeLeftFaces
Definition: SurfaceMesh.h:751
std::vector< RealVector > myVertexNormals
For each vertex, its normal vector.
Definition: SurfaceMesh.h:729
const std::vector< Faces > & allNeighborFaces() const
Definition: SurfaceMesh.h:371
TRealVector RealVector
Definition: SurfaceMesh.h:94
std::vector< RealPoint > myPositions
For each vertex, its position.
Definition: SurfaceMesh.h:727
void writeNeighbors(OutputIterator &it, const Vertex &v) const
Definition: SurfaceMesh.h:481
const RealPoint & position(Vertex v) const
Definition: SurfaceMesh.h:542
Scalar averageEdgeLength() const
Scalar vertexInclusionRatio(RealPoint p, Scalar r, Index v) const
const std::vector< Faces > & allIncidentFaces() const
Definition: SurfaceMesh.h:367
void selfDisplay(std::ostream &out) const