DGtal  1.3.beta
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
138  template <typename TDigitalSurfaceContainer>
140  {
141  public:
142  typedef TDigitalSurfaceContainer DigitalSurfaceContainer;
144 
145  // ----------------------- boost graph tags ------------------------------
146  // JOL (2013/02/01): required to define internal tags (boost/graph/copy.hpp, l. 251 error ?).
147  public:
149  typedef boost::undirected_tag directed_category;
153  typedef boost::disallow_parallel_edge_tag edge_parallel_category;
154 
155 
156  // ----------------------- types ------------------------------
157  public:
161  typedef typename DigitalSurfaceContainer::SCell SCell;
163  typedef typename DigitalSurfaceContainer::SurfelConstIterator ConstIterator;
164  typedef typename DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker;
165  typedef typename KSpace::Point Point;
166  typedef typename KSpace::Vector Vector;
167  typedef typename KSpace::SurfelSet SurfelSet;
170  template <typename Value> struct SurfelMap {
171  typedef typename KSpace::template SurfelMap<Value>::Type Type;
172  };
173 
174  // ----------------------- UndirectedSimpleGraph --------------------------
175  public:
177  typedef Surfel Vertex;
179  typedef typename KSpace::Size Size;
181  typedef typename KSpace::SurfelSet VertexSet;
184  template <typename Value> struct VertexMap {
185  typedef typename KSpace::template SurfelMap<Value>::Type Type;
186  };
192  struct Edge {
200  Edge( const Vertex & v1, const Vertex & v2 )
201  {
202  if ( v1 <= v2 )
203  {
204  vertices[ 0 ] = v1;
205  vertices[ 1 ] = v2;
206  }
207  else
208  {
209  vertices[ 0 ] = v2;
210  vertices[ 1 ] = v1;
211  }
212  }
213  bool operator==( const Edge & other ) const
214  {
215  return ( vertices[ 0 ] == other.vertices[ 0 ] )
216  && ( vertices[ 1 ] == other.vertices[ 1 ] );
217  }
218  bool operator<( const Edge & other ) const
219  {
220  return ( vertices[ 0 ] < other.vertices[ 0 ] )
221  || ( ( vertices[ 0 ] == other.vertices[ 0 ] )
222  && ( vertices[ 1 ] < other.vertices[ 1 ] ) );
223  }
224 
225  };
226 
227  // ----------------------- CombinatorialSurface --------------------------
228  public:
229 
234  typedef typename Umbrella::State UmbrellaState;
235 
238  struct Arc {
241  bool epsilon;
242 
245  inline Arc()
246  : base(), k( 0 ), epsilon( false ) {}
247  inline Arc( const Vertex & theTail, Dimension aK, bool aEpsilon )
248  : base( theTail ), k( aK ), epsilon( aEpsilon ) {}
249  inline bool operator==( const Arc & other ) const
250  {
251  return ( base == other.base )
252  && ( k == other.k ) && ( epsilon == other.epsilon );
253  }
254  inline bool operator<( const Arc & other ) const
255  {
256  return ( base < other.base )
257  || ( ( base == other.base )
258  && ( ( k < other.k )
259  || ( ( k == other.k )
260  && ( epsilon < other.epsilon ) ) ) );
261  }
262  inline bool operator!=( const Arc & other ) const
263  {
264  return ( base != other.base )
265  || ( k != other.k ) || ( epsilon != other.epsilon );
266  }
267  };
268 
278  struct Face {
280  unsigned int nbVertices;
282  bool closed;
283  inline Face( const UmbrellaState & aState,
284  unsigned int nb, bool aIsClosed )
285  : state( aState ), nbVertices( nb ), closed( aIsClosed )
286  {}
287  inline bool isClosed() const
288  { return closed; }
289  inline bool operator==( const Face & other ) const
290  {
291  return state == other.state;
292  }
293  inline bool operator<( const Face & other ) const
294  {
295  return state < other.state;
296  }
297 
298  };
299 
301  typedef std::vector<Arc> ArcRange;
303  typedef std::vector<Face> FaceRange;
305  typedef std::vector<Vertex> VertexRange;
307  typedef std::set<Face> FaceSet;
308 
309 
310  // ----------------------- Standard services ------------------------------
311  public:
312 
316  ~DigitalSurface();
317 
322  DigitalSurface ( const DigitalSurface & other );
323 
329 
334  DigitalSurface( DigitalSurfaceContainer* containerPtr );
335 
341  DigitalSurface & operator= ( const DigitalSurface & other );
342 
343  // ----------------------- Services --------------------------------------
344  public:
345 
349  const DigitalSurfaceContainer & container() const;
350 
356 
357  // ----------------- UndirectedSimpleGraph realization --------------------
358  public:
359 
402  ConstIterator begin() const;
403 
407  ConstIterator end() const;
408 
410  Size size() const;
411 
417  Size degree( const Vertex & v ) const;
418 
427  Size bestCapacity() const;
428 
443  template <typename OutputIterator>
444  void writeNeighbors( OutputIterator & it,
445  const Vertex & v ) const;
446 
466  template <typename OutputIterator, typename VertexPredicate>
467  void writeNeighbors( OutputIterator & it,
468  const Vertex & v,
469  const VertexPredicate & pred ) const;
470 
471 
472  // ----------------------- CombinatorialSurface --------------------------
473  public:
474 
479  ArcRange outArcs( const Vertex & v ) const;
480 
485  ArcRange inArcs( const Vertex & v ) const;
486 
504  bool order_ccw_in_3d = false ) const;
505 
510  Vertex head( const Arc & a ) const;
511 
516  Vertex tail( const Arc & a ) const;
517 
522  Arc opposite( const Arc & a ) const;
523 
531  Arc arc( const Vertex & tail, const Vertex & head ) const;
532 
540  FaceRange facesAroundArc( const Arc & a ) const;
541 
551  VertexRange verticesAroundFace( const Face & f ) const;
552 
557  FaceSet allFaces() const;
558 
563  FaceSet allClosedFaces() const;
564 
570  FaceSet allOpenFaces() const;
571 
576  Face computeFace( UmbrellaState state ) const;
577 
583  SCell separator( const Arc & a ) const;
584 
592  SCell pivot( const Face & f ) const;
593 
594 
595  // ----------------------- Interface --------------------------------------
596  public:
597 
602  void selfDisplay ( std::ostream & out ) const;
603 
608  bool isValid() const;
609 
616  void exportSurfaceAs3DOFF ( std::ostream & out ) const;
617 
628  template <typename CellEmbedder>
629  void exportEmbeddedSurfaceAs3DOFF ( std::ostream & out,
630  const CellEmbedder & cembedder ) const;
631 
642  template <typename CellEmbedder>
643  void exportEmbeddedSurfaceAs3DNOFF ( std::ostream & out,
644  const CellEmbedder & cembedder ) const;
645 
657  template <typename SCellEmbedderWithGradientMap>
658  void exportAs3DNOFF( std::ostream & out,
659  const SCellEmbedderWithGradientMap & scembedder ) const;
660 
669  template <typename CellEmbedder>
670  void exportEmbeddedIteratedSurfaceAs3DNOFF ( std::ostream & out,
671  const CellEmbedder & cembedder ) const;
672 
673  // ------------------------- Protected Datas ------------------------------
674  private:
675  // ------------------------- Private Datas --------------------------------
676  private:
677 
684 
685  // ------------------------- Hidden services ------------------------------
686  protected:
687 
692  DigitalSurface();
693 
694  private:
695 
696 
697  // ------------------------- Internals ------------------------------------
698  private:
699 
700  }; // end of class DigitalSurface
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/DigitalSurface.ih"
720 
721 // //
723 
724 #endif // !defined DigitalSurface_h
725 
726 #undef DigitalSurface_RECURSES
727 #endif // else defined(DigitalSurface_RECURSES)
DGtal::DigitalSurface::ArcRange
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
Definition: DigitalSurface.h:301
DGtal::DigitalSurface::Arc::Arc
Arc()
Definition: DigitalSurface.h:245
DGtal::DigitalSurface::inArcs
ArcRange inArcs(const Vertex &v) const
DGtal::DigitalSurface::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::DigitalSurface::Face
Definition: DigitalSurface.h:278
DGtal::DigitalSurface::Arc::base
Vertex base
base surfel
Definition: DigitalSurface.h:239
DGtal::DigitalSurface::Arc::operator<
bool operator<(const Arc &other) const
Definition: DigitalSurface.h:254
DGtal::DigitalSurface::SurfelSet
KSpace::SurfelSet SurfelSet
Definition: DigitalSurface.h:167
DGtal::DigitalSurface::degree
Size degree(const Vertex &v) const
DGtal::DigitalSurface::Point
KSpace::Point Point
Definition: DigitalSurface.h:165
DGtal::DigitalSurface::ConstIterator
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Definition: DigitalSurface.h:163
DGtal::DigitalSurface::Edge::operator<
bool operator<(const Edge &other) const
Definition: DigitalSurface.h:218
DGtal::DigitalSurface::VertexRange
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
Definition: DigitalSurface.h:305
DGtal::DigitalSurface::allOpenFaces
FaceSet allOpenFaces() const
DGtal::DigitalSurface::~DigitalSurface
~DigitalSurface()
DGtal::DigitalSurface::Face::operator<
bool operator<(const Face &other) const
Definition: DigitalSurface.h:293
DGtal::KhalimskySpaceND::SurfelSet
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Definition: KhalimskySpaceND.h:450
DGtal::DigitalSurface::Size
KSpace::Size Size
Defines how to represent a size (unsigned integral type).
Definition: DigitalSurface.h:179
DGtal::DigitalSurface::DigitalSurfaceTracker
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
Definition: DigitalSurface.h:164
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::DigitalSurface::SurfelMap::Type
KSpace::template SurfelMap< Value >::Type Type
Definition: DigitalSurface.h:171
DGtal::DigitalSurface::size
Size size() const
DGtal::DigitalSurface::Edge::Edge
Edge(const Vertex &v1, const Vertex &v2)
Definition: DigitalSurface.h:200
DGtal::DigitalSurface::opposite
Arc opposite(const Arc &a) const
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:137
DGtal::DigitalSurface::exportEmbeddedSurfaceAs3DOFF
void exportEmbeddedSurfaceAs3DOFF(std::ostream &out, const CellEmbedder &cembedder) const
boost
Definition: Boost.dox:28
DGtal::DigitalSurface::exportAs3DNOFF
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
DGtal::DigitalSurface::Face::state
UmbrellaState state
Definition: DigitalSurface.h:279
DGtal::DigitalSurface::DigitalSurfaceContainer
TDigitalSurfaceContainer DigitalSurfaceContainer
Definition: DigitalSurface.h:142
DGtal::DigitalSurface::Face::operator==
bool operator==(const Face &other) const
Definition: DigitalSurface.h:289
DGtal::DigitalSurface::Vector
KSpace::Vector Vector
Definition: DigitalSurface.h:166
DGtal::DigitalSurface::FaceSet
std::set< Face > FaceSet
The set of faces is defined as set.
Definition: DigitalSurface.h:307
DGtal::DigitalSurface::allClosedFaces
FaceSet allClosedFaces() const
DGtal::concepts::CDigitalSurfaceContainer
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
Definition: CDigitalSurfaceContainer.h:127
DGtal::DigitalSurface::exportSurfaceAs3DOFF
void exportSurfaceAs3DOFF(std::ostream &out) const
DGtal::DigitalSurface::DigitalSurface
DigitalSurface()
DGtal::DigitalSurface::Edge::vertices
Vertex vertices[2]
The two vertices.
Definition: DigitalSurface.h:194
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::DigitalSurface::myContainer
CountedPtr< DigitalSurfaceContainer > myContainer
a smart pointer on the container.
Definition: DigitalSurface.h:679
DGtal::DigitalSurface::isValid
bool isValid() const
KSpace
Z3i::KSpace KSpace
Definition: testArithmeticalDSSComputerOnSurfels.cpp:48
Surfel
KSpace::SCell Surfel
Definition: testArithmeticalDSSComputerOnSurfels.cpp:50
DGtal::DigitalSurface::VertexMap::Type
KSpace::template SurfelMap< Value >::Type Type
Definition: DigitalSurface.h:185
DGtal::DigitalSurface::separator
SCell separator(const Arc &a) const
DGtal::DigitalSurface::begin
ConstIterator begin() const
DGtal::DigitalSurface::Cell
DigitalSurfaceContainer::Cell Cell
Definition: DigitalSurface.h:160
DGtal::KhalimskySpaceND::Size
NumberTraits< Integer >::UnsignedVersion Size
Type used to represent sizes in the digital space.
Definition: KhalimskySpaceND.h:407
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::DigitalSurface::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
DGtal::DigitalSurface::UmbrellaState
Umbrella::State UmbrellaState
Definition: DigitalSurface.h:234
DGtal::DigitalSurface::myTracker
DigitalSurfaceTracker * myTracker
a pointer on a tracker.
Definition: DigitalSurface.h:681
DGtal::DigitalSurface::bestCapacity
Size bestCapacity() const
DGtal::DigitalSurface::allFaces
FaceSet allFaces() const
DGtal::DigitalSurface::SCell
DigitalSurfaceContainer::SCell SCell
Definition: DigitalSurface.h:161
DGtal::DigitalSurface::SurfelMap
Definition: DigitalSurface.h:170
DGtal::DigitalSurface::Face::Face
Face(const UmbrellaState &aState, unsigned int nb, bool aIsClosed)
Definition: DigitalSurface.h:283
DGtal::DigitalSurface::computeFace
Face computeFace(UmbrellaState state) const
DGtal::DigitalSurface::writeNeighbors
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DGtal::DigitalSurface::Face::nbVertices
unsigned int nbVertices
number of vertices incident to face.
Definition: DigitalSurface.h:281
boost::DigitalSurface_graph_traversal_category
Definition: DigitalSurface.h:63
DGtal::DigitalSurface::facesAroundArc
FaceRange facesAroundArc(const Arc &a) const
DGtal::DigitalSurface::FaceRange
std::vector< Face > FaceRange
The range of faces is defined as a vector.
Definition: DigitalSurface.h:303
DGtal::CountedPtr< DigitalSurfaceContainer >
DGtal::DigitalSurface::facesAroundVertex
FaceRange facesAroundVertex(const Vertex &v, bool order_ccw_in_3d=false) const
DGtal::DigitalSurface::Arc
Definition: DigitalSurface.h:238
DGtal::DigitalSurface::Edge::operator==
bool operator==(const Edge &other) const
Definition: DigitalSurface.h:213
DGtal::DigitalSurface::end
ConstIterator end() const
DGtal::DigitalSurface::VertexMap
Definition: DigitalSurface.h:184
DGtal::DigitalSurface::VertexSet
KSpace::SurfelSet VertexSet
Defines how to represent a set of vertex.
Definition: DigitalSurface.h:181
DGtal::DigitalSurface::exportEmbeddedIteratedSurfaceAs3DNOFF
void exportEmbeddedIteratedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
DGtal::DigitalSurface::operator=
DigitalSurface & operator=(const DigitalSurface &other)
DGtal::DigitalSurface::Vertex
Surfel Vertex
Defines the type for a vertex.
Definition: DigitalSurface.h:177
DGtal::DigitalSurface::exportEmbeddedSurfaceAs3DNOFF
void exportEmbeddedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
DGtal::DigitalSurface::Surfel
DigitalSurfaceContainer::Surfel Surfel
Definition: DigitalSurface.h:162
DGtal::PointVector< dim, Integer >
DGtal::DigitalSurface::Arc::operator!=
bool operator!=(const Arc &other) const
Definition: DigitalSurface.h:262
DGtal::DigitalSurface::Arc::operator==
bool operator==(const Arc &other) const
Definition: DigitalSurface.h:249
DGtal::DigitalSurface::directed_category
boost::undirected_tag directed_category
the graph is undirected.
Definition: DigitalSurface.h:149
DGtal::DigitalSurface::traversal_category
boost::DigitalSurface_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
Definition: DigitalSurface.h:151
Cell
KSpace::Cell Cell
Definition: testCubicalComplex.cpp:56
DGtal::DigitalSurface::Face::closed
bool closed
tells if the face is closed or open.
Definition: DigitalSurface.h:282
DGtal::DigitalSurface::KSpace
DigitalSurfaceContainer::KSpace KSpace
Definition: DigitalSurface.h:159
DGtal::DigitalSurface::myUmbrellaComputer
UmbrellaComputer< DigitalSurfaceTracker > myUmbrellaComputer
This object is used to compute umbrellas over the surface.
Definition: DigitalSurface.h:683
DGtal::DigitalSurface::container
const DigitalSurfaceContainer & container() const
DGtal::DigitalSurface::arc
Arc arc(const Vertex &tail, const Vertex &head) const
DGtal::UmbrellaComputer< DigitalSurfaceTracker >
DGtal::DigitalSurface::Arc::k
Dimension k
direction toward the head surfel
Definition: DigitalSurface.h:240
DGtal::DigitalSurface::Umbrella
UmbrellaComputer< DigitalSurfaceTracker > Umbrella
This define a utility class for computing umbrellas.
Definition: DigitalSurface.h:231
DGtal::DigitalSurface::Arc::epsilon
bool epsilon
orientation toward the head surfel
Definition: DigitalSurface.h:241
DGtal::DigitalSurface::Face::isClosed
bool isClosed() const
Definition: DigitalSurface.h:287
DGtal::DigitalSurface::verticesAroundFace
VertexRange verticesAroundFace(const Face &f) const
DGtal::DigitalSurface::Self
DigitalSurface< DigitalSurfaceContainer > Self
Definition: DigitalSurface.h:158
DGtal::DigitalSurface::outArcs
ArcRange outArcs(const Vertex &v) const
DGtal::DigitalSurface::Arc::Arc
Arc(const Vertex &theTail, Dimension aK, bool aEpsilon)
Definition: DigitalSurface.h:247
DGtal::DigitalSurface::pivot
SCell pivot(const Face &f) const
DGtal::DigitalSurface::Edge
Definition: DigitalSurface.h:192
DGtal::DigitalSurface::tail
Vertex tail(const Arc &a) const
DGtal::DigitalSurface::edge_parallel_category
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
Definition: DigitalSurface.h:153
DGtal::DigitalSurface::head
Vertex head(const Arc &a) const