DGtal  1.5.beta
ctopo-2.cpp
Go to the documentation of this file.
1 
44 #include <iostream>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/topology/KhalimskySpaceND.h"
47 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
48 #include "DGtal/images/ImageSelector.h"
49 #include "DGtal/helpers/StdDefs.h"
50 #include "DGtal/topology/helpers/Surfaces.h"
51 
52 #include "DGtal/io/readers/PGMReader.h"
53 #include "DGtal/io/colormaps/GradientColorMap.h"
54 #include "DGtal/io/boards/Board2D.h"
55 #include "DGtal/io/Color.h"
56 
57 #include "ConfigExamples.h"
58 
59 
60 
61 
63 
64 using namespace std;
65 using namespace DGtal;
66 
68 
69 int main( int /*argc*/, char** /*argv*/ )
70 {
72  std::string inputFilename = examplesPath + "samples/circleR10modif.pgm";
73  Image image = PGMReader<Image>::importPGM( inputFilename );
74 
75  Z2i::DigitalSet set2d (image.domain());
77  Board2D board;
78  board << image.domain() << set2d; // display domain and set
79 
80  Board2D board2;
81  board2 << image.domain() << set2d; // display domain and set
82 
83  Board2D board3;
84  board3 << image.domain() << set2d; // display domain and set
85 
86 
87  // Construct the Khalimsky space from the image domain
88  Z2i::KSpace ks;
89  bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
90 
91 
92 
93  //Extract a boundary cell
94  Z2i::SCell aCell = Surfaces<Z2i::KSpace>::findABel(ks, set2d );
95 
96  // Getting the consecutive surfels of the 2D boundary
97  std::vector<Z2i::SCell> vectBdrySCell;
98  SurfelAdjacency<2> SAdj( true );
100  ks, SAdj, set2d, aCell );
101 
102  board << CustomStyle( (*(vectBdrySCell.begin())).className(),
103  new CustomColors( Color( 255, 255, 0 ),
104  Color( 192, 192, 0 ) ));
105 
106  GradientColorMap<int> cmap_grad( 0, (int)vectBdrySCell.size() );
107  cmap_grad.addColor( Color( 50, 50, 255 ) );
108  cmap_grad.addColor( Color( 255, 0, 0 ) );
109  cmap_grad.addColor( Color( 255, 255, 10 ) );
110 
111  unsigned int d=0;
112  std::vector<Z2i::SCell>::iterator it;
113  for ( it=vectBdrySCell.begin() ; it != vectBdrySCell.end(); it++ ){
114  board<< CustomStyle((*it).className() ,
115  new CustomColors( Color::Black,
116  cmap_grad( d )))<< *it;
117  d++;
118  }
119 
120 
121  // Extract all boundaries:
122  std::set<Z2i::SCell> bdry;
123  // Z2i::Cell low = ks.uFirst(ks.uSpel(ks.lowerBound()));
124  // Z2i::Cell upp = ks.uLast(ks.uSpel(ks.upperBound()));
126  ( bdry,
127  ks, set2d, ks.lowerBound(), ks.upperBound() );
128 
129 
130  std::set<Z2i::SCell>::iterator itB;
131  for ( itB=bdry.begin() ; itB != bdry.end(); itB++ ){
132  board2<< CustomStyle((*itB).className() ,
133  new CustomColors( Color::Black,
134  cmap_grad( d )))<< *itB;
135  d++;
136  }
137 
138  std::vector< std::vector<Z2i::SCell> > vectContoursBdrySCell;
140  ks, SAdj, set2d );
141  GradientColorMap<int> cmap_grad3( 0, (int)vectContoursBdrySCell.size() );
142  cmap_grad3.addColor( Color( 50, 50, 255 ) );
143  cmap_grad3.addColor( Color( 255, 0, 0 ) );
144  cmap_grad3.addColor( Color( 20, 200, 0 ) );
145  cmap_grad3.addColor( Color( 200, 200, 200 ) );
146  cmap_grad3.addColor( Color( 20, 200, 200 ) );
147  cmap_grad3.addColor( Color( 200, 20, 200 ) );
148 
149  d=0;
150  for(unsigned int i=0; i< vectContoursBdrySCell.size(); i++){
151  d++;
152  for(unsigned int j=0; j< vectContoursBdrySCell.at(i).size(); j++){
153  board3<< CustomStyle(vectContoursBdrySCell.at(i).at(j).className() ,
154  new CustomColors( Color::Black,
155  cmap_grad3( d )))<<vectContoursBdrySCell.at(i).at(j) ;
156 
157  }
158  }
159 
160 
161 
162 
163  board << aCell;
164  board.saveEPS( "ctopo-2.eps");
165  board.saveFIG( "ctopo-2.fig");
166 
167  board2.saveEPS( "ctopo-2d.eps");
168  board2.saveFIG( "ctopo-2d.fig");
169 
170  board3.saveEPS( "ctopo-2e.eps");
171  board3.saveFIG( "ctopo-2e.fig");
172 
173  return (space_ok);
174 }
175 // //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
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...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
const Point & lowerBound() const
Return the lower bound for digital points in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:906
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
int main(int, char **)
Definition: ctopo-2.cpp:69
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: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:98
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
ImageContainerBySTLVector< Domain, Value > Image