DGtal  1.5.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)
35 #define DigitalSurface_RECURSES
36 
37 #if !defined DigitalSurface_h
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:
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;
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 {
281  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 
317 
322  DigitalSurface ( const DigitalSurface & other );
323 
329 
335 
342 
343  // ----------------------- Services --------------------------------------
344  public:
345 
350 
356 
357  // ----------------- UndirectedSimpleGraph realization --------------------
358  public:
359 
403 
408 
410  Size size() const;
411 
417  Size degree( const Vertex & v ) const;
418 
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 
564 
571 
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 
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)
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
void exportEmbeddedSurfaceAs3DOFF(std::ostream &out, const CellEmbedder &cembedder) const
void exportEmbeddedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
DigitalSurfaceContainer::Surfel Surfel
ArcRange outArcs(const Vertex &v) const
DigitalSurface & operator=(const DigitalSurface &other)
DigitalSurface< DigitalSurfaceContainer > Self
void selfDisplay(std::ostream &out) const
DigitalSurfaceContainer::Cell Cell
Face computeFace(UmbrellaState state) const
TDigitalSurfaceContainer DigitalSurfaceContainer
Arc arc(const Vertex &tail, const Vertex &head) const
UmbrellaComputer< DigitalSurfaceTracker > myUmbrellaComputer
This object is used to compute umbrellas over the surface.
boost::undirected_tag directed_category
the graph is undirected.
FaceSet allClosedFaces() const
void writeNeighbors(OutputIterator &it, const Vertex &v, const VertexPredicate &pred) const
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Vertex tail(const Arc &a) const
void exportSurfaceAs3DOFF(std::ostream &out) const
UmbrellaComputer< DigitalSurfaceTracker > Umbrella
This define a utility class for computing umbrellas.
DigitalSurfaceContainer & container()
FaceSet allFaces() const
Size bestCapacity() const
SCell pivot(const Face &f) const
KSpace::SurfelSet VertexSet
Defines how to represent a set of vertex.
KSpace::Size Size
Defines how to represent a size (unsigned integral type).
Surfel Vertex
Defines the type for a vertex.
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
ArcRange inArcs(const Vertex &v) const
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
Arc opposite(const Arc &a) const
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
Umbrella::State UmbrellaState
DigitalSurfaceTracker * myTracker
a pointer on a tracker.
CountedPtr< DigitalSurfaceContainer > myContainer
a smart pointer on the container.
DigitalSurface(const DigitalSurface &other)
ConstIterator begin() const
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
const DigitalSurfaceContainer & container() const
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
ConstIterator end() const
DigitalSurface(DigitalSurfaceContainer *containerPtr)
DigitalSurfaceContainer::KSpace KSpace
std::vector< Face > FaceRange
The range of faces is defined as a vector.
VertexRange verticesAroundFace(const Face &f) const
FaceRange facesAroundVertex(const Vertex &v, bool order_ccw_in_3d=false) const
KSpace::SurfelSet SurfelSet
void exportEmbeddedIteratedSurfaceAs3DNOFF(std::ostream &out, const CellEmbedder &cembedder) const
KSpace::Vector Vector
bool isValid() const
DigitalSurfaceContainer::SCell SCell
FaceSet allOpenFaces() const
std::set< Face > FaceSet
The set of faces is defined as set.
boost::DigitalSurface_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
DigitalSurface(const DigitalSurfaceContainer &container)
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
FaceRange facesAroundArc(const Arc &a) const
Size degree(const Vertex &v) const
void writeNeighbors(OutputIterator &it, const Vertex &v) const
SCell separator(const Arc &a) const
Vertex head(const Arc &a) const
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
NumberTraits< Integer >::UnsignedVersion Size
Type used to represent sizes in the digital space.
Z3i::SCell SCell
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
Definition: Boost.dox:28
bool operator!=(const Arc &other) const
bool operator==(const Arc &other) const
Dimension k
direction toward the head surfel
Arc(const Vertex &theTail, Dimension aK, bool aEpsilon)
bool epsilon
orientation toward the head surfel
bool operator<(const Arc &other) const
Vertex vertices[2]
The two vertices.
bool operator<(const Edge &other) const
Edge(const Vertex &v1, const Vertex &v2)
bool operator==(const Edge &other) const
bool closed
tells if the face is closed or open.
unsigned int nbVertices
number of vertices incident to face.
bool operator<(const Face &other) const
Face(const UmbrellaState &aState, unsigned int nb, bool aIsClosed)
bool operator==(const Face &other) const
KSpace::template SurfelMap< Value >::Type Type
KSpace::template SurfelMap< Value >::Type Type
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
KSpace::Cell Cell