Example of Preimage2D.
#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 Z2i;
int main(
int argc,
char** argv )
{
trace.
beginBlock (
"Example for Preimage computation" );
for ( int i = 0; i < argc; ++i )
trace.
info() <<
" " << argv[ i ];
std::string filename = examplesPath + "samples/DSS.dat";
ifstream instream;
instream.open (filename.c_str(), ifstream::in);
Curve c;
c.initFromVectorStream(instream);
{
StraightLine aStraightLine;
Curve::IncidentPointsRange r = c.getIncidentPointsRange();
Curve::IncidentPointsRange::ConstIterator it (r.begin());
Curve::IncidentPointsRange::ConstIterator itEnd (r.end());
Preimage2D thePreimage(it->first, it->second, aStraightLine);
++it;
while ( (it != itEnd) &&
(thePreimage.
addFront(it->first, it->second)) )
{
++it;
}
trace.
info() << thePreimage << endl;
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 );
Curve::IncidentPointsRange r = c.getIncidentPointsRange();
Curve::IncidentPointsRange::ConstIterator it (r.begin());
Curve::IncidentPointsRange::ConstIterator itEnd (r.end());
Preimage2D thePreimage(it->first, it->second, aCircle);
++it;
while ( (it != itEnd) &&
(thePreimage.
addFront(it->first, it->second)) )
{
++it;
}
trace.
info() << thePreimage << endl;
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;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Aim: Computes the preimage of the 2D Euclidean shapes crossing a sequence of n straigth segments in O...
bool addFront(const Point &aP, const Point &aQ)
Aim: Represents a straight line uniquely defined by two 2D points and that is able to return for any ...
void beginBlock(const std::string &keyword="")
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
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....