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 std;
using namespace Z2i;
template <typename CI>
void displayAll(
const CI& ciBegin,
const CI& ciEnd )
{
{
CI i( ciBegin);
do
{
i++;
} while (i != ciEnd);
}
}
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
string square = examplesPath +
"samples/smallSquare.dat";
string S = examplesPath + "samples/contourS.fc";
Point lowerBound( -50, -50 );
Point upperBound( 50, 50 );
K2 ks; ks.
init( lowerBound, upperBound,
true );
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;
{
{
if ( (*it - o ).norm1() <= 30 ) set.insertNew( *it );
}
vector<SCell> contour;
SurfelAdjacency<K2::dimension> sAdj( true );
SCell s = Surfaces<KSpace>::findABel( ks, set, 1000 );
Surfaces<KSpace>::track2DBoundary( contour, ks, sAdj, set, s );
c2.initFromSCellsVector( contour );
}
trace.
info() <<
"\t from a FreemanChain (from a file) " << endl;
{
fstream inputStream;
inputStream.open (S.c_str(), ios::in);
FreemanChain<int> fc(inputStream);
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;
{
Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
aBoard << c2;
aBoard.saveEPS( "myGridCurve.eps", Board2D::BoundingBox, 5000 );
}
trace.
info() <<
"\t into a FreemanChain " << endl;
{
typedef FreemanChain<Curve::KSpace::Integer> FreemanChain;
FreemanChain fc;
FreemanChain::readFromPointsRange( c1.getPointsRange(), fc );
}
{
Board2D aBoard;
aBoard.setUnit(Board2D::UCentimeter);
{
Curve::SCellsRange r = c1.getSCellsRange();
aBoard << SetMode(aDomain.className(), "Grid") << aDomain;
aBoard << r;
aBoard.saveEPS( "My1CellsRange.eps", Board2D::BoundingBox, 5000 );
aBoard.clear();
}
{
Curve::IncidentPointsRange r = c1.getIncidentPointsRange();
aBoard << SetMode(aDomain.className(), "Grid") << aDomain;
aBoard << r;
aBoard.saveEPS( "MyIncidentPointsRange.eps", Board2D::BoundingBox, 5000 );
aBoard.clear();
}
{
Curve::CodesRange r = c1.getCodesRange();
}
}
{
typedef Curve::CodesRange
Range;
Range r = c1.getCodesRange();
trace.
info() <<
"\t iterate over the range" << endl;
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;
}
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
void beginBlock(const std::string &keyword="")
void displayAll(const CI &ciBegin, const CI &ciEnd)
[GridCurveGenericFunctionDisplayAll]
MyDigitalSurface::ConstIterator ConstIterator
bool isNotEmpty(const IC &itb, const IC &ite, IteratorType)
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet