DGtal 1.4.0
Loading...
Searching...
No Matches
testL1LengthEstimator.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33
34#include "DGtal/kernel/SpaceND.h"
35#include "DGtal/kernel/domains/HyperRectDomain.h"
36#include "DGtal/kernel/sets/DigitalSetSelector.h"
37#include "DGtal/topology/KhalimskySpaceND.h"
38#include "DGtal/topology/SurfelAdjacency.h"
39#include "DGtal/topology/SurfelNeighborhood.h"
40
41
42#include "DGtal/geometry/curves/GridCurve.h"
43#include "DGtal/geometry/2d/L1LengthEstimator.h"
44#include "DGtal/geometry/2d/TwoStepLocalLengthEstimator.h"
45#include "DGtal/geometry/2d/MLPLengthEstimator.h"
46#include "DGtal/geometry/2d/FPLengthEstimator.h"
47#include "DGtal/geometry/2d/DSSLengthEstimator.h"
48
49#include "ConfigTest.h"
50
51
53
54using namespace std;
55using namespace DGtal;
56
58// Functions for testing Length Estimator classes.
60
64bool testL1LengthEstimator(std::string &filename)
65{
66
67 trace.info() << "Reading GridCurve " << endl;
68
69 ifstream instream; // input stream
70 instream.open (filename.c_str(), ifstream::in);
71
72 GridCurve<KhalimskySpaceND<2> > c; //grid curve
73 c.initFromVectorStream(instream);
74
76 GridCurve<KhalimskySpaceND<2> >::ArrowsRange ra = c.getArrowsRange(); //range
77 L1LengthEstimator< GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > l1length;
78 TwoStepLocalLengthEstimator< GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > locallength(1.0,sqrt(2.0));
79
80 l1length.init(1, ra.begin(), ra.end(), c.isClosed());
81 trace.info() << "L1 length (h=1) = "<< l1length.eval()<<std::endl;
82
83 l1length.init(10, ra.begin(), ra.end(), c.isClosed());
84 trace.info() << "L1 length (h=10) = "<< l1length.eval()<<std::endl;
85
87 TwoStepLocalLengthEstimator< GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > locallength(1.0,sqrt(2.0));
88
89 localength.init(1, ra.begin(), ra.end(), c.isClosed());
90 trace.info() << "Local length (h=1) = "<< localength.eval()<<std::endl;
91
92
94 GridCurve<KhalimskySpaceND<2> >::PointsRange rp = c.getPointsRange(); //range
95 MLPLengthEstimator< GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > MLPlength;
96
97 MLPlength.init(1, rp.begin(), rp.end(), c.isClosed());
98 trace.info() << "MLP Length (h=1) = "<< MLPlength.eval()<<std::endl;
99
100 MLPlength.init(10, rp.begin(), rp.end(), c.isClosed());
101 trace.info() << "MLP Length (h=10) = "<< MLPlength.eval()<<std::endl;
102
104 FPLengthEstimator< GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > FPlength;
105
106 FPlength.init(1, rp.begin(), rp.end(), c.isClosed());
107 trace.info() << "FP Length (h=1) = "<< FPlength.eval()<<std::endl;
108
109 FPlength.init(10, rp.begin(), rp.end(), c.isClosed());
110 trace.info() << "FP Length (h=10) = "<< FPlength.eval()<<std::endl;
111
113 DSSLengthEstimator< GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > DSSlength;
114
115 DSSlength.init(1, rp.begin(), rp.end(), c.isClosed());
116 trace.info() << "DSS Length (h=1) = "<< DSSlength.eval()<<std::endl;
117
118 DSSlength.init(10, rp.begin(), rp.end(), c.isClosed());
119 trace.info() << "DSS Length (h=10) = "<< DSSlength.eval()<<std::endl;
120
121 return true;
122}
123
124
125
127// Standard services - public :
128
129int main( int argc, char** argv )
130{
131 trace.beginBlock ( "Testing class LengthEstimators" );
132 trace.info() << "Args:";
133 for ( int i = 0; i < argc; ++i )
134 trace.info() << " " << argv[ i ];
135 trace.info() << endl;
136
137 std::string sinus2D4 = testPath + "samples/sinus2D4.dat";
138
139
140
141 bool res = testL1LengthEstimator(sinus2D4); // && ... other tests
142 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
143 trace.endBlock();
144 return res ? 0 : 1;
145}
146// //
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
Aim: a model of CGlobalCurveEstimator that computes the length of a digital curve using its FP (faith...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
ConstIterator begin() const
bool initFromVectorStream(std::istream &in)
PointsRange getPointsRange() const
Definition GridCurve.h:426
ArrowsRange getArrowsRange() const
Definition GridCurve.h:450
ConstIterator end() const
Aim: a simple model of CGlobalCurveEstimator that compute the length of a curve using the l_1 metric ...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h) const
Aim: a model of CGlobalCurveEstimator that computes the length of a digital curve using its MLP (give...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Aim: a simple model of CGlobalCurveEstimator that compute the length of a curve using the l_1 metric ...
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
int main()
Definition testBits.cpp:56
bool testL1LengthEstimator(std::string &filename)