DGtal  1.0.0
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;
162  typedef typename DigitalSurfaceContainer::Surfel Surfel;
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)
UmbrellaComputer< DigitalSurfaceTracker > myUmbrellaComputer
This object is used to compute umbrellas over the surface.
bool operator<(const Face &other) const
Vertex tail(const Arc &a) const
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
VertexRange verticesAroundFace(const Face &f) const
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
DigitalSurface< DigitalSurfaceContainer > Self
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
Definition: Boost.dox:28
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
SCell pivot(const Face &f) const
bool operator<(const Arc &other) const
Vertex head(const Arc &a) const
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
DGtal::uint32_t Dimension
Definition: Common.h:127
Vertex vertices[2]
The two vertices.
KSpace::SurfelSet SurfelSet
Size degree(const Vertex &v) const
KSpace::template SurfelMap< Value >::Type Type
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...
KSpace::Vector Vector
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
std::set< Face > FaceSet
The set of faces is defined as set.
void exportEmbeddedSurfaceAs3DOFF(std::ostream &out, const CellEmbedder &cembedder) const
ConstIterator begin() const
KSpace::template SurfelMap< Value >::Type Type
NumberTraits< Integer >::UnsignedVersion Size
Type used to represent sizes in the digital space.
bool isValid() const
Arc opposite(const Arc &a) const
void exportSurfaceAs3DOFF(std::ostream &out) const
DigitalSurfaceContainer::SCell SCell
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
Face computeFace(UmbrellaState state) const
Arc(const Vertex &theTail, Dimension aK, bool aEpsilon)
TDigitalSurfaceContainer DigitalSurfaceContainer
std::vector< Face > FaceRange
The range of faces is defined as a vector.
FaceSet allClosedFaces() const
SCell separator(const Arc &a) const
FaceRange facesAroundVertex(const Vertex &v, bool order_ccw_in_3d=false) const
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DigitalSurfaceContainer::Cell Cell
bool operator==(const Arc &other) const
bool operator==(const Face &other) const
bool operator==(const Edge &other) const
void exportEmbeddedIteratedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
Edge(const Vertex &v1, const Vertex &v2)
DigitalSurfaceTracker * myTracker
a pointer on a tracker.
FaceSet allFaces() const
Surfel Vertex
Defines the type for a vertex.
bool closed
tells if the face is closed or open.
Z3i::KSpace KSpace
Dimension k
direction toward the head surfel
unsigned int nbVertices
number of vertices incident to face.
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DGtal is the top-level namespace which contains all DGtal functions and types.
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
DigitalSurfaceContainer::KSpace KSpace
FaceRange facesAroundArc(const Arc &a) const
Umbrella::State UmbrellaState
const DigitalSurfaceContainer & container() const
Size bestCapacity() const
void exportEmbeddedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
ConstIterator end() const
boost::undirected_tag directed_category
the graph is undirected.
KSpace::SurfelSet VertexSet
Defines how to represent a set of vertex.
bool operator!=(const Arc &other) const
bool epsilon
orientation toward the head surfel
ArcRange inArcs(const Vertex &v) const
ArcRange outArcs(const Vertex &v) const
bool operator<(const Edge &other) const
boost::DigitalSurface_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
KSpace::Cell Cell
DigitalSurface & operator=(const DigitalSurface &other)
Arc arc(const Vertex &tail, const Vertex &head) const
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.
DigitalSurfaceContainer::Surfel Surfel
Face(const UmbrellaState &aState, unsigned int nb, bool aIsClosed)
FaceSet allOpenFaces() const
KSpace::Size Size
Defines how to represent a size (unsigned integral type).
void selfDisplay(std::ostream &out) const