DGtal 2.0.0
Loading...
Searching...
No Matches
testCOBAGenericNaivePlaneComputer-benchmark.cpp File Reference
#include <cstdlib>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/math/Statistic.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/CPointPredicate.h"
#include "DGtal/geometry/surfaces/COBAGenericNaivePlaneComputer.h"
Include dependency graph for testCOBAGenericNaivePlaneComputer-benchmark.cpp:

Go to the source code of this file.

Functions

template<typename Integer>
Integer getRandomInteger (const Integer &first, const Integer &after_last)
template<typename Integer, typename NaivePlaneComputer>
bool checkGenericPlane (Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints, Statistic< double > &stats)
template<typename NaivePlaneComputer>
bool checkGenericPlanes (unsigned int nbplanes, int diameter, unsigned int nbpoints, Statistic< double > &stats)
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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/03/05

Functions for testing class COBAGenericNaivePlaneComputer.

This file is part of the DGtal library.

Definition in file testCOBAGenericNaivePlaneComputer-benchmark.cpp.

Function Documentation

◆ checkGenericPlane()

template<typename Integer, typename NaivePlaneComputer>
bool checkGenericPlane ( Integer a,
Integer b,
Integer c,
Integer d,
int diameter,
unsigned int nbpoints,
Statistic< double > & stats )

Checks the naive plane d <= ax+by+cz <= d + max(|a|,|b|,|c|)-1

Definition at line 59 of file testCOBAGenericNaivePlaneComputer-benchmark.cpp.

62{
63 typedef typename NaivePlaneComputer::Point Point;
64 typedef typename Point::Component PointInteger;
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;
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}
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
bool extend(const Point &p)
Aim: This class gathers several types and methods to make computation with integers.
static Integer abs(IntegerParamType a)
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
void addValue(Quantity v)
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
DGtal::uint32_t Dimension
Definition Common.h:119
Aim: The traits class for all models of Cinteger.
Integer getRandomInteger(const Integer &first, const Integer &after_last)

References DGtal::IntegerComputer< TInteger >::abs(), DGtal::Statistic< TQuantity >::addValue(), DGtal::IntegerComputer< TInteger >::ceilDiv(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::complexity(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend(), getRandomInteger(), and DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init().

Referenced by checkGenericPlanes().

◆ checkGenericPlanes()

template<typename NaivePlaneComputer>
bool checkGenericPlanes ( unsigned int nbplanes,
int diameter,
unsigned int nbpoints,
Statistic< double > & stats )

Definition at line 117 of file testCOBAGenericNaivePlaneComputer-benchmark.cpp.

119{
120 //using namespace Z3i;
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}
bool checkGenericPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints, Statistic< double > &stats)

References checkGenericPlane(), and getRandomInteger().

Referenced by main().

◆ getRandomInteger()

template<typename Integer>
Integer getRandomInteger ( const Integer & first,
const Integer & after_last )

Definition at line 48 of file testCOBAGenericNaivePlaneComputer-benchmark.cpp.

49{
50 Integer r = (Integer) rand();
51 return ( r % (after_last - first) ) + first;
52}

Referenced by checkGenericPlane(), and checkGenericPlanes().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 148 of file testCOBAGenericNaivePlaneComputer-benchmark.cpp.

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}
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition Statistic.h:70
double variance() const
unsigned int samples() const
double mean() const
Z3i this namespace gathers the standard of types for 3D imagery.
Trace trace
bool checkGenericPlanes(unsigned int nbplanes, int diameter, unsigned int nbpoints, Statistic< double > &stats)

References checkGenericPlanes(), DGtal::Statistic< TQuantity >::mean(), DGtal::Statistic< TQuantity >::samples(), DGtal::Statistic< TQuantity >::terminate(), DGtal::trace, and DGtal::Statistic< TQuantity >::variance().