DGtal  0.9.4.1
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 
103  typedef typename DigitalSurfaceContainer::KSpace KSpace;
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 
285  // ------------------------- standard services ------------------------------
286  public:
288  Size nbArcs() const { return myHEDS.nbHalfEdges(); }
289 
291  Size nbVertices() const { return myHEDS.nbVertices(); }
292 
294  Size nbEdges() const { return myHEDS.nbEdges(); }
295 
297  Size nbFaces() const { return myHEDS.nbFaces(); }
298 
302  long Euler() const { return myHEDS.Euler(); }
303 
307  {
308  return PositionsMap( *this, myPositions );
309  }
310 
314  {
316  }
317 
321  {
322  return IndexedPropertyMap< SCell >( *this, myArc2Linel );
323  }
324 
328  {
330  }
331 
333  template <typename AnyData>
335  {
336  return IndexedPropertyMap< AnyData >( *this, nbVertices() );
337  }
338 
341  template <typename AnyData>
343  {
344  return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
345  }
346 
348  template <typename AnyData>
350  {
351  return IndexedPropertyMap< AnyData >( *this, nbEdges() );
352  }
353 
356  template <typename AnyData>
358  {
359  return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
360  }
361 
363  template <typename AnyData>
365  {
366  return IndexedPropertyMap< AnyData >( *this, nbFaces() );
367  }
368 
371  template <typename AnyData>
373  {
374  return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
375  }
376 
380  RealPoint& position( Vertex v );
384  const RealPoint& position( Vertex v ) const;
385 
388  const SCell& surfel( Vertex v ) const
389  {
390  ASSERT( v < nbVertices() );
391  return myVertexIndex2Surfel[ v ];
392  }
393 
396  const SCell& linel( Arc a ) const
397  {
398  ASSERT( a < nbArcs() );
399  return myArc2Linel[ a ];
400  }
401 
404  const SCell& pointel( Face f ) const
405  {
406  ASSERT( f < nbFaces() );
407  return myFaceIndex2Pointel[ f ];
408  }
409 
414  Vertex getVertex( const SCell& aSurfel ) const
415  {
416  auto it = mySurfel2VertexIndex.find( aSurfel );
417  return it != mySurfel2VertexIndex.end() ? it->second : INVALID_FACE;
418  }
419 
424  Arc getArc( const SCell& aLinel ) const
425  {
426  auto it = myLinel2Arc.find( aLinel );
427  return it != myLinel2Arc.end() ? it->second : INVALID_FACE;
428  }
429 
434  Face getFace( const SCell& aPointel ) const
435  {
436  auto it = myPointel2FaceIndex.find( aPointel );
437  return it != myPointel2FaceIndex.end() ? it->second : INVALID_FACE;
438  }
439 
440  // ----------------------- Undirected simple graph services -------------------------
441  public:
445  Size size() const;
446 
453  Size bestCapacity() const;
454 
460  Size degree( const Vertex & v ) const;
461 
473  template <typename OutputIterator>
474  void
475  writeNeighbors( OutputIterator &it ,
476  const Vertex & v ) const;
477 
494  template <typename OutputIterator, typename VertexPredicate>
495  void
496  writeNeighbors( OutputIterator &it ,
497  const Vertex & v,
498  const VertexPredicate & pred) const;
499 
502  { return ConstIterator( 0 ); }
503 
506  { return ConstIterator( nbVertices() ); }
507 
508  // ----------------------- CombinatorialSurface --------------------------
509  public:
510 
515  ArcRange outArcs( const Vertex & v ) const;
516 
521  ArcRange inArcs( const Vertex & v ) const;
522 
527  FaceRange facesAroundVertex( const Vertex & v ) const;
528 
533  Vertex head( const Arc & a ) const;
534 
539  Vertex tail( const Arc & a ) const;
540 
545  Arc opposite( const Arc & a ) const;
546 
553  Arc next( const Arc & a ) const;
554 
562  Arc arc( const Vertex & t, const Vertex & h ) const;
563 
574  Face faceAroundArc( const Arc & a ) const;
575 
584  FaceRange facesAroundArc( const Arc & a ) const;
585 
596  VertexRange verticesAroundFace( const Face & f ) const;
597 
603  bool isVertexBoundary( const Vertex& v ) const;
604 
611  bool isArcBoundary( const Arc& v ) const;
612 
617  FaceRange allFaces() const;
622  ArcRange allArcs() const;
627  VertexRange allVertices() const;
628 
636  ArcRange allBoundaryArcs() const;
637 
646 
647  // ----------------------- Interface --------------------------------------
648  public:
649 
654  void selfDisplay ( std::ostream & out ) const;
655 
660  bool isValid() const;
661 
662  // ------------------------- Protected Datas ------------------------------
663  protected:
670 
676  std::map< SCell, VertexIndex > mySurfel2VertexIndex;
678  std::map< SCell, Arc > myLinel2Arc;
680  std::map< SCell, FaceIndex > myPointel2FaceIndex;
687 
688 
689  // ------------------------- Private Datas --------------------------------
690  private:
691 
692  // ------------------------- Hidden services ------------------------------
693  protected:
694 
695  private:
696 
697  // ------------------------- Internals ------------------------------------
698  private:
699 
700  }; // end of class IndexedDigitalSurface
701 
702 
709  template <typename TDigitalSurfaceContainer>
710  std::ostream&
711  operator<< ( std::ostream & out,
713 
714 } // namespace DGtal
715 
716 
718 // Includes inline functions.
719 #include "DGtal/topology/IndexedDigitalSurface.ih"
720 
721 // //
723 
724 #endif // !defined IndexedDigitalSurface_h
725 
726 #undef IndexedDigitalSurface_RECURSES
727 #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.
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
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:141
IndexedPropertyMap< AnyData > makeFaceMap() const
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
Face getFace(const SCell &aPointel) const
const SCell & linel(Arc a) const
TriMesh::Arc Arc
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 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.
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