DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
examplePreimage.cpp
1 
30 
31 #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 // //