DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testCOBAGenericNaivePlaneComputer-benchmark.cpp
Go to the documentation of this file.
1
16
29
31
#include <cstdlib>
32
#include <iostream>
33
#include "DGtal/base/Common.h"
34
#include "DGtal/math/Statistic.h"
35
#include "DGtal/helpers/StdDefs.h"
36
#include "DGtal/kernel/CPointPredicate.h"
37
#include "DGtal/geometry/surfaces/COBAGenericNaivePlaneComputer.h"
39
40
using namespace
std
;
41
using namespace
DGtal
;
42
44
// Functions for testing class COBAGenericNaivePlaneComputer.
46
47
template
<
typename
Integer>
48
Integer
getRandomInteger
(
const
Integer
& first,
const
Integer
& after_last )
49
{
50
Integer
r = (
Integer
) rand();
51
return
( r % (after_last - first) ) + first;
52
}
53
57
template
<
typename
Integer,
typename
NaivePlaneComputer>
58
bool
59
checkGenericPlane
(
Integer
a,
Integer
b,
Integer
c,
Integer
d,
60
int
diameter,
unsigned
int
nbpoints,
61
Statistic<double>
& stats )
62
{
63
typedef
typename
NaivePlaneComputer::Point
Point
;
64
typedef
typename
Point::Component PointInteger;
65
IntegerComputer<Integer>
ic;
66
Integer
absA = ic.
abs
( a );
67
Integer
absB = ic.
abs
( b );
68
Integer
absC = ic.
abs
( c );
69
Integer
x, y, z;
70
Dimension
axis;
71
if
( ( absA >= absB ) && ( absA >= absC ) )
72
axis = 0;
73
else
if
( ( absB >= absA ) && ( absB >= absC ) )
74
axis = 1;
75
else
76
axis = 2;
77
Point
p;
78
NaivePlaneComputer
plane;
79
plane.
init
( diameter, 1, 1 );
80
// Checks that points within the naive plane are correctly recognized.
81
unsigned
int
nb = 0;
82
unsigned
int
nbok = 0;
83
unsigned
int
nbchanges = 0;
84
auto
complexity = plane.
complexity
();
85
while
( nb != nbpoints )
86
{
87
p[ 0 ] =
getRandomInteger<PointInteger>
( -diameter+1, diameter );
88
p[ 1 ] =
getRandomInteger<PointInteger>
( -diameter+1, diameter );
89
p[ 2 ] =
getRandomInteger<PointInteger>
( -diameter+1, diameter );
90
x = (
Integer
) p[ 0 ];
91
y = (
Integer
) p[ 1 ];
92
z = (
Integer
) p[ 2 ];
93
switch
( axis ) {
94
case
0: p[ 0 ] =
static_cast<
typename Point::Component
>
(
NumberTraits<Integer>::castToInt64_t
( ic.
ceilDiv
( d - b * y - c * z, a ) ));
break
;
95
case
1: p[ 1 ] =
static_cast<
typename Point::Component
>
(
NumberTraits<Integer>::castToInt64_t
( ic.
ceilDiv
( d - a * x - c * z, b ) ));
break
;
96
case
2: p[ 2 ] =
static_cast<
typename Point::Component
>
(
NumberTraits<Integer>::castToInt64_t
( ic.
ceilDiv
( d - a * x - b * y, c )));
break
;
97
}
98
bool
ok = plane.
extend
( p );
// should be ok
99
++nb; nbok += ok ? 1 : 0;
100
if
( ! ok )
101
{
102
std::cerr <<
"[ERROR] p="
<< p <<
" NOT IN plane="
<< plane << std::endl;
103
break
;
104
}
105
if
( plane.
complexity
() != complexity )
106
{
107
complexity = plane.
complexity
();
108
++nbchanges;
109
}
110
}
111
stats.
addValue
( (
double
) nbchanges );
112
return
nb == nbok;
113
}
114
115
template
<
typename
NaivePlaneComputer>
116
bool
117
checkGenericPlanes
(
unsigned
int
nbplanes,
int
diameter,
unsigned
int
nbpoints,
118
Statistic<double>
& stats )
119
{
120
//using namespace Z3i;
121
typedef
typename
NaivePlaneComputer::InternalInteger
Integer
;
122
unsigned
int
nb = 0;
123
unsigned
int
nbok = 0;
124
for
(
unsigned
int
nbp = 0; nbp < nbplanes; ++nbp )
125
{
126
Integer
a =
getRandomInteger<Integer>
( (
Integer
) 0, (
Integer
) diameter / 2 );
127
Integer
b =
getRandomInteger<Integer>
( (
Integer
) 0, (
Integer
) diameter / 2 );
128
Integer
c =
getRandomInteger<Integer>
( (
Integer
) 0, (
Integer
) diameter / 2 );
129
Integer
d =
getRandomInteger<Integer>
( (
Integer
) 0, (
Integer
) diameter / 2 );
130
if
( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
131
{
132
++nb; nbok +=
checkGenericPlane<Integer, NaivePlaneComputer>
( a, b, c, d, diameter, nbpoints, stats ) ? 1 : 0;
133
if
( nb != nbok )
134
{
135
std::cerr <<
"[ERROR] for plane "
<< a <<
" * x + "
136
<< b <<
" * y + "
<< c <<
" * z = "
<< d << std::endl;
137
break
;
138
}
139
}
140
}
141
return
nb == nbok;
142
}
143
144
146
// Standard services - public :
147
148
int
main
(
int
argc,
char
** argv )
149
{
150
using namespace
Z3i
;
151
Statistic<double>
stats;
152
unsigned
int
nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 100;
153
unsigned
int
nbpoints = ( argc > 2 ) ? atoi( argv[ 2 ] ) : 100;
154
unsigned
int
diameter = ( argc > 3 ) ? atoi( argv[ 3 ] ) : 100;
155
std::cout <<
"# Usage: "
<< argv[0] <<
" <nbtries> <nbpoints> <diameter>."
<< std::endl;
156
std::cout <<
"# Test class COBAGenericNaivePlaneComputer. Points are randomly chosen in [-diameter,diameter]^3."
<< std::endl;
157
std::cout <<
"# Integer nbtries nbpoints diameter time/plane(ms) E(comp) V(comp)"
<< std::endl;
158
159
// Max diameter is ~20 for int32_t, ~500 for int64_t, any with BigInteger.
160
trace
.
beginBlock
(
"Testing class COBAGenericNaivePlaneComputer"
);
161
bool
res =
true
162
&&
checkGenericPlanes<COBAGenericNaivePlaneComputer<Z3, DGtal::BigInteger>
>( nbtries, diameter, nbpoints, stats );
163
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
164
long
t =
trace
.
endBlock
();
165
stats.
terminate
();
166
std::cout <<
"BigInteger"
<<
" "
<< stats.
samples
()
167
<<
" "
<< nbpoints
168
<<
" "
<< diameter
169
<<
" "
<< ( (double) t / (double) stats.
samples
() )
170
<<
" "
<< stats.
mean
()
171
<<
" "
<< stats.
variance
()
172
<< std::endl;
173
return
res ? 0 : 1;
174
}
175
// //
DGtal::COBANaivePlaneComputer::init
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
DGtal::COBANaivePlaneComputer::complexity
Size complexity() const
DGtal::COBANaivePlaneComputer< Z3, InternalInteger >::Point
Space::Point Point
Definition
COBANaivePlaneComputer.h:139
DGtal::COBANaivePlaneComputer< Z3, InternalInteger >::InternalInteger
InternalInteger InternalInteger
Definition
COBANaivePlaneComputer.h:144
DGtal::COBANaivePlaneComputer::extend
bool extend(const Point &p)
DGtal::IntegerComputer
Aim: This class gathers several types and methods to make computation with integers.
Definition
IntegerComputer.h:83
DGtal::IntegerComputer::abs
static Integer abs(IntegerParamType a)
DGtal::IntegerComputer::ceilDiv
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
DGtal::Point
DGtal::Statistic
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition
Statistic.h:70
DGtal::Statistic::variance
double variance() const
DGtal::Statistic::terminate
void terminate()
DGtal::Statistic::samples
unsigned int samples() const
DGtal::Statistic::mean
double mean() const
DGtal::Statistic::addValue
void addValue(Quantity v)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::endBlock
double endBlock()
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
NaivePlaneComputer
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
Definition
greedy-plane-segmentation-ex2.cpp:85
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
DGtal::trace
Trace trace
std
STL namespace.
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition
NumberTraits.h:562
checkGenericPlanes
bool checkGenericPlanes(unsigned int nbplanes, int diameter, unsigned int nbpoints, Statistic< double > &stats)
Definition
testCOBAGenericNaivePlaneComputer-benchmark.cpp:117
checkGenericPlane
bool checkGenericPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints, Statistic< double > &stats)
Definition
testCOBAGenericNaivePlaneComputer-benchmark.cpp:59
getRandomInteger
Integer getRandomInteger(const Integer &first, const Integer &after_last)
Definition
testChordNaivePlaneComputer-benchmark.cpp:49
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
tests
benchmarks
geometry
surfaces
testCOBAGenericNaivePlaneComputer-benchmark.cpp
Generated on
for DGtal by
1.18.0