DGtal  1.5.beta
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)
35 #define PolygonalSurface_RECURSES
36 
37 #if !defined PolygonalSurface_h
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/Clone.h"
48 #include "DGtal/base/OwningOrAliasingPtr.h"
49 #include "DGtal/base/IntegerSequenceIterator.h"
50 #include "DGtal/topology/HalfEdgeDataStructure.h"
52 
53 namespace DGtal
54 {
55 
57  // template class PolygonalSurface
85  template <typename TPoint>
87  {
88  public:
89  typedef TPoint Point;
98  typedef std::vector<Point> PositionsStorage;
99  typedef std::vector<PolygonalFace> PolygonalFacesStorage;
100 
101  // Required by CUndirectedSimpleLocalGraph
103  typedef std::set<Vertex> VertexSet;
104  template <typename Value> struct VertexMap {
105  typedef typename std::map<Vertex, Value> Type;
106  };
107 
108  // Required by CUndirectedSimpleGraph
109  typedef EdgeIndex Edge;
111 
112  // Required for CCombinatorialSurface
115  typedef std::vector<Arc> ArcRange;
116  typedef std::vector<Face> FaceRange;
117  typedef std::vector<Vertex> VertexRange;
118 
120 
129  template <typename TData>
131  typedef Index Argument;
132  typedef TData Data;
133  typedef std::vector<Data> Storage;
134 
137 
142  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
143  : mySurface( &aSurface ),
144  myData( Storage( s, def_data ) )
145  {}
146 
154  IndexedPropertyMap( const Self& aSurface,
155  Storage& aStorage )
156  : mySurface( &aSurface ),
157  myData( &aStorage, false )
158  {}
159 
161  const Self& surface() const
162  {
163  ASSERT( isValid() );
164  return *mySurface;
165  }
166 
170  const Data& operator()( Argument v ) const
171  {
172  ASSERT( isValid() && v < myData->size() );
173  return (*myData)[ v ];
174  }
175 
179  const Data& operator[]( Argument v ) const
180  {
181  ASSERT( isValid() && v < myData->size() );
182  return (*myData)[ v ];
183  }
184 
189  {
190  ASSERT( isValid() && v < myData->size() );
191  return (*myData)[ v ];
192  }
193 
195  bool isValid() const { return mySurface != 0; }
196 
198  Size size() const { return myData->size(); }
199 
201  Storage& storage() { return *myData; }
202 
204  const Storage& storage() const { return *myData; }
205 
206  private:
208  const Self* mySurface;
211  };
212 
214 
215  protected:
217 
218  // ----------------------- Standard services ------------------------------
219  public:
220 
225 
230 
242 
244  void clear();
245 
252  bool build();
253 
257  VertexIndex addVertex( const Point& vdata );
258 
262 
266 
270 
274 
277  const HalfEdgeDataStructure& heds() const { return myHEDS; }
278 
279  // ------------------------- standard services ------------------------------
280  public:
282  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
283 
285  Size nbVertices() const { return myHEDS.nbVertices(); }
286 
288  Size nbEdges() const { return myHEDS.nbEdges(); }
289 
291  Size nbFaces() const { return myHEDS.nbFaces(); }
292 
296  long Euler() const { return myHEDS.Euler(); }
297 
301  {
302  return PositionsMap( *this, myPositions );
303  }
304 
306  template <typename AnyData>
308  {
309  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
310  }
311 
314  template <typename AnyData>
316  {
317  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
318  }
319 
321  template <typename AnyData>
323  {
324  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
325  }
326 
329  template <typename AnyData>
331  {
332  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
333  }
334 
336  template <typename AnyData>
338  {
339  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
340  }
341 
344  template <typename AnyData>
346  {
347  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
348  }
349 
357  const Point& position( Vertex v ) const;
358 
359  // ----------------------- Undirected simple graph services -------------------------
360  public:
364  Size size() const;
365 
373 
379  Size degree( const Vertex & v ) const;
380 
392  template <typename OutputIterator>
393  void
394  writeNeighbors( OutputIterator &it ,
395  const Vertex & v ) const;
396 
413  template <typename OutputIterator, typename VertexPredicate>
414  void
415  writeNeighbors( OutputIterator &it ,
416  const Vertex & v,
417  const VertexPredicate & pred) const;
418 
421  { return ConstIterator( 0 ); }
422 
425  { return ConstIterator( nbVertices() ); }
426 
427  // ----------------------- CombinatorialSurface --------------------------
428  public:
429 
434  ArcRange outArcs( const Vertex & v ) const;
435 
440  ArcRange inArcs( const Vertex & v ) const;
441 
446  FaceRange facesAroundVertex( const Vertex & v ) const;
447 
452  Vertex head( const Arc & a ) const;
453 
458  Vertex tail( const Arc & a ) const;
459 
464  Arc opposite( const Arc & a ) const;
465 
472  Arc next( const Arc & a ) const;
473 
481  Arc arc( const Vertex & t, const Vertex & h ) const;
482 
493  Face faceAroundArc( const Arc & a ) const;
494 
503  FaceRange facesAroundArc( const Arc & a ) const;
504 
515  VertexRange verticesAroundFace( const Face & f ) const;
516 
526  ArcRange arcsAroundFace( const Face & f ) const;
527 
533  bool isVertexBoundary( const Vertex& v ) const;
534 
541  bool isArcBoundary( const Arc& v ) const;
542 
552  ArcRange allArcs() const;
558 
567 
576 
577  // ----------------------- Interface --------------------------------------
578  public:
579 
584  void selfDisplay ( std::ostream & out ) const;
585 
590  bool isValid() const;
591 
592  // ------------------------- Protected Datas ------------------------------
593  protected:
602 
603  // ------------------------- Private Datas --------------------------------
604  private:
605 
606  // ------------------------- Hidden services ------------------------------
607  protected:
608 
609  private:
610 
611  // ------------------------- Internals ------------------------------------
612  private:
613 
614  }; // end of class PolygonalSurface
615 
616 
623  template <typename TPoint>
624  std::ostream&
625  operator<< ( std::ostream & out, const PolygonalSurface<TPoint> & object );
626 
627 } // namespace DGtal
628 
629 
631 // Includes inline functions.
632 #include "DGtal/shapes/PolygonalSurface.ih"
633 
634 // //
636 
637 #endif // !defined PolygonalSurface_h
638 
639 #undef PolygonalSurface_RECURSES
640 #endif // else defined(PolygonalSurface_RECURSES)
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:267
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
std::vector< VertexIndex > PolygonalFace
Index FaceIndex
The type for numbering faces.
Index EdgeIndex
The type for numbering edges.
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
Index VertexIndex
The type for numbering vertices.
std::size_t Size
The type for counting elements.
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it,...
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
HalfEdgeDataStructure::FaceIndex FaceIndex
ConstIterator begin() const
FaceRange facesAroundArc(const Arc &a) const
std::vector< Point > PositionsStorage
std::vector< Vertex > VertexRange
void writeNeighbors(OutputIterator &it, const Vertex &v) const
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
ConstIterator end() const
IndexedPropertyMap< AnyData > makeVertexMap() const
ArcRange allBoundaryArcs() const
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
HalfEdgeDataStructure::Index Index
HalfEdgeDataStructure::EdgeIndex EdgeIndex
FaceIndex addQuadrangle(VertexIndex v0, VertexIndex v1, VertexIndex v2, VertexIndex v3)
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
VertexRange allBoundaryVertices() const
ArcRange arcsAroundFace(const Face &f) const
HalfEdgeDataStructure::HalfEdge HalfEdge
Arc next(const Arc &a) const
Arc opposite(const Arc &a) const
Arc arc(const Vertex &t, const Vertex &h) const
FaceRange facesAroundVertex(const Vertex &v) const
PolygonalSurface(Clone< HalfEdgeDataStructure > aHeds, Clone< PositionsStorage > pos)
PolygonalFacesStorage myPolygonalFaces
Stores the polygonal faces.
bool isVertexBoundary(const Vertex &v) const
HalfEdgeDataStructure::Size Size
VertexRange verticesAroundFace(const Face &f) const
void writeNeighbors(OutputIterator &it, const Vertex &v, const VertexPredicate &pred) const
std::set< Vertex > VertexSet
IndexedPropertyMap< AnyData > makeEdgeMap() const
std::vector< PolygonalFace > PolygonalFacesStorage
void selfDisplay(std::ostream &out) const
PositionsStorage myPositions
Stores the information for each Vertex.
Point & position(Vertex v)
FaceRange allFaces() const
Vertex tail(const Arc &a) const
HalfEdgeDataStructure::Triangle Triangle
Size degree(const Vertex &v) const
IndexedPropertyMap< Point > PositionsMap
VertexIndex addVertex(const Point &vdata)
const Point & position(Vertex v) const
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
HalfEdgeDataStructure::PolygonalFace PolygonalFace
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
HalfEdgeDataStructure::HalfEdgeIndex Arc
HalfEdgeDataStructure::VertexIndex VertexIndex
IntegerSequenceIterator< VertexIndex > ConstIterator
Face faceAroundArc(const Arc &a) const
Size bestCapacity() const
Vertex head(const Arc &a) const
std::vector< Arc > ArcRange
PolygonalSurface< TPoint > Self
VertexRange allVertices() const
ArcRange outArcs(const Vertex &v) const
FaceIndex addPolygonalFace(const PolygonalFace &f)
const HalfEdgeDataStructure & heds() const
void clear()
Clears everything.
HalfEdgeDataStructure::FaceIndex Face
bool isArcBoundary(const Arc &v) const
IndexedPropertyMap< AnyData > makeFaceMap() const
std::vector< Face > FaceRange
ArcRange allArcs() const
ArcRange inArcs(const Vertex &v) const
HalfEdgeDataStructure & heds()
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
DGtal is the top-level namespace which contains all DGtal functions and types.
static std::size_t const HALF_EDGE_INVALID_INDEX
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Represents an unoriented triangle as three vertices.
const Self * mySurface
The associated polygonal surface.
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
const Data & operator[](Argument v) const
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
const Data & operator()(Argument v) const
IndexedPropertyMap()
Default constructor. The object is invalid.
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
std::map< Vertex, Value > Type