DGtal  1.5.beta
exampleAlphaThickSegmentNoisy.cpp
Go to the documentation of this file.
1 
43 #include <iostream>
44 #include "ConfigExamples.h"
45 #include "DGtal/base/Common.h"
47 #include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
48 #include "DGtal/helpers/StdDefs.h"
49 #include "DGtal/io/readers/PointListReader.h"
51 #include "DGtal/io/boards/Board2D.h"
53 
54 using namespace std;
55 using namespace DGtal;
56 
58 
59 int main( )
60 {
61  trace.beginBlock ( "Example exampleAlphaThickSegment" );
62 
64  typedef AlphaThickSegmentComputer< Z2i::RealPoint > AlphaThickSegmentComputer2D;
66 
67  Board2D aBoard;
68  std::string file = examplesPath + "samples/contourSnoisy.sdp";
70  std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile(file);
72 
73  // displaying contour
74  aBoard << SetMode(aContour[0].className(), "Grid");
75  for (unsigned int i = 0; i< aContour.size(); i++){
76  aBoard << aContour[i];
77  aBoard.drawLine(aContour[i][0], aContour[i][1],
78  aContour[(i+1)%aContour.size()][0], aContour[(i+1)%aContour.size()][1]);
79  }
80 
81 
82  //initialisation of an AlphaThickSegmentComputer2D of thickness 10 and forward recognition.
85  AlphaThickSegmentComputer2D anAlphaSegment(15);
88  std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin();
89  while (anAlphaSegment.extendFront(*it)) {
90  it++;
91  }
94 
96  aBoard << anAlphaSegment;
98  AlphaThickSegmentComputer2D anAlphaSegment2(9);
100  anAlphaSegment2.init(aContour.begin());
101  while (anAlphaSegment2.end() != aContour.end() &&
102  anAlphaSegment2.extendFront()) {
103  }
105 
107  aBoard << CustomStyle( anAlphaSegment2.className(), new CustomColors( DGtal::Color::Blue, DGtal::Color::None ) );
108  aBoard << anAlphaSegment2;
110 
111  AlphaThickSegmentComputer2D anAlphaSegment3(2);
112  anAlphaSegment3.init(aContour.begin());
113  while (anAlphaSegment3.end() != aContour.end() &&
114  anAlphaSegment3.extendFront()) {
115  }
116  aBoard << CustomStyle( anAlphaSegment3.className(), new CustomColors( DGtal::Color::Green, DGtal::Color::None ) );
117  aBoard << anAlphaSegment3;
118 
119 
120  aBoard.saveEPS("exampleAlphaThickSegmentNoisy.eps");
121 
122  trace.endBlock();
123  return 0;
124 }
125 // //
Aim: This class is devoted to the recognition of alpha thick segments as described in ....
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
static const Color None
Definition: Color.h:412
static const Color Green
Definition: Color.h:417
static const Color Blue
Definition: Color.h:419
void beginBlock(const std::string &keyword="")
double endBlock()
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:367
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Aim: Implements method to read a set of points represented in each line of a file.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247