DGtal  1.3.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");
StraightLine aStraightLine; //instance of straight line
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);
Circle aCircle( pole ); //instance of circle passing through point 'pole'
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;
}
// //
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::Trace::endBlock
double endBlock()
DGtal::Preimage2D
Aim: Computes the preimage of the 2D Euclidean shapes crossing a sequence of n straigth segments in O...
Definition: Preimage2D.h:93
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Preimage2D::addFront
bool addFront(const Point &aP, const Point &aQ)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::StraightLineFrom2Points
Aim: Represents a straight line uniquely defined by two 2D points and that is able to return for any ...
Definition: StraightLineFrom2Points.h:68
DGtal::CircleFrom2Points
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Definition: CircleFrom2Points.h:67
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal::Z2i::Curve
GridCurve< K2 > Curve
Definition: StdDefs.h:116
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Point
MyPointD Point
Definition: testClone2.cpp:383