DGtal  0.9.2
DigitalSurface.h
1 
17 #pragma once
18 
31 #if defined(DigitalSurface_RECURSES)
32 #error Recursive header files inclusion detected in DigitalSurface.h
33 #else // defined(DigitalSurface_RECURSES)
34 
35 #define DigitalSurface_RECURSES
36 
37 #if !defined DigitalSurface_h
38 
39 #define DigitalSurface_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include <set>
46 // JOL (2013/02/01): required to define internal tags (boost/graph/copy.hpp, l. 251 error ?).
47 #include <boost/graph/graph_traits.hpp>
48 #include <boost/graph/properties.hpp>
49 #include "DGtal/base/Common.h"
50 #include "DGtal/base/CountedPtr.h"
51 #include "DGtal/kernel/CWithGradientMap.h"
52 #include "DGtal/topology/CCellEmbedder.h"
53 #include "DGtal/topology/CSCellEmbedder.h"
54 #include "DGtal/topology/CDigitalSurfaceContainer.h"
55 #include "DGtal/topology/CDigitalSurfaceTracker.h"
56 #include "DGtal/topology/UmbrellaComputer.h"
58 namespace boost
59 {
64  : public virtual adjacency_graph_tag,
65  public virtual vertex_list_graph_tag,
66  public virtual incidence_graph_tag,
67  public virtual edge_list_graph_tag { };
68 }
69 
70 namespace DGtal
71 {
72 
74  // template class DigitalSurface
120  template <typename TDigitalSurfaceContainer>
122  {
123  public:
124  typedef TDigitalSurfaceContainer DigitalSurfaceContainer;
126 
127  // ----------------------- boost graph tags ------------------------------
128  // JOL (2013/02/01): required to define internal tags (boost/graph/copy.hpp, l. 251 error ?).
129  public:
131  typedef boost::undirected_tag directed_category;
135  typedef boost::disallow_parallel_edge_tag edge_parallel_category;
136 
137 
138  // ----------------------- types ------------------------------
139  public:
141  typedef typename DigitalSurfaceContainer::KSpace KSpace;
142  typedef typename DigitalSurfaceContainer::Cell Cell;
143  typedef typename DigitalSurfaceContainer::SCell SCell;
144  typedef typename DigitalSurfaceContainer::Surfel Surfel;
145  typedef typename DigitalSurfaceContainer::SurfelConstIterator ConstIterator;
146  typedef typename DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker;
147  typedef typename KSpace::Point Point;
148  typedef typename KSpace::SurfelSet SurfelSet;
151  template <typename Value> struct SurfelMap {
152  typedef typename KSpace::template SurfelMap<Value>::Type Type;
153  };
154 
155  // ----------------------- UndirectedSimpleGraph --------------------------
156  public:
158  typedef Surfel Vertex;
160  typedef typename KSpace::Size Size;
162  typedef typename KSpace::SurfelSet VertexSet;
165  template <typename Value> struct VertexMap {
166  typedef typename KSpace::template SurfelMap<Value>::Type Type;
167  };
173  struct Edge {
175  Vertex vertices[ 2 ];
181  Edge( const Vertex & v1, const Vertex & v2 )
182  {
183  if ( v1 <= v2 )
184  {
185  vertices[ 0 ] = v1;
186  vertices[ 1 ] = v2;
187  }
188  else
189  {
190  vertices[ 0 ] = v2;
191  vertices[ 1 ] = v1;
192  }
193  }
194  bool operator==( const Edge & other ) const
195  {
196  return ( vertices[ 0 ] == other.vertices[ 0 ] )
197  && ( vertices[ 1 ] == other.vertices[ 1 ] );
198  }
199  bool operator<( const Edge & other ) const
200  {
201  return ( vertices[ 0 ] < other.vertices[ 0 ] )
202  || ( ( vertices[ 0 ] == other.vertices[ 0 ] )
203  && ( vertices[ 1 ] < other.vertices[ 1 ] ) );
204  }
205 
206  };
207 
208  // ----------------------- CombinatorialSurface --------------------------
209  public:
210 
215  typedef typename Umbrella::State UmbrellaState;
216 
219  struct Arc {
220  Vertex base;
222  bool epsilon;
223 
226  inline Arc()
227  : base(), k( 0 ), epsilon( false ) {}
228  inline Arc( const Vertex & theTail, Dimension aK, bool aEpsilon )
229  : base( theTail ), k( aK ), epsilon( aEpsilon ) {}
230  inline bool operator==( const Arc & other ) const
231  {
232  return ( base == other.base )
233  && ( k == other.k ) && ( epsilon == other.epsilon );
234  }
235  inline bool operator<( const Arc & other ) const
236  {
237  return ( base < other.base )
238  || ( ( base == other.base )
239  && ( ( k < other.k )
240  || ( ( k == other.k )
241  && ( epsilon < other.epsilon ) ) ) );
242  }
243  inline bool operator!=( const Arc & other ) const
244  {
245  return ( base != other.base )
246  || ( k != other.k ) || ( epsilon != other.epsilon );
247  }
248  };
249 
259  struct Face {
260  UmbrellaState state;
261  unsigned int nbVertices;
263  bool closed;
264  inline Face( const UmbrellaState & aState,
265  unsigned int nb, bool aIsClosed )
266  : state( aState ), nbVertices( nb ), closed( aIsClosed )
267  {}
268  inline bool isClosed() const
269  { return closed; }
270  inline bool operator==( const Face & other ) const
271  {
272  return state == other.state;
273  }
274  inline bool operator<( const Face & other ) const
275  {
276  return state < other.state;
277  }
278 
279  };
280 
282  typedef std::vector<Arc> ArcRange;
284  typedef std::vector<Face> FaceRange;
286  typedef std::vector<Vertex> VertexRange;
288  typedef std::set<Face> FaceSet;
289 
290 
291  // ----------------------- Standard services ------------------------------
292  public:
293 
297  ~DigitalSurface();
298 
303  DigitalSurface ( const DigitalSurface & other );
304 
309  DigitalSurface( const DigitalSurfaceContainer & container );
310 
315  DigitalSurface( DigitalSurfaceContainer* containerPtr );
316 
322  DigitalSurface & operator= ( const DigitalSurface & other );
323 
324  // ----------------------- Services --------------------------------------
325  public:
326 
330  const DigitalSurfaceContainer & container() const;
331 
336  DigitalSurfaceContainer & container();
337 
338  // ----------------- UndirectedSimpleGraph realization --------------------
339  public:
340 
383  ConstIterator begin() const;
384 
388  ConstIterator end() const;
389 
391  Size size() const;
392 
398  Size degree( const Vertex & v ) const;
399 
408  Size bestCapacity() const;
409 
424  template <typename OutputIterator>
425  void writeNeighbors( OutputIterator & it,
426  const Vertex & v ) const;
427 
447  template <typename OutputIterator, typename VertexPredicate>
448  void writeNeighbors( OutputIterator & it,
449  const Vertex & v,
450  const VertexPredicate & pred ) const;
451 
452 
453  // ----------------------- CombinatorialSurface --------------------------
454  public:
455 
460  ArcRange outArcs( const Vertex & v ) const;
461 
466  ArcRange inArcs( const Vertex & v ) const;
467 
473  FaceRange facesAroundVertex( const Vertex & v ) const;
474 
479  Vertex head( const Arc & a ) const;
480 
485  Vertex tail( const Arc & a ) const;
486 
491  Arc opposite( const Arc & a ) const;
492 
500  Arc arc( const Vertex & tail, const Vertex & head ) const;
501 
509  FaceRange facesAroundArc( const Arc & a ) const;
510 
520  VertexRange verticesAroundFace( const Face & f ) const;
521 
526  FaceSet allFaces() const;
527 
532  FaceSet allClosedFaces() const;
533 
539  FaceSet allOpenFaces() const;
540 
545  Face computeFace( UmbrellaState state ) const;
546 
552  SCell separator( const Arc & a ) const;
553 
561  SCell pivot( const Face & f ) const;
562 
563 
564  // ----------------------- Interface --------------------------------------
565  public:
566 
571  void selfDisplay ( std::ostream & out ) const;
572 
577  bool isValid() const;
578 
585  void exportSurfaceAs3DOFF ( std::ostream & out ) const;
586 
597  template <typename CellEmbedder>
598  void exportEmbeddedSurfaceAs3DOFF ( std::ostream & out,
599  const CellEmbedder & cembedder ) const;
600 
611  template <typename CellEmbedder>
612  void exportEmbeddedSurfaceAs3DNOFF ( std::ostream & out,
613  const CellEmbedder & cembedder ) const;
614 
626  template <typename SCellEmbedderWithGradientMap>
627  void exportAs3DNOFF( std::ostream & out,
628  const SCellEmbedderWithGradientMap & scembedder ) const;
629 
638  template <typename CellEmbedder>
639  void exportEmbeddedIteratedSurfaceAs3DNOFF ( std::ostream & out,
640  const CellEmbedder & cembedder ) const;
641 
642  // ------------------------- Protected Datas ------------------------------
643  private:
644  // ------------------------- Private Datas --------------------------------
645  private:
646 
650  mutable DigitalSurfaceTracker* myTracker;
653 
654  // ------------------------- Hidden services ------------------------------
655  protected:
656 
661  DigitalSurface();
662 
663  private:
664 
665 
666  // ------------------------- Internals ------------------------------------
667  private:
668 
669  }; // end of class DigitalSurface
670 
671 
678  template <typename TDigitalSurfaceContainer>
679  std::ostream&
680  operator<< ( std::ostream & out,
682 
683 } // namespace DGtal
684 
685 
687 // Includes inline functions.
688 #include "DGtal/topology/DigitalSurface.ih"
689 
690 // //
692 
693 #endif // !defined DigitalSurface_h
694 
695 #undef DigitalSurface_RECURSES
696 #endif // else defined(DigitalSurface_RECURSES)
bool operator!=(const Arc &other) const
UmbrellaComputer< DigitalSurfaceTracker > myUmbrellaComputer
This object is used to compute umbrellas over the surface.
Arc arc(const Vertex &tail, const Vertex &head) const
SCell separator(const Arc &a) const
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
bool operator==(const Edge &other) const
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
DigitalSurface< DigitalSurfaceContainer > Self
void exportEmbeddedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
ArcRange outArcs(const Vertex &v) const
Definition: Boost.dox:28
SCell pivot(const Face &f) const
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Face computeFace(UmbrellaState state) const
DGtal::uint32_t Dimension
Definition: Common.h:113
Vertex vertices[2]
The two vertices.
bool operator<(const Face &other) const
Size size() const
KSpace::SurfelSet SurfelSet
KSpace::template SurfelMap< Value >::Type Type
bool isValid() const
Vertex tail(const Arc &a) const
CountedPtr< DigitalSurfaceContainer > myContainer
a smart pointer on the container.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
std::set< Face > FaceSet
The set of faces is defined as set.
void writeNeighbors(OutputIterator &it, const Vertex &v) const
FaceSet allFaces() const
bool operator<(const Edge &other) const
void exportEmbeddedSurfaceAs3DOFF(std::ostream &out, const CellEmbedder &cembedder) const
KSpace::template SurfelMap< Value >::Type Type
void selfDisplay(std::ostream &out) const
DigitalSurfaceContainer::SCell SCell
void exportSurfaceAs3DOFF(std::ostream &out) const
Arc(const Vertex &theTail, Dimension aK, bool aEpsilon)
TDigitalSurfaceContainer DigitalSurfaceContainer
bool operator<(const Arc &other) const
std::vector< Face > FaceRange
The range of faces is defined as a vector.
void exportEmbeddedIteratedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
Size bestCapacity() const
Arc opposite(const Arc &a) const
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DigitalSurfaceContainer::Cell Cell
Vertex base
base surfel
Size degree(const Vertex &v) const
FaceRange facesAroundVertex(const Vertex &v) const
ArcRange inArcs(const Vertex &v) const
Edge(const Vertex &v1, const Vertex &v2)
DigitalSurfaceTracker * myTracker
a pointer on a tracker.
Surfel Vertex
Defines the type for a vertex.
bool closed
tells if the face is closed or open.
bool operator==(const Face &other) const
Dimension k
direction toward the head surfel
unsigned int nbVertices
number of vertices incident to face.
VertexRange verticesAroundFace(const Face &f) const
DGtal is the top-level namespace which contains all DGtal functions and types.
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
Vertex head(const Arc &a) const
FaceRange facesAroundArc(const Arc &a) const
DigitalSurfaceContainer::KSpace KSpace
Umbrella::State UmbrellaState
boost::undirected_tag directed_category
the graph is undirected.
bool operator==(const Arc &other) const
KSpace::SurfelSet VertexSet
Defines how to represent a set of vertex.
const DigitalSurfaceContainer & container() const
bool epsilon
orientation toward the head surfel
FaceSet allClosedFaces() const
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
boost::DigitalSurface_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
DigitalSurface & operator=(const DigitalSurface &other)
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
UmbrellaComputer< DigitalSurfaceTracker > Umbrella
This define a utility class for computing umbrellas.
ConstIterator begin() const
DigitalSurfaceContainer::Surfel Surfel
ConstIterator end() const
Face(const UmbrellaState &aState, unsigned int nb, bool aIsClosed)
KSpace::Size Size
Defines how to represent a size (unsigned integral type).
FaceSet allOpenFaces() const