DGtal  1.3.beta
testLambdaMST2D.cpp
Go to the documentation of this file.
1 
30 #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 // //
DGtal::LambdaMST2D
Aim: Simplify creation of Lambda MST tangent estimator.
Definition: LambdaMST2D.h:167
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::Trace::endBlock
double endBlock()
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition: ArithmeticalDSSComputer.h:86
DGtal::SimpleRandomAccessRangeFromPoint::begin
Iterator begin()
Definition: SimpleRandomAccessRangeFromPoint.h:203
SegmentComputer
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
Definition: testArithmeticalDSSComputerOnSurfels.cpp:55
DGtal::Trace::error
std::ostream & error()
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::LambdaMST2DEstimator< Z2i::Space, DSSSegmentationComputer, TangentFromDSS2DFunctor< DSSSegmentationComputer::SegmentComputer, functors::Lambda64Function > >::init
void init(ConstIterator itb, ConstIterator ite)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::SimpleRandomAccessRangeFromPoint::end
Iterator end()
Definition: SimpleRandomAccessRangeFromPoint.h:243
DGtal::PointListReader
Aim: Implements method to read a set of points represented in each line of a file.
Definition: PointListReader.h:84
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
main
int main(int, char **)
Definition: testLambdaMST2D.cpp:98
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:73
Range
Image::Range Range
Definition: testSimpleRandomAccessRangeFromPoint.cpp:46
Segmentation
SaturatedSegmentation< SegmentComputer > Segmentation
Definition: testArithmeticalDSSComputerOnSurfels.cpp:56
DGtal::LambdaMST2DEstimator< Z2i::Space, DSSSegmentationComputer, TangentFromDSS2DFunctor< DSSSegmentationComputer::SegmentComputer, functors::Lambda64Function > >::attach
void attach(Alias< DSSSegmentationComputer > SegmentComputer)
DGtal::LambdaMST2DEstimator< Z2i::Space, DSSSegmentationComputer, TangentFromDSS2DFunctor< DSSSegmentationComputer::SegmentComputer, functors::Lambda64Function > >::eval
RealVector eval(const Point &p)
DGtal::SaturatedSegmentation
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Definition: SaturatedSegmentation.h:153
DGtal::IOException
Definition: Exceptions.h:52