DGtal  1.5.beta
testLambdaMST2D.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <fstream>
33 #include <iterator>
34 #include <vector>
35 #include "DGtal/base/Common.h"
36 #include "ConfigTest.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/io/readers/PointListReader.h"
39 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
40 #include "DGtal/geometry/curves/estimation/LambdaMST2D.h"
41 #include "DGtal/geometry/curves/SaturatedSegmentation.h"
42 
44 
45 using namespace std;
46 using namespace DGtal;
47 using namespace Z2i;
48 
50 // Functions for testing class LambdaMST2D.
52 
53 class testLambdaMST2D
54 {
55  typedef vector < Point > Range;
56  typedef Range::const_iterator ConstIterator;
59 private:
60  Range curve;
61 public:
62  testLambdaMST2D ()
63  {
64  fstream inputStream;
65  inputStream.open ( (testPath + "samples/sinus2D4.dat").c_str(), ios::in );
66  try {
68  if ( curve.size() == 0) throw IOException();
69  } catch (DGtal::IOException & ioe) {
70  trace.error() << "Size is null." << endl;
71  }
72  }
73  bool lambda64ByPoint ()
74  {
75  Segmentation segmenter ( curve.begin(), curve.end(), SegmentComputer() );
77  lmst64.attach ( segmenter );
78  for ( ConstIterator it = curve.begin(); it != curve.end(); ++it )
79  lmst64.eval ( *it );
80  return true;
81  }
82  bool lambda64()
83  {
84  Segmentation segmenter ( curve.begin(), curve.end(), SegmentComputer() );
86  lmst64.attach ( segmenter );
87  lmst64.init ( curve.begin(), curve.end() );
88  std::vector < RealVector > tangent;
89  lmst64.eval < back_insert_iterator< vector < RealVector > > > ( curve.begin(), curve.end(), back_inserter ( tangent ) );
90  return true;
91  }
92 };
93 
94 
96 // Standard services - public :
97 
98 int main( int , char** )
99 {
100  bool res = true;
101  testLambdaMST2D testLMST;
102  trace.beginBlock ( "Testing LambdaMST2D" );
103  trace.beginBlock ( "Testing point only calculation" );
104  res &= testLMST.lambda64ByPoint();
105  trace.endBlock();
106  trace.beginBlock ( "Testing calculation for whole curve" );
107  res &= testLMST.lambda64();
108  trace.endBlock();
109  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
110  trace.endBlock();
111  return res ? 0 : 1;
112 }
113 // //
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
RealVector eval(const Point &p)
void init(ConstIterator itb, ConstIterator ite)
void attach(Alias< TSegmentation > SegmentComputer)
Aim: Simplify creation of Lambda MST tangent estimator.
Definition: LambdaMST2D.h:170
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Implements method to read a set of points represented in each line of a file.
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation
int main(int, char **)