DGtal  1.3.beta
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
84  template <typename TPoint>
86  {
87  public:
88  typedef TPoint Point;
96  typedef std::vector<Point> PositionsStorage;
97  typedef std::vector<Triangle> TriangleStorage;
98 
99  // Required by CUndirectedSimpleLocalGraph
101  typedef std::set<Vertex> VertexSet;
102  template <typename Value> struct VertexMap {
103  typedef typename std::map<Vertex, Value> Type;
104  };
105 
106  // Required by CUndirectedSimpleGraph
107  typedef EdgeIndex Edge;
109 
110  // Required for CCombinatorialSurface
113  typedef std::vector<Arc> ArcRange;
114  typedef std::vector<Face> FaceRange;
115  typedef std::vector<Vertex> VertexRange;
116 
118 
127  template <typename TData>
129  typedef Index Argument;
130  typedef TData Data;
131  typedef std::vector<Data> Storage;
132 
135 
140  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
141  : mySurface( &aSurface ),
142  myData( Storage( s, def_data ) )
143  {}
144 
152  IndexedPropertyMap( const Self& aSurface,
153  Storage& aStorage )
154  : mySurface( &aSurface ),
155  myData( &aStorage, false )
156  {}
157 
159  const Self& surface() const
160  {
161  ASSERT( isValid() );
162  return *mySurface;
163  }
164 
168  const Data& operator()( Argument v ) const
169  {
170  ASSERT( isValid() && v < myData->size() );
171  return (*myData)[ v ];
172  }
173 
177  const Data& operator[]( Argument v ) const
178  {
179  ASSERT( isValid() && v < myData->size() );
180  return (*myData)[ v ];
181  }
182 
187  {
188  ASSERT( isValid() && v < myData->size() );
189  return (*myData)[ v ];
190  }
191 
193  bool isValid() const { return mySurface != 0; }
194 
196  Size size() const { return myData->size(); }
197 
199  Storage& storage() { return *myData; }
200 
202  const Storage& storage() const { return *myData; }
203 
204  private:
206  const Self* mySurface;
209  };
210 
212 
213  protected:
215 
216  // ----------------------- Standard services ------------------------------
217  public:
218 
223 
228 
230  void clear();
231 
238  bool build();
239 
243  VertexIndex addVertex( const Point& vdata );
244 
248 
252 
255  const HalfEdgeDataStructure& heds() const { return myHEDS; }
256 
257  // ------------------------- standard services ------------------------------
258  public:
260  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
261 
263  Size nbVertices() const { return myHEDS.nbVertices(); }
264 
266  Size nbEdges() const { return myHEDS.nbEdges(); }
267 
269  Size nbFaces() const { return myHEDS.nbFaces(); }
270 
274  long Euler() const { return myHEDS.Euler(); }
275 
279  {
280  return PositionsMap( *this, myPositions );
281  }
282 
284  template <typename AnyData>
286  {
287  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
288  }
289 
292  template <typename AnyData>
294  {
295  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
296  }
297 
299  template <typename AnyData>
301  {
302  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
303  }
304 
307  template <typename AnyData>
309  {
310  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
311  }
312 
314  template <typename AnyData>
316  {
317  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
318  }
319 
322  template <typename AnyData>
324  {
325  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
326  }
327 
331  Point& position( Vertex v );
335  const Point& position( Vertex v ) const;
336 
337  // ----------------------- Undirected simple graph services -------------------------
338  public:
342  Size size() const;
343 
350  Size bestCapacity() const;
351 
357  Size degree( const Vertex & v ) const;
358 
370  template <typename OutputIterator>
371  void
372  writeNeighbors( OutputIterator &it ,
373  const Vertex & v ) const;
374 
391  template <typename OutputIterator, typename VertexPredicate>
392  void
393  writeNeighbors( OutputIterator &it ,
394  const Vertex & v,
395  const VertexPredicate & pred) const;
396 
399  { return ConstIterator( 0 ); }
400 
403  { return ConstIterator( nbVertices() ); }
404 
405  // ----------------------- CombinatorialSurface --------------------------
406  public:
407 
412  ArcRange outArcs( const Vertex & v ) const;
413 
418  ArcRange inArcs( const Vertex & v ) const;
419 
424  FaceRange facesAroundVertex( const Vertex & v ) const;
425 
430  Vertex head( const Arc & a ) const;
431 
436  Vertex tail( const Arc & a ) const;
437 
442  Arc opposite( const Arc & a ) const;
443 
450  Arc next( const Arc & a ) const;
451 
459  Arc arc( const Vertex & t, const Vertex & h ) const;
460 
471  Face faceAroundArc( const Arc & a ) const;
472 
481  FaceRange facesAroundArc( const Arc & a ) const;
482 
492  VertexRange verticesAroundFace( const Face & f ) const;
493 
503  ArcRange arcsAroundFace( const Face & f ) const;
504 
510  bool isVertexBoundary( const Vertex& v ) const;
511 
518  bool isArcBoundary( const Arc& v ) const;
519 
524  FaceRange allFaces() const;
529  ArcRange allArcs() const;
534  VertexRange allVertices() const;
535 
543  ArcRange allBoundaryArcs() const;
544 
553 
566  VertexRange verticesOfFacesAroundArc( const Arc a ) const;
567 
568  // ----------------------- Other services ---------------------------------
569  public:
570 
580  bool isFlippable( const Arc a ) const;
581 
593  void flip( const Arc a );
594 
607  Vertex split( const Arc a, const Point& data );
608 
617  bool isMergeable( const Arc a ) const;
618 
640  Vertex merge( const Arc a, const Point& data );
641 
642  // ----------------------- Interface --------------------------------------
643  public:
644 
649  void selfDisplay ( std::ostream & out ) const;
650 
655  bool isValid() const;
656 
657  // ------------------------- Protected Datas ------------------------------
658  protected:
667 
668  // ------------------------- Private Datas --------------------------------
669  private:
670 
671  // ------------------------- Hidden services ------------------------------
672  protected:
673 
674  private:
675 
676  // ------------------------- Internals ------------------------------------
677  private:
678 
679  }; // end of class TriangulatedSurface
680 
681 
688  template <typename TPoint>
689  std::ostream&
690  operator<< ( std::ostream & out, const TriangulatedSurface<TPoint> & object );
691 
692 } // namespace DGtal
693 
694 
696 // Includes inline functions.
697 #include "DGtal/shapes/TriangulatedSurface.ih"
698 
699 // //
701 
702 #endif // !defined TriangulatedSurface_h
703 
704 #undef TriangulatedSurface_RECURSES
705 #endif // else defined(TriangulatedSurface_RECURSES)
DGtal::TriangulatedSurface::verticesAroundFace
VertexRange verticesAroundFace(const Face &f) const
DGtal::TriangulatedSurface::IndexedPropertyMap::Data
TData Data
Definition: TriangulatedSurface.h:130
DGtal::TriangulatedSurface::inArcs
ArcRange inArcs(const Vertex &v) const
DGtal::TriangulatedSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap()
Default constructor. The object is invalid.
Definition: TriangulatedSurface.h:134
DGtal::HalfEdgeDataStructure::nbEdges
Size nbEdges() const
Definition: HalfEdgeDataStructure.h:373
DGtal::TriangulatedSurface::Arc
HalfEdgeDataStructure::HalfEdgeIndex Arc
Definition: TriangulatedSurface.h:111
DGtal::TriangulatedSurface::IndexedPropertyMap::operator[]
Data & operator[](Argument v)
Definition: TriangulatedSurface.h:186
DGtal::TriangulatedSurface::isMergeable
bool isMergeable(const Arc a) const
DGtal::OwningOrAliasingPtr< Storage >
DGtal::TriangulatedSurface::VertexMap::Type
std::map< Vertex, Value > Type
Definition: TriangulatedSurface.h:103
DGtal::TriangulatedSurface::IndexedPropertyMap::size
Size size() const
Definition: TriangulatedSurface.h:196
DGtal::TriangulatedSurface::clear
void clear()
Clears everything.
DGtal::TriangulatedSurface::next
Arc next(const Arc &a) const
DGtal::TriangulatedSurface::~TriangulatedSurface
~TriangulatedSurface()
Definition: TriangulatedSurface.h:222
DGtal::TriangulatedSurface::allVertices
VertexRange allVertices() const
DGtal::TriangulatedSurface::selfDisplay
void selfDisplay(std::ostream &out) 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::TriangulatedSurface::VertexMap
Definition: TriangulatedSurface.h:102
DGtal::TriangulatedSurface::makeVertexMap
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
Definition: TriangulatedSurface.h:293
DGtal::TriangulatedSurface::IndexedPropertyMap::storage
Storage & storage()
Definition: TriangulatedSurface.h:199
DGtal::TriangulatedSurface::PositionsMap
IndexedPropertyMap< Point > PositionsMap
Definition: TriangulatedSurface.h:211
DGtal::TriangulatedSurface::Triangle
HalfEdgeDataStructure::Triangle Triangle
Definition: TriangulatedSurface.h:95
DGtal::HalfEdgeDataStructure::nbHalfEdges
Size nbHalfEdges() const
Definition: HalfEdgeDataStructure.h:367
DGtal::TriangulatedSurface::isVertexBoundary
bool isVertexBoundary(const Vertex &v) const
DGtal::TriangulatedSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
Definition: TriangulatedSurface.h:140
DGtal::HALF_EDGE_INVALID_INDEX
static const std::size_t HALF_EDGE_INVALID_INDEX
Definition: HalfEdgeDataStructure.h:57
DGtal::TriangulatedSurface::VertexRange
std::vector< Vertex > VertexRange
Definition: TriangulatedSurface.h:115
DGtal::TriangulatedSurface::myTriangles
TriangleStorage myTriangles
Stores the triangles.
Definition: TriangulatedSurface.h:666
DGtal::TriangulatedSurface::addTriangle
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
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::HalfEdgeDataStructure::Euler
long Euler() const
Definition: HalfEdgeDataStructure.h:379
DGtal::HalfEdgeDataStructure::nbVertices
Size nbVertices() const
Definition: HalfEdgeDataStructure.h:370
DGtal::TriangulatedSurface::allBoundaryVertices
VertexRange allBoundaryVertices() const
DGtal::TriangulatedSurface::split
Vertex split(const Arc a, const Point &data)
DGtal::TriangulatedSurface::faceAroundArc
Face faceAroundArc(const Arc &a) const
DGtal::HalfEdgeDataStructure::HalfEdge
Definition: HalfEdgeDataStructure.h:188
Vertex
TriMesh::Vertex Vertex
Definition: testTriangulatedSurface.cpp:57
DGtal::TriangulatedSurface::makeEdgeMap
IndexedPropertyMap< AnyData > makeEdgeMap() const
Definition: TriangulatedSurface.h:300
VertexRange
TriMesh::VertexRange VertexRange
Definition: testTriangulatedSurface.cpp:53
DGtal::TriangulatedSurface::makeVertexMap
IndexedPropertyMap< AnyData > makeVertexMap() const
Definition: TriangulatedSurface.h:285
DGtal::TriangulatedSurface::nbEdges
Size nbEdges() const
Definition: TriangulatedSurface.h:266
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::HalfEdgeDataStructure::HalfEdgeIndex
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
Definition: HalfEdgeDataStructure.h:91
DGtal::TriangulatedSurface::merge
Vertex merge(const Arc a, const Point &data)
DGtal::TriangulatedSurface::flip
void flip(const Arc a)
DGtal::TriangulatedSurface::VertexIndex
HalfEdgeDataStructure::VertexIndex VertexIndex
Definition: TriangulatedSurface.h:92
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::TriangulatedSurface::IndexedPropertyMap::Argument
Index Argument
Definition: TriangulatedSurface.h:129
DGtal::TriangulatedSurface::nbFaces
Size nbFaces() const
Definition: TriangulatedSurface.h:269
DGtal::TriangulatedSurface::heds
const HalfEdgeDataStructure & heds() const
Definition: TriangulatedSurface.h:255
DGtal::TriangulatedSurface::IndexedPropertyMap::storage
const Storage & storage() const
Definition: TriangulatedSurface.h:202
DGtal::HalfEdgeDataStructure::Size
std::size_t Size
The type for counting elements.
Definition: HalfEdgeDataStructure.h:87
DGtal::TriangulatedSurface::allFaces
FaceRange allFaces() const
DGtal::TriangulatedSurface::makeEdgeMap
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
Definition: TriangulatedSurface.h:308
DGtal::TriangulatedSurface::outArcs
ArcRange outArcs(const Vertex &v) const
DGtal::TriangulatedSurface::allBoundaryArcs
ArcRange allBoundaryArcs() const
DGtal::HalfEdgeDataStructure::EdgeIndex
Index EdgeIndex
The type for numbering edges.
Definition: HalfEdgeDataStructure.h:95
DGtal::TriangulatedSurface::bestCapacity
Size bestCapacity() const
DGtal::TriangulatedSurface::IndexedPropertyMap::Storage
std::vector< Data > Storage
Definition: TriangulatedSurface.h:131
DGtal::TriangulatedSurface::ArcRange
std::vector< Arc > ArcRange
Definition: TriangulatedSurface.h:113
DGtal::TriangulatedSurface::myHEDS
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
Definition: TriangulatedSurface.h:662
DGtal::TriangulatedSurface::writeNeighbors
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DGtal::TriangulatedSurface::makeFaceMap
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
Definition: TriangulatedSurface.h:323
DGtal::TriangulatedSurface::positions
PositionsMap positions()
Definition: TriangulatedSurface.h:278
DGtal::TriangulatedSurface::IndexedPropertyMap::myData
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
Definition: TriangulatedSurface.h:208
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::TriangulatedSurface::IndexedPropertyMap::operator()
const Data & operator()(Argument v) const
Definition: TriangulatedSurface.h:168
DGtal::HalfEdgeDataStructure
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
Definition: HalfEdgeDataStructure.h:82
DGtal::TriangulatedSurface::head
Vertex head(const Arc &a) const
DGtal::TriangulatedSurface::arcsAroundFace
ArcRange arcsAroundFace(const Face &f) const
DGtal::TriangulatedSurface::PositionsStorage
std::vector< Point > PositionsStorage
Definition: TriangulatedSurface.h:96
DGtal::TriangulatedSurface::TriangulatedSurface
TriangulatedSurface()
Definition: TriangulatedSurface.h:227
DGtal::TriangulatedSurface::Vertex
VertexIndex Vertex
Definition: TriangulatedSurface.h:100
DGtal::TriangulatedSurface::position
Point & position(Vertex v)
DGtal::TriangulatedSurface::Index
HalfEdgeDataStructure::Index Index
Definition: TriangulatedSurface.h:91
DGtal::TriangulatedSurface::facesAroundVertex
FaceRange facesAroundVertex(const Vertex &v) const
DGtal::TriangulatedSurface::FaceRange
std::vector< Face > FaceRange
Definition: TriangulatedSurface.h:114
DGtal::TriangulatedSurface::opposite
Arc opposite(const Arc &a) const
DGtal::TriangulatedSurface::IndexedPropertyMap
Definition: TriangulatedSurface.h:128
DGtal::TriangulatedSurface::size
Size size() const
DGtal::TriangulatedSurface::isValid
bool isValid() const
DGtal::TriangulatedSurface::degree
Size degree(const Vertex &v) const
ArcRange
TriMesh::ArcRange ArcRange
Definition: testTriangulatedSurface.cpp:54
DGtal::TriangulatedSurface::Self
TriangulatedSurface< TPoint > Self
Definition: TriangulatedSurface.h:89
DGtal::TriangulatedSurface::isHEDSValid
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
Definition: TriangulatedSurface.h:660
DGtal::TriangulatedSurface::nbVertices
Size nbVertices() const
Definition: TriangulatedSurface.h:263
DGtal::TriangulatedSurface::Point
TPoint Point
Definition: TriangulatedSurface.h:88
DGtal::TriangulatedSurface::Edge
EdgeIndex Edge
Definition: TriangulatedSurface.h:107
DGtal::HalfEdgeDataStructure::VertexIndex
Index VertexIndex
The type for numbering vertices.
Definition: HalfEdgeDataStructure.h:93
DGtal::TriangulatedSurface::build
bool build()
DGtal::TriangulatedSurface
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
Definition: TriangulatedSurface.h:85
DGtal::TriangulatedSurface::isFlippable
bool isFlippable(const Arc a) const
DGtal::TriangulatedSurface::end
ConstIterator end() const
Definition: TriangulatedSurface.h:402
DGtal::TriangulatedSurface::FaceIndex
HalfEdgeDataStructure::FaceIndex FaceIndex
Definition: TriangulatedSurface.h:94
DGtal::TriangulatedSurface::isArcBoundary
bool isArcBoundary(const Arc &v) const
DGtal::TriangulatedSurface::arc
Arc arc(const Vertex &t, const Vertex &h) const
DGtal::TriangulatedSurface::facesAroundArc
FaceRange facesAroundArc(const Arc &a) const
DGtal::TriangulatedSurface::IndexedPropertyMap::surface
const Self & surface() const
Definition: TriangulatedSurface.h:159
DGtal::TriangulatedSurface::IndexedPropertyMap::IndexedPropertyMap
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
Definition: TriangulatedSurface.h:152
DGtal::TriangulatedSurface::IndexedPropertyMap::operator[]
const Data & operator[](Argument v) const
Definition: TriangulatedSurface.h:177
DGtal::TriangulatedSurface::addVertex
VertexIndex addVertex(const Point &vdata)
DGtal::TriangulatedSurface::HalfEdge
HalfEdgeDataStructure::HalfEdge HalfEdge
Definition: TriangulatedSurface.h:214
DGtal::TriangulatedSurface::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
DGtal::TriangulatedSurface::IndexedPropertyMap::isValid
bool isValid() const
Definition: TriangulatedSurface.h:193
DGtal::HalfEdgeDataStructure::nbFaces
Size nbFaces() const
Definition: HalfEdgeDataStructure.h:376
DGtal::TriangulatedSurface::TriangleStorage
std::vector< Triangle > TriangleStorage
Definition: TriangulatedSurface.h:97
DGtal::TriangulatedSurface::makeFaceMap
IndexedPropertyMap< AnyData > makeFaceMap() const
Definition: TriangulatedSurface.h:315
DGtal::TriangulatedSurface::tail
Vertex tail(const Arc &a) const
DGtal::HalfEdgeDataStructure::FaceIndex
Index FaceIndex
The type for numbering faces.
Definition: HalfEdgeDataStructure.h:97
DGtal::TriangulatedSurface::ConstIterator
IntegerSequenceIterator< VertexIndex > ConstIterator
Definition: TriangulatedSurface.h:108
DGtal::TriangulatedSurface::EdgeIndex
HalfEdgeDataStructure::EdgeIndex EdgeIndex
Definition: TriangulatedSurface.h:93
DGtal::TriangulatedSurface::myPositions
PositionsStorage myPositions
Stores the information for each Vertex.
Definition: TriangulatedSurface.h:664
DGtal::TriangulatedSurface::VertexSet
std::set< Vertex > VertexSet
Definition: TriangulatedSurface.h:101
DGtal::TriangulatedSurface::allArcs
ArcRange allArcs() const
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::TriangulatedSurface::nbArcs
Size nbArcs() const
Definition: TriangulatedSurface.h:260
DGtal::TriangulatedSurface::Euler
long Euler() const
Definition: TriangulatedSurface.h:274
DGtal::TriangulatedSurface::verticesOfFacesAroundArc
VertexRange verticesOfFacesAroundArc(const Arc a) const
DGtal::TriangulatedSurface::heds
HalfEdgeDataStructure & heds()
Definition: TriangulatedSurface.h:251
DGtal::TriangulatedSurface::begin
ConstIterator begin() const
Definition: TriangulatedSurface.h:398
DGtal::TriangulatedSurface::IndexedPropertyMap::mySurface
const Self * mySurface
The associated polygonal surface.
Definition: TriangulatedSurface.h:206
DGtal::TriangulatedSurface::Size
HalfEdgeDataStructure::Size Size
Definition: TriangulatedSurface.h:90
DGtal::TriangulatedSurface::Face
HalfEdgeDataStructure::FaceIndex Face
Definition: TriangulatedSurface.h:112