DGtal  1.1.0
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 82 of file testChordGenericStandardPlaneComputer.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( 1, 1 );
105  ++nb;
106  nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
107  trace.info() << "Primitive=" << computer.primitive() << std::endl;
108  trace.info() << "(" << nbok << "/" << nb << ") extend "
109  << pts.size() << " points of plane "
110  << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
111  << " < " << (mu+a+b+c) << std::endl;
112  computer.init( 1, 1 );
113  std::random_shuffle( pts.begin(), pts.end() );
114  ++nb;
115  nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
116  trace.info() << "Primitive=" << computer.primitive() << std::endl;
117  trace.info() << "(" << nbok << "/" << nb << ") extend "
118  << pts.size() << " shuffled points of plane "
119  << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
120  << " < " << (mu+a+b+c) << std::endl;
121  }
122  return nb == nbok;
123 }

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 testChordGenericStandardPlaneComputer.cpp.

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

Referenced by checkChordGenericStandardPlaneComputer().

◆ main()

int main ( int  ,
char **   
)

Definition at line 126 of file testChordGenericStandardPlaneComputer.cpp.

127 {
128  using namespace Z3i;
129 
131  PlaneComputer;
132 
133  bool ok;
134  PlaneComputer plane;
135  plane.init( 1, 1 );
136  ok = plane.extend( Point(0,0,0) );
137  trace.info() << "Point(0,0,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
138  trace.info() << plane << std::endl;
139  ok = plane.extend( Point(1,0,0) );
140  trace.info() << "Point(1,0,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
141  trace.info() << plane << std::endl;
142  ok = plane.extend( Point(0,1,0) );
143  trace.info() << "Point(0,1,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
144  trace.info() << plane << std::endl;
145  ok = plane.extend( Point(1,1,0) );
146  trace.info() << "Point(1,1,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
147  trace.info() << plane << std::endl;
148  ok = plane.extend( Point(2,0,0) );
149  trace.info() << "Point(2,0,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(0,2,0) );
155  trace.info() << "Point(0,2,0) is " << ( ok ? "ok" : "ko" ) << std::endl;
156  trace.info() << plane << std::endl;
157  ok = plane.extend( Point(1,1,1) );
158  trace.info() << "Point(1,1,1) is " << ( ok ? "ok" : "ko" ) << std::endl;
159  trace.info() << plane << std::endl;
161 
162  return 0;
163 }

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 58 of file testChordGenericStandardPlaneComputer.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 }

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

Referenced by checkChordGenericStandardPlaneComputer().

ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::HyperRectDomain< Space >
pointsInStandardPlane
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: testChordGenericStandardPlaneComputer.cpp:59
DGtal::ChordGenericStandardPlaneComputer
Aim: A class that recognizes pieces of digital planes of given diagonal width. When the width is ,...
Definition: ChordGenericStandardPlaneComputer.h:123
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::Trace::info
std::ostream & info()
getRandomInteger
Integer getRandomInteger(const Integer &first, const Integer &after_last)
Definition: testChordGenericStandardPlaneComputer.cpp:51
DGtal::Z2i::Integer
DGtal::int32_t Integer
Definition: StdDefs.h:74
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::ChordGenericStandardPlaneComputer::init
void init(InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::functions::abs
T abs(const T &a)
Definition: BasicMathFunctions.h:116
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:154
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::HyperRectDomain::Integer
Space::Integer Integer
Definition: HyperRectDomain.h:114
DGtal::PointVector< dim, Integer >
Space
SpaceND< 2 > Space
Definition: testSimpleRandomAccessRangeFromPoint.cpp:42
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::SpaceND::Integer
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
checkChordGenericStandardPlaneComputer
bool checkChordGenericStandardPlaneComputer(PlaneComputer &computer, unsigned int nbplanes, int diameter)
Definition: testChordGenericStandardPlaneComputer.cpp:83