DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ctopo-2.cpp
1 
31 
32 #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/PNMReader.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 = PNMReader<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  SetPredicate<Z2i::DigitalSet> set2dPredicate( set2d );
83  Z2i::SCell aCell = Surfaces<Z2i::KSpace>::findABel(ks, set2dPredicate );
84 
85  // Getting the consecutive surfels of the 2D boundary
86  std::vector<Z2i::SCell> vectBdrySCell;
87  SurfelAdjacency<2> SAdj( true );
89  ks, SAdj, set2dPredicate, aCell );
90 
91  board << CustomStyle( (*(vectBdrySCell.begin())).className(),
92  new CustomColors( Color( 255, 255, 0 ),
93  Color( 192, 192, 0 ) ));
94 
95  GradientColorMap<int> cmap_grad( 0, (const int)vectBdrySCell.size() );
96  cmap_grad.addColor( Color( 50, 50, 255 ) );
97  cmap_grad.addColor( Color( 255, 0, 0 ) );
98  cmap_grad.addColor( Color( 255, 255, 10 ) );
99 
100  unsigned int d=0;
101  std::vector<Z2i::SCell>::iterator it;
102  for ( it=vectBdrySCell.begin() ; it != vectBdrySCell.end(); it++ ){
103  board<< CustomStyle((*it).className() ,
104  new CustomColors( Color::Black,
105  cmap_grad( d )))<< *it;
106  d++;
107  }
108 
109 
110  // Extract all boundaries:
111  std::set<Z2i::SCell> bdry;
112  // Z2i::Cell low = ks.uFirst(ks.uSpel(ks.lowerBound()));
113  // Z2i::Cell upp = ks.uLast(ks.uSpel(ks.upperBound()));
115  ( bdry,
116  ks, set2dPredicate, ks.lowerBound(), ks.upperBound() );
117 
118 
119  std::set<Z2i::SCell>::iterator itB;
120  for ( itB=bdry.begin() ; itB != bdry.end(); itB++ ){
121  board2<< CustomStyle((*itB).className() ,
122  new CustomColors( Color::Black,
123  cmap_grad( d )))<< *itB;
124  d++;
125  }
126 
127  std::vector< std::vector<Z2i::SCell> > vectContoursBdrySCell;
129  ks, SAdj, set2dPredicate );
130  GradientColorMap<int> cmap_grad3( 0, (const int)vectContoursBdrySCell.size() );
131  cmap_grad3.addColor( Color( 50, 50, 255 ) );
132  cmap_grad3.addColor( Color( 255, 0, 0 ) );
133  cmap_grad3.addColor( Color( 20, 200, 0 ) );
134  cmap_grad3.addColor( Color( 200, 200, 200 ) );
135  cmap_grad3.addColor( Color( 20, 200, 200 ) );
136  cmap_grad3.addColor( Color( 200, 20, 200 ) );
137 
138  d=0;
139  for(unsigned int i=0; i< vectContoursBdrySCell.size(); i++){
140  d++;
141  for(unsigned int j=0; j< vectContoursBdrySCell.at(i).size(); j++){
142  board3<< CustomStyle(vectContoursBdrySCell.at(i).at(j).className() ,
143  new CustomColors( Color::Black,
144  cmap_grad3( d )))<<vectContoursBdrySCell.at(i).at(j) ;
145 
146  }
147  }
148 
149 
150 
151 
152  board << aCell;
153  board.saveEPS( "ctopo-2.eps");
154  board.saveFIG( "ctopo-2.fig");
155 
156  board2.saveEPS( "ctopo-2d.eps");
157  board2.saveFIG( "ctopo-2d.fig");
158 
159  board3.saveEPS( "ctopo-2e.eps");
160  board3.saveFIG( "ctopo-2e.fig");
161 
162  return (space_ok);
163 }
164 // //