DGtal  0.9.2
examplePreimage.cpp
1 
30 #include <iostream>
32 
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "ConfigExamples.h"
36 
37 #include "DGtal/geometry/tools/Preimage2D.h"
38 #include "DGtal/shapes/fromPoints/StraightLineFrom2Points.h"
39 #include "DGtal/shapes/fromPoints/CircleFrom2Points.h"
40 
41 #include "DGtal/io/boards/Board2D.h"
42 
44 
45 using namespace std;
46 using namespace DGtal;
47 using namespace Z2i;
48 
49 
51 int main( int argc, char** argv )
52 {
53  trace.beginBlock ( "Example for Preimage computation" );
54  trace.info() << "Args:";
55  for ( int i = 0; i < argc; ++i )
56  trace.info() << " " << argv[ i ];
57  trace.info() << endl;
58 
59  std::string filename = examplesPath + "samples/DSS.dat";
60  ifstream instream; // input stream
61  instream.open (filename.c_str(), ifstream::in);
62 
63  Curve c; //grid curve
64  c.initFromVectorStream(instream);
65 
66 {
67  trace.beginBlock("Simple preimage example");
68 
70  typedef StraightLineFrom2Points<Curve::Point> StraightLine;
71  StraightLine aStraightLine; //instance of straight line
74 
75 
77  Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
78  Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
79  Curve::IncidentPointsRange::ConstIterator itEnd (r.end());
80 
81  //preimage computation
82  Preimage2D thePreimage(it->first, it->second, aStraightLine);
83  ++it;
84  while ( (it != itEnd) &&
85  (thePreimage.addFront(it->first, it->second)) )
86  {
87  ++it;
88  }
89  trace.info() << thePreimage << endl;
90  //display
91  Board2D board;
92  board.setUnit(Board2D::UCentimeter);
93  board << r << thePreimage;
94  board.saveEPS( "PreimageExample.eps" );
96 
97  trace.endBlock();
98 }
99 
100 {
101  trace.beginBlock("Preimage example with circles");
102  Curve::Point pole(7,2);
103 
105  typedef CircleFrom2Points<Curve::Point> Circle;
106  Circle aCircle( pole ); //instance of circle passing through point 'pole'
107  typedef Preimage2D<Circle> Preimage2D;
109 
110  Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
111  Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
112  Curve::IncidentPointsRange::ConstIterator itEnd (r.end());
113 
114  //preimage computation
115  Preimage2D thePreimage(it->first, it->second, aCircle);
116  ++it;
117  while ( (it != itEnd) &&
118  (thePreimage.addFront(it->first, it->second)) )
119  {
120  ++it;
121  }
122  trace.info() << thePreimage << endl;
123  //display
124  Board2D board;
125  board.setUnit(Board2D::UCentimeter);
126  board << r << SetMode(pole.className(),"Grid") << pole << thePreimage;
127  board.saveEPS( "PreimageExample2.eps" );
128  board.saveSVG( "PreimageExample2.svg" );
129 #ifdef WITH_CAIRO
130  board.saveCairo("PreimageExample2.pdf", Board2D::CairoPDF);
131 #endif
132 
133  trace.endBlock();
134 }
135 
136  return 0;
137 }
138 // //
void beginBlock(const std::string &keyword="")
Aim: Computes the preimage of the 2D Euclidean shapes crossing a sequence of n straigth segments in O...
Definition: Preimage2D.h:93
Trace trace
Definition: Common.h:130
Aim: Represents a straight line uniquely defined by two 2D points and that is able to return for any ...
GridCurve< K2 > Curve
Definition: StdDefs.h:116
STL namespace.
double endBlock()
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
std::ostream & info()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70