DGtal  1.0.0
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
83  template <typename TPoint>
85  {
86  public:
87  typedef TPoint Point;
95  typedef std::vector<Point> PositionsStorage;
96  typedef std::vector<Triangle> TriangleStorage;
97 
98  // Required by CUndirectedSimpleLocalGraph
100  typedef std::set<Vertex> VertexSet;
101  template <typename Value> struct VertexMap {
102  typedef typename std::map<Vertex, Value> Type;
103  };
104 
105  // Required by CUndirectedSimpleGraph
106  typedef EdgeIndex Edge;
108 
109  // Required for CCombinatorialSurface
112  typedef std::vector<Arc> ArcRange;
113  typedef std::vector<Face> FaceRange;
114  typedef std::vector<Vertex> VertexRange;
115 
117 
126  template <typename TData>
128  typedef Index Argument;
129  typedef TData Data;
130  typedef std::vector<Data> Storage;
131 
134 
139  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
140  : mySurface( &aSurface ),
141  myData( Storage( s, def_data ) )
142  {}
143 
151  IndexedPropertyMap( const Self& aSurface,
152  Storage& aStorage )
153  : mySurface( &aSurface ),
154  myData( &aStorage, false )
155  {}
156 
158  const Self& surface() const
159  {
160  ASSERT( isValid() );
161  return *mySurface;
162  }
163 
167  const Data& operator()( Argument v ) const
168  {
169  ASSERT( isValid() && v < myData->size() );
170  return (*myData)[ v ];
171  }
172 
176  const Data& operator[]( Argument v ) const
177  {
178  ASSERT( isValid() && v < myData->size() );
179  return (*myData)[ v ];
180  }
181 
186  {
187  ASSERT( isValid() && v < myData->size() );
188  return (*myData)[ v ];
189  }
190 
192  bool isValid() const { return mySurface != 0; }
193 
195  Size size() const { return myData->size(); }
196 
198  Storage& storage() { return *myData; }
199 
201  const Storage& storage() const { return *myData; }
202 
203  private:
205  const Self* mySurface;
208  };
209 
211 
212  protected:
214 
215  // ----------------------- Standard services ------------------------------
216  public:
217 
222 
227 
229  void clear();
230 
237  bool build();
238 
242  VertexIndex addVertex( const Point& vdata );
243 
247 
250  { return myHEDS; }
251 
252  // ------------------------- standard services ------------------------------
253  public:
255  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
256 
258  Size nbVertices() const { return myHEDS.nbVertices(); }
259 
261  Size nbEdges() const { return myHEDS.nbEdges(); }
262 
264  Size nbFaces() const { return myHEDS.nbFaces(); }
265 
269  long Euler() const { return myHEDS.Euler(); }
270 
274  {
275  return PositionsMap( *this, myPositions );
276  }
277 
279  template <typename AnyData>
281  {
282  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
283  }
284 
287  template <typename AnyData>
289  {
290  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
291  }
292 
294  template <typename AnyData>
296  {
297  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
298  }
299 
302  template <typename AnyData>
304  {
305  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
306  }
307 
309  template <typename AnyData>
311  {
312  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
313  }
314 
317  template <typename AnyData>
319  {
320  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
321  }
322 
326  Point& position( Vertex v );
330  const Point& position( Vertex v ) const;
331 
332  // ----------------------- Undirected simple graph services -------------------------
333  public:
337  Size size() const;
338 
345  Size bestCapacity() const;
346 
352  Size degree( const Vertex & v ) const;
353 
365  template <typename OutputIterator>
366  void
367  writeNeighbors( OutputIterator &it ,
368  const Vertex & v ) const;
369 
386  template <typename OutputIterator, typename VertexPredicate>
387  void
388  writeNeighbors( OutputIterator &it ,
389  const Vertex & v,
390  const VertexPredicate & pred) const;
391 
394  { return ConstIterator( 0 ); }
395 
398  { return ConstIterator( nbVertices() ); }
399 
400  // ----------------------- CombinatorialSurface --------------------------
401  public:
402 
407  ArcRange outArcs( const Vertex & v ) const;
408 
413  ArcRange inArcs( const Vertex & v ) const;
414 
419  FaceRange facesAroundVertex( const Vertex & v ) const;
420 
425  Vertex head( const Arc & a ) const;
426 
431  Vertex tail( const Arc & a ) const;
432 
437  Arc opposite( const Arc & a ) const;
438 
445  Arc next( const Arc & a ) const;
446 
454  Arc arc( const Vertex & t, const Vertex & h ) const;
455 
466  Face faceAroundArc( const Arc & a ) const;
467 
476  FaceRange facesAroundArc( const Arc & a ) const;
477 
487  VertexRange verticesAroundFace( const Face & f ) const;
488 
498  ArcRange arcsAroundFace( const Face & f ) const;
499 
505  bool isVertexBoundary( const Vertex& v ) const;
506 
513  bool isArcBoundary( const Arc& v ) const;
514 
519  FaceRange allFaces() const;
524  ArcRange allArcs() const;
529  VertexRange allVertices() const;
530 
538  ArcRange allBoundaryArcs() const;
539 
548 
549  // ----------------------- Interface --------------------------------------
550  public:
551 
556  void selfDisplay ( std::ostream & out ) const;
557 
562  bool isValid() const;
563 
564  // ------------------------- Protected Datas ------------------------------
565  protected:
574 
575  // ------------------------- Private Datas --------------------------------
576  private:
577 
578  // ------------------------- Hidden services ------------------------------
579  protected:
580 
581  private:
582 
583  // ------------------------- Internals ------------------------------------
584  private:
585 
586  }; // end of class TriangulatedSurface
587 
588 
595  template <typename TPoint>
596  std::ostream&
597  operator<< ( std::ostream & out, const TriangulatedSurface<TPoint> & object );
598 
599 } // namespace DGtal
600 
601 
603 // Includes inline functions.
604 #include "DGtal/shapes/TriangulatedSurface.ih"
605 
606 // //
608 
609 #endif // !defined TriangulatedSurface_h
610 
611 #undef TriangulatedSurface_RECURSES
612 #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.
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
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
HalfEdgeDataStructure::Triangle Triangle
VertexRange verticesAroundFace(const Face &f) const
const HalfEdgeDataStructure & heds() 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.
ArcRange arcsAroundFace(const Face &f) const
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