DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleGridCurve2d.cpp File Reference

An example file for GridCurve. More...

#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"

Go to the source code of this file.

Functions

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

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.

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}
std::ostream & info()
bool isNotEmpty(const IC &itb, const IC &ite)
Trace trace
Definition: Common.h:154

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

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

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;
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
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
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
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;
239 Range::ConstReverseIterator rit = r.rbegin();
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}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
static void readFromPointsRange(const TConstIterator &itBegin, const TConstIterator &itEnd, FreemanChain &c)
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
SCellsRange getSCellsRange() const
Definition: GridCurve.h:415
bool initFromVectorStream(std::istream &in)
PointsRange getPointsRange() const
Definition: GridCurve.h:426
IncidentPointsRange getIncidentPointsRange() const
Definition: GridCurve.h:486
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
GridCurve::CodesRange getCodesRange() const
Definition: GridCurve.h:496
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
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.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
std::reverse_iterator< ConstIterator > ConstReverseIterator
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
static void track2DBoundary(std::vector< SCell > &aSCellContour2D, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void setUnit(Unit unit)
Definition: Board.cpp:240
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Domain domain

References DGtal::FreemanChain< TInteger >::begin(), DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), domain, DGtal::Trace::emphase(), DGtal::FreemanChain< TInteger >::end(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GridCurve< TKSpace >::getCodesRange(), DGtal::GridCurve< TKSpace >::getIncidentPointsRange(), DGtal::GridCurve< TKSpace >::getPointsRange(), DGtal::GridCurve< TKSpace >::getSCellsRange(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GridCurve< TKSpace >::initFromPointsRange(), DGtal::GridCurve< TKSpace >::initFromSCellsVector(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::FreemanChain< TInteger >::readFromPointsRange(), LibBoard::Board::saveEPS(), LibBoard::Board::setUnit(), DGtal::trace, DGtal::Surfaces< TKSpace >::track2DBoundary(), and DGtal::GridCurve< TKSpace >::writeVectorToStream().