DGtal  1.4.beta
testBreadthFirstPropagation.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/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/graph/CUndirectedSimpleGraph.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/graph/CGraphVisitor.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include <set>
#include <iterator>
Include dependency graph for testBreadthFirstPropagation.cpp:

Go to the source code of this file.

Typedefs

typedef ImageContainerBySTLVector< Z2i::Domain, int > Image
 

Functions

void testBreadthFirstPropagation ()
 
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
Jérémy Gaillard (jerem.nosp@m.y.ga.nosp@m.illar.nosp@m.d@in.nosp@m.sa-ly.nosp@m.on.f.nosp@m.r )
Date
2012/06/18

Functions for testing objects as graph.

This file is part of the DGtal library.

Definition in file testBreadthFirstPropagation.cpp.

Typedef Documentation

◆ Image

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 140 of file testBreadthFirstPropagation.cpp.

141 {
143  return 0;
144 }
void testBreadthFirstPropagation()

References testBreadthFirstPropagation().

◆ testBreadthFirstPropagation()

void testBreadthFirstPropagation ( )

Definition at line 54 of file testBreadthFirstPropagation.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  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 }
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...
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...
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
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...
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
Image image(domain)
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), image(), and LibBoard::Board::saveEPS().

Referenced by main().