This snippet shows how to construct, scan and display a 2d grid curve.
#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"
using namespace Z2i;
template <typename CI>
void displayAll(
const CI& ciBegin,
const CI& ciEnd )
{
if ( isNotEmpty(ciBegin, ciEnd) )
{
CI i( ciBegin);
do
{
i++;
} while (i != ciEnd);
}
}
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
trace.
info() <<
" " << argv[ i ];
string square = examplesPath + "samples/smallSquare.dat";
string S = examplesPath + "samples/contourS.fc";
Point lowerBound( -50, -50 );
Point upperBound( 50, 50 );
Curve c1;
K2 ks; ks.
init( lowerBound, upperBound,
true );
Curve c2( ks );
trace.
emphase() <<
"Input" << endl;
trace.
info() <<
"\t from a data file " << endl;
{
fstream inputStream;
inputStream.open (square.c_str(), ios::in);
c1.initFromVectorStream(inputStream);
inputStream.close();
}
trace.
info() <<
"\t from a digital set " << endl;
{
for ( Domain::ConstIterator it =
domain.begin(); it !=
domain.end(); ++it )
{
if ( (*it - o ).norm1() <= 30 ) set.insertNew( *it );
}
vector<SCell> contour;
c2.initFromSCellsVector( contour );
}
trace.
info() <<
"\t from a FreemanChain (from a file) " << endl;
{
fstream inputStream;
inputStream.open (S.c_str(), ios::in);
inputStream.close();
c.initFromPointsRange( fc.begin(), fc.end() );
}
trace.
info() <<
"\t standard output " << endl;
{
}
trace.
info() <<
"\t into a data file " << endl;
{
ofstream outputStream("myGridCurve.dat");
if (outputStream.is_open())
c2.writeVectorToStream(outputStream);
outputStream.close();
}
trace.
info() <<
"\t into a vector graphics file " << endl;
{
aBoard.
setUnit(Board2D::UCentimeter);
aBoard << c2;
aBoard.
saveEPS(
"myGridCurve.eps", Board2D::BoundingBox, 5000 );
}
trace.
info() <<
"\t into a FreemanChain " << endl;
{
FreemanChain::readFromPointsRange( c1.getPointsRange(), fc );
}
{
aBoard.
setUnit(Board2D::UCentimeter);
{
Curve::SCellsRange r = c1.getSCellsRange();
aBoard <<
SetMode(aDomain.className(),
"Grid") << aDomain;
aBoard << r;
aBoard.
saveEPS(
"My1CellsRange.eps", Board2D::BoundingBox, 5000 );
}
{
Curve::IncidentPointsRange r = c1.getIncidentPointsRange();
aBoard <<
SetMode(aDomain.className(),
"Grid") << aDomain;
aBoard << r;
aBoard.
saveEPS(
"MyIncidentPointsRange.eps", Board2D::BoundingBox, 5000 );
}
{
Curve::CodesRange r = c1.getCodesRange();
}
}
{
typedef Curve::CodesRange
Range;
Range r = c1.getCodesRange();
trace.
info() <<
"\t iterate over the range" << endl;
Range::ConstIterator it = r.begin();
Range::ConstIterator itEnd = r.end();
for ( ; it != itEnd; ++it)
{
}
trace.
info() <<
"\t iterate over the range in the reverse way" << endl;
Range::ConstReverseIterator rit = r.rbegin();
Range::ConstReverseIterator ritEnd = r.rend();
for ( ; rit != ritEnd; ++rit)
{
}
trace.
info() <<
"\t iterate over the range in a circular way" << endl;
Range::ConstCirculator c = r.c();
for (unsigned i = 0; i < 20; ++i) ++c;
Range::ConstCirculator cend( c );
do
{
c++;
} while (c!=cend);
trace.
info() <<
"\t Generic function working with any (circular)iterator" << endl;
displayAll<Range::ConstIterator>(r.begin(),r.end());
displayAll<Range::ConstReverseIterator>(r.rbegin(),r.rend());
displayAll<Range::ConstCirculator>(r.c(),r.c());
}
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void displayAll(const CI &ciBegin, const CI &ciEnd)
[GridCurveGenericFunctionDisplayAll]
DGtal is the top-level namespace which contains all DGtal functions and types.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet