DGtal  1.0.0
IndexedDigitalSurface.h
1 
17 #pragma once
18 
31 #if defined(IndexedDigitalSurface_RECURSES)
32 #error Recursive header files inclusion detected in IndexedDigitalSurface.h
33 #else // defined(IndexedDigitalSurface_RECURSES)
34 
35 #define IndexedDigitalSurface_RECURSES
36 
37 #if !defined IndexedDigitalSurface_h
38 
39 #define IndexedDigitalSurface_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <set>
45 #include <map>
46 #include <vector>
47 #include "DGtal/base/Common.h"
48 #include "DGtal/base/OwningOrAliasingPtr.h"
49 #include "DGtal/base/IntegerSequenceIterator.h"
50 #include "DGtal/topology/HalfEdgeDataStructure.h"
51 #include "DGtal/topology/CDigitalSurfaceContainer.h"
53 
54 namespace DGtal
55 {
56 
58  // template class IndexedDigitalSurface
95  template <typename TDigitalSurfaceContainer>
97  {
98  public:
100  typedef TDigitalSurfaceContainer DigitalSurfaceContainer;
102 
104  typedef typename KSpace::Space Space;
105  typedef typename KSpace::Surfel Surfel;
106  typedef typename KSpace::SCell SCell;
107  typedef typename KSpace::Cell Cell;
108  typedef typename Space::RealPoint RealPoint;
116  typedef std::vector<RealPoint> PositionsStorage;
117  typedef std::vector<PolygonalFace> PolygonalFacesStorage;
118  typedef std::vector<SCell> SCellStorage;
119 
120  // Required by CUndirectedSimpleLocalGraph
122  typedef std::set<Vertex> VertexSet;
123  template <typename Value> struct VertexMap {
124  typedef typename std::map<Vertex, Value> Type;
125  };
126 
127  // Required by CUndirectedSimpleGraph
128  typedef EdgeIndex Edge;
130 
131  // Required for CCombinatorialSurface
134  typedef std::vector<Arc> ArcRange;
135  typedef std::vector<Face> FaceRange;
136  typedef std::vector<Vertex> VertexRange;
137 
139 
148  template <typename TData>
150  typedef Index Argument;
151  typedef TData Data;
152  typedef std::vector<Data> Storage;
153 
156 
161  IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
162  : mySurface( &aSurface ),
163  myData( Storage( s, def_data ) )
164  {}
165 
173  IndexedPropertyMap( const Self& aSurface,
174  Storage& aStorage )
175  : mySurface( &aSurface ),
176  myData( &aStorage, false )
177  {}
178 
180  const Self& surface() const
181  {
182  ASSERT( isValid() );
183  return *mySurface;
184  }
185 
189  const Data& operator()( Argument v ) const
190  {
191  ASSERT( isValid() && v < myData->size() );
192  return (*myData)[ v ];
193  }
194 
198  const Data& operator[]( Argument v ) const
199  {
200  ASSERT( isValid() && v < myData->size() );
201  return (*myData)[ v ];
202  }
203 
208  {
209  ASSERT( isValid() && v < myData->size() );
210  return (*myData)[ v ];
211  }
212 
214  bool isValid() const { return mySurface != 0; }
215 
217  Size size() const { return myData->size(); }
218 
220  Storage& storage() { return *myData; }
221 
223  const Storage& storage() const { return *myData; }
224 
225  private:
227  const Self* mySurface;
230  };
231 
233 
234  protected:
236 
237  // ----------------------- Standard services ------------------------------
238  public:
239 
244 
249 
255  : isHEDSValid( false ), myContainer( 0 )
256  {
257  build( surfContainer );
258  }
259 
261  void clear();
262 
273  bool build( ConstAlias< DigitalSurfaceContainer > surfContainer );
274 
279  { return *myContainer; }
280 
282  const KSpace& space() const
283  { return myContainer->space(); }
284 
287  { return myHEDS; }
288 
289  // ------------------------- standard services ------------------------------
290  public:
292  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
293 
295  Size nbVertices() const { return myHEDS.nbVertices(); }
296 
298  Size nbEdges() const { return myHEDS.nbEdges(); }
299 
301  Size nbFaces() const { return myHEDS.nbFaces(); }
302 
306  long Euler() const { return myHEDS.Euler(); }
307 
311  {
312  return PositionsMap( *this, myPositions );
313  }
314 
318  {
320  }
321 
325  {
326  return IndexedPropertyMap< SCell >( *this, myArc2Linel );
327  }
328 
332  {
334  }
335 
337  template <typename AnyData>
339  {
340  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
341  }
342 
345  template <typename AnyData>
347  {
348  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
349  }
350 
352  template <typename AnyData>
354  {
355  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
356  }
357 
360  template <typename AnyData>
362  {
363  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
364  }
365 
367  template <typename AnyData>
369  {
370  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
371  }
372 
375  template <typename AnyData>
377  {
378  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
379  }
380 
384  RealPoint& position( Vertex v );
388  const RealPoint& position( Vertex v ) const;
389 
392  const SCell& surfel( Vertex v ) const
393  {
394  ASSERT( v < nbVertices() );
395  return myVertexIndex2Surfel[ v ];
396  }
397 
400  const SCell& linel( Arc a ) const
401  {
402  ASSERT( a < nbArcs() );
403  return myArc2Linel[ a ];
404  }
405 
408  const SCell& pointel( Face f ) const
409  {
410  ASSERT( f < nbFaces() );
411  return myFaceIndex2Pointel[ f ];
412  }
413 
418  Vertex getVertex( const SCell& aSurfel ) const
419  {
420  auto it = mySurfel2VertexIndex.find( aSurfel );
421  return it != mySurfel2VertexIndex.end() ? it->second : INVALID_FACE;
422  }
423 
428  Arc getArc( const SCell& aLinel ) const
429  {
430  auto it = myLinel2Arc.find( aLinel );
431  return it != myLinel2Arc.end() ? it->second : INVALID_FACE;
432  }
433 
438  Face getFace( const SCell& aPointel ) const
439  {
440  auto it = myPointel2FaceIndex.find( aPointel );
441  return it != myPointel2FaceIndex.end() ? it->second : INVALID_FACE;
442  }
443 
444  // ----------------------- Undirected simple graph services -------------------------
445  public:
449  Size size() const;
450 
457  Size bestCapacity() const;
458 
464  Size degree( const Vertex & v ) const;
465 
477  template <typename OutputIterator>
478  void
479  writeNeighbors( OutputIterator &it ,
480  const Vertex & v ) const;
481 
498  template <typename OutputIterator, typename VertexPredicate>
499  void
500  writeNeighbors( OutputIterator &it ,
501  const Vertex & v,
502  const VertexPredicate & pred) const;
503 
506  { return ConstIterator( 0 ); }
507 
510  { return ConstIterator( nbVertices() ); }
511 
512  // ----------------------- CombinatorialSurface --------------------------
513  public:
514 
519  ArcRange outArcs( const Vertex & v ) const;
520 
525  ArcRange inArcs( const Vertex & v ) const;
526 
531  FaceRange facesAroundVertex( const Vertex & v ) const;
532 
537  Vertex head( const Arc & a ) const;
538 
543  Vertex tail( const Arc & a ) const;
544 
549  Arc opposite( const Arc & a ) const;
550 
557  Arc next( const Arc & a ) const;
558 
566  Arc arc( const Vertex & t, const Vertex & h ) const;
567 
578  Face faceAroundArc( const Arc & a ) const;
579 
588  FaceRange facesAroundArc( const Arc & a ) const;
589 
600  VertexRange verticesAroundFace( const Face & f ) const;
601 
607  bool isVertexBoundary( const Vertex& v ) const;
608 
615  bool isArcBoundary( const Arc& v ) const;
616 
621  FaceRange allFaces() const;
626  ArcRange allArcs() const;
631  VertexRange allVertices() const;
632 
640  ArcRange allBoundaryArcs() const;
641 
650 
651  // ----------------------- Interface --------------------------------------
652  public:
653 
658  void selfDisplay ( std::ostream & out ) const;
659 
664  bool isValid() const;
665 
666  // ------------------------- Protected Datas ------------------------------
667  protected:
674 
680  std::map< SCell, VertexIndex > mySurfel2VertexIndex;
682  std::map< SCell, Arc > myLinel2Arc;
684  std::map< SCell, FaceIndex > myPointel2FaceIndex;
691 
692 
693  // ------------------------- Private Datas --------------------------------
694  private:
695 
696  // ------------------------- Hidden services ------------------------------
697  protected:
698 
699  private:
700 
701  // ------------------------- Internals ------------------------------------
702  private:
703 
704  }; // end of class IndexedDigitalSurface
705 
706 
713  template <typename TDigitalSurfaceContainer>
714  std::ostream&
715  operator<< ( std::ostream & out,
717 
718 } // namespace DGtal
719 
720 
722 // Includes inline functions.
723 #include "DGtal/topology/IndexedDigitalSurface.ih"
724 
725 // //
727 
728 #endif // !defined IndexedDigitalSurface_h
729 
730 #undef IndexedDigitalSurface_RECURSES
731 #endif // else defined(IndexedDigitalSurface_RECURSES)
Index FaceIndex
The type for numbering faces.
HalfEdgeDataStructure::HalfEdge HalfEdge
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
VertexRange allVertices() const
std::vector< PolygonalFace > PolygonalFacesStorage
Arc arc(const Vertex &t, const Vertex &h) const
TriMesh::VertexRange VertexRange
IndexedPropertyMap< SCell > surfels()
Arc opposite(const Arc &a) const
CountedConstPtrOrConstPtr< DigitalSurfaceContainer > myContainer
The (secured or not) pointer to the associated digital surface container.
SCellStorage myFaceIndex2Pointel
Mapping FaceIndex -> Pointel.
HalfEdgeDataStructure::FaceIndex FaceIndex
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
void selfDisplay(std::ostream &out) const
Arc getArc(const SCell &aLinel) const
bool build(ConstAlias< DigitalSurfaceContainer > surfContainer)
TriMesh::Face Face
HalfEdgeDataStructure::FaceIndex Face
RealPoint & position(Vertex v)
bool isVertexBoundary(const Vertex &v) const
HalfEdgeDataStructure::Index Index
Represents an unoriented triangle as three vertices.
IntegerSequenceIterator< VertexIndex > ConstIterator
bool isArcBoundary(const Arc &v) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
IndexedPropertyMap< AnyData > makeFaceMap() const
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
Face getFace(const SCell &aPointel) const
const SCell & linel(Arc a) const
Vertex getVertex(const SCell &aSurfel) const
const Self * mySurface
The associated indexed digital surface.
SCellStorage myVertexIndex2Surfel
Mapping VertexIndex -> Surfel.
std::map< SCell, Arc > myLinel2Arc
Mapping Linel -> Arc.
IndexedPropertyMap()
Default constructor. The object is invalid.
SCellStorage myArc2Linel
Mapping Arc -> Linel.
FaceRange facesAroundVertex(const Vertex &v) const
const SCell & pointel(Face f) const
IndexedPropertyMap< SCell > pointels()
ArcRange allBoundaryArcs() const
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
void clear()
Clears everything.
Size degree(const Vertex &v) const
FaceRange facesAroundArc(const Arc &a) const
std::vector< VertexIndex > PolygonalFace
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
const HalfEdgeDataStructure & heds() const
const DigitalSurfaceContainer & container() const
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())
TriMesh::Vertex Vertex
HalfEdgeDataStructure::Triangle Triangle
PolygonalFacesStorage myPolygonalFaces
Stores the polygonal faces.
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it,...
std::map< SCell, VertexIndex > mySurfel2VertexIndex
Mapping Surfel -> VertexIndex.
Z3i::KSpace KSpace
VertexRange allBoundaryVertices() const
IndexedPropertyMap< SCell > linels()
std::vector< RealPoint > PositionsStorage
DGtal is the top-level namespace which contains all DGtal functions and types.
Arc next(const Arc &a) const
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
Vertex tail(const Arc &a) const
const SCell & surfel(Vertex v) const
Vertex head(const Arc &a) const
TDigitalSurfaceContainer DigitalSurfaceContainer
ArcRange outArcs(const Vertex &v) const
Aim: Represents a digital surface with the topology of its dual surface. Its aim is to mimick the sta...
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
HalfEdgeDataStructure::VertexIndex VertexIndex
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
FaceRange allFaces() const
PositionsStorage myPositions
Stores the information for each Vertex.
DigitalSurfaceContainer::KSpace KSpace
IndexedDigitalSurface< TDigitalSurfaceContainer > Self
Index VertexIndex
The type for numbering vertices.
HalfEdgeDataStructure::EdgeIndex EdgeIndex
HalfEdgeDataStructure::HalfEdgeIndex Arc
VertexRange verticesAroundFace(const Face &f) const
HalfEdgeDataStructure::Size Size
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
IndexedPropertyMap< AnyData > makeEdgeMap() const
std::map< SCell, FaceIndex > myPointel2FaceIndex
Mapping Pointel -> FaceIndex.
std::size_t Size
The type for counting elements.
IndexedPropertyMap< AnyData > makeVertexMap() const
Face faceAroundArc(const Arc &a) const
static std::size_t const HALF_EDGE_INVALID_INDEX
IndexedPropertyMap< RealPoint > PositionsMap
TriMesh::ArcRange ArcRange
IndexedDigitalSurface(ConstAlias< DigitalSurfaceContainer > surfContainer)
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
Index EdgeIndex
The type for numbering edges.
void writeNeighbors(OutputIterator &it, const Vertex &v) const
ArcRange inArcs(const Vertex &v) const
HalfEdgeDataStructure::PolygonalFace PolygonalFace