DGtal 1.4.0
Loading...
Searching...
No Matches
examplePreimage.cpp
Go to the documentation of this file.
1
39#include <iostream>
40
41#include "DGtal/base/Common.h"
42#include "DGtal/helpers/StdDefs.h"
43#include "ConfigExamples.h"
44
45#include "DGtal/geometry/tools/Preimage2D.h"
46#include "DGtal/shapes/fromPoints/StraightLineFrom2Points.h"
47#include "DGtal/shapes/fromPoints/CircleFrom2Points.h"
48
49#include "DGtal/io/boards/Board2D.h"
50
52
53using namespace std;
54using namespace DGtal;
55using namespace Z2i;
56
57
59int main( int argc, char** argv )
60{
61 trace.beginBlock ( "Example for Preimage computation" );
62 trace.info() << "Args:";
63 for ( int i = 0; i < argc; ++i )
64 trace.info() << " " << argv[ i ];
65 trace.info() << endl;
66
67 std::string filename = examplesPath + "samples/DSS.dat";
68 ifstream instream; // input stream
69 instream.open (filename.c_str(), ifstream::in);
70
71 Curve c; //grid curve
72 c.initFromVectorStream(instream);
73
74{
75 trace.beginBlock("Simple preimage example");
76
78 typedef StraightLineFrom2Points<Curve::Point> StraightLine;
79 StraightLine aStraightLine; //instance of straight line
82
83
85 Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
86 Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
88
89 //preimage computation
90 Preimage2D thePreimage(it->first, it->second, aStraightLine);
91 ++it;
92 while ( (it != itEnd) &&
93 (thePreimage.addFront(it->first, it->second)) )
94 {
95 ++it;
96 }
97 trace.info() << thePreimage << endl;
98 //display
99 Board2D board;
100 board.setUnit(Board2D::UCentimeter);
101 board << r << thePreimage;
102 board.saveEPS( "PreimageExample.eps" );
104
105 trace.endBlock();
106}
107
108{
109 trace.beginBlock("Preimage example with circles");
110 Curve::Point pole(7,2);
111
113 typedef CircleFrom2Points<Curve::Point> Circle;
114 Circle aCircle( pole ); //instance of circle passing through point 'pole'
117
118 Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
119 Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
121
122 //preimage computation
123 Preimage2D thePreimage(it->first, it->second, aCircle);
124 ++it;
125 while ( (it != itEnd) &&
126 (thePreimage.addFront(it->first, it->second)) )
127 {
128 ++it;
129 }
130 trace.info() << thePreimage << endl;
131 //display
132 Board2D board;
133 board.setUnit(Board2D::UCentimeter);
134 board << r << SetMode(pole.className(),"Grid") << pole << thePreimage;
135 board.saveEPS( "PreimageExample2.eps" );
136 board.saveSVG( "PreimageExample2.svg" );
137#ifdef WITH_CAIRO
138 board.saveCairo("PreimageExample2.pdf", Board2D::CairoPDF);
139#endif
140
141 trace.endBlock();
142}
143
144 return 0;
145}
146// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
bool initFromVectorStream(std::istream &in)
Storage::const_iterator ConstIterator
Definition GridCurve.h:314
std::string className() const
Aim: Computes the preimage of the 2D Euclidean shapes crossing a sequence of n straigth segments in O...
Definition Preimage2D.h:94
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="")
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void setUnit(Unit unit)
Definition Board.cpp:239
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1138
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
int main()
Definition testBits.cpp:56