DGtal  1.5.beta
exampleAlphaThickSegmentTgtCover.cpp
Go to the documentation of this file.
1 
44 #include <iostream>
45 #include "ConfigExamples.h"
46 #include "DGtal/helpers/StdDefs.h"
47 #include "DGtal/base/Common.h"
49 #include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
50 #include "DGtal/geometry/curves/SaturatedSegmentation.h"
51 #include "DGtal/base/Circulator.h"
54 #include "DGtal/geometry/curves/SegmentComputerUtils.h"
56 
57 
58 #include "DGtal/io/boards/Board2D.h"
59 
61 
62 using namespace std;
63 using namespace DGtal;
64 
66 
67 int main()
68 {
69  trace.beginBlock ( "Example of AlphaThickSegment tangential cover obtained from SaturatedSegmentation" );
70 
72  typedef std::vector<Z2i::RealPoint>::const_iterator RAConstIterator;
73  typedef Circulator<RAConstIterator> ConstCirculator;
74  typedef AlphaThickSegmentComputer<Z2i::RealPoint, ConstCirculator> AlphaThickSegmentComputer2D;
77 
78 
79  Board2D aBoard, aBoard2;
80  std::string file = examplesPath + "samples/contourSnoisy.sdp";
81  std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile (file);
82 
83  // displaying contour
84  aBoard << SetMode(aContour[0].className(), "Grid");
85  aBoard2 << SetMode(aContour[0].className(), "Grid");
86  std::vector<LibBoard::Point> poly;
87  for (unsigned int i = 0; i< aContour.size(); i++) poly.push_back(LibBoard::Point(aContour[i][0], aContour[i][1]));
88  aBoard.setPenColor(DGtal::Color(200, 200, 200));
89  aBoard.fillPolyline(poly);
90  aBoard2.setPenColor(DGtal::Color(200, 200, 200));
91  aBoard2.fillPolyline(poly);
92 
94  Circulator<RAConstIterator> circulator (aContour.begin(), aContour.begin(), aContour.end());
96 
98  AlphaThickSegmentComputer2D computer(4, functions::Hull2D::EuclideanThickness);
99  AlphaSegmentation segmentator(circulator, circulator, computer);
101 
103  AlphaSegmentation::SegmentComputerIterator i = segmentator.begin();
104  AlphaSegmentation::SegmentComputerIterator end = segmentator.end();
105 
106  for ( ; i != end; ++i) {
107  AlphaThickSegmentComputer2D current(*i);
108  aBoard << SetMode(current.className(), "BoundingBox");
109  aBoard << current;
110  }
112  aBoard.saveEPS("exampleAlphaThickSegmentTgtCover.eps");
113  trace.endBlock();
114 
115  trace.beginBlock ( "Example of AlphaThickSegment tangential cover obtained for a single point" );
116 
117  // Displaying Tangential cover associated to a single point:
118 
120  unsigned int index = 80;
121  firstMaximalSegment(computer, circulator+index, circulator, circulator);
122  AlphaThickSegmentComputer2D first (computer);
123  lastMaximalSegment(computer, circulator+index, circulator, circulator);
124  AlphaThickSegmentComputer2D last (computer);
126 
128  aBoard2.fillCircle((*(circulator+index))[0], (*(circulator+index))[1], 1.0);
130  while(first.end() != last.end()){
131  aBoard2 << SetMode(first.className(), "BoundingBox");
132  aBoard2 << first;
133  nextMaximalSegment(first, circulator);
134  }
135  aBoard2 << last;
137 
138  stringstream name;
139  name << "exampleAlphaThickSegmentTgtCoverPoint" << index<< ".eps";
140  aBoard2.saveEPS(name.str().c_str());
141  trace.endBlock();
142 
143 
144 
145 
146  return 0;
147 }
148 // //
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
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Blue
Definition: Color.h:419
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
void beginBlock(const std::string &keyword="")
double endBlock()
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:297
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:470
void fillPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:550
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.
void lastMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
Trace trace
Definition: Common.h:153
void nextMaximalSegment(SC &s, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
void firstMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
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
Struct representing a 2D point.
Definition: Point.h:27