DGtal  0.9.2
Object.h
1 
17 #pragma once
18 
35 #if defined(Object_RECURSES)
36 #error Recursive header files inclusion detected in Object.h
37 #else // defined(Object_RECURSES)
38 
39 #define Object_RECURSES
40 
41 #if !defined Object_h
42 
43 #define Object_h
44 
46 // Inclusions
47 #include <iostream>
48 #include <string>
49 #include <map>
50 #include "DGtal/base/Common.h"
51 #include "DGtal/base/CowPtr.h"
52 #include "DGtal/base/CountedPtr.h"
53 #include "DGtal/base/Clone.h"
54 #include "DGtal/base/Alias.h"
55 #include "DGtal/base/ConstAlias.h"
56 #include "DGtal/kernel/sets/CDigitalSet.h"
57 #include "DGtal/kernel/sets/DigitalSetSelector.h"
58 #include "DGtal/topology/Topology.h"
59 #include <boost/graph/graph_traits.hpp>
60 #include <boost/graph/properties.hpp>
61 #include <boost/dynamic_bitset.hpp>
62 #include <unordered_map>
63 #include <DGtal/topology/helpers/NeighborhoodConfigurationsHelper.h>
65 
66 namespace boost
67 {
72  : public virtual adjacency_graph_tag,
73  public virtual vertex_list_graph_tag,
74  public virtual incidence_graph_tag,
75  public virtual edge_list_graph_tag { };
76 }
77 
78 namespace DGtal
79 {
80 
82  // template class Object
118  template <typename TDigitalTopology, typename TDigitalSet>
119  class Object
120  {
121  // ----------------------- Standard services ------------------------------
122  public:
123  typedef TDigitalSet DigitalSet;
124 
126 
127  // ----------------------- boost graph tags ------------------------------
128  // JOL (2013/02/01): required to define internal tags (boost/graph/copy.hpp, l. 251 error ?).
129  // PHC(2016/02/01): copied from digital surface to use connected_components
130  public:
132  typedef boost::undirected_tag directed_category;
136  typedef boost::disallow_parallel_edge_tag edge_parallel_category;
137 
138  typedef TDigitalTopology DigitalTopology;
140  typedef typename DigitalSet::Size Size;
141  typedef typename DigitalSet::Point Point;
142  // should be the same as Point.
143  typedef typename DigitalTopology::Point DTPoint;
144 
145  typedef typename DigitalSet::Domain Domain;
146  typedef typename Domain::Space Space;
147  typedef
148  typename DigitalSetSelector < Domain,
155 
156  // Required by CUndirectedSimpleLocalGraph
157  typedef typename DigitalSet::Point Vertex;
158  typedef TDigitalSet VertexSet;
159  template <typename Value> struct VertexMap {
160  typedef typename std::map<Vertex, Value> Type;
161  };
162  typedef typename DigitalSet::ConstIterator ConstIterator;
163 
164  // Required by CUndirectedSimpleGraph
165  struct Edge
166  {
167  Vertex vertices [2];
168 
172  inline Edge(){}
173 
179  Edge( const Vertex & v1, const Vertex & v2, const bool )
180  {
181  vertices[ 0 ] = v1;
182  vertices[ 1 ] = v2;
183  }
190  Edge( const Vertex & v1, const Vertex & v2 )
191  {
192  if ( v1 <= v2 )
193  {
194  vertices[ 0 ] = v1;
195  vertices[ 1 ] = v2;
196  }
197  else
198  {
199  vertices[ 0 ] = v2;
200  vertices[ 1 ] = v1;
201  }
202  }
203  bool operator==( const Edge & other ) const
204  {
205  return ( vertices[ 0 ] == other.vertices[ 0 ] )
206  && ( vertices[ 1 ] == other.vertices[ 1 ] );
207  }
208  bool operator!=( const Edge & other ) const
209  {
210  return ( vertices[ 0 ] != other.vertices[ 0 ] )
211  || ( vertices[ 1 ] != other.vertices[ 1 ] );
212  }
213  bool operator<( const Edge & other ) const
214  {
215  return ( vertices[ 0 ] < other.vertices[ 0 ] )
216  || ( ( vertices[ 0 ] == other.vertices[ 0 ] )
217  && ( vertices[ 1 ] < other.vertices[ 1 ] ) );
218  }
219  };
220  // ... End added
221 
222  typedef std::vector<Edge> EdgeRange;
223 
227  Object();
228 
240  Object( Clone<DigitalTopology> aTopology,
241  Clone<DigitalSet> aPointSet,
242  Connectedness cxn = UNKNOWN );
243 
244 
253  Object( Clone<DigitalTopology> aTopology,
255 
263  Object ( const Object & other );
264 
268  ~Object();
269 
275  Object & operator= ( const Object & other );
276 
282  void setTable(Alias<boost::dynamic_bitset<> >inputTable);
283 
295  const Point & center,
296  const std::unordered_map< Point,
297  NeighborhoodConfiguration> & mapZeroNeighborhoodToMask) const;
301  Size size() const;
302 
306  const Domain & domain() const;
307 
312 
317  const DigitalSet & pointSet() const;
318 
323  DigitalSet & pointSet();
324 
328  const DigitalTopology & topology() const;
329 
333  const ForegroundAdjacency & adjacency() const;
334 
335  // ----------------------- Object services --------------------------------
336  public:
337 
351  SmallObject neighborhood( const Point & p ) const;
352 
363  Size neighborhoodSize( const Point & p ) const;
364 
380  SmallObject properNeighborhood( const Point & p ) const;
381 
393  Size properNeighborhoodSize( const Point & p ) const;
394 
395 
396  // ----------------------- border services -------------------------------
397  public:
398 
399 
406  Object border() const;
407 
408 
409  // ----------------------- Connectedness services -------------------------
410  public:
411 
449  template <typename OutputObjectIterator>
450  Size writeComponents( OutputObjectIterator & it ) const;
451 
459 
471 
472  // ----------------------- Graph services ------------------------------
473  public:
474 
478  ConstIterator begin() const;
479 
480 
485  ConstIterator end() const;
486 
492  Size degree( const Vertex & v ) const;
493 
497  Size bestCapacity() const;
498 
509  template <typename OutputIterator>
510  void
511  writeNeighbors( OutputIterator &it ,
512  const Vertex & v ) const;
513 
530  template <typename OutputIterator, typename VertexPredicate>
531  void
532  writeNeighbors( OutputIterator &it ,
533  const Vertex & v,
534  const VertexPredicate & pred) const;
535 
544  EdgeRange outEdges( const Vertex & v) const;
545 
554  Edge opposite(const Edge & e) const;
555 
563  Vertex head( const Edge & e) const;
571  Vertex tail( const Edge & e) const;
572 
573  // ----------------------- Simple points -------------------------------
574  public:
575 
580  template <typename TAdjacency>
581  SmallObject
582  geodesicNeighborhood( const TAdjacency & adj,
583  const Point & p, unsigned int k ) const;
584 
589  template <typename TAdjacency>
590  SmallComplementObject
591  geodesicNeighborhoodInComplement( const TAdjacency & adj,
592  const Point & p, unsigned int k ) const;
593 
594 
606  bool isSimple( const Point & v ) const;
607 
622  inline bool isSimpleFromTable(
623  const Point & v,
624  const boost::dynamic_bitset<> & input_table,
625  const std::unordered_map< Point,
626  NeighborhoodConfiguration > & mapZeroNeighborhoodToMask) const;
627  // ----------------------- Interface --------------------------------------
628  public:
629 
634  void selfDisplay ( std::ostream & out ) const;
635 
640  bool isValid() const;
641 
642  // ------------------------- Protected Datas ------------------------------
643  private:
644  // ------------------------- Private Datas --------------------------------
645  private:
646 
651 
656 
661 
666 
671 
676 
677  // --------------- CDrawableWithBoard2D realization ------------------
678  public:
682  std::string className() const;
683 
684 
685  }; // end of class Object
686 
687 
694  template <typename TDigitalTopology, typename TDigitalSet>
695  std::ostream&
696  operator<< ( std::ostream & out,
697  const Object<TDigitalTopology, TDigitalSet> & object );
698 
699 
700 
701 } // namespace DGtal
702 
703 
705 // Includes inline functions.
706 #include "DGtal/topology/Object.ih"
707 
708 // //
710 
711 #endif // !defined Object_h
712 
713 #undef Object_RECURSES
714 #endif // else defined(Object_RECURSES)
bool isSimpleFromTable(const Point &v, const boost::dynamic_bitset<> &input_table, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
DigitalSet::Size Size
Definition: Object.h:140
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
ConstIterator begin() const
Edge(const Vertex &v1, const Vertex &v2)
Definition: Object.h:190
DigitalSet::Point Point
Definition: Object.h:141
DigitalTopology::ReverseTopology ReverseTopology
Definition: Object.h:139
Size degree(const Vertex &v) const
DigitalTopology::Point DTPoint
Definition: Object.h:143
EdgeRange outEdges(const Vertex &v) const
Connectedness computeConnectedness() const
Definition: Boost.dox:28
TForegroundAdjacency ForegroundAdjacency
Size neighborhoodSize(const Point &p) const
boost::Object_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
Definition: Object.h:134
TDigitalSet DigitalSet
Definition: Object.h:123
Object< DigitalTopology, SmallSet > SmallObject
Definition: Object.h:153
Size bestCapacity() const
Size properNeighborhoodSize(const Point &p) const
Vertex head(const Edge &e) const
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:182
SmallObject geodesicNeighborhood(const TAdjacency &adj, const Point &p, unsigned int k) const
std::map< Vertex, Value > Type
Definition: Object.h:160
uint32_t NeighborhoodConfiguration
void writeNeighbors(OutputIterator &it, const Vertex &v) const
const Domain & domain() const
bool operator!=(const Edge &other) const
Definition: Object.h:208
Vertex vertices[2]
Definition: Object.h:167
TDigitalTopology DigitalTopology
Definition: Object.h:138
const DigitalSet & pointSet() const
void selfDisplay(std::ostream &out) const
bool myTableIsLoaded
Definition: Object.h:675
Object< ReverseTopology, SmallSet > SmallComplementObject
Definition: Object.h:154
TDigitalSet VertexSet
Definition: Object.h:158
ConstIterator end() const
DigitalSet::Point Vertex
Definition: Object.h:157
boost::undirected_tag directed_category
the graph is undirected.
Definition: Object.h:132
Edge(const Vertex &v1, const Vertex &v2, const bool)
Definition: Object.h:179
SmallObject neighborhood(const Point &p) const
SmallObject properNeighborhood(const Point &p) const
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple po...
Definition: CountedPtr.h:51
TBackgroundAdjacency BackgroundAdjacency
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:266
Aim: Represents a digital topology as a couple of adjacency relations.
DigitalTopology::BackgroundAdjacency BackgroundAdjacency
Definition: Object.h:151
DigitalTopology::ForegroundAdjacency ForegroundAdjacency
Definition: Object.h:150
DigitalSet::ConstIterator ConstIterator
Definition: Object.h:162
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
Definition: Object.h:136
bool operator<(const Edge &other) const
Definition: Object.h:213
Object< ReverseTopology, DigitalSet > ComplementObject
Definition: Object.h:152
Connectedness myConnectedness
Definition: Object.h:660
CowPtr< DigitalSet > myPointSet
Definition: Object.h:655
Connectedness connectedness() const
const DigitalTopology & topology() const
bool operator==(const Edge &other) const
Definition: Object.h:203
CountedPtrOrPtr< boost::dynamic_bitset<> > myTable
Definition: Object.h:665
DGtal is the top-level namespace which contains all DGtal functions and types.
void setTable(Alias< boost::dynamic_bitset<> >inputTable)
ForegroundAdjacency::Point Point
Size size() const
Vertex tail(const Edge &e) const
Aim: Automatically defines an adequate digital set type according to the hints given by the user...
DigitalSet::Domain Domain
Definition: Object.h:145
DigitalSetSelector< Domain, SMALL_DS+HIGH_ITER_DS >::Type SmallSet
Definition: Object.h:149
bool isSimple(const Point &v) const
CowPtr< DigitalTopology > myTopo
Definition: Object.h:650
SmallComplementObject geodesicNeighborhoodInComplement(const TAdjacency &adj, const Point &p, unsigned int k) const
BOOST_CONCEPT_ASSERT((concepts::CDigitalSet< TDigitalSet >))
bool isValid() const
Domain::Space Space
Definition: Object.h:146
const ForegroundAdjacency & adjacency() const
Connectedness
Definition: Topology.h:50
CowPtr< Domain > domainPointer() const
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Definition: CDigitalSet.h:138
std::vector< Edge > EdgeRange
Definition: Object.h:222
std::string className() const
Object border() const
CountedPtrOrPtr< std::unordered_map< Point, unsigned int > > myNeighborConfigurationMap
Definition: Object.h:670
Edge opposite(const Edge &e) const
Object & operator=(const Object &other)
NeighborhoodConfiguration getNeighborhoodConfigurationOccupancy(const Point &center, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
Size writeComponents(OutputObjectIterator &it) const