DGtal  1.3.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)
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/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 
353  Point& position( Vertex v );
357  const Point& position( Vertex v ) const;
358 
359  // ----------------------- Undirected simple graph services -------------------------
360  public:
364  Size size() const;
365 
372  Size bestCapacity() const;
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 
547  FaceRange allFaces() const;
552  ArcRange allArcs() const;
557  VertexRange allVertices() const;
558 
566  ArcRange allBoundaryArcs() const;
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)
DGtal::PolygonalSurface::end
ConstIterator end() const
Definition: PolygonalSurface.h:424
DGtal::Clone
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:266
DGtal::PolygonalSurface::size
Size size() const
DGtal::PolygonalSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
Definition: PolygonalSurface.h:142
DGtal::PolygonalSurface::nbEdges
Size nbEdges() const
Definition: PolygonalSurface.h:288
DGtal::PolygonalSurface::positions
PositionsMap positions()
Definition: PolygonalSurface.h:300
DGtal::PolygonalSurface::nbVertices
Size nbVertices() const
Definition: PolygonalSurface.h:285
DGtal::PolygonalSurface::PolygonalFace
HalfEdgeDataStructure::PolygonalFace PolygonalFace
Definition: PolygonalSurface.h:97
DGtal::PolygonalSurface::IndexedPropertyMap::size
Size size() const
Definition: PolygonalSurface.h:198
DGtal::HalfEdgeDataStructure::nbEdges
Size nbEdges() const
Definition: HalfEdgeDataStructure.h:373
DGtal::PolygonalSurface::Self
PolygonalSurface< TPoint > Self
Definition: PolygonalSurface.h:90
DGtal::PolygonalSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap()
Default constructor. The object is invalid.
Definition: PolygonalSurface.h:136
DGtal::PolygonalSurface::PositionsMap
IndexedPropertyMap< Point > PositionsMap
Definition: PolygonalSurface.h:213
DGtal::PolygonalSurface::FaceIndex
HalfEdgeDataStructure::FaceIndex FaceIndex
Definition: PolygonalSurface.h:95
DGtal::OwningOrAliasingPtr< Storage >
DGtal::PolygonalSurface::arcsAroundFace
ArcRange arcsAroundFace(const Face &f) const
DGtal::PolygonalSurface::nbFaces
Size nbFaces() const
Definition: PolygonalSurface.h:291
DGtal::PolygonalSurface::outArcs
ArcRange outArcs(const Vertex &v) const
DGtal::PolygonalSurface::IndexedPropertyMap::operator()
const Data & operator()(Argument v) const
Definition: PolygonalSurface.h:170
DGtal::PolygonalSurface::IndexedPropertyMap::Storage
std::vector< Data > Storage
Definition: PolygonalSurface.h:133
DGtal::PolygonalSurface::begin
ConstIterator begin() const
Definition: PolygonalSurface.h:420
DGtal::PolygonalSurface::bestCapacity
Size bestCapacity() const
DGtal::PolygonalSurface::arc
Arc arc(const Vertex &t, const Vertex &h) const
Face
TriMesh::Face Face
Definition: testTriangulatedSurface.cpp:56
DGtal::HalfEdgeDataStructure::Index
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
Definition: HalfEdgeDataStructure.h:89
DGtal::PolygonalSurface::heds
HalfEdgeDataStructure & heds()
Definition: PolygonalSurface.h:273
DGtal::PolygonalSurface::Vertex
VertexIndex Vertex
Definition: PolygonalSurface.h:102
DGtal::PolygonalSurface::~PolygonalSurface
~PolygonalSurface()
Definition: PolygonalSurface.h:224
DGtal::PolygonalSurface::PositionsStorage
std::vector< Point > PositionsStorage
Definition: PolygonalSurface.h:98
DGtal::HalfEdgeDataStructure::nbHalfEdges
Size nbHalfEdges() const
Definition: HalfEdgeDataStructure.h:367
DGtal::PolygonalSurface::inArcs
ArcRange inArcs(const Vertex &v) const
DGtal::PolygonalSurface::IndexedPropertyMap::storage
Storage & storage()
Definition: PolygonalSurface.h:201
DGtal::PolygonalSurface::PolygonalFacesStorage
std::vector< PolygonalFace > PolygonalFacesStorage
Definition: PolygonalSurface.h:99
DGtal::HALF_EDGE_INVALID_INDEX
static const std::size_t HALF_EDGE_INVALID_INDEX
Definition: HalfEdgeDataStructure.h:57
DGtal::PolygonalSurface::IndexedPropertyMap::Argument
Index Argument
Definition: PolygonalSurface.h:131
DGtal::PolygonalSurface::head
Vertex head(const Arc &a) const
DGtal::PolygonalSurface::ArcRange
std::vector< Arc > ArcRange
Definition: PolygonalSurface.h:115
DGtal::PolygonalSurface::position
Point & position(Vertex v)
DGtal::PolygonalSurface::Index
HalfEdgeDataStructure::Index Index
Definition: PolygonalSurface.h:92
DGtal::IntegerSequenceIterator
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it,...
Definition: IntegerSequenceIterator.h:65
DGtal::PolygonalSurface::myPolygonalFaces
PolygonalFacesStorage myPolygonalFaces
Stores the polygonal faces.
Definition: PolygonalSurface.h:601
DGtal::PolygonalSurface::EdgeIndex
HalfEdgeDataStructure::EdgeIndex EdgeIndex
Definition: PolygonalSurface.h:94
DGtal::HalfEdgeDataStructure::Euler
long Euler() const
Definition: HalfEdgeDataStructure.h:379
DGtal::HalfEdgeDataStructure::nbVertices
Size nbVertices() const
Definition: HalfEdgeDataStructure.h:370
DGtal::HalfEdgeDataStructure::HalfEdge
Definition: HalfEdgeDataStructure.h:188
Vertex
TriMesh::Vertex Vertex
Definition: testTriangulatedSurface.cpp:57
VertexRange
TriMesh::VertexRange VertexRange
Definition: testTriangulatedSurface.cpp:53
DGtal::PolygonalSurface::IndexedPropertyMap::mySurface
const Self * mySurface
The associated polygonal surface.
Definition: PolygonalSurface.h:208
DGtal::PolygonalSurface::VertexRange
std::vector< Vertex > VertexRange
Definition: PolygonalSurface.h:117
PolygonalFace
HalfEdgeDataStructure::PolygonalFace PolygonalFace
Definition: testHalfEdgeDataStructure.cpp:46
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::PolygonalSurface::degree
Size degree(const Vertex &v) const
DGtal::PolygonalSurface::Size
HalfEdgeDataStructure::Size Size
Definition: PolygonalSurface.h:91
DGtal::HalfEdgeDataStructure::HalfEdgeIndex
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
Definition: HalfEdgeDataStructure.h:91
DGtal::PolygonalSurface::IndexedPropertyMap::Data
TData Data
Definition: PolygonalSurface.h:132
DGtal::PolygonalSurface::VertexMap
Definition: PolygonalSurface.h:104
DGtal::PolygonalSurface::isHEDSValid
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
Definition: PolygonalSurface.h:595
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::HalfEdgeDataStructure::Triangle
Represents an unoriented triangle as three vertices.
Definition: HalfEdgeDataStructure.h:154
DGtal::PolygonalSurface::faceAroundArc
Face faceAroundArc(const Arc &a) const
DGtal::PolygonalSurface::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::PolygonalSurface::makeEdgeMap
IndexedPropertyMap< AnyData > makeEdgeMap() const
Definition: PolygonalSurface.h:322
DGtal::PolygonalSurface::myPositions
PositionsStorage myPositions
Stores the information for each Vertex.
Definition: PolygonalSurface.h:599
DGtal::PolygonalSurface::IndexedPropertyMap::operator[]
const Data & operator[](Argument v) const
Definition: PolygonalSurface.h:179
DGtal::PolygonalSurface::IndexedPropertyMap::myData
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
Definition: PolygonalSurface.h:210
DGtal::HalfEdgeDataStructure::Size
std::size_t Size
The type for counting elements.
Definition: HalfEdgeDataStructure.h:87
DGtal::PolygonalSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
Definition: PolygonalSurface.h:154
DGtal::PolygonalSurface::VertexSet
std::set< Vertex > VertexSet
Definition: PolygonalSurface.h:103
DGtal::PolygonalSurface::Edge
EdgeIndex Edge
Definition: PolygonalSurface.h:109
DGtal::HalfEdgeDataStructure::EdgeIndex
Index EdgeIndex
The type for numbering edges.
Definition: HalfEdgeDataStructure.h:95
DGtal::PolygonalSurface::VertexIndex
HalfEdgeDataStructure::VertexIndex VertexIndex
Definition: PolygonalSurface.h:93
DGtal::PolygonalSurface::isVertexBoundary
bool isVertexBoundary(const Vertex &v) const
DGtal::PolygonalSurface::myHEDS
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
Definition: PolygonalSurface.h:597
DGtal::PolygonalSurface::facesAroundVertex
FaceRange facesAroundVertex(const Vertex &v) const
DGtal::PolygonalSurface::Triangle
HalfEdgeDataStructure::Triangle Triangle
Definition: PolygonalSurface.h:96
DGtal::PolygonalSurface::FaceRange
std::vector< Face > FaceRange
Definition: PolygonalSurface.h:116
DGtal::PolygonalSurface::Point
TPoint Point
Definition: PolygonalSurface.h:89
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::PolygonalSurface::next
Arc next(const Arc &a) const
DGtal::HalfEdgeDataStructure
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
Definition: HalfEdgeDataStructure.h:82
DGtal::PolygonalSurface::isArcBoundary
bool isArcBoundary(const Arc &v) const
DGtal::PolygonalSurface::VertexMap::Type
std::map< Vertex, Value > Type
Definition: PolygonalSurface.h:105
DGtal::PolygonalSurface::allFaces
FaceRange allFaces() const
DGtal::PolygonalSurface::allArcs
ArcRange allArcs() const
DGtal::PolygonalSurface::build
bool build()
DGtal::PolygonalSurface::clear
void clear()
Clears everything.
DGtal::PolygonalSurface::allBoundaryArcs
ArcRange allBoundaryArcs() const
DGtal::PolygonalSurface::IndexedPropertyMap
Definition: PolygonalSurface.h:130
DGtal::PolygonalSurface::ConstIterator
IntegerSequenceIterator< VertexIndex > ConstIterator
Definition: PolygonalSurface.h:110
DGtal::PolygonalSurface::PolygonalSurface
PolygonalSurface()
Definition: PolygonalSurface.h:229
DGtal::PolygonalSurface::IndexedPropertyMap::surface
const Self & surface() const
Definition: PolygonalSurface.h:161
DGtal::PolygonalSurface::facesAroundArc
FaceRange facesAroundArc(const Arc &a) const
ArcRange
TriMesh::ArcRange ArcRange
Definition: testTriangulatedSurface.cpp:54
DGtal::PolygonalSurface::addTriangle
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
DGtal::PolygonalSurface::writeNeighbors
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DGtal::HalfEdgeDataStructure::VertexIndex
Index VertexIndex
The type for numbering vertices.
Definition: HalfEdgeDataStructure.h:93
DGtal::PolygonalSurface::Face
HalfEdgeDataStructure::FaceIndex Face
Definition: PolygonalSurface.h:114
DGtal::PolygonalSurface::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
DGtal::PolygonalSurface::makeEdgeMap
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
Definition: PolygonalSurface.h:330
DGtal::PolygonalSurface::Arc
HalfEdgeDataStructure::HalfEdgeIndex Arc
Definition: PolygonalSurface.h:113
DGtal::PolygonalSurface::tail
Vertex tail(const Arc &a) const
DGtal::HalfEdgeDataStructure::nbFaces
Size nbFaces() const
Definition: HalfEdgeDataStructure.h:376
DGtal::PolygonalSurface::nbArcs
Size nbArcs() const
Definition: PolygonalSurface.h:282
DGtal::PolygonalSurface::IndexedPropertyMap::operator[]
Data & operator[](Argument v)
Definition: PolygonalSurface.h:188
DGtal::PolygonalSurface::makeVertexMap
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
Definition: PolygonalSurface.h:315
DGtal::PolygonalSurface::IndexedPropertyMap::storage
const Storage & storage() const
Definition: PolygonalSurface.h:204
DGtal::PolygonalSurface::makeFaceMap
IndexedPropertyMap< AnyData > makeFaceMap() const
Definition: PolygonalSurface.h:337
DGtal::PolygonalSurface::allVertices
VertexRange allVertices() const
DGtal::PolygonalSurface::Euler
long Euler() const
Definition: PolygonalSurface.h:296
DGtal::HalfEdgeDataStructure::FaceIndex
Index FaceIndex
The type for numbering faces.
Definition: HalfEdgeDataStructure.h:97
DGtal::PolygonalSurface::addVertex
VertexIndex addVertex(const Point &vdata)
DGtal::PolygonalSurface::addQuadrangle
FaceIndex addQuadrangle(VertexIndex v0, VertexIndex v1, VertexIndex v2, VertexIndex v3)
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::PolygonalSurface
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
Definition: PolygonalSurface.h:86
DGtal::PolygonalSurface::IndexedPropertyMap::isValid
bool isValid() const
Definition: PolygonalSurface.h:195
DGtal::PolygonalSurface::allBoundaryVertices
VertexRange allBoundaryVertices() const
DGtal::PolygonalSurface::opposite
Arc opposite(const Arc &a) const
DGtal::PolygonalSurface::addPolygonalFace
FaceIndex addPolygonalFace(const PolygonalFace &f)
DGtal::PolygonalSurface::HalfEdge
HalfEdgeDataStructure::HalfEdge HalfEdge
Definition: PolygonalSurface.h:216
DGtal::PolygonalSurface::verticesAroundFace
VertexRange verticesAroundFace(const Face &f) const
DGtal::PolygonalSurface::makeFaceMap
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
Definition: PolygonalSurface.h:345
DGtal::PolygonalSurface::makeVertexMap
IndexedPropertyMap< AnyData > makeVertexMap() const
Definition: PolygonalSurface.h:307
DGtal::PolygonalSurface::isValid
bool isValid() const
DGtal::HalfEdgeDataStructure::PolygonalFace
std::vector< VertexIndex > PolygonalFace
Definition: HalfEdgeDataStructure.h:182
DGtal::PolygonalSurface::heds
const HalfEdgeDataStructure & heds() const
Definition: PolygonalSurface.h:277