DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #include "DGtal/base/Common.h"
47 #include "DGtal/base/CountedPtr.h"
48 #include "DGtal/kernel/CWithGradientMap.h"
49 #include "DGtal/topology/CCellEmbedder.h"
50 #include "DGtal/topology/CSCellEmbedder.h"
51 #include "DGtal/topology/CDigitalSurfaceContainer.h"
52 #include "DGtal/topology/CDigitalSurfaceTracker.h"
53 #include "DGtal/topology/UmbrellaComputer.h"
55 
56 namespace DGtal
57 {
58 
60  // template class DigitalSurface
104  template <typename TDigitalSurfaceContainer>
106  {
107  public:
108  typedef TDigitalSurfaceContainer DigitalSurfaceContainer;
110 
111  // ----------------------- types ------------------------------
112  public:
114  typedef typename DigitalSurfaceContainer::KSpace KSpace;
115  typedef typename DigitalSurfaceContainer::Cell Cell;
116  typedef typename DigitalSurfaceContainer::SCell SCell;
117  typedef typename DigitalSurfaceContainer::Surfel Surfel;
118  typedef typename DigitalSurfaceContainer::SurfelConstIterator ConstIterator;
119  typedef typename DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker;
120  typedef typename KSpace::Point Point;
121  typedef typename KSpace::SurfelSet SurfelSet;
124  template <typename Value> struct SurfelMap {
125  typedef typename KSpace::template SurfelMap<Value>::Type Type;
126  };
127 
128  // ----------------------- UndirectedSimpleGraph --------------------------
129  public:
131  typedef Surfel Vertex;
133  typedef typename KSpace::Size Size;
135  typedef typename KSpace::SurfelSet VertexSet;
138  template <typename Value> struct VertexMap {
139  typedef typename KSpace::template SurfelMap<Value>::Type Type;
140  };
146  struct Edge {
154  Edge( const Vertex & v1, const Vertex & v2 )
155  {
156  if ( v1 <= v2 )
157  {
158  vertices[ 0 ] = v1;
159  vertices[ 1 ] = v2;
160  }
161  else
162  {
163  vertices[ 0 ] = v2;
164  vertices[ 1 ] = v1;
165  }
166  }
167  bool operator==( const Edge & other ) const
168  {
169  return ( vertices[ 0 ] == other.vertices[ 0 ] )
170  && ( vertices[ 1 ] == other.vertices[ 1 ] );
171  }
172  bool operator<( const Edge & other ) const
173  {
174  return ( vertices[ 0 ] < other.vertices[ 0 ] )
175  || ( ( vertices[ 0 ] == other.vertices[ 0 ] )
176  && ( vertices[ 1 ] < other.vertices[ 1 ] ) );
177  }
178 
179  };
180 
181  // ----------------------- CombinatorialSurface --------------------------
182  public:
183 
188  typedef typename Umbrella::State UmbrellaState;
189 
192  struct Arc {
195  bool epsilon;
196  inline Arc( const Vertex & theTail, Dimension aK, bool aEpsilon )
197  : base( theTail ), k( aK ), epsilon( aEpsilon ) {}
198  inline bool operator==( const Arc & other ) const
199  {
200  return ( base == other.base )
201  && ( k == other.k ) && ( epsilon == other.epsilon );
202  }
203  inline bool operator<( const Arc & other ) const
204  {
205  return ( base < other.base )
206  || ( ( base == other.base )
207  && ( ( k < other.k )
208  || ( ( k == other.k )
209  && ( epsilon < other.epsilon ) ) ) );
210  }
211  };
212 
222  struct Face {
224 
225  unsigned int nbVertices;
226  bool closed;
227  inline Face( const UmbrellaState & aState,
228  unsigned int nb, bool aIsClosed )
229  : state( aState ), nbVertices( nb ), closed( aIsClosed )
230  {}
231  inline bool isClosed() const
232  { return closed; }
233  inline bool operator==( const Face & other ) const
234  {
235  return state == other.state;
236  }
237  inline bool operator<( const Face & other ) const
238  {
239  return state < other.state;
240  }
241 
242  };
243 
245  typedef std::vector<Arc> ArcRange;
247  typedef std::vector<Face> FaceRange;
249  typedef std::vector<Vertex> VertexRange;
251  typedef std::set<Face> FaceSet;
252 
253 
254  // ----------------------- Standard services ------------------------------
255  public:
256 
260  ~DigitalSurface();
261 
266  DigitalSurface ( const DigitalSurface & other );
267 
273 
278  DigitalSurface( DigitalSurfaceContainer* containerPtr );
279 
285  DigitalSurface & operator= ( const DigitalSurface & other );
286 
287  // ----------------------- Services --------------------------------------
288  public:
289 
293  const DigitalSurfaceContainer & container() const;
294 
300 
301  // ----------------- UndirectedSimpleGraph realization --------------------
302  public:
303 
307  ConstIterator begin() const;
308 
312  ConstIterator end() const;
313 
315  Size size() const;
316 
322  Size degree( const Vertex & v ) const;
323 
332  Size bestCapacity() const;
333 
348  template <typename OutputIterator>
349  void writeNeighbors( OutputIterator & it,
350  const Vertex & v ) const;
351 
371  template <typename OutputIterator, typename VertexPredicate>
372  void writeNeighbors( OutputIterator & it,
373  const Vertex & v,
374  const VertexPredicate & pred ) const;
375 
376 
377  // ----------------------- CombinatorialSurface --------------------------
378  public:
379 
384  ArcRange outArcs( const Vertex & v ) const;
385 
390  ArcRange inArcs( const Vertex & v ) const;
391 
397  FaceRange facesAroundVertex( const Vertex & v ) const;
398 
399  /*
400  @param a any arc (s,t)
401  @return the vertex t
402  */
403  Vertex head( const Arc & a ) const;
404 
405  /*
406  @param a any arc (s,t)
407  @return the vertex s
408  */
409  Vertex tail( const Arc & a ) const;
410 
415  Arc opposite( const Arc & a ) const;
416 
424  Arc arc( const Vertex & tail, const Vertex & head ) const;
425 
433  FaceRange facesAroundArc( const Arc & a ) const;
434 
444  VertexRange verticesAroundFace( const Face & f ) const;
445 
450  FaceSet allFaces() const;
451 
456  FaceSet allClosedFaces() const;
457 
463  FaceSet allOpenFaces() const;
464 
469  Face computeFace( UmbrellaState state ) const;
470 
476  SCell separator( const Arc & a ) const;
477 
485  SCell pivot( const Face & f ) const;
486 
487 
488  // ----------------------- Interface --------------------------------------
489  public:
490 
495  void selfDisplay ( std::ostream & out ) const;
496 
501  bool isValid() const;
502 
509  void exportSurfaceAs3DOFF ( std::ostream & out ) const;
510 
521  template <typename CellEmbedder>
522  void exportEmbeddedSurfaceAs3DOFF ( std::ostream & out,
523  const CellEmbedder & cembedder ) const;
524 
535  template <typename CellEmbedder>
536  void exportEmbeddedSurfaceAs3DNOFF ( std::ostream & out,
537  const CellEmbedder & cembedder ) const;
538 
550  template <typename SCellEmbedderWithGradientMap>
551  void exportAs3DNOFF( std::ostream & out,
552  const SCellEmbedderWithGradientMap & scembedder ) const;
553 
562  template <typename CellEmbedder>
563  void exportEmbeddedIteratedSurfaceAs3DNOFF ( std::ostream & out,
564  const CellEmbedder & cembedder ) const;
565 
566  // ------------------------- Protected Datas ------------------------------
567  private:
568  // ------------------------- Private Datas --------------------------------
569  private:
570 
577 
578  // ------------------------- Hidden services ------------------------------
579  protected:
580 
585  DigitalSurface();
586 
587  private:
588 
589 
590  // ------------------------- Internals ------------------------------------
591  private:
592 
593  }; // end of class DigitalSurface
594 
595 
602  template <typename TDigitalSurfaceContainer>
603  std::ostream&
604  operator<< ( std::ostream & out,
606 
607 } // namespace DGtal
608 
609 
611 // Includes inline functions.
612 #include "DGtal/topology/DigitalSurface.ih"
613 
614 // //
616 
617 #endif // !defined DigitalSurface_h
618 
619 #undef DigitalSurface_RECURSES
620 #endif // else defined(DigitalSurface_RECURSES)