33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "ConfigExamples.h"
37 #include "DGtal/geometry/curves/FreemanChain.h"
38 #include "DGtal/geometry/curves/GridCurve.h"
40 #include "DGtal/topology/helpers/Surfaces.h"
41 #include "DGtal/io/boards/Board2D.h"
46 using namespace DGtal;
51 template <
typename CI>
52 void displayAll(
const CI& ciBegin,
const CI& ciEnd )
68 int main(
int argc,
char** argv )
72 for (
int i = 0; i < argc; ++i )
76 string square = examplesPath +
"samples/smallSquare.dat";
77 string S = examplesPath +
"samples/contourS.fc";
80 Point lowerBound( -50, -50 );
81 Point upperBound( 50, 50 );
88 K2 ks; ks.
init( lowerBound, upperBound,
true );
93 trace.
info() <<
"\t from a data file " << endl;
97 inputStream.open (square.c_str(), ios::in);
98 c1.initFromVectorStream(inputStream);
102 trace.
info() <<
"\t from a digital set " << endl;
107 Domain domain( lowerBound, upperBound );
109 for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
111 if ( (*it - o ).norm1() <= 30 )
set.insertNew( *it );
115 vector<SCell> contour;
122 c2.initFromSCellsVector( contour );
126 trace.
info() <<
"\t from a FreemanChain (from a file) " << endl;
129 inputStream.open (S.c_str(), ios::in);
135 c.initFromPointsRange( fc.begin(), fc.end() );
141 trace.
info() <<
"\t standard output " << endl;
147 trace.
info() <<
"\t into a data file " << endl;
150 ofstream outputStream(
"myGridCurve.dat");
151 if (outputStream.is_open())
152 c2.writeVectorToStream(outputStream);
153 outputStream.close();
156 trace.
info() <<
"\t into a vector graphics file " << endl;
160 aBoard.
setUnit(Board2D::UCentimeter);
162 aBoard.
saveEPS(
"myGridCurve.eps", Board2D::BoundingBox, 5000 );
166 trace.
info() <<
"\t into a FreemanChain " << endl;
171 FreemanChain::readFromPointsRange( c1.getPointsRange(), fc );
179 aBoard.
setUnit(Board2D::UCentimeter);
186 Curve::SCellsRange r = c1.getSCellsRange();
190 aBoard <<
SetMode(aDomain.className(),
"Grid") << aDomain;
192 aBoard.
saveEPS(
"My1CellsRange.eps", Board2D::BoundingBox, 5000 );
197 Curve::IncidentPointsRange r = c1.getIncidentPointsRange();
201 aBoard <<
SetMode(aDomain.className(),
"Grid") << aDomain;
203 aBoard.
saveEPS(
"MyIncidentPointsRange.eps", Board2D::BoundingBox, 5000 );
208 Curve::CodesRange r = c1.getCodesRange();
216 typedef Curve::CodesRange
Range;
220 trace.
info() <<
"\t iterate over the range" << endl;
221 Range::ConstIterator it = r.
begin();
222 Range::ConstIterator itEnd = r.
end();
223 for ( ; it != itEnd; ++it)
229 trace.
info() <<
"\t iterate over the range in the reverse way" << endl;
230 Range::ConstReverseIterator rit = r.rbegin();
231 Range::ConstReverseIterator ritEnd = r.rend();
232 for ( ; rit != ritEnd; ++rit)
238 trace.
info() <<
"\t iterate over the range in a circular way" << endl;
239 Range::ConstCirculator c = r.c();
241 for (
unsigned i = 0; i < 20; ++i) ++c;
243 Range::ConstCirculator cend( c );
252 trace.
info() <<
"\t Generic function working with any (circular)iterator" << endl;
253 displayAll<Range::ConstIterator>(r.
begin(),r.
end());
254 displayAll<Range::ConstReverseIterator>(r.rbegin(),r.rend());
255 displayAll<Range::ConstCirculator>(r.c(),r.c());