DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testL1LengthEstimator.cpp
Go to the documentation of this file.
1
16
29
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
54
using namespace
std
;
55
using namespace
DGtal
;
56
58
// Functions for testing Length Estimator classes.
60
64
bool
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
129
int
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
// //
DGtal::DSSLengthEstimator
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Definition
DSSLengthEstimator.h:77
DGtal::DSSLengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
DGtal::FPLengthEstimator
Aim: a model of CGlobalCurveEstimator that computes the length of a digital curve using its FP (faith...
Definition
FPLengthEstimator.h:70
DGtal::FPLengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition
GridCurve.h:173
DGtal::GridCurve::begin
ConstIterator begin() const
DGtal::GridCurve::initFromVectorStream
bool initFromVectorStream(std::istream &in)
DGtal::GridCurve::getPointsRange
PointsRange getPointsRange() const
Definition
GridCurve.h:418
DGtal::GridCurve::getArrowsRange
ArrowsRange getArrowsRange() const
Definition
GridCurve.h:442
DGtal::GridCurve::end
ConstIterator end() const
DGtal::GridCurve::isClosed
bool isClosed() const
DGtal::L1LengthEstimator
Aim: a simple model of CGlobalCurveEstimator that compute the length of a curve using the l_1 metric ...
Definition
L1LengthEstimator.h:68
DGtal::L1LengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h) const
DGtal::MLPLengthEstimator
Aim: a model of CGlobalCurveEstimator that computes the length of a digital curve using its MLP (give...
Definition
MLPLengthEstimator.h:70
DGtal::MLPLengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::TwoStepLocalLengthEstimator
Aim: a simple model of CGlobalCurveEstimator that compute the length of a curve using the l_1 metric ...
Definition
TwoStepLocalLengthEstimator.h:66
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testL1LengthEstimator
bool testL1LengthEstimator(std::string &filename)
Definition
testL1LengthEstimator.cpp:64
tests
geometry
curves
estimation
testL1LengthEstimator.cpp
Generated on
for DGtal by
1.18.0