DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testChordNaivePlaneComputer-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/arithmetic/IntegerComputer.h"
#include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.h"

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 checkPlane (Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints)
 
template<typename NaivePlaneComputer >
bool checkPlanes (unsigned int nbplanes, unsigned int diameter, unsigned int nbpoints)
 
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 ChordNaivePlaneComputer.

This file is part of the DGtal library.

Definition in file testChordNaivePlaneComputer-benchmark.cpp.

Function Documentation

◆ checkPlane()

template<typename Integer , typename NaivePlaneComputer >
bool checkPlane ( Integer  a,
Integer  b,
Integer  c,
Integer  d,
int  diameter,
unsigned int  nbpoints 
)

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

Definition at line 60 of file testChordNaivePlaneComputer-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( axis, 1, 1 );
80 // Checks that points within the naive plane are correctly recognized.
81 unsigned int nb = 0;
82 unsigned int nbok = 0;
83 while ( nb != nbpoints )
84 {
85 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
86 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
87 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
88 x = (Integer) p[ 0 ];
89 y = (Integer) p[ 1 ];
90 z = (Integer) p[ 2 ];
91 switch ( axis ) {
92 case 0: p[ 0 ] = NumberTraits<Integer>::castToInt64_t( ic.ceilDiv( d - b * y - c * z, a ) ); break;
93 case 1: p[ 1 ] = NumberTraits<Integer>::castToInt64_t( ic.ceilDiv( d - a * x - c * z, b ) ); break;
94 case 2: p[ 2 ] = NumberTraits<Integer>::castToInt64_t( ic.ceilDiv( d - a * x - b * y, c ) ); break;
95 }
96 bool ok = plane.extend( p ); // should be ok
97 ++nb; nbok += ok ? 1 : 0;
98 if ( ! ok )
99 {
100 std::cerr << "[ERROR] p=" << p << " NOT IN plane=" << plane << std::endl;
101 break;
102 }
103 }
104 return nb == nbok;
105}
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
DGtal::uint32_t Dimension
Definition: Common.h:137
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::IntegerComputer< TInteger >::abs(), DGtal::IntegerComputer< TInteger >::ceilDiv(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend(), and DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init().

◆ checkPlanes()

template<typename NaivePlaneComputer >
bool checkPlanes ( unsigned int  nbplanes,
unsigned int  diameter,
unsigned int  nbpoints 
)

Definition at line 109 of file testChordNaivePlaneComputer-benchmark.cpp.

110{
111 //using namespace Z3i;
112 typedef typename NaivePlaneComputer::InternalScalar Integer;
113 unsigned int nb = 0;
114 unsigned int nbok = 0;
115 for ( unsigned int nbp = 0; nbp < nbplanes; ++nbp )
116 {
117 Integer a = getRandomInteger<Integer>( (Integer) 0, (Integer) diameter / 2 );
118 Integer b = getRandomInteger<Integer>( (Integer) 0, (Integer) diameter / 2 );
119 Integer c = getRandomInteger<Integer>( (Integer) 0, (Integer) diameter / 2 );
120 Integer d = getRandomInteger<Integer>( (Integer) 0, (Integer) diameter / 2 );
121 if ( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
122 {
123 ++nb; nbok += checkPlane<Integer, NaivePlaneComputer>( a, b, c, d, diameter, nbpoints ) ? 1 : 0;
124 if ( nb != nbok )
125 {
126 std::cerr << "[ERROR] for plane " << a << " * x + "
127 << b << " * y + " << c << " * z = " << d << std::endl;
128 break;
129 }
130 }
131 }
132 return nb == nbok;
133}

◆ getRandomInteger()

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

Definition at line 49 of file testChordNaivePlaneComputer-benchmark.cpp.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 139 of file testChordNaivePlaneComputer-benchmark.cpp.

140{
141 using namespace Z3i;
142 unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 100;
143 unsigned int nbpoints = ( argc > 2 ) ? atoi( argv[ 2 ] ) : 100;
144 unsigned int diameter = ( argc > 3 ) ? atoi( argv[ 3 ] ) : 100;
145 std::cout << "# Usage: " << argv[0] << " <nbtries> <nbpoints> <diameter>." << std::endl;
146 std::cout << "# Test class ChordNaivePlaneComputer. Points are randomly chosen in [-diameter,diameter]^3." << std::endl;
147 std::cout << "# Integer nbtries nbpoints diameter time/plane(ms)" << std::endl;
148
149 trace.beginBlock ( "Testing class ChordNaivePlaneComputer" );
150 bool res = true
151 && checkPlanes<ChordNaivePlaneComputer<Space, Point, DGtal::int64_t> >( nbtries, diameter, nbpoints );
152 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
153 long t = trace.endBlock();
154 std::cout << "int64_t" << " " << nbtries
155 << " " << nbpoints
156 << " " << diameter
157 << " " << ( (double) t / (double) nbtries )
158 << std::endl;
159 return res ? 0 : 1;
160}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition: Common.h:154

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), and DGtal::trace.