DGtal  0.9.3
testBreadthFirstPropagation.cpp
Go to the documentation of this file.
1 
29 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/io/boards/Board2D.h"
33 #include "DGtal/io/Color.h"
34 #include "DGtal/io/colormaps/GradientColorMap.h"
35 #include "DGtal/shapes/Shapes.h"
36 #include "DGtal/graph/CUndirectedSimpleGraph.h"
37 #include "DGtal/graph/BreadthFirstVisitor.h"
38 #include "DGtal/graph/CGraphVisitor.h"
39 #include <set>
40 #include <iterator>
42 
43 
44 using namespace std;
45 using namespace DGtal;
46 using namespace DGtal::concepts;
47 
49 // Functions for testing objects as graph.
51 
54 {
55  typedef Z2i::Point Point;
56  typedef Z2i::Domain Domain;
57  typedef Z2i::DigitalSet DigitalSet;
58  typedef Z2i::Object4_8 Object;
59 
60  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
61 
62  Point p1( -41, -36 );
63  Point p2( 18, 18 );
64  Domain domain( p1, p2 );
65  Point c1( -2, -1 );
66  Point c2( -14, 5 );
67  Point c3( -30, -15 );
68  Point c4( -10, -20 );
69  Point c5( 12, -1 );
70  DigitalSet shape_set( domain );
71 
72  Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
73  Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
74  Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
75  Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
76  Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
77 
78  Object obj(Z2i::dt4_8, shape_set);
79 
80 
81  GradientColorMap<int> cmap_grad( 0, 52);
82  cmap_grad.addColor( Color( 0, 0, 255 ) );
83  cmap_grad.addColor( Color( 0, 255, 0 ) );
84  cmap_grad.addColor( Color( 255, 0, 0 ) );
85 
86  Board2D board;
87  board << SetMode( domain.className(), "Paving" )
88  << domain
89  << SetMode( p1.className(), "Paving" );
90 
91  Image image = ImageFromSet<Image>::create(shape_set, 1);
92 
94  BOOST_CONCEPT_ASSERT(( CGraphVisitor< Visitor > ));
95  Visitor bfv (obj, c1);
96 
97 
98  while( !bfv.finished() )
99  {
100  image.setValue(bfv.current().first, bfv.current().second);
101  bfv.expand();
102  }
103 
104  string specificStyle = p1.className() + "/Paving";
105 
106  for ( DigitalSet::ConstIterator it = shape_set.begin();
107  it != shape_set.end();
108  ++it )
109  {
110  if( image(*it) == 0)
111  {
112  board << CustomStyle( specificStyle,
113  new CustomColors( Color::Black,
114  Color::Red ) )
115  << *it;
116  }
117  else
118  {
119  if( image(*it) > 0 )
120  {
121  board << CustomStyle( specificStyle,
122  new CustomColors( Color::Black,
123  cmap_grad( image(*it) ) ) )
124  << *it;
125  }
126  else
127  {
128  board << CustomStyle( specificStyle,
129  new CustomColors( Color::Black,
130  cmap_grad( 0 ) ) )
131  << *it;
132  }
133  }
134  }
135 
136  board.saveEPS("testBreadthFirstPropagation.eps");
137 }
138 
139 int main( int /*argc*/, char** /*argv*/ )
140 {
142  return 0;
143 }
144 
145 
146 
147 
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
HyperRectDomain< Space > Domain
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Aim: Define utilities to convert a digital set into an image.
Definition: ImageFromSet.h:63
void addColor(const Color &color)
const Node & current() const
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
BreadthFirstVisitor< MyDigitalSurface > Visitor
int main(int, char **)
Aim: Gathers several functions useful for concept checks.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
ImageSelector< Z2i::Domain, int >::Type Image
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents the concept of local graph: each vertex has neighboring vertices, but we do not neces...
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Image image(domain)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70
Aim: Defines the concept of a visitor onto a graph, that is an object that traverses vertices of the ...
void testBreadthFirstPropagation()