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