DGtal 1.3.0
Loading...
Searching...
No Matches
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 <set>
40#include <iterator>
42
43
44using namespace std;
45using namespace DGtal;
46using namespace DGtal::concepts;
47
49// Functions for testing objects as graph.
51
54{
55 typedef Z2i::Point Point;
56 typedef Z2i::Domain Domain;
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,
114 Color::Red ) )
115 << *it;
116 }
117 else
118 {
119 if( image(*it) > 0 )
120 {
121 board << CustomStyle( specificStyle,
123 cmap_grad( image(*it) ) ) )
124 << *it;
125 }
126 else
127 {
128 board << CustomStyle( specificStyle,
130 cmap_grad( 0 ) ) )
131 << *it;
132 }
133 }
134 }
135
136 board.saveEPS("testBreadthFirstPropagation.eps");
137}
138
139int main( int /*argc*/, char** /*argv*/ )
140{
142 return 0;
143}
144
145
146
147
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
static const Color Red
Definition: Color.h:416
static const Color Black
Definition: Color.h:413
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
static void addNorm1Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
BreadthFirstVisitor< MyDigitalSurface > Visitor
static const DT4_8 dt4_8
Definition: StdDefs.h:113
Aim: Gathers several functions useful for concept checks.
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
static Image create(const Set &aSet, const Value &defaultValue, const bool addBorder, typename Set::ConstIterator itBegin, typename Set::ConstIterator itEnd, const bool keepSetDomain=false)
ImageContainerBySTLVector< Domain, Value > Type
Definition: ImageSelector.h:78
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...
int main()
Definition: testBits.cpp:56
ImageSelector< Z2i::Domain, int >::Type Image
void testBreadthFirstPropagation()
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet