DGtal  1.5.beta
testMostCenteredMSEstimator.cpp File Reference
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <iostream>
#include <iterator>
#include "DGtal/base/Common.h"
#include "DGtal/base/Exceptions.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
#include "DGtal/geometry/curves/estimation/CCurveLocalGeometricEstimator.h"
#include "ConfigTest.h"
Include dependency graph for testMostCenteredMSEstimator.cpp:

Go to the source code of this file.

Functions

template<typename I >
bool test (const I &itb, const I &ite)
 
bool testEval (string filename)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/06/28

This file is part of the DGtal library

Definition in file testMostCenteredMSEstimator.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 176 of file testMostCenteredMSEstimator.cpp.

177 {
178 
179  trace.beginBlock ( "Testing class MostCenteredMaximalSegmentEstimator" );
180  trace.info() << "Args:";
181  for ( int i = 0; i < argc; ++i )
182  trace.info() << " " << argv[ i ];
183  trace.info() << endl;
184 
185  std::string sinus2D4 = testPath + "samples/sinus2D4.dat";
186  std::string square = testPath + "samples/smallSquare.dat";
187  std::string dss = testPath + "samples/DSS.dat";
188 
189  bool res = testEval(sinus2D4)
190  && testEval(square)
191  && testEval(dss)
192  //other tests
193  ;
194  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
195  trace.endBlock();
196 
197  return res ? 0 : 1;
198 
199 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testEval(string filename)

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testEval(), and DGtal::trace.

◆ test()

template<typename I >
bool test ( const I &  itb,
const I &  ite 
)

Test

Definition at line 71 of file testMostCenteredMSEstimator.cpp.

72 {
73  typedef I ConstIterator;//constIterator
76  typedef TangentVectorFromDSSEstimator<SegmentComputer> SCEstimator; //functor
77  typedef typename SCEstimator::Quantity Value; //value
80  SegmentComputer sc;
81  SCEstimator f;
82 
83  Estimator e(sc,f);
84  e.init(itb,ite);
85 
86  unsigned int nb = 0;
87  unsigned int nbok = 0;
88  std::vector<Value> v1, v2, v3;
89 
90  {
91  trace.info() << "Eval at one element" << endl;
92  if (isNotEmpty(itb, ite))
93  {
94  ConstIterator it = itb;
95  do
96  {
97  Value q = e.eval(it,1.);
98  cout << q << " ";
99  v1.push_back( q );
100  ++it;
101  } while (it != ite);
102  }
103  cout << endl;
104  }
105 
106  {
107  trace.info() << "Eval for each element between begin and end " << endl;
108  e.eval(itb, ite, std::back_inserter(v2));
109 
110  for (typename std::vector<Value>::iterator i = v2.begin(); i != v2.end(); ++i) {
111  cout << *i << " ";
112  }
113  cout << endl;
114  }
115 
116  nbok += ( ( v1.size() == v2.size() ) &&
117  ( std::equal(v1.begin(), v1.end(), v2.begin() ) ) )?1:0;
118  nb++;
119 
120  trace.info() << "(" << nbok << "/" << nb << ")" << std::endl;
121 
122  if ( (ite-itb) >= 10)
123  {
124 
125  trace.info() << "Eval for each element between begin+4 and begin+9 " << endl;
126 
127  e.eval((itb+4),(itb+9),std::back_inserter(v3));
128 
129  for (typename vector<Value>::iterator i = v3.begin(); i != v3.end(); ++i) {
130  cout << *i << " ";
131  }
132  cout << endl;
133 
134  nbok += ( (v3.size() == 5) &&
135  ( std::equal( (v1.begin()+4), (v1.begin()+9), v3.begin()) ) )?1:0;
136  nb++;
137 
138  trace.info() << "(" << nbok << "/" << nb << ")" << std::endl;
139  }
140 
141  return (nb == nbok);
142 }
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
PlaneProbingParallelepipedEstimator< DigitalPlane, ProbingMode::R1 > Estimator
MyDigitalSurface::ConstIterator ConstIterator
bool isNotEmpty(const IC &itb, const IC &ite, IteratorType)
Aim: This concept describes an object that can process a range so as to return one estimated quantity...
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::info(), DGtal::isNotEmpty(), and DGtal::trace.

Referenced by main(), test_operator(), testEval(), testPublicSercives(), and testStaticServices().

◆ testEval()

bool testEval ( string  filename)

Applying test on a given data file

Definition at line 148 of file testMostCenteredMSEstimator.cpp.

149 {
150 
151  trace.info() << endl;
152  trace.info() << "Reading GridCurve from " << filename << endl;
153 
154  ifstream instream; // input stream
155  instream.open (filename.c_str(), ifstream::in);
156  typedef KhalimskySpaceND<2> Kspace; //space
157  GridCurve<Kspace> c; //building grid curve
158  c.initFromVectorStream(instream);
159  typedef GridCurve<Kspace >::PointsRange Range;//range
160  Range r = c.getPointsRange();//building range
161 
162  trace.info() << "Building Estimator (process range as";
163  trace.info() << ( (c.isClosed())?"closed":"open" ) << ")" << endl;
164 
165  if (c.isClosed())
166  return test(r.c(), r.c());
167  else
168  return test(r.begin(), r.end());
169 
170 }
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromVectorStream(std::istream &in)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
bool test(const I &itb, const I &ite)

References DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), test(), and DGtal::trace.

Referenced by main().