DGtal  0.9.2
exampleAlphaThickSegmentTgtCover.cpp
1 
30 #include <iostream>
32 #include "ConfigExamples.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/base/Common.h"
36 #include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
37 #include "DGtal/geometry/curves/SaturatedSegmentation.h"
38 #include "DGtal/base/Circulator.h"
41 #include "DGtal/geometry/curves/SegmentComputerUtils.h"
43 
44 
45 #include "DGtal/io/boards/Board2D.h"
46 
48 
49 using namespace std;
50 using namespace DGtal;
51 
53 
54 int main()
55 {
56  trace.beginBlock ( "Example of AlphaThickSegment tangential cover obtained from SaturatedSegmentation" );
57 
59  typedef std::vector<Z2i::RealPoint>::const_iterator RAConstIterator;
60  typedef Circulator<RAConstIterator> ConstCirculator;
61  typedef AlphaThickSegmentComputer<Z2i::RealPoint, ConstCirculator> AlphaThickSegmentComputer2D;
64 
65 
66  Board2D aBoard, aBoard2;
67  std::string file = examplesPath + "samples/contourSnoisy.sdp";
68  std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile (file);
69 
70  // displaying contour
71  aBoard << SetMode(aContour[0].className(), "Grid");
72  aBoard2 << SetMode(aContour[0].className(), "Grid");
73  std::vector<LibBoard::Point> poly;
74  for (unsigned int i = 0; i< aContour.size(); i++) poly.push_back(LibBoard::Point(aContour[i][0], aContour[i][1]));
75  aBoard.setPenColor(DGtal::Color(200, 200, 200));
76  aBoard.fillPolyline(poly);
77  aBoard2.setPenColor(DGtal::Color(200, 200, 200));
78  aBoard2.fillPolyline(poly);
79 
81  Circulator<RAConstIterator> circulator (aContour.begin(), aContour.begin(), aContour.end());
83 
85  AlphaThickSegmentComputer2D computer(4, functions::Hull2D::EuclideanThickness);
86  AlphaSegmentation segmentator(circulator, circulator, computer);
88 
90  AlphaSegmentation::SegmentComputerIterator i = segmentator.begin();
91  AlphaSegmentation::SegmentComputerIterator end = segmentator.end();
92 
93  for ( ; i != end; ++i) {
94  AlphaThickSegmentComputer2D current(*i);
95  aBoard << SetMode(current.className(), "BoundingBox");
96  aBoard << current;
97  }
99  aBoard.saveEPS("exampleAlphaThickSegmentTgtCover.eps");
100  trace.endBlock();
101 
102  trace.beginBlock ( "Example of AlphaThickSegment tangential cover obtained for a single point" );
103 
104  // Displaying Tangential cover associated to a single point:
105 
107  unsigned int index = 80;
108  firstMaximalSegment(computer, circulator+index, circulator, circulator);
109  AlphaThickSegmentComputer2D first (computer);
110  lastMaximalSegment(computer, circulator+index, circulator, circulator);
111  AlphaThickSegmentComputer2D last (computer);
113 
115  aBoard2.fillCircle((*(circulator+index))[0], (*(circulator+index))[1], 1.0);
117  while(first.end() != last.end()){
118  aBoard2 << SetMode(first.className(), "BoundingBox");
119  aBoard2 << first;
120  nextMaximalSegment(first, circulator);
121  }
122  aBoard2 << last;
124 
125  stringstream name;
126  name << "exampleAlphaThickSegmentTgtCoverPoint" << index<< ".eps";
127  aBoard2.saveEPS(name.str().c_str());
128  trace.endBlock();
129 
130 
131 
132 
133  return 0;
134 }
135 // //
void beginBlock(const std::string &keyword="")
void fillPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:551
void nextMaximalSegment(SC &s, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
Struct representing a 2D point.
Definition: Point.h:27
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:471
static const Color Blue
Definition: Color.h:394
Aim: Implements method to read a set of points represented in each line of a file.
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
DGtal is the top-level namespace which contains all DGtal functions and types.
void lastMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
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: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
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 ...
void firstMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70