DGtal  1.0.0
Functions
testCOBAGenericStandardPlaneComputer.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/COBAGenericStandardPlaneComputer.h"
Include dependency graph for testCOBAGenericStandardPlaneComputer.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 checkCOBAGenericStandardPlaneComputer (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 COBAStandardPlaneComputer.

This file is part of the DGtal library.

Definition in file testCOBAGenericStandardPlaneComputer.cpp.

Function Documentation

◆ checkCOBAGenericStandardPlaneComputer()

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

Definition at line 83 of file testCOBAGenericStandardPlaneComputer.cpp.

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( 2*diameter, 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( 2*diameter, 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
Trace trace
Definition: Common.h:144
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)
Domain domain
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()

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 51 of file testCOBAGenericStandardPlaneComputer.cpp.

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

Referenced by checkCOBAGenericStandardPlaneComputer().

◆ main()

int main ( int  ,
char **   
)

Definition at line 124 of file testCOBAGenericStandardPlaneComputer.cpp.

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

References checkCOBAGenericStandardPlaneComputer(), DGtal::Trace::info(), DGtal::COBAGenericStandardPlaneComputer< TSpace, TInternalInteger >::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 
)

Definition at line 59 of file testCOBAGenericStandardPlaneComputer.cpp.

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
Domain domain
const ConstIterator & begin() const
MyPointD Point
Definition: testClone2.cpp:383

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

Referenced by checkCOBAGenericStandardPlaneComputer().