DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
test2x2DetComputers.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/NumberTraits.h"
#include "DGtal/geometry/tools/determinant/C2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/Simple2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/SimpleIncremental2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
#include "DGtal/geometry/tools/determinant/Filtered2x2DetComputer.h"

Go to the source code of this file.

Functions

template<typename DetComputer >
bool simpleTest2x2DetComputer (DetComputer aComputer)
 
template<typename I1 , typename I2 >
bool hasTheSameSign (I1 x1, I2 x2)
 
DGtal::int32_t randomBelow2exp15 ()
 
DGtal::int32_t adHocRandom ()
 
template<typename DetComputer >
bool randomTest2x2DetComputer (DetComputer aComputer)
 
int main (int argc, char **argv)
 

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/11/18

Functions for testing classes that implements a model of C2x2DetComputer.

This file is part of the DGtal library.

Definition in file test2x2DetComputers.cpp.

Function Documentation

◆ adHocRandom()

DGtal::int32_t adHocRandom ( )

Definition at line 188 of file test2x2DetComputers.cpp.

189{
191 32768 * ( randomBelow2exp15() );
192 return ((rand() % 2) ? x : -x);
193}
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
DGtal::int32_t randomBelow2exp15()

References randomBelow2exp15().

Referenced by randomTest2x2DetComputer().

◆ hasTheSameSign()

template<typename I1 , typename I2 >
bool hasTheSameSign ( I1  x1,
I2  x2 
)

Function that retuns 'true' if x1 and x2 have the same sign:

  • both strictly positive
  • both strictly negative
  • both null and 'false' otherwise.
Parameters
x1a first integer
x2a second integer
Template Parameters
I1type of the first integer
I2type of the second integer

Definition at line 159 of file test2x2DetComputers.cpp.

160{
161 if (x1 == NumberTraits<I1>::ZERO)
162 {
163 if (x2 == NumberTraits<I2>::ZERO)
164 return true;
165 else
166 return false;
167 }
168 else if (x1 > NumberTraits<I1>::ZERO)
169 {
170 if (x2 > NumberTraits<I2>::ZERO)
171 return true;
172 else
173 return false;
174 }
175 else //if (x1 < NumberTraits<I1>::ZERO)
176 {
177 if (x2 < NumberTraits<I2>::ZERO)
178 return true;
179 else
180 return false;
181 }
182}
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564

Referenced by randomTest2x2DetComputer().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 245 of file test2x2DetComputers.cpp.

246{
247 trace.beginBlock ( "Testing class 2x2DetComputers" );
248 trace.info() << "Args:";
249 for ( int i = 0; i < argc; ++i )
250 trace.info() << " " << argv[ i ];
251 trace.info() << endl;
252
253 bool res = true;
254
255
256 res = res
259#ifdef WITH_BIGINTEGER
261#endif
264#ifdef WITH_BIGINTEGER
266#endif
272
273#ifdef WITH_BIGINTEGER
276#endif
279 ;
280
281 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
282 trace.endBlock();
283 return res ? 0 : 1;
284}
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Small class useful to compute the determinant of a 2x2 matrix from its four coefficients,...
Aim: Small class useful to compute, in an incremental way, the determinant of a 2x2 matrix from its f...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool randomTest2x2DetComputer(DetComputer aComputer)
bool simpleTest2x2DetComputer(DetComputer aComputer)

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), randomTest2x2DetComputer(), simpleTest2x2DetComputer(), and DGtal::trace.

◆ randomBelow2exp15()

DGtal::int32_t randomBelow2exp15 ( )

Definition at line 184 of file test2x2DetComputers.cpp.

185{
186 return static_cast<DGtal::int32_t>(rand() % 32768);
187}

Referenced by adHocRandom().

◆ randomTest2x2DetComputer()

template<typename DetComputer >
bool randomTest2x2DetComputer ( DetComputer  aComputer)

Function that compares the result returned by aComputer against the result returned by Simple2x2DetComputer using integers on 32 and 64 bits for various matrices whose entries are random integers whose absolute value is less than 2^32.

Parameters
aComputera determinant computer to test
Template Parameters
DetComputera model of CIncremental2x2DetComputer

Definition at line 205 of file test2x2DetComputers.cpp.

206{
207 BOOST_CONCEPT_ASSERT(( C2x2DetComputer<DetComputer> ));
208
210 TrueComputer trueComputer;
211
212 trace.beginBlock ( "Testing block ..." );
213 trace.info() << trueComputer << " vs " << aComputer << endl;
214
215 bool isOk = true;
216
217 DGtal::int32_t a, b, x, y;
218
219 const int n = 10000;
220 for (int i = 0; ( (i < n)&&(isOk) ); ++i)
221 {
222 a = adHocRandom();
223 b = adHocRandom();
224 x = adHocRandom();
225 y = adHocRandom();
226 trueComputer.init(a, b);
227 aComputer.init(a, b);
228 TrueComputer::Value trueRes = trueComputer(x,y);
229 typename DetComputer::Value res = aComputer(x,y);
230 // trace.info() << a << "." << y << " - "
231 // << b << " " << x << " => "
232 // << trueRes << " / " << res << endl;
233 if ( !hasTheSameSign( trueRes, res ) )
234 isOk = false;
235 }
236
237 trace.endBlock();
238
239 return isOk;
240}
Aim: This concept gathers all models that are able to compute the (sign of the) determinant of a 2x2 ...
DGtal::int32_t adHocRandom()
bool hasTheSameSign(I1 x1, I2 x2)

References adHocRandom(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), hasTheSameSign(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ simpleTest2x2DetComputer()

template<typename DetComputer >
bool simpleTest2x2DetComputer ( DetComputer  aComputer)

Function that compares the result returned by aComputer with a ground truth in each quadrant.

Parameters
aComputerany determinant computer
Template Parameters
DetComputera model of CIncremental2x2DetComputer

Definition at line 56 of file test2x2DetComputers.cpp.

57{
58 BOOST_CONCEPT_ASSERT(( C2x2DetComputer<DetComputer> ));
59 typedef typename DetComputer::Integer Integer;
60 typedef typename DetComputer::Value Value;
61
62 unsigned int nbok = 0;
63 unsigned int nb = 0;
64
65 trace.beginBlock ( "Testing block ..." );
66 trace.info() << aComputer << endl;
67
68 Integer a = 5;
69 Integer b = 2;
70
71
72 //first quadrant
73 aComputer.init(a,b);
74 if (aComputer(2,1) == NumberTraits<Value>::ONE)
75 nbok++;
76 nb++;
77 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
78
79 if (aComputer(3,1) == -NumberTraits<Value>::ONE)
80 nbok++;
81 nb++;
82 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
83
84 if (aComputer(5,2) == NumberTraits<Value>::ZERO)
85 nbok++;
86 nb++;
87 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
88
89 //second quadrant
90 aComputer.init(-a,b);
91 if (aComputer(2,-1) == NumberTraits<Value>::ONE)
92 nbok++;
93 nb++;
94 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
95
96 if (aComputer(3,-1) == -NumberTraits<Value>::ONE)
97 nbok++;
98 nb++;
99 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
100
101 if (aComputer(5,-2) == NumberTraits<Value>::ZERO)
102 nbok++;
103 nb++;
104 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
105
106 //third quadrant
107 aComputer.init(-a,-b);
108 if (aComputer(-2,-1) == NumberTraits<Value>::ONE)
109 nbok++;
110 nb++;
111 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
112
113 if (aComputer(-3,-1) == -NumberTraits<Value>::ONE)
114 nbok++;
115 nb++;
116 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
117
118 if (aComputer(-5,-2) == NumberTraits<Value>::ZERO)
119 nbok++;
120 nb++;
121 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
122
123 //fourth quadrant
124 aComputer.init(a,-b);
125 if (aComputer(-2,1) == NumberTraits<Value>::ONE)
126 nbok++;
127 nb++;
128 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
129
130 if (aComputer(-3,1) == -NumberTraits<Value>::ONE)
131 nbok++;
132 nb++;
133 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
134
135 if (aComputer(-5,2) == NumberTraits<Value>::ZERO)
136 nbok++;
137 nb++;
138 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
139
140 trace.endBlock();
141
142 return nbok == nb;
143}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().