DGtal  1.0.0
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
84  template <typename TPoint>
86  {
87  public:
88  typedef TPoint Point;
97  typedef std::vector<Point> PositionsStorage;
98  typedef std::vector<PolygonalFace> PolygonalFacesStorage;
99 
100  // Required by CUndirectedSimpleLocalGraph
102  typedef std::set<Vertex> VertexSet;
103  template <typename Value> struct VertexMap {
104  typedef typename std::map<Vertex, Value> Type;
105  };
106 
107  // Required by CUndirectedSimpleGraph
108  typedef EdgeIndex Edge;
110 
111  // Required for CCombinatorialSurface
114  typedef std::vector<Arc> ArcRange;
115  typedef std::vector<Face> FaceRange;
116  typedef std::vector<Vertex> VertexRange;
117 
119 
128  template <typename TData>
130  typedef Index Argument;
131  typedef TData Data;
132  typedef std::vector<Data> Storage;
133 
136 
141  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
142  : mySurface( &aSurface ),
143  myData( Storage( s, def_data ) )
144  {}
145 
153  IndexedPropertyMap( const Self& aSurface,
154  Storage& aStorage )
155  : mySurface( &aSurface ),
156  myData( &aStorage, false )
157  {}
158 
160  const Self& surface() const
161  {
162  ASSERT( isValid() );
163  return *mySurface;
164  }
165 
169  const Data& operator()( Argument v ) const
170  {
171  ASSERT( isValid() && v < myData->size() );
172  return (*myData)[ v ];
173  }
174 
178  const Data& operator[]( Argument v ) const
179  {
180  ASSERT( isValid() && v < myData->size() );
181  return (*myData)[ v ];
182  }
183 
188  {
189  ASSERT( isValid() && v < myData->size() );
190  return (*myData)[ v ];
191  }
192 
194  bool isValid() const { return mySurface != 0; }
195 
197  Size size() const { return myData->size(); }
198 
200  Storage& storage() { return *myData; }
201 
203  const Storage& storage() const { return *myData; }
204 
205  private:
207  const Self* mySurface;
210  };
211 
213 
214  protected:
216 
217  // ----------------------- Standard services ------------------------------
218  public:
219 
224 
229 
241 
243  void clear();
244 
251  bool build();
252 
256  VertexIndex addVertex( const Point& vdata );
257 
261 
265 
269 
272  { return myHEDS; }
273 
274  // ------------------------- standard services ------------------------------
275  public:
277  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
278 
280  Size nbVertices() const { return myHEDS.nbVertices(); }
281 
283  Size nbEdges() const { return myHEDS.nbEdges(); }
284 
286  Size nbFaces() const { return myHEDS.nbFaces(); }
287 
291  long Euler() const { return myHEDS.Euler(); }
292 
296  {
297  return PositionsMap( *this, myPositions );
298  }
299 
301  template <typename AnyData>
303  {
304  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
305  }
306 
309  template <typename AnyData>
311  {
312  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
313  }
314 
316  template <typename AnyData>
318  {
319  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
320  }
321 
324  template <typename AnyData>
326  {
327  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
328  }
329 
331  template <typename AnyData>
333  {
334  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
335  }
336 
339  template <typename AnyData>
341  {
342  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
343  }
344 
348  Point& position( Vertex v );
352  const Point& position( Vertex v ) const;
353 
354  // ----------------------- Undirected simple graph services -------------------------
355  public:
359  Size size() const;
360 
367  Size bestCapacity() const;
368 
374  Size degree( const Vertex & v ) const;
375 
387  template <typename OutputIterator>
388  void
389  writeNeighbors( OutputIterator &it ,
390  const Vertex & v ) const;
391 
408  template <typename OutputIterator, typename VertexPredicate>
409  void
410  writeNeighbors( OutputIterator &it ,
411  const Vertex & v,
412  const VertexPredicate & pred) const;
413 
416  { return ConstIterator( 0 ); }
417 
420  { return ConstIterator( nbVertices() ); }
421 
422  // ----------------------- CombinatorialSurface --------------------------
423  public:
424 
429  ArcRange outArcs( const Vertex & v ) const;
430 
435  ArcRange inArcs( const Vertex & v ) const;
436 
441  FaceRange facesAroundVertex( const Vertex & v ) const;
442 
447  Vertex head( const Arc & a ) const;
448 
453  Vertex tail( const Arc & a ) const;
454 
459  Arc opposite( const Arc & a ) const;
460 
467  Arc next( const Arc & a ) const;
468 
476  Arc arc( const Vertex & t, const Vertex & h ) const;
477 
488  Face faceAroundArc( const Arc & a ) const;
489 
498  FaceRange facesAroundArc( const Arc & a ) const;
499 
510  VertexRange verticesAroundFace( const Face & f ) const;
511 
521  ArcRange arcsAroundFace( const Face & f ) const;
522 
528  bool isVertexBoundary( const Vertex& v ) const;
529 
536  bool isArcBoundary( const Arc& v ) const;
537 
542  FaceRange allFaces() const;
547  ArcRange allArcs() const;
552  VertexRange allVertices() const;
553 
561  ArcRange allBoundaryArcs() const;
562 
571 
572  // ----------------------- Interface --------------------------------------
573  public:
574 
579  void selfDisplay ( std::ostream & out ) const;
580 
585  bool isValid() const;
586 
587  // ------------------------- Protected Datas ------------------------------
588  protected:
597 
598  // ------------------------- Private Datas --------------------------------
599  private:
600 
601  // ------------------------- Hidden services ------------------------------
602  protected:
603 
604  private:
605 
606  // ------------------------- Internals ------------------------------------
607  private:
608 
609  }; // end of class PolygonalSurface
610 
611 
618  template <typename TPoint>
619  std::ostream&
620  operator<< ( std::ostream & out, const PolygonalSurface<TPoint> & object );
621 
622 } // namespace DGtal
623 
624 
626 // Includes inline functions.
627 #include "DGtal/shapes/PolygonalSurface.ih"
628 
629 // //
631 
632 #endif // !defined PolygonalSurface_h
633 
634 #undef PolygonalSurface_RECURSES
635 #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.
const HalfEdgeDataStructure & heds() const
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
FaceRange allFaces() const
FaceIndex addQuadrangle(VertexIndex v0, VertexIndex v1, VertexIndex v2, VertexIndex v3)
IndexedPropertyMap< AnyData > makeFaceMap() const
IndexedPropertyMap< AnyData > makeVertexMap() const
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:266
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
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
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
ArcRange arcsAroundFace(const Face &f) 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...