DGtal  0.9.4.1
PolygonalSurface.h
1 
17 #pragma once
18 
31 #if defined(PolygonalSurface_RECURSES)
32 #error Recursive header files inclusion detected in PolygonalSurface.h
33 #else // defined(PolygonalSurface_RECURSES)
34 
35 #define PolygonalSurface_RECURSES
36 
37 #if !defined PolygonalSurface_h
38 
39 #define PolygonalSurface_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 PolygonalSurface
81  template <typename TPoint>
83  {
84  public:
85  typedef TPoint Point;
94  typedef std::vector<Point> PositionsStorage;
95  typedef std::vector<PolygonalFace> PolygonalFacesStorage;
96 
97  // Required by CUndirectedSimpleLocalGraph
99  typedef std::set<Vertex> VertexSet;
100  template <typename Value> struct VertexMap {
101  typedef typename std::map<Vertex, Value> Type;
102  };
103 
104  // Required by CUndirectedSimpleGraph
105  typedef EdgeIndex Edge;
107 
108  // Required for CCombinatorialSurface
111  typedef std::vector<Arc> ArcRange;
112  typedef std::vector<Face> FaceRange;
113  typedef std::vector<Vertex> VertexRange;
114 
116 
125  template <typename TData>
127  typedef Index Argument;
128  typedef TData Data;
129  typedef std::vector<Data> Storage;
130 
133 
138  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
139  : mySurface( &aSurface ),
140  myData( Storage( s, def_data ) )
141  {}
142 
150  IndexedPropertyMap( const Self& aSurface,
151  Storage& aStorage )
152  : mySurface( &aSurface ),
153  myData( &aStorage, false )
154  {}
155 
157  const Self& surface() const
158  {
159  ASSERT( isValid() );
160  return *mySurface;
161  }
162 
166  const Data& operator()( Argument v ) const
167  {
168  ASSERT( isValid() && v < myData->size() );
169  return (*myData)[ v ];
170  }
171 
175  const Data& operator[]( Argument v ) const
176  {
177  ASSERT( isValid() && v < myData->size() );
178  return (*myData)[ v ];
179  }
180 
185  {
186  ASSERT( isValid() && v < myData->size() );
187  return (*myData)[ v ];
188  }
189 
191  bool isValid() const { return mySurface != 0; }
192 
194  Size size() const { return myData->size(); }
195 
197  Storage& storage() { return *myData; }
198 
200  const Storage& storage() const { return *myData; }
201 
202  private:
204  const Self* mySurface;
207  };
208 
210 
211  protected:
213 
214  // ----------------------- Standard services ------------------------------
215  public:
216 
221 
226 
228  void clear();
229 
236  bool build();
237 
241  VertexIndex addVertex( const Point& vdata );
242 
246 
250 
254 
255  // ------------------------- standard services ------------------------------
256  public:
258  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
259 
261  Size nbVertices() const { return myHEDS.nbVertices(); }
262 
264  Size nbEdges() const { return myHEDS.nbEdges(); }
265 
267  Size nbFaces() const { return myHEDS.nbFaces(); }
268 
272  long Euler() const { return myHEDS.Euler(); }
273 
277  {
278  return PositionsMap( *this, myPositions );
279  }
280 
282  template <typename AnyData>
284  {
285  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
286  }
287 
290  template <typename AnyData>
292  {
293  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
294  }
295 
297  template <typename AnyData>
299  {
300  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
301  }
302 
305  template <typename AnyData>
307  {
308  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
309  }
310 
312  template <typename AnyData>
314  {
315  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
316  }
317 
320  template <typename AnyData>
322  {
323  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
324  }
325 
329  Point& position( Vertex v );
333  const Point& position( Vertex v ) const;
334 
335  // ----------------------- Undirected simple graph services -------------------------
336  public:
340  Size size() const;
341 
348  Size bestCapacity() const;
349 
355  Size degree( const Vertex & v ) const;
356 
368  template <typename OutputIterator>
369  void
370  writeNeighbors( OutputIterator &it ,
371  const Vertex & v ) const;
372 
389  template <typename OutputIterator, typename VertexPredicate>
390  void
391  writeNeighbors( OutputIterator &it ,
392  const Vertex & v,
393  const VertexPredicate & pred) const;
394 
397  { return ConstIterator( 0 ); }
398 
401  { return ConstIterator( nbVertices() ); }
402 
403  // ----------------------- CombinatorialSurface --------------------------
404  public:
405 
410  ArcRange outArcs( const Vertex & v ) const;
411 
416  ArcRange inArcs( const Vertex & v ) const;
417 
422  FaceRange facesAroundVertex( const Vertex & v ) const;
423 
428  Vertex head( const Arc & a ) const;
429 
434  Vertex tail( const Arc & a ) const;
435 
440  Arc opposite( const Arc & a ) const;
441 
448  Arc next( const Arc & a ) const;
449 
457  Arc arc( const Vertex & t, const Vertex & h ) const;
458 
469  Face faceAroundArc( const Arc & a ) const;
470 
479  FaceRange facesAroundArc( const Arc & a ) const;
480 
491  VertexRange verticesAroundFace( const Face & f ) const;
492 
498  bool isVertexBoundary( const Vertex& v ) const;
499 
506  bool isArcBoundary( const Arc& v ) const;
507 
512  FaceRange allFaces() const;
517  ArcRange allArcs() const;
522  VertexRange allVertices() const;
523 
531  ArcRange allBoundaryArcs() const;
532 
541 
542  // ----------------------- Interface --------------------------------------
543  public:
544 
549  void selfDisplay ( std::ostream & out ) const;
550 
555  bool isValid() const;
556 
557  // ------------------------- Protected Datas ------------------------------
558  protected:
567 
568  // ------------------------- Private Datas --------------------------------
569  private:
570 
571  // ------------------------- Hidden services ------------------------------
572  protected:
573 
574  private:
575 
576  // ------------------------- Internals ------------------------------------
577  private:
578 
579  }; // end of class PolygonalSurface
580 
581 
588  template <typename TPoint>
589  std::ostream&
590  operator<< ( std::ostream & out, const PolygonalSurface<TPoint> & object );
591 
592 } // namespace DGtal
593 
594 
596 // Includes inline functions.
597 #include "DGtal/shapes/PolygonalSurface.ih"
598 
599 // //
601 
602 #endif // !defined PolygonalSurface_h
603 
604 #undef PolygonalSurface_RECURSES
605 #endif // else defined(PolygonalSurface_RECURSES)
ArcRange allArcs() const
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
HalfEdgeDataStructure::VertexIndex VertexIndex
Index FaceIndex
The type for numbering faces.
std::set< Vertex > VertexSet
HalfEdgeDataStructure::PolygonalFace PolygonalFace
IntegerSequenceIterator< VertexIndex > ConstIterator
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
ConstIterator end() const
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
std::vector< Point > PositionsStorage
TriMesh::VertexRange VertexRange
HalfEdgeDataStructure::PolygonalFace PolygonalFace
HalfEdgeDataStructure::EdgeIndex EdgeIndex
bool isArcBoundary(const Arc &v) const
const Self * mySurface
The associated polygonal surface.
VertexRange allVertices() const
void selfDisplay(std::ostream &out) const
HalfEdgeDataStructure::HalfEdgeIndex Arc
Arc arc(const Vertex &t, const Vertex &h) const
HalfEdgeDataStructure::Index Index
Vertex tail(const Arc &a) const
HalfEdgeDataStructure::FaceIndex FaceIndex
TriMesh::Face Face
PositionsStorage myPositions
Stores the information for each Vertex.
Face faceAroundArc(const Arc &a) const
FaceIndex addPolygonalFace(const PolygonalFace &f)
Represents an unoriented triangle as three vertices.
std::map< Vertex, Value > Type
HalfEdgeDataStructure::Triangle Triangle
TriMesh::Arc Arc
FaceRange allFaces() const
FaceIndex addQuadrangle(VertexIndex v0, VertexIndex v1, VertexIndex v2, VertexIndex v3)
IndexedPropertyMap< AnyData > makeFaceMap() const
IndexedPropertyMap< AnyData > makeVertexMap() const
Arc opposite(const Arc &a) const
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
Point & position(Vertex v)
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
ConstIterator begin() const
Size degree(const Vertex &v) const
std::vector< VertexIndex > PolygonalFace
IndexedPropertyMap< AnyData > makeEdgeMap() const
void writeNeighbors(OutputIterator &it, const Vertex &v) const
ArcRange inArcs(const Vertex &v) const
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
IndexedPropertyMap< Point > PositionsMap
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
TriMesh::Vertex Vertex
std::vector< PolygonalFace > PolygonalFacesStorage
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it...
ArcRange allBoundaryArcs() const
const Data & operator()(Argument v) const
HalfEdgeDataStructure::HalfEdge HalfEdge
std::vector< Face > FaceRange
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
ArcRange outArcs(const Vertex &v) const
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
bool isVertexBoundary(const Vertex &v) const
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
std::vector< Vertex > VertexRange
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
HalfEdgeDataStructure::Size Size
VertexRange allBoundaryVertices() const
Index VertexIndex
The type for numbering vertices.
PolygonalFacesStorage myPolygonalFaces
Stores the polygonal faces.
VertexRange verticesAroundFace(const Face &f) const
FaceRange facesAroundArc(const Arc &a) const
std::vector< Arc > ArcRange
std::size_t Size
The type for counting elements.
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
HalfEdgeDataStructure::FaceIndex Face
static std::size_t const HALF_EDGE_INVALID_INDEX
TriMesh::ArcRange ArcRange
VertexIndex addVertex(const Point &vdata)
FaceRange facesAroundVertex(const Vertex &v) const
Index EdgeIndex
The type for numbering edges.
Size bestCapacity() const
Arc next(const Arc &a) const
IndexedPropertyMap()
Default constructor. The object is invalid.
const Data & operator[](Argument v) const
void clear()
Clears everything.
PolygonalSurface< TPoint > Self
Vertex head(const Arc &a) const
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...