DGtal  1.4.beta
testChordGenericStandardPlaneComputer.cpp File Reference
#include <cstdlib>
#include <iostream>
#include <random>
#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.

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

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

Referenced by main().

◆ getRandomInteger()

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

Definition at line 52 of file testChordGenericStandardPlaneComputer.cpp.

53 {
54  Integer r = (Integer) rand();
55  return ( r % (after_last - first) ) + first;
56 }

Referenced by checkChordGenericStandardPlaneComputer().

◆ main()

int main ( int  ,
char **   
)

Definition at line 130 of file testChordGenericStandardPlaneComputer.cpp.

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

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

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

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

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

Referenced by checkChordGenericStandardPlaneComputer().