DGtal  1.4.beta
ctopo-2.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "ConfigExamples.h"
Include dependency graph for ctopo-2.cpp:

Go to the source code of this file.

Functions

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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/04/28

An example file named ctopo-2.

This file is part of the DGtal library.

Definition in file ctopo-2.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 69 of file ctopo-2.cpp.

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 }
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...
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
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

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), LibBoard::Board::saveEPS(), LibBoard::Board::saveFIG(), and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().