DGtal 1.4.0
Loading...
Searching...
No Matches
testDepthFirstPropagation.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/graph/CUndirectedSimpleGraph.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/CGraphVisitor.h"
#include <set>
#include <iterator>
#include "DGtal/images/ImageContainerBySTLVector.h"
Include dependency graph for testDepthFirstPropagation.cpp:

Go to the source code of this file.

Typedefs

typedef ImageContainerBySTLVector< Z2i::Domain, int > Image
 

Functions

void testDepthFirstPropagation ()
 
int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/06/18

Functions for testing objects as graph.

This file is part of the DGtal library.

Definition in file testDepthFirstPropagation.cpp.

Typedef Documentation

◆ Image

Definition at line 54 of file testDepthFirstPropagation.cpp.

Function Documentation

◆ main()

int main ( int ,
char **  )

Definition at line 184 of file testDepthFirstPropagation.cpp.

185{
187 return 0;
188}
void testDepthFirstPropagation()

References testDepthFirstPropagation().

◆ testDepthFirstPropagation()

void testDepthFirstPropagation ( )

Definition at line 55 of file testDepthFirstPropagation.cpp.

56{
57 typedef Z2i::Point Point;
58 typedef Z2i::Domain Domain;
60 typedef Z2i::Object4_8 Object;
61
62 BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
63
64 Point p1( -41, -36 );
65 Point p2( 18, 18 );
66 Domain domain( p1, p2 );
67 Point c1( -2, -1 );
68 Point c2( -14, 5 );
69 Point c3( -30, -15 );
70 Point c4( -10, -20 );
71 Point c5( 12, -1 );
72 DigitalSet shape_set( domain );
73
74 Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
75 Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
76 Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
77 Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
78 Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
79
80 Object obj(Z2i::dt4_8, shape_set);
81
82
83 HueShadeColorMap<int,3> cmap_grad( 0, (int)obj.size());
84 //cmap_grad.addColor( Color( 0, 0, 200 ) );
85 //cmap_grad.addColor( Color( 0, 0, 50 ) );
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 int cpt=0;
99
100 while( !bfv.finished() )
101 {
102 image.setValue(bfv.current().first, ++cpt);
103 bfv.expand();
104 }
105
106 string specificStyle = p1.className() + "/Paving";
107
108 for ( DigitalSet::ConstIterator it = shape_set.begin();
109 it != shape_set.end();
110 ++it )
111 {
112 if( image(*it) == 0)
113 {
114 board << CustomStyle( specificStyle,
116 Color::Red ) )
117 << *it;
118 }
119 else
120 {
121 if( image(*it) > 0 )
122 {
123 board << CustomStyle( specificStyle,
125 cmap_grad( image(*it) ) ) )
126 << *it;
127 }
128 else
129 {
130 board << CustomStyle( specificStyle,
132 cmap_grad( 0 ) ) )
133 << *it;
134 }
135 }
136 }
137 board.saveEPS("testDepthFirstPropagation.eps");
138
139 board.clear();
140
142
143
144 while( !bfv2.finished() )
145 {
146 image.setValue(bfv2.current().first, bfv2.current().second);
147 bfv2.expand();
148 }
149
150 specificStyle = p1.className() + "/Paving";
151
152 for ( DigitalSet::ConstIterator it = shape_set.begin();
153 it != shape_set.end();
154 ++it )
155 {
156 if( image(*it) == 0)
157 {
158 board << CustomStyle( specificStyle,
160 Color::Red ) )
161 << *it;
162 }
163 else
164 {
165 if( image(*it) > 0 )
166 {
167 board << CustomStyle( specificStyle,
169 cmap_grad( image(*it) ) ) )
170 << *it;
171 }
172 else
173 {
174 board << CustomStyle( specificStyle,
176 cmap_grad( 0 ) ) )
177 << *it;
178 }
179 }
180 }
181 board.saveEPS("testDepthFirstPropagation-distance.eps");
182}
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...
static const Color Red
Definition Color.h:416
static const Color Black
Definition Color.h:413
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
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...
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 clear(const DGtal::Color &color=DGtal::Color::None)
Definition Board.cpp:151
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
BreadthFirstVisitor< MyDigitalSurface > Visitor
static const DT4_8 dt4_8
Definition StdDefs.h:113
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)
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...
MyPointD Point
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet

References DGtal::Shapes< TDomain >::addNorm1Ball(), DGtal::Shapes< TDomain >::addNorm2Ball(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), DGtal::Color::Black, DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), DGtal::ImageFromSet< TImage >::create(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), DGtal::DepthFirstVisitor< TGraph, TMarkSet >::current(), domain, DGtal::Z2i::dt4_8, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::DepthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::DepthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::Color::Red, and LibBoard::Board::saveEPS().

Referenced by main().