DGtal  0.9.2
ctopo-2.cpp
1 
31 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/topology/KhalimskySpaceND.h"
35 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
36 #include "DGtal/images/ImageSelector.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/topology/helpers/Surfaces.h"
39 
40 #include "DGtal/io/readers/PGMReader.h"
41 #include "DGtal/io/colormaps/GradientColorMap.h"
42 #include "DGtal/io/boards/Board2D.h"
43 #include "DGtal/io/Color.h"
44 
45 #include "ConfigExamples.h"
46 
47 
48 
49 
51 
52 using namespace std;
53 using namespace DGtal;
54 
56 
57 int main( int /*argc*/, char** /*argv*/ )
58 {
60  std::string inputFilename = examplesPath + "samples/circleR10modif.pgm";
61  Image image = PGMReader<Image>::importPGM( inputFilename );
62 
63  Z2i::DigitalSet set2d (image.domain());
64  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 0, 255);
65  Board2D board;
66  board << image.domain() << set2d; // display domain and set
67 
68  Board2D board2;
69  board2 << image.domain() << set2d; // display domain and set
70 
71  Board2D board3;
72  board3 << image.domain() << set2d; // display domain and set
73 
74 
75  // Construct the Khalimsky space from the image domain
76  Z2i::KSpace ks;
77  bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
78 
79 
80 
81  //Extract a boundary cell
82  Z2i::SCell aCell = Surfaces<Z2i::KSpace>::findABel(ks, set2d );
83 
84  // Getting the consecutive surfels of the 2D boundary
85  std::vector<Z2i::SCell> vectBdrySCell;
86  SurfelAdjacency<2> SAdj( true );
88  ks, SAdj, set2d, aCell );
89 
90  board << CustomStyle( (*(vectBdrySCell.begin())).className(),
91  new CustomColors( Color( 255, 255, 0 ),
92  Color( 192, 192, 0 ) ));
93 
94  GradientColorMap<int> cmap_grad( 0, (const int)vectBdrySCell.size() );
95  cmap_grad.addColor( Color( 50, 50, 255 ) );
96  cmap_grad.addColor( Color( 255, 0, 0 ) );
97  cmap_grad.addColor( Color( 255, 255, 10 ) );
98 
99  unsigned int d=0;
100  std::vector<Z2i::SCell>::iterator it;
101  for ( it=vectBdrySCell.begin() ; it != vectBdrySCell.end(); it++ ){
102  board<< CustomStyle((*it).className() ,
103  new CustomColors( Color::Black,
104  cmap_grad( d )))<< *it;
105  d++;
106  }
107 
108 
109  // Extract all boundaries:
110  std::set<Z2i::SCell> bdry;
111  // Z2i::Cell low = ks.uFirst(ks.uSpel(ks.lowerBound()));
112  // Z2i::Cell upp = ks.uLast(ks.uSpel(ks.upperBound()));
114  ( bdry,
115  ks, set2d, ks.lowerBound(), ks.upperBound() );
116 
117 
118  std::set<Z2i::SCell>::iterator itB;
119  for ( itB=bdry.begin() ; itB != bdry.end(); itB++ ){
120  board2<< CustomStyle((*itB).className() ,
121  new CustomColors( Color::Black,
122  cmap_grad( d )))<< *itB;
123  d++;
124  }
125 
126  std::vector< std::vector<Z2i::SCell> > vectContoursBdrySCell;
128  ks, SAdj, set2d );
129  GradientColorMap<int> cmap_grad3( 0, (const int)vectContoursBdrySCell.size() );
130  cmap_grad3.addColor( Color( 50, 50, 255 ) );
131  cmap_grad3.addColor( Color( 255, 0, 0 ) );
132  cmap_grad3.addColor( Color( 20, 200, 0 ) );
133  cmap_grad3.addColor( Color( 200, 200, 200 ) );
134  cmap_grad3.addColor( Color( 20, 200, 200 ) );
135  cmap_grad3.addColor( Color( 200, 20, 200 ) );
136 
137  d=0;
138  for(unsigned int i=0; i< vectContoursBdrySCell.size(); i++){
139  d++;
140  for(unsigned int j=0; j< vectContoursBdrySCell.at(i).size(); j++){
141  board3<< CustomStyle(vectContoursBdrySCell.at(i).at(j).className() ,
142  new CustomColors( Color::Black,
143  cmap_grad3( d )))<<vectContoursBdrySCell.at(i).at(j) ;
144 
145  }
146  }
147 
148 
149 
150 
151  board << aCell;
152  board.saveEPS( "ctopo-2.eps");
153  board.saveFIG( "ctopo-2.fig");
154 
155  board2.saveEPS( "ctopo-2d.eps");
156  board2.saveFIG( "ctopo-2d.fig");
157 
158  board3.saveEPS( "ctopo-2e.eps");
159  board3.saveFIG( "ctopo-2e.fig");
160 
161  return (space_ok);
162 }
163 // //
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
void addColor(const Color &color)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
const Point & lowerBound() const
bool init(const Point &lower, const Point &upper, bool isClosed)
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
const Domain & domain() const
Definition: Image.h:192
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70