DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testMostCenteredMSEstimator.cpp
Go to the documentation of this file.
1
16
//LICENSE-END
28
32
33
#include <cstdio>
34
#include <cmath>
35
#include <fstream>
36
#include <vector>
37
#include <iostream>
38
#include <iterator>
39
40
41
42
43
#include "DGtal/base/Common.h"
44
#include "DGtal/base/Exceptions.h"
45
#include "DGtal/io/boards/Board2D.h"
46
47
#include "DGtal/topology/KhalimskySpaceND.h"
48
49
#include "DGtal/geometry/curves/GridCurve.h"
50
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
51
#include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
52
#include "DGtal/geometry/curves/estimation/CCurveLocalGeometricEstimator.h"
53
54
55
#include "ConfigTest.h"
56
57
58
using namespace
DGtal
;
59
using namespace
std
;
60
using namespace
LibBoard
;
61
63
// Functions for testing class MostCenteredMaximalSegmentEstimator
65
70
template
<
typename
I>
71
bool
test
(
const
I& itb,
const
I& ite)
72
{
73
typedef
I
ConstIterator
;
//constIterator
74
typedef
typename
IteratorCirculatorTraits<ConstIterator>::Value
Point
;
75
typedef
ArithmeticalDSSComputer<ConstIterator,typename Point::Coordinate,4>
SegmentComputer
;
//segmentComputer
76
typedef
TangentVectorFromDSSEstimator<SegmentComputer>
SCEstimator;
//functor
77
typedef
typename
SCEstimator::Quantity
Value
;
//value
78
typedef
MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
Estimator
;
//estimator
79
BOOST_CONCEPT_ASSERT((
concepts::CCurveLocalGeometricEstimator< Estimator >
));
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
}
143
148
bool
testEval
(
string
filename)
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
}
171
175
176
int
main
(
int
argc,
char
**argv)
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
}
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition
ArithmeticalDSSComputer.h:87
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::initFromVectorStream
bool initFromVectorStream(std::istream &in)
DGtal::GridCurve::getPointsRange
PointsRange getPointsRange() const
Definition
GridCurve.h:418
DGtal::GridCurve::PointsRange
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint< KSpace >, Point > PointsRange
Definition
GridCurve.h:413
DGtal::GridCurve::isClosed
bool isClosed() const
DGtal::ConstIterator
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition
KhalimskySpaceND.h:394
DGtal::MostCenteredMaximalSegmentEstimator
Aim: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
Definition
MostCenteredMaximalSegmentEstimator.h:84
DGtal::SimpleRandomAccessRangeFromPoint::begin
Iterator begin()
Definition
SimpleRandomAccessRangeFromPoint.h:204
DGtal::SimpleRandomAccessRangeFromPoint::c
Circulator c()
Definition
SimpleRandomAccessRangeFromPoint.h:359
DGtal::SimpleRandomAccessRangeFromPoint::end
Iterator end()
Definition
SimpleRandomAccessRangeFromPoint.h:244
DGtal::TangentVectorFromDSSEstimator
Definition
SegmentComputerEstimators.h:1040
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()
Estimator
PlaneProbingParallelepipedEstimator< DigitalPlane, ProbingMode::R1 > Estimator
Definition
examplePlaneProbingParallelepipedEstimator.cpp:46
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::isNotEmpty
bool isNotEmpty(const IC &itb, const IC &ite)
DGtal::trace
Trace trace
LibBoard
Definition
Board.cpp:86
std
STL namespace.
DGtal::Value
DGtal::IteratorCirculatorTraits::Value
IC::value_type Value
Definition
IteratorCirculatorTraits.h:303
DGtal::concepts::CCurveLocalGeometricEstimator
Aim: This concept describes an object that can process a range so as to return one estimated quantity...
Definition
CCurveLocalGeometricEstimator.h:99
LibBoard::Point
Struct representing a 2D point.
Definition
Point.h:27
SegmentComputer
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
Definition
testArithmeticalDSSComputerOnSurfels.cpp:55
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testEval
bool testEval(string filename)
Definition
testMostCenteredMSEstimator.cpp:148
test
bool test(const I &itb, const I &ite)
Definition
testMostCenteredMSEstimator.cpp:71
Range
Image::Range Range
Definition
testSimpleRandomAccessRangeFromPoint.cpp:46
tests
geometry
curves
estimation
testMostCenteredMSEstimator.cpp
Generated on
for DGtal by
1.18.0