DGtal  1.5.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)
39 #define Object_RECURSES
40 
41 #if !defined Object_h
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 
228 
241  Clone<DigitalSet> aPointSet,
242  Connectedness cxn = UNKNOWN );
243 
244 
255 
263  Object ( const Object & other );
264 
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 
324 
328  const DigitalTopology & topology() const;
329 
334 
335  // ----------------------- Object services --------------------------------
336  public:
337 
351  SmallObject neighborhood( const Point & p ) const;
352 
363  Size neighborhoodSize( const Point & p ) const;
364 
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 
479 
480 
486 
492  Size degree( const Vertex & v ) const;
493 
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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:183
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:267
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple po...
Container::size_type Size
Size type of the container;.
Container::const_iterator ConstIterator
ConstIterator type of the container;.
Aim: Represents a digital topology as a couple of adjacency relations.
ForegroundAdjacency::Point Point
TForegroundAdjacency ForegroundAdjacency
TBackgroundAdjacency BackgroundAdjacency
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:120
Size neighborhoodSize(const Point &p) const
Connectedness connectedness() const
bool isSimpleFromTable(const Point &v, const boost::dynamic_bitset<> &input_table, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
EdgeRange outEdges(const Vertex &v) const
SmallComplementObject geodesicNeighborhoodInComplement(const TAdjacency &adj, const Point &p, unsigned int k) const
DigitalSet::Size Size
Definition: Object.h:140
ConstIterator begin() const
const DigitalTopology & topology() const
const Domain & domain() const
Size size() const
void writeNeighbors(OutputIterator &it, const Vertex &v) const
DigitalSet & pointSet()
TDigitalSet DigitalSet
Definition: Object.h:123
std::vector< Edge > EdgeRange
Definition: Object.h:222
ConstIterator end() const
Object< ReverseTopology, SmallSet > SmallComplementObject
Definition: Object.h:154
DigitalSetSelector< Domain, SMALL_DS+HIGH_ITER_DS >::Type SmallSet
Definition: Object.h:149
NeighborhoodConfiguration getNeighborhoodConfigurationOccupancy(const Point &center, const std::unordered_map< Point, NeighborhoodConfiguration > &mapZeroNeighborhoodToMask) const
DigitalTopology::ReverseTopology ReverseTopology
Definition: Object.h:139
Object border() const
Connectedness computeConnectedness() const
Object(Clone< DigitalTopology > aTopology, Clone< DigitalSet > aPointSet, Connectedness cxn=UNKNOWN)
const DigitalSet & pointSet() const
Vertex head(const Edge &e) const
std::string className() const
SmallObject properNeighborhood(const Point &p) const
DigitalSet::Point Point
Definition: Object.h:141
SmallObject geodesicNeighborhood(const TAdjacency &adj, const Point &p, unsigned int k) const
CowPtr< Domain > domainPointer() const
SmallObject neighborhood(const Point &p) const
Object< DigitalTopology, SmallSet > SmallObject
Definition: Object.h:153
DigitalSet::Point Vertex
Definition: Object.h:157
TDigitalSet VertexSet
Definition: Object.h:158
Size degree(const Vertex &v) const
const ForegroundAdjacency & adjacency() const
Size writeComponents(OutputObjectIterator &it) const
bool myTableIsLoaded
Definition: Object.h:675
Object< ReverseTopology, DigitalSet > ComplementObject
Definition: Object.h:152
bool isValid() const
DigitalTopology::Point DTPoint
Definition: Object.h:143
boost::disallow_parallel_edge_tag edge_parallel_category
the graph does not allow parallel edges.
Definition: Object.h:136
Domain::Space Space
Definition: Object.h:146
CountedPtrOrPtr< boost::dynamic_bitset<> > myTable
Definition: Object.h:665
Size bestCapacity() const
TDigitalTopology DigitalTopology
Definition: Object.h:138
DigitalTopology::BackgroundAdjacency BackgroundAdjacency
Definition: Object.h:151
Object(Clone< DigitalTopology > aTopology, Clone< Domain > domain)
void selfDisplay(std::ostream &out) const
void setTable(Alias< boost::dynamic_bitset<> >inputTable)
Edge opposite(const Edge &e) const
CowPtr< DigitalTopology > myTopo
Definition: Object.h:650
DigitalSet::Domain Domain
Definition: Object.h:145
Size properNeighborhoodSize(const Point &p) const
BOOST_CONCEPT_ASSERT((concepts::CDigitalSet< TDigitalSet >))
DigitalTopology::ForegroundAdjacency ForegroundAdjacency
Definition: Object.h:150
boost::Object_graph_traversal_category traversal_category
the graph satisfies AdjacencyListGraph and VertexListGraph concepts.
Definition: Object.h:134
Connectedness myConnectedness
Definition: Object.h:660
CowPtr< DigitalSet > myPointSet
Definition: Object.h:655
bool isSimple(const Point &v) const
void writeNeighbors(OutputIterator &it, const Vertex &v, const VertexPredicate &pred) const
DigitalSet::ConstIterator ConstIterator
Definition: Object.h:162
Object(const Object &other)
Vertex tail(const Edge &e) const
boost::undirected_tag directed_category
the graph is undirected.
Definition: Object.h:132
Object & operator=(const Object &other)
CountedPtrOrPtr< std::unordered_map< Point, unsigned int > > myNeighborConfigurationMap
Definition: Object.h:670
DGtal is the top-level namespace which contains all DGtal functions and types.
uint32_t NeighborhoodConfiguration
Connectedness
Definition: Topology.h:51
@ UNKNOWN
Definition: Topology.h:52
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Definition: Boost.dox:28
Aim: Automatically defines an adequate digital set type according to the hints given by the user.
bool operator==(const Edge &other) const
Definition: Object.h:203
bool operator!=(const Edge &other) const
Definition: Object.h:208
Edge(const Vertex &v1, const Vertex &v2, const bool)
Definition: Object.h:179
Vertex vertices[2]
Definition: Object.h:167
Edge(const Vertex &v1, const Vertex &v2)
Definition: Object.h:190
bool operator<(const Edge &other) const
Definition: Object.h:213
std::map< Vertex, Value > Type
Definition: Object.h:160
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Definition: CDigitalSet.h:141