DGtal  1.0.0
Typedefs | Functions
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 dependency graph for testDepthFirstPropagation.cpp:

Go to the source code of this file.

Typedefs

typedef ImageSelector< Z2i::Domain, int >::Type 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

typedef ImageSelector< Z2i::Domain, int>::Type Image

Definition at line 53 of file testDepthFirstPropagation.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 183 of file testDepthFirstPropagation.cpp.

184 {
186  return 0;
187 }
void testDepthFirstPropagation()

References testDepthFirstPropagation().

◆ testDepthFirstPropagation()

void testDepthFirstPropagation ( )

Definition at line 54 of file testDepthFirstPropagation.cpp.

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  HueShadeColorMap<int,3> cmap_grad( 0, obj.size());
83  //cmap_grad.addColor( Color( 0, 0, 200 ) );
84  //cmap_grad.addColor( Color( 0, 0, 50 ) );
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  int cpt=0;
98 
99  while( !bfv.finished() )
100  {
101  image.setValue(bfv.current().first, ++cpt);
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  board.saveEPS("testDepthFirstPropagation.eps");
137 
138  board.clear();
139 
140  DepthFirstVisitor<Object, set<Point> > bfv2 (obj, c1);
141 
142 
143  while( !bfv2.finished() )
144  {
145  image.setValue(bfv2.current().first, bfv2.current().second);
146  bfv2.expand();
147  }
148 
149  specificStyle = p1.className() + "/Paving";
150 
151  for ( DigitalSet::ConstIterator it = shape_set.begin();
152  it != shape_set.end();
153  ++it )
154  {
155  if( image(*it) == 0)
156  {
157  board << CustomStyle( specificStyle,
158  new CustomColors( Color::Black,
159  Color::Red ) )
160  << *it;
161  }
162  else
163  {
164  if( image(*it) > 0 )
165  {
166  board << CustomStyle( specificStyle,
167  new CustomColors( Color::Black,
168  cmap_grad( image(*it) ) ) )
169  << *it;
170  }
171  else
172  {
173  board << CustomStyle( specificStyle,
174  new CustomColors( Color::Black,
175  cmap_grad( 0 ) ) )
176  << *it;
177  }
178  }
179  }
180  board.saveEPS("testDepthFirstPropagation-distance.eps");
181 }
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
HyperRectDomain< Space > Domain
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
MyDigitalSurface::ConstIterator ConstIterator
Aim: Define utilities to convert a digital set into an image.
Definition: ImageFromSet.h:63
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
BreadthFirstVisitor< MyDigitalSurface > Visitor
Domain domain
std::string className() const
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....
Definition: Board2D.h:247
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Image image(domain)
Aim: This class specializes a 'Board' 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 ...

References DGtal::HyperRectDomain< TSpace >::className(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), DGtal::DepthFirstVisitor< TGraph, TMarkSet >::current(), domain, DGtal::DepthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::DepthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), and image().

Referenced by main().