DGtal  0.9.2
exampleAlphaThickSegmentNoisy.cpp
1 
30 #include <iostream>
32 #include "ConfigExamples.h"
33 #include "DGtal/base/Common.h"
35 #include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/io/readers/PointListReader.h"
39 #include "DGtal/io/boards/Board2D.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 
47 int main( )
48 {
49  trace.beginBlock ( "Example exampleAlphaThickSegment" );
50 
52  typedef AlphaThickSegmentComputer< Z2i::RealPoint > AlphaThickSegmentComputer2D;
54 
55  Board2D aBoard;
56  std::string file = examplesPath + "samples/contourSnoisy.sdp";
58  std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile(file);
60 
61  // displaying contour
62  aBoard << SetMode(aContour[0].className(), "Grid");
63  for (unsigned int i = 0; i< aContour.size(); i++){
64  aBoard << aContour[i];
65  aBoard.drawLine(aContour[i][0], aContour[i][1],
66  aContour[(i+1)%aContour.size()][0], aContour[(i+1)%aContour.size()][1]);
67  }
68 
69 
70  //initialisation of an AlphaThickSegmentComputer2D of thickness 10 and forward recognition.
73  AlphaThickSegmentComputer2D anAlphaSegment(15);
76  std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin();
77  while (anAlphaSegment.extendFront(*it)) {
78  it++;
79  }
82 
84  aBoard << anAlphaSegment;
86  AlphaThickSegmentComputer2D anAlphaSegment2(9);
88  anAlphaSegment2.init(aContour.begin());
89  while (anAlphaSegment2.end() != aContour.end() &&
90  anAlphaSegment2.extendFront()) {
91  }
93 
95  aBoard << CustomStyle( anAlphaSegment2.className(), new CustomColors( DGtal::Color::Blue, DGtal::Color::None ) );
96  aBoard << anAlphaSegment2;
98 
99  AlphaThickSegmentComputer2D anAlphaSegment3(2);
100  anAlphaSegment3.init(aContour.begin());
101  while (anAlphaSegment3.end() != aContour.end() &&
102  anAlphaSegment3.extendFront()) {
103  }
104  aBoard << CustomStyle( anAlphaSegment3.className(), new CustomColors( DGtal::Color::Green, DGtal::Color::None ) );
105  aBoard << anAlphaSegment3;
106 
107 
108  aBoard.saveEPS("exampleAlphaThickSegmentNoisy.eps");
109 
110  trace.endBlock();
111  return 0;
112 }
113 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:368
STL namespace.
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
static const Color None
Definition: Color.h:387
static const Color Blue
Definition: Color.h:394
Aim: Implements method to read a set of points represented in each line of a file.
DGtal is the top-level namespace which contains all DGtal functions and types.
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: This class is devoted to the recognition of alpha thick segments as described in ...
static const Color Green
Definition: Color.h:392
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70