DGtal  1.3.beta
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  };
163 
164  // Required by CUndirectedSimpleGraph
165  struct Edge
166  {
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>
582  geodesicNeighborhood( const TAdjacency & adj,
583  const Point & p, unsigned int k ) const;
584 
589  template <typename TAdjacency>
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)
DGtal::Object::DTPoint
DigitalTopology::Point DTPoint
Definition: Object.h:143
DGtal::Clone
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:266
DGtal::Object::Domain
DigitalSet::Domain Domain
Definition: Object.h:145
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::Object::Edge::operator<
bool operator<(const Edge &other) const
Definition: Object.h:213
DGtal::Object::SmallComplementObject
Object< ReverseTopology, SmallSet > SmallComplementObject
Definition: Object.h:154
DGtal::Object::topology
const DigitalTopology & topology() const
DGtal::HyperRectDomain< Space >::Space
Space Space
Definition: HyperRectDomain.h:110
DGtal::Object::head
Vertex head(const Edge &e) const
DGtal::DigitalTopology::BackgroundAdjacency
TBackgroundAdjacency BackgroundAdjacency
Definition: DigitalTopology.h:100
DGtal::DigitalTopology
Aim: Represents a digital topology as a couple of adjacency relations.
Definition: DigitalTopology.h:95
DGtal::Object::myConnectedness
Connectedness myConnectedness
Definition: Object.h:660
DGtal::DigitalSetSelector
Aim: Automatically defines an adequate digital set type according to the hints given by the user.
Definition: DigitalSetSelector.h:88
DGtal::Object::end
ConstIterator end() const
DGtal::Object::VertexSet
TDigitalSet VertexSet
Definition: Object.h:158
DGtal::Object::EdgeRange
std::vector< Edge > EdgeRange
Definition: Object.h:222
DGtal::Object::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::Object::setTable
void setTable(Alias< boost::dynamic_bitset<> >inputTable)
DGtal::Object::myNeighborConfigurationMap
CountedPtrOrPtr< std::unordered_map< Point, unsigned int > > myNeighborConfigurationMap
Definition: Object.h:670
DGtal::Object::operator=
Object & operator=(const Object &other)
DGtal::Object::geodesicNeighborhoodInComplement
SmallComplementObject geodesicNeighborhoodInComplement(const TAdjacency &adj, const Point &p, unsigned int k) const
DGtal::NeighborhoodConfiguration
uint32_t NeighborhoodConfiguration
Definition: NeighborhoodConfigurationsHelper.h:43
DGtal::Object::Edge::Edge
Edge(const Vertex &v1, const Vertex &v2)
Definition: Object.h:190
DGtal::Object::DigitalTopology
TDigitalTopology DigitalTopology
Definition: Object.h:138
DGtal::Object::myTopo
CowPtr< DigitalTopology > myTopo
Definition: Object.h:650
DGtal::Object::neighborhood
SmallObject neighborhood(const Point &p) const
DGtal::Object::degree
Size degree(const Vertex &v) const
boost
Definition: Boost.dox:28
DGtal::Object::writeComponents
Size writeComponents(OutputObjectIterator &it) const
DGtal::Object::myTableIsLoaded
bool myTableIsLoaded
Definition: Object.h:675
DGtal::Object::ComplementObject
Object< ReverseTopology, DigitalSet > ComplementObject
Definition: Object.h:152
DGtal::Object::VertexMap
Definition: Object.h:159
DGtal::Object::Space
Domain::Space Space
Definition: Object.h:146
DGtal::Object::myPointSet
CowPtr< DigitalSet > myPointSet
Definition: Object.h:655
DGtal::Object::VertexMap::Type
std::map< Vertex, Value > Type
Definition: Object.h:160
DGtal::SMALL_DS
@ SMALL_DS
Definition: DigitalSetSelector.h:60
DGtal::Connectedness
Connectedness
Definition: Topology.h:50
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::Object::ReverseTopology
DigitalTopology::ReverseTopology ReverseTopology
Definition: Object.h:139
DGtal::Object::domainPointer
CowPtr< Domain > domainPointer() const
DGtal::UNKNOWN
@ UNKNOWN
Definition: Topology.h:52
DGtal::Object::computeConnectedness
Connectedness computeConnectedness() const
DGtal::Object::ConstIterator
DigitalSet::ConstIterator ConstIterator
Definition: Object.h:162
DGtal::Object::Edge::operator!=
bool operator!=(const Edge &other) const
Definition: Object.h:208
DGtal::Object::traversal_category
boost::Object_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
Definition: Object.h:134
DGtal::Object::adjacency
const ForegroundAdjacency & adjacency() const
DGtal::Object::begin
ConstIterator begin() const
DGtal::Object::DigitalSet
TDigitalSet DigitalSet
Definition: Object.h:123
DGtal::Object::SmallSet
DigitalSetSelector< Domain, SMALL_DS+HIGH_ITER_DS >::Type SmallSet
Definition: Object.h:149
DGtal::Object::~Object
~Object()
DGtal::Object::directed_category
boost::undirected_tag directed_category
the graph is undirected.
Definition: Object.h:132
DGtal::Object::Edge::vertices
Vertex vertices[2]
Definition: Object.h:167
DGtal::Object::connectedness
Connectedness connectedness() const
DGtal::Object::Edge::Edge
Edge(const Vertex &v1, const Vertex &v2, const bool)
Definition: Object.h:179
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::Object::outEdges
EdgeRange outEdges(const Vertex &v) const
DGtal::Object::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalSet< TDigitalSet >))
DGtal::Object::isSimple
bool isSimple(const Point &v) const
DGtal::Object::getNeighborhoodConfigurationOccupancy
NeighborhoodConfiguration getNeighborhoodConfigurationOccupancy(const Point &center, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
DGtal::Object::tail
Vertex tail(const Edge &e) const
DGtal::Object::properNeighborhood
SmallObject properNeighborhood(const Point &p) const
DGtal::Object::border
Object border() const
DGtal::CountedPtrOrPtr
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
DGtal::Object::Point
DigitalSet::Point Point
Definition: Object.h:141
DGtal::Object::Edge
Definition: Object.h:165
DGtal::Object::edge_parallel_category
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
Definition: Object.h:136
DGtal::Object::Object
Object()
DGtal::Object::className
std::string className() const
boost::Object_graph_traversal_category
Definition: Object.h:71
DGtal::Object::opposite
Edge opposite(const Edge &e) const
DGtal::Object::Size
DigitalSet::Size Size
Definition: Object.h:140
DGtal::Object::domain
const Domain & domain() const
DGtal::Object::Vertex
DigitalSet::Point Vertex
Definition: Object.h:157
Edge
HalfEdgeDataStructure::Edge Edge
Definition: testHalfEdgeDataStructure.cpp:47
DGtal::DigitalTopology::Point
ForegroundAdjacency::Point Point
Definition: DigitalTopology.h:101
DGtal::Object::BackgroundAdjacency
DigitalTopology::BackgroundAdjacency BackgroundAdjacency
Definition: Object.h:151
DGtal::DigitalTopology::ForegroundAdjacency
TForegroundAdjacency ForegroundAdjacency
Definition: DigitalTopology.h:99
DGtal::Object::neighborhoodSize
Size neighborhoodSize(const Point &p) const
DGtal::Alias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:182
DGtal::HIGH_ITER_DS
@ HIGH_ITER_DS
Definition: DigitalSetSelector.h:62
DGtal::Object::geodesicNeighborhood
SmallObject geodesicNeighborhood(const TAdjacency &adj, const Point &p, unsigned int k) const
DGtal::Object
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
DGtal::Object::size
Size size() const
DGtal::Object::Edge::Edge
Edge()
Definition: Object.h:172
DGtal::concepts::CDigitalSet
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Definition: CDigitalSet.h:138
DGtal::Object::pointSet
const DigitalSet & pointSet() const
DGtal::Object::SmallObject
Object< DigitalTopology, SmallSet > SmallObject
Definition: Object.h:153
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::Object::isValid
bool isValid() const
DGtal::Object::Edge::operator==
bool operator==(const Edge &other) const
Definition: Object.h:203
DGtal::Object::properNeighborhoodSize
Size properNeighborhoodSize(const Point &p) const
DGtal::Object::myTable
CountedPtrOrPtr< boost::dynamic_bitset<> > myTable
Definition: Object.h:665
DGtal::Object::writeNeighbors
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DGtal::Object::isSimpleFromTable
bool isSimpleFromTable(const Point &v, const boost::dynamic_bitset<> &input_table, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
DGtal::Object::ForegroundAdjacency
DigitalTopology::ForegroundAdjacency ForegroundAdjacency
Definition: Object.h:150
DGtal::Object::bestCapacity
Size bestCapacity() const
DGtal::CowPtr< Domain >