DGtal  0.9.3
Functions
exampleGridCurve2d.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for exampleGridCurve2d.cpp:

Go to the source code of this file.

Functions

template<typename CI >
void displayAll (const CI &ciBegin, const CI &ciEnd)
 
int main (int argc, char **argv)
 

Detailed Description

An example file for GridCurve.

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/09/09

This file is part of the DGtal library.

Definition in file exampleGridCurve2d.cpp.

Function Documentation

◆ displayAll()

template<typename CI >
void displayAll ( const CI &  ciBegin,
const CI &  ciEnd 
)

[GridCurveGenericFunctionDisplayAll]

Examples:
geometry/curves/exampleGridCurve2d.cpp.

Definition at line 62 of file exampleGridCurve2d.cpp.

References DGtal::Trace::info(), and DGtal::trace.

63 {
64  if ( isNotEmpty(ciBegin, ciEnd) )
65  { //if the range is not empty
66  CI i( ciBegin);
67  do
68  {
69  trace.info() << *i;
70  i++;
71  } while (i != ciEnd);
72  trace.info() << endl;
73  }
74 }
Trace trace
Definition: Common.h:137
bool isNotEmpty(const IC &itb, const IC &ite, IteratorType)
std::ostream & info()

◆ main()

int main ( int  argc,
char **  argv 
)

[GridCurveGenericFunctionDisplayAll]

[GridCurveDeclaration]

[GridCurveDeclaration]

[GridCurveFromDataFile]

[GridCurveFromDataFile]

[GridCurveFromDigitalSet]

[GridCurveFromDigitalSet]

[GridCurveFromFreemanChain]

[GridCurveFromFreemanChain]

[GridCurveStandardOutput]

[GridCurveStandardOutput]

[GridCurveToDataFile]

[GridCurveToDataFile]

[GridCurveToGraphics]

[GridCurveToGraphics]

[GridCurveToFreemanChain]

[GridCurveToFreemanChain]

[GridCurveIncidentPointsRangeIO]

[GridCurveIncidentPointsRangeIO]

[GridCurveRangeIterators]

[GridCurveRangeIterators]

Definition at line 78 of file exampleGridCurve2d.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::begin(), DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::c(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), domain(), DGtal::Trace::emphase(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::end(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::rbegin(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::rend(), LibBoard::Board::saveEPS(), LibBoard::Board::setUnit(), and DGtal::trace.

79 {
80  trace.beginBlock ( "Example for 2d gridcurves" );
81  trace.info() << "Args:";
82  for ( int i = 0; i < argc; ++i )
83  trace.info() << " " << argv[ i ];
84  trace.info() << endl;
85 
86  string square = examplesPath + "samples/smallSquare.dat";
87  string S = examplesPath + "samples/contourS.fc";
88 
89  // domain
90  Point lowerBound( -50, -50 );
91  Point upperBound( 50, 50 );
92 
94  //default construction
95  Curve c1;
96 
97  //from a Khalimsky space
98  K2 ks; ks.init( lowerBound, upperBound, true );
99  Curve c2( ks );
101 
102  trace.emphase() << "Input" << endl;
103  trace.info() << "\t from a data file " << endl;
104  {
106  fstream inputStream;
107  inputStream.open (square.c_str(), ios::in);
108  c1.initFromVectorStream(inputStream);
109  inputStream.close();
111  }
112  trace.info() << "\t from a digital set " << endl;
113  {
114 
115  // digital set: diamond of radius 30 centered at the origin
116  Point o( 0, 0 );
117  Domain domain( lowerBound, upperBound );
118  DigitalSet set( domain );
119  for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
120  {
121  if ( (*it - o ).norm1() <= 30 ) set.insertNew( *it );
122  }
123 
125  vector<SCell> contour; //contour
126  SurfelAdjacency<K2::dimension> sAdj( true ); //adjacency
127 
128  //tracking and init grid curve
129  SCell s = Surfaces<KSpace>::findABel( ks, set, 1000 );
130  Surfaces<KSpace>::track2DBoundary( contour, ks, sAdj, set, s );
131  c2.initFromSCellsVector( contour );
133  }
134 
135  trace.info() << "\t from a FreemanChain (from a file) " << endl;
136  {
137  fstream inputStream;
138  inputStream.open (S.c_str(), ios::in);
139  FreemanChain<int> fc(inputStream);
140  inputStream.close();
141 
142  Curve c;
144  c.initFromPointsRange( fc.begin(), fc.end() );
146 
147  }
148 
149  trace.emphase() << "Output" << endl;
150  trace.info() << "\t standard output " << endl;
151  {
153  trace.info() << c1 << std::endl;
155  }
156  trace.info() << "\t into a data file " << endl;
157  {
159  ofstream outputStream("myGridCurve.dat");
160  if (outputStream.is_open())
161  c2.writeVectorToStream(outputStream);
162  outputStream.close();
164  }
165  trace.info() << "\t into a vector graphics file " << endl;
166  {
168  Board2D aBoard;
169  aBoard.setUnit(Board2D::UCentimeter);
170  aBoard << c2;
171  aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox, 5000 );
173  }
174 
175  trace.info() << "\t into a FreemanChain " << endl;
176  {
179  FreemanChain fc;
180  FreemanChain::readFromPointsRange( c1.getPointsRange(), fc );
181  trace.info() << "\t" << fc << endl;
183  }
184 
185  trace.emphase() << "Ranges Ouput" << endl;
186  {
187  Board2D aBoard;
188  aBoard.setUnit(Board2D::UCentimeter);
189 
190  Point low(-1,-1);
191  Point up(3,3);
192  Domain aDomain( low,up );
193 
194  {//1cellsRange
195  Curve::SCellsRange r = c1.getSCellsRange();
196 
197  trace.info() << r << endl;
198 
199  aBoard << SetMode(aDomain.className(), "Grid") << aDomain;
200  aBoard << r;
201  aBoard.saveEPS( "My1CellsRange.eps", Board2D::BoundingBox, 5000 );
202  aBoard.clear();
203  }
204  {//IncidentPointsRange
206  Curve::IncidentPointsRange r = c1.getIncidentPointsRange();
207 
208  trace.info() << r << endl;
209 
210  aBoard << SetMode(aDomain.className(), "Grid") << aDomain;
211  aBoard << r;
212  aBoard.saveEPS( "MyIncidentPointsRange.eps", Board2D::BoundingBox, 5000 );
214  aBoard.clear();
215  }
216  {//CodesRange
217  Curve::CodesRange r = c1.getCodesRange();
218 
219  trace.info() << r << endl;
220  }
221  }
222 
223  trace.emphase() << "Ranges Iterators" << endl;
224  {
225  typedef Curve::CodesRange Range;
226  Range r = c1.getCodesRange();
227 
229  trace.info() << "\t iterate over the range" << endl;
230  Range::ConstIterator it = r.begin();
231  Range::ConstIterator itEnd = r.end();
232  for ( ; it != itEnd; ++it)
233  {
234  trace.info() << *it;
235  }
236  trace.info() << endl;
237 
238  trace.info() << "\t iterate over the range in the reverse way" << endl;
240  Range::ConstReverseIterator ritEnd = r.rend();
241  for ( ; rit != ritEnd; ++rit)
242  {
243  trace.info() << *rit;
244  }
245  trace.info() << endl;
246 
247  trace.info() << "\t iterate over the range in a circular way" << endl;
248  Range::ConstCirculator c = r.c();
249  //set the starting element wherever you want...
250  for (unsigned i = 0; i < 20; ++i) ++c;
251  //... and circulate
252  Range::ConstCirculator cend( c );
253  do
254  {
255  trace.info() << *c;
256  c++;
257  } while (c!=cend);
258  trace.info() << endl;
260 
261  trace.info() << "\t Generic function working with any (circular)iterator" << endl;
262  displayAll<Range::ConstIterator>(r.begin(),r.end());
263  displayAll<Range::ConstReverseIterator>(r.rbegin(),r.rend());
264  displayAll<Range::ConstCirculator>(r.c(),r.c());
265 
266  }
267 
268  trace.endBlock();
269  return 0;
270 }
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
const ConstIterator & end() const
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
GridCurve< K2 > Curve
Definition: StdDefs.h:116
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
double endBlock()
KSpace K2
Definition: StdDefs.h:78
std::ostream & emphase()
bool init(const Point &lower, const Point &upper, bool isClosed)
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
const ConstIterator & begin() const
std::reverse_iterator< ConstIterator > ConstReverseIterator
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70