DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testCOBAGenericStandardPlaneComputer.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/COBAGenericStandardPlaneComputer.h"

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.

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( 2*diameter, 1, 1 );
109 ++nb; nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
110 trace.info() << "Primitive=" << computer.primitive() << std::endl;
111 trace.info() << "(" << nbok << "/" << nb << ") extend "
112 << pts.size() << " points of plane "
113 << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
114 << " < " << (mu+a+b+c) << std::endl;
115 computer.init( 2*diameter, 1, 1 );
116 std::shuffle( pts.begin(), pts.end(), g );
117 ++nb; nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
118 trace.info() << "Primitive=" << computer.primitive() << std::endl;
119 trace.info() << "(" << nbok << "/" << nb << ") extend "
120 << pts.size() << " shuffled points of plane "
121 << mu << " <= " << a << "*x+" << b << "*y+" << c << "*z+"
122 << " < " << (mu+a+b+c) << std::endl;
123 }
124 return nb == nbok;
125}
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
std::ostream & info()
Trace trace
Definition: Common.h:154
Integer getRandomInteger(const Integer &first, const Integer &after_last)
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)
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 testCOBAGenericStandardPlaneComputer.cpp.

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

Referenced by checkCOBAGenericStandardPlaneComputer().

◆ main()

int main ( int  ,
char **   
)

Definition at line 128 of file testCOBAGenericStandardPlaneComputer.cpp.

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

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 & begin() const
const ConstIterator & end() const
MyDigitalSurface::ConstIterator ConstIterator

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

Referenced by checkCOBAGenericStandardPlaneComputer().