DGtal  0.9.2
greedyAlphaThickDecomposition.cpp
1 
30 #include <iostream>
32 #include "ConfigExamples.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/base/Common.h"
35 #include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
36 #include "DGtal/io/boards/Board2D.h"
37 #include "DGtal/geometry/curves/GreedySegmentation.h"
38 #include <DGtal/io/readers/GenericReader.h>
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 
46 int main()
47 {
48  trace.beginBlock ( "Example of greedy alpha thick segment decompotion" );
49 
50  typedef std::vector<Z2i::RealPoint>::const_iterator ConstIterator;
51  typedef AlphaThickSegmentComputer<Z2i::RealPoint, ConstIterator > AlphaThickSegmentComputer2D;
52 
53  Board2D aBoard;
54  std::string file = examplesPath + "samples/contourSnoisy.sdp";
55  std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile (file);
56 
58 
59  // displaying contour
60  aBoard << SetMode(aContour[0].className(), "Grid");
61  std::vector<LibBoard::Point> poly;
62  for (unsigned int i = 0; i< aContour.size(); i++) poly.push_back(LibBoard::Point(aContour[i][0], aContour[i][1]));
64  aBoard.fillPolyline(poly);
65 
66  // Computing greedy Alpha Thick decomposition.
68  aBoard << SetMode("AlphaThickSegment", "BoundingBox");
70 
72  DecompositionAT theDecomposition(aContour.begin(), aContour.end(), AlphaThickSegmentComputer2D(4));
74 
76  for ( DecompositionAT::SegmentComputerIterator
77  it = theDecomposition.begin(),
78  itEnd = theDecomposition.end();
79  it != itEnd; ++it )
80  {
81  aBoard << CustomStyle( (*it).className(),
82  new CustomPenColor( Color::Blue ) );
83  aBoard<< *it;
84  }
86 
87  aBoard.saveEPS("greedyAlphaThickDecomposition.eps");
88 
89  trace.endBlock();
90  return 0;
91 }
92 // //
void beginBlock(const std::string &keyword="")
void fillPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:551
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
Struct representing a 2D point.
Definition: Point.h:27
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.
static const Color Gray
Definition: Color.h:389
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
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
Aim: This class is devoted to the recognition of alpha thick segments as described in ...
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:312
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70