DGtal  0.9.4.1
TriangulatedSurface.h
1 
17 #pragma once
18 
31 #if defined(TriangulatedSurface_RECURSES)
32 #error Recursive header files inclusion detected in TriangulatedSurface.h
33 #else // defined(TriangulatedSurface_RECURSES)
34 
35 #define TriangulatedSurface_RECURSES
36 
37 #if !defined TriangulatedSurface_h
38 
39 #define TriangulatedSurface_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <set>
45 #include <map>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/base/OwningOrAliasingPtr.h"
48 #include "DGtal/base/IntegerSequenceIterator.h"
49 #include "DGtal/topology/HalfEdgeDataStructure.h"
51 
52 namespace DGtal
53 {
54 
56  // template class TriangulatedSurface
80  template <typename TPoint>
82  {
83  public:
84  typedef TPoint Point;
92  typedef std::vector<Point> PositionsStorage;
93  typedef std::vector<Triangle> TriangleStorage;
94 
95  // Required by CUndirectedSimpleLocalGraph
97  typedef std::set<Vertex> VertexSet;
98  template <typename Value> struct VertexMap {
99  typedef typename std::map<Vertex, Value> Type;
100  };
101 
102  // Required by CUndirectedSimpleGraph
103  typedef EdgeIndex Edge;
105 
106  // Required for CCombinatorialSurface
109  typedef std::vector<Arc> ArcRange;
110  typedef std::vector<Face> FaceRange;
111  typedef std::vector<Vertex> VertexRange;
112 
114 
123  template <typename TData>
125  typedef Index Argument;
126  typedef TData Data;
127  typedef std::vector<Data> Storage;
128 
131 
136  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
137  : mySurface( &aSurface ),
138  myData( Storage( s, def_data ) )
139  {}
140 
148  IndexedPropertyMap( const Self& aSurface,
149  Storage& aStorage )
150  : mySurface( &aSurface ),
151  myData( &aStorage, false )
152  {}
153 
155  const Self& surface() const
156  {
157  ASSERT( isValid() );
158  return *mySurface;
159  }
160 
164  const Data& operator()( Argument v ) const
165  {
166  ASSERT( isValid() && v < myData->size() );
167  return (*myData)[ v ];
168  }
169 
173  const Data& operator[]( Argument v ) const
174  {
175  ASSERT( isValid() && v < myData->size() );
176  return (*myData)[ v ];
177  }
178 
183  {
184  ASSERT( isValid() && v < myData->size() );
185  return (*myData)[ v ];
186  }
187 
189  bool isValid() const { return mySurface != 0; }
190 
192  Size size() const { return myData->size(); }
193 
195  Storage& storage() { return *myData; }
196 
198  const Storage& storage() const { return *myData; }
199 
200  private:
202  const Self* mySurface;
205  };
206 
208 
209  protected:
211 
212  // ----------------------- Standard services ------------------------------
213  public:
214 
219 
224 
226  void clear();
227 
234  bool build();
235 
239  VertexIndex addVertex( const Point& vdata );
240 
244 
245  // ------------------------- standard services ------------------------------
246  public:
248  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
249 
251  Size nbVertices() const { return myHEDS.nbVertices(); }
252 
254  Size nbEdges() const { return myHEDS.nbEdges(); }
255 
257  Size nbFaces() const { return myHEDS.nbFaces(); }
258 
262  long Euler() const { return myHEDS.Euler(); }
263 
267  {
268  return PositionsMap( *this, myPositions );
269  }
270 
272  template <typename AnyData>
274  {
275  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
276  }
277 
280  template <typename AnyData>
282  {
283  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
284  }
285 
287  template <typename AnyData>
289  {
290  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
291  }
292 
295  template <typename AnyData>
297  {
298  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
299  }
300 
302  template <typename AnyData>
304  {
305  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
306  }
307 
310  template <typename AnyData>
312  {
313  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
314  }
315 
319  Point& position( Vertex v );
323  const Point& position( Vertex v ) const;
324 
325  // ----------------------- Undirected simple graph services -------------------------
326  public:
330  Size size() const;
331 
338  Size bestCapacity() const;
339 
345  Size degree( const Vertex & v ) const;
346 
358  template <typename OutputIterator>
359  void
360  writeNeighbors( OutputIterator &it ,
361  const Vertex & v ) const;
362 
379  template <typename OutputIterator, typename VertexPredicate>
380  void
381  writeNeighbors( OutputIterator &it ,
382  const Vertex & v,
383  const VertexPredicate & pred) const;
384 
387  { return ConstIterator( 0 ); }
388 
391  { return ConstIterator( nbVertices() ); }
392 
393  // ----------------------- CombinatorialSurface --------------------------
394  public:
395 
400  ArcRange outArcs( const Vertex & v ) const;
401 
406  ArcRange inArcs( const Vertex & v ) const;
407 
412  FaceRange facesAroundVertex( const Vertex & v ) const;
413 
418  Vertex head( const Arc & a ) const;
419 
424  Vertex tail( const Arc & a ) const;
425 
430  Arc opposite( const Arc & a ) const;
431 
438  Arc next( const Arc & a ) const;
439 
447  Arc arc( const Vertex & t, const Vertex & h ) const;
448 
459  Face faceAroundArc( const Arc & a ) const;
460 
469  FaceRange facesAroundArc( const Arc & a ) const;
470 
480  VertexRange verticesAroundFace( const Face & f ) const;
481 
487  bool isVertexBoundary( const Vertex& v ) const;
488 
495  bool isArcBoundary( const Arc& v ) const;
496 
501  FaceRange allFaces() const;
506  ArcRange allArcs() const;
511  VertexRange allVertices() const;
512 
520  ArcRange allBoundaryArcs() const;
521 
530 
531  // ----------------------- Interface --------------------------------------
532  public:
533 
538  void selfDisplay ( std::ostream & out ) const;
539 
544  bool isValid() const;
545 
546  // ------------------------- Protected Datas ------------------------------
547  protected:
556 
557  // ------------------------- Private Datas --------------------------------
558  private:
559 
560  // ------------------------- Hidden services ------------------------------
561  protected:
562 
563  private:
564 
565  // ------------------------- Internals ------------------------------------
566  private:
567 
568  }; // end of class TriangulatedSurface
569 
570 
577  template <typename TPoint>
578  std::ostream&
579  operator<< ( std::ostream & out, const TriangulatedSurface<TPoint> & object );
580 
581 } // namespace DGtal
582 
583 
585 // Includes inline functions.
586 #include "DGtal/shapes/TriangulatedSurface.ih"
587 
588 // //
590 
591 #endif // !defined TriangulatedSurface_h
592 
593 #undef TriangulatedSurface_RECURSES
594 #endif // else defined(TriangulatedSurface_RECURSES)
void writeNeighbors(OutputIterator &it, const Vertex &v) const
Index FaceIndex
The type for numbering faces.
PositionsStorage myPositions
Stores the information for each Vertex.
HalfEdgeDataStructure::FaceIndex FaceIndex
Arc arc(const Vertex &t, const Vertex &h) const
IndexedPropertyMap< AnyData > makeEdgeMap() const
HalfEdgeDataStructure::HalfEdge HalfEdge
TriMesh::VertexRange VertexRange
VertexIndex addVertex(const Point &vdata)
ConstIterator begin() const
HalfEdgeDataStructure::EdgeIndex EdgeIndex
bool isArcBoundary(const Arc &v) const
Size degree(const Vertex &v) const
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
FaceRange facesAroundArc(const Arc &a) const
ArcRange inArcs(const Vertex &v) const
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
HalfEdgeDataStructure::Size Size
ArcRange allArcs() const
TriangulatedSurface< TPoint > Self
TriMesh::Face Face
ArcRange outArcs(const Vertex &v) const
Point & position(Vertex v)
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
HalfEdgeDataStructure::Index Index
Represents an unoriented triangle as three vertices.
Arc opposite(const Arc &a) const
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
TriMesh::Arc Arc
std::vector< Triangle > TriangleStorage
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
IndexedPropertyMap()
Default constructor. The object is invalid.
Face faceAroundArc(const Arc &a) const
IntegerSequenceIterator< VertexIndex > ConstIterator
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure...
HalfEdgeDataStructure::VertexIndex VertexIndex
HalfEdgeDataStructure::Triangle Triangle
VertexRange verticesAroundFace(const Face &f) const
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
Arc next(const Arc &a) const
TriMesh::Vertex Vertex
Vertex tail(const Arc &a) const
std::vector< Vertex > VertexRange
ArcRange allBoundaryArcs() const
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it...
IndexedPropertyMap< AnyData > makeVertexMap() const
const Self * mySurface
The associated polygonal surface.
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
HalfEdgeDataStructure::HalfEdgeIndex Arc
bool isVertexBoundary(const Vertex &v) const
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
Index VertexIndex
The type for numbering vertices.
std::vector< Point > PositionsStorage
TriangleStorage myTriangles
Stores the triangles.
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
HalfEdgeDataStructure::FaceIndex Face
std::size_t Size
The type for counting elements.
VertexRange allVertices() const
void selfDisplay(std::ostream &out) const
static std::size_t const HALF_EDGE_INVALID_INDEX
TriMesh::ArcRange ArcRange
IndexedPropertyMap< Point > PositionsMap
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
VertexRange allBoundaryVertices() const
Index EdgeIndex
The type for numbering edges.
FaceRange facesAroundVertex(const Vertex &v) const
void clear()
Clears everything.
FaceRange allFaces() const
Vertex head(const Arc &a) const
IndexedPropertyMap< AnyData > makeFaceMap() const