DGtal  1.4.beta
geometry/tools/examplePreimage.cpp

Example of Preimage2D.

Example of preimage based arc recognition.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/geometry/tools/Preimage2D.h"
#include "DGtal/shapes/fromPoints/StraightLineFrom2Points.h"
#include "DGtal/shapes/fromPoints/CircleFrom2Points.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
using namespace Z2i;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example for Preimage computation" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
std::string filename = examplesPath + "samples/DSS.dat";
ifstream instream; // input stream
instream.open (filename.c_str(), ifstream::in);
Curve c; //grid curve
c.initFromVectorStream(instream);
{
trace.beginBlock("Simple preimage example");
typedef StraightLineFrom2Points<Curve::Point> StraightLine;
StraightLine aStraightLine; //instance of straight line
typedef Preimage2D<StraightLine> Preimage2D;
Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
//preimage computation
Preimage2D thePreimage(it->first, it->second, aStraightLine);
++it;
while ( (it != itEnd) &&
(thePreimage.addFront(it->first, it->second)) )
{
++it;
}
trace.info() << thePreimage << endl;
//display
Board2D board;
board.setUnit(Board2D::UCentimeter);
board << r << thePreimage;
board.saveEPS( "PreimageExample.eps" );
}
{
trace.beginBlock("Preimage example with circles");
Curve::Point pole(7,2);
typedef CircleFrom2Points<Curve::Point> Circle;
Circle aCircle( pole ); //instance of circle passing through point 'pole'
typedef Preimage2D<Circle> Preimage2D;
Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
//preimage computation
Preimage2D thePreimage(it->first, it->second, aCircle);
++it;
while ( (it != itEnd) &&
(thePreimage.addFront(it->first, it->second)) )
{
++it;
}
trace.info() << thePreimage << endl;
//display
Board2D board;
board.setUnit(Board2D::UCentimeter);
board << r << SetMode(pole.className(),"Grid") << pole << thePreimage;
board.saveEPS( "PreimageExample2.eps" );
board.saveSVG( "PreimageExample2.svg" );
#ifdef WITH_CAIRO
board.saveCairo("PreimageExample2.pdf", Board2D::CairoPDF);
#endif
}
return 0;
}
// //
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
GridCurve< K2 > Curve
Definition: StdDefs.h:116
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383