92template <
typename dtype >
114 auto ev = vspline::make_evaluator < spline_type , double >
119 vigra::MultiArray<1,dtype> result ( 100 ) ;
120 vigra::MultiArray<1,dtype> reference ( 100 ) ;
124 dtype * p_center = &(reference[50]) ;
129 for (
int x = - degree / 2 ; x <= degree / 2 ; x++ )
131 p_center[x] = vspline::bspline_basis_2<dtype> ( x+x , degree ) ;
142 p_center = &(bspl.
core[50]) ;
159 for (
int x = 50 - degree / 2 ; x <= 50 + degree / 2 ; x++ )
161 assert ( result[x] == reference[x] ) ;
162 assert ( bf ( x - 50 ) == reference[x] ) ;
174 for (
int x = - degree / 2 ; x <= degree / 2 ; x++ )
180 error = std::fabs ( p_center [ x ] - 1.0 ) ;
185 error = std::fabs ( p_center [ x ] ) ;
187 if ( error > threshold )
188 std::cout <<
"unit pulse test, x = " << x <<
", error = "
189 << error << std::endl ;
190 max_error = std::max ( max_error , error ) ;
200 int xmin = - degree - 1 ;
201 int xmax = degree + 1 ;
203 for (
int x2 = xmin ; x2 <= xmax ; x2++ )
205 auto a = bf ( x2 / 2.0L ) ;
206 auto b = vspline::bspline_basis_2<dtype> ( x2 , degree ) ;
207 auto error = std::abs ( a - b ) ;
208 if ( error > strict_threshold )
209 std::cout <<
"bfx2: " << x2 / 2.0 <<
" : "
210 << a <<
" <--> " << b
211 <<
" error " << error << std::endl << std::endl ;
212 max_error = std::max ( max_error , error ) ;
221 std::random_device rd ;
222 std::mt19937 gen ( rd() ) ;
223 std::uniform_real_distribution<>
224 dis ( 50 - degree -1 , 50 + degree + 1 ) ;
227 for (
int k = 0 ; k < 1000 ; k++ )
229 double x = dis ( gen ) ;
231 dtype error = std::abs ( y - 1 ) ;
232 if ( error > strict_threshold )
233 std::cout <<
"partition of unity test, d0: " << x <<
" : "
234 << y <<
" <--> " << 1
235 <<
" error " << error << std::endl << std::endl ;
236 max_error = std::max ( max_error , error ) ;
239 vigra::TinyVector < int , 1 > deriv_spec ;
247 auto dev = vspline::make_evaluator < spline_type , double >
248 ( bspl , deriv_spec ) ;
249 for (
int k = 0 ; k < 1000 ; k++ )
251 double x = dis ( gen ) ;
252 dtype y = dev ( x ) ;
253 dtype error = std::abs ( y ) ;
254 if ( error > strict_threshold )
255 std::cout <<
"partition of unity test, d1: " << x <<
" : "
256 << y <<
" <--> " << 0
257 <<
" error " << error << std::endl << std::endl ;
258 max_error = std::max ( max_error , error ) ;
265 auto ddev = vspline::make_evaluator< spline_type , double >
266 ( bspl , deriv_spec ) ;
267 for (
int k = 0 ; k < 1000 ; k++ )
269 double x = dis ( gen ) ;
270 dtype y = ddev ( x ) ;
271 dtype error = std::abs ( y ) ;
272 if ( error > strict_threshold )
273 std::cout <<
"partition of unity test, d2: " << x <<
" : "
274 << y <<
" <--> " << 0
275 <<
" error " << error << std::endl << std::endl ;
276 max_error = std::max ( max_error , error ) ;
289 std::random_device rd ;
290 std::mt19937 gen ( rd() ) ;
291 std::uniform_real_distribution<> dis ( - degree -1 , degree + 1 ) ;
292 for (
int k = 0 ; k < 1000 ; k++ )
294 dtype x = dis ( gen ) ;
297 dtype error = std::abs ( a - b ) ;
298 if ( error > strict_threshold )
299 std::cout <<
"bf: " << x <<
" : "
300 << a <<
" <--> " << b
301 <<
" error " << error << std::endl << std::endl ;
302 max_error = std::max ( max_error , error ) ;
306 if ( degree > 1 && degree < 13 )
309 std::random_device rd ;
310 std::mt19937 gen ( rd() ) ;
311 std::uniform_real_distribution<> dis ( - degree -1 , degree + 1 ) ;
312 for (
int k = 0 ; k < 1000 ; k++ )
314 dtype x = dis ( gen ) ;
315 dtype a = dbf ( x ) ;
317 dtype error = std::abs ( a - b ) ;
318 if ( error > strict_threshold )
319 std::cout <<
"dbf: " << x <<
" : "
320 << a <<
" <--> " << b
321 <<
" error " << error << std::endl << std::endl ;
322 max_error = std::max ( max_error , error ) ;
326 if ( degree > 2 && degree < 13 )
329 std::random_device rd ;
330 std::mt19937 gen ( rd() ) ;
331 std::uniform_real_distribution<> dis ( - degree -1 , degree + 1 ) ;
332 for (
int k = 0 ; k < 1000 ; k++ )
334 dtype x = dis ( gen ) ;
335 dtype a = ddbf ( x ) ;
337 dtype error = std::abs ( a - b ) ;
338 if ( error > strict_threshold )
339 std::cout <<
"ddbf: " << x <<
" : "
340 << a <<
" <--> " << b
341 <<
" error " << error << std::endl << std::endl ;
342 max_error = std::max ( max_error , error ) ;
348 std::random_device rd ;
349 std::mt19937 gen ( rd() ) ;
350 std::uniform_real_distribution<>
353 dtype circle_error = 0 ;
354 dtype avg_circle_error = 0 ;
361 dtype v2 = bf ( 1 ) * bf ( 0 ) ;
366 for (
int k = 0 ; k < 10000 ; k++ )
370 double x = dis ( gen ) ;
371 double y = dis ( gen ) ;
375 double s = sqrt ( x * x + y * y ) ;
383 dtype v1 = bf ( x ) * bf ( y ) ;
390 dtype error = std::abs ( v1 - v2 ) ;
391 circle_error = std::max ( circle_error , error ) ;
392 avg_circle_error += error ;
419int main (
int argc ,
char * argv[] )
421 long double max_error_l = 0 ;
423 for (
int degree = 0 ; degree <= vspline_constants::max_degree ; degree++ )
425 max_error_l = std::max ( max_error_l ,
426 self_test<long double>
427 ( degree , 4e-13l , 1e-18 ) ) ;
430 std::cout <<
"maximal error of tests with long double precision: "
432 << max_error_l << std::endl ;
434 double max_error_d = 0 ;
436 for (
int degree = 0 ; degree <= vspline_constants::max_degree ; degree++ )
438 max_error_d = std::max ( max_error_d ,
440 ( degree , 1e-9 , 7e-16 ) ) ;
443 std::cout <<
"maximal error of tests with double precision: "
444 << max_error_d << std::endl ;
446 float max_error_f = 0 ;
450 for (
int degree = 0 ; degree < 16 ; degree++ )
452 max_error_f = std::max ( max_error_f ,
454 ( degree , 3e-6 , 4e-7 ) ) ;
457 std::cout <<
"maximal error of tests with float precision: "
458 << max_error_f << std::endl ;
460 if ( max_error_l < 4e-13
462 && max_error_f < 3e-6 )
464 std::cout <<
"test passed" << std::endl ;
466 std::cout <<
"test failed" << std::endl ;
vspline::bspline< pixel_type, 2 > spline_type
void transform(const unary_functor_type &functor, const vigra::MultiArrayView< dimension, typename unary_functor_type::in_type > &input, vigra::MultiArrayView< dimension, typename unary_functor_type::out_type > &output, int njobs=vspline::default_njobs, vspline::atomic< bool > *p_cancel=0)
implementation of two-array transform using wielding::coupled_wield.
real_type cdb_bspline_basis(real_type x, int degree, int derivative=0)
Implementation of the Cox-de Boor recursion formula to calculate the value of the bspline basis funct...
int main(int argc, char *argv[])
dtype self_test(int degree, dtype threshold, dtype strict_threshold)
long double circular_test_previous
basis_functor is an object producing the b-spline basis function value for given arguments,...
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
void prefilter(vspline::xlf_type boost=vspline::xlf_type(1), int njobs=vspline::default_njobs)
prefilter converts the knot point data in the 'core' area into b-spline coefficients....
includes all headers from vspline (most of them indirectly)