DGtal  0.9.3
Functions
testChordGenericStandardPlaneComputer.cpp File Reference
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/CPointPredicate.h"
#include "DGtal/geometry/surfaces/CAdditivePrimitiveComputer.h"
#include "DGtal/geometry/surfaces/ChordGenericStandardPlaneComputer.h"
Include dependency graph for testChordGenericStandardPlaneComputer.cpp:

Go to the source code of this file.

Functions

template<typename Integer >
Integer getRandomInteger (const Integer &first, const Integer &after_last)
 
template<typename Domain >
std::vector< typename Domain::PointpointsInStandardPlane (const Domain &domain, typename Domain::Integer a, typename Domain::Integer b, typename Domain::Integer c, typename Domain::Integer mu)
 
template<typename PlaneComputer >
bool checkChordGenericStandardPlaneComputer (PlaneComputer &computer, unsigned int nbplanes, int diameter)
 
int main (int, char **)
 

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 ChordStandardPlaneComputer.

This file is part of the DGtal library.

Definition in file testChordGenericStandardPlaneComputer.cpp.

Function Documentation

◆ checkChordGenericStandardPlaneComputer()

template<typename PlaneComputer >
bool checkChordGenericStandardPlaneComputer ( PlaneComputer &  computer,
unsigned int  nbplanes,
int  diameter 
)

Definition at line 83 of file testChordGenericStandardPlaneComputer.cpp.

References domain(), getRandomInteger(), DGtal::Trace::info(), pointsInStandardPlane(), and DGtal::trace.

Referenced by main(), and pointsInStandardPlane().

84 {
85  typedef typename PlaneComputer::Space Space;
87  typedef typename Space::Integer Integer;
88  typedef typename Space::Point Point;
89  unsigned int nb = 0;
90  unsigned int nbok = 0;
91  Domain domain( Point( -diameter, -diameter, -diameter ),
92  Point( diameter, diameter, diameter ) );
93  Integer a, b, c, mu;
94  for ( unsigned int p = 0; p < nbplanes; ++p )
95  {
96  do {
97  a = getRandomInteger( -diameter, diameter+1 );
98  b = getRandomInteger( -diameter, diameter+1 );
99  c = getRandomInteger( -diameter, diameter+1 );
100  }
101  while ( ( a == 0 ) && ( b == 0 ) && ( c == 0 ) );
102  mu = getRandomInteger( -diameter, diameter );
103  std::vector<Point> pts = pointsInStandardPlane( domain, a, b, c, mu );
104  computer.init( 1, 1 );
105  ++nb, nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
106  trace.info() << "Primitive=" << computer.primitive() << std::endl;
107  trace.info() << "(" << nbok << "/" << nb << ") extend "
108  << pts.size() << " points of plane "
109  << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
110  << " < " << (mu+a+b+c) << std::endl;
111  computer.init( 1, 1 );
112  std::random_shuffle( pts.begin(), pts.end() );
113  ++nb, nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
114  trace.info() << "Primitive=" << computer.primitive() << std::endl;
115  trace.info() << "(" << nbok << "/" << nb << ") extend "
116  << pts.size() << " shuffled points of plane "
117  << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
118  << " < " << (mu+a+b+c) << std::endl;
119  }
120  return nb == nbok;
121 }
DGtal::int32_t Integer
Definition: StdDefs.h:74
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
MyPointD Point
Definition: testClone2.cpp:383
Integer getRandomInteger(const Integer &first, const Integer &after_last)
std::ostream & info()
std::vector< typename Domain::Point > pointsInStandardPlane(const Domain &domain, typename Domain::Integer a, typename Domain::Integer b, typename Domain::Integer c, typename Domain::Integer mu)

◆ getRandomInteger()

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

Definition at line 51 of file testChordGenericStandardPlaneComputer.cpp.

References pointsInStandardPlane().

Referenced by checkChordGenericStandardPlaneComputer().

52 {
53  Integer r = (Integer) rand();
54  return ( r % (after_last - first) ) + first;
55 }
DGtal::int32_t Integer
Definition: StdDefs.h:74

◆ main()

int main ( int  ,
char **   
)

Definition at line 124 of file testChordGenericStandardPlaneComputer.cpp.

References checkChordGenericStandardPlaneComputer(), DGtal::Trace::info(), DGtal::ChordGenericStandardPlaneComputer< TSpace, TInputPoint, TInternalScalar >::init(), and DGtal::trace.

125 {
126  using namespace Z3i;
127 
129  PlaneComputer;
130 
131  bool ok;
132  PlaneComputer plane;
133  plane.init( 1, 1 );
134  ok = plane.extend( Point(0,0,0) );
135  trace.info() << "Point(0,0,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
136  trace.info() << plane << std::endl;
137  ok = plane.extend( Point(1,0,0) );
138  trace.info() << "Point(1,0,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
139  trace.info() << plane << std::endl;
140  ok = plane.extend( Point(0,1,0) );
141  trace.info() << "Point(0,1,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
142  trace.info() << plane << std::endl;
143  ok = plane.extend( Point(1,1,0) );
144  trace.info() << "Point(1,1,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
145  trace.info() << plane << std::endl;
146  ok = plane.extend( Point(2,0,0) );
147  trace.info() << "Point(2,0,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
148  trace.info() << plane << std::endl;
149  ok = plane.extend( Point(0,2,0) );
150  trace.info() << "Point(0,2,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
151  trace.info() << plane << std::endl;
152  ok = plane.extend( Point(0,2,0) );
153  trace.info() << "Point(0,2,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
154  trace.info() << plane << std::endl;
155  ok = plane.extend( Point(1,1,1) );
156  trace.info() << "Point(1,1,1) is " << ( ok ? "ok" : "ko" ) << std::endl;
157  trace.info() << plane << std::endl;
159 
160  return 0;
161 }
Trace trace
Definition: Common.h:137
bool checkChordGenericStandardPlaneComputer(PlaneComputer &computer, unsigned int nbplanes, int diameter)
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
void init(InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
Aim: A class that recognizes pieces of digital planes of given diagonal width. When the width is ...

◆ pointsInStandardPlane()

template<typename Domain >
std::vector<typename Domain::Point> pointsInStandardPlane ( const Domain domain,
typename Domain::Integer  a,
typename Domain::Integer  b,
typename Domain::Integer  c,
typename Domain::Integer  mu 
)
Examples:
io/viewers/viewer3D-7-stdplane.cpp, and io/viewers/viewer3D-7bis-stdplane.cpp.

Definition at line 59 of file testChordGenericStandardPlaneComputer.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), checkChordGenericStandardPlaneComputer(), and DGtal::HyperRectDomain< TSpace >::end().

Referenced by checkChordGenericStandardPlaneComputer(), and getRandomInteger().

64 {
65  typedef typename Domain::Integer Integer;
66  typedef typename Domain::Point Point;
67  typedef typename Domain::ConstIterator ConstIterator;
68  std::vector<Point> pts;
69  Integer mup = mu + abs(a) + abs(b) + abs(c);
70  for ( ConstIterator it = domain.begin(), itE = domain.end();
71  it != itE; ++it )
72  {
73  Point p = *it;
74  Integer r = a * p[ 0 ] + b * p[ 1 ] + c * p[ 2 ];
75  if ( ( mu <= r ) && ( r < mup ) )
76  pts.push_back( p );
77  }
78  return pts;
79 }
DGtal::int32_t Integer
Definition: StdDefs.h:74
const ConstIterator & end() const
MyDigitalSurface::ConstIterator ConstIterator
const ConstIterator & begin() const
MyPointD Point
Definition: testClone2.cpp:383