vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
complex.cc
Go to the documentation of this file.
1/************************************************************************/
2/* */
3/* vspline - a set of generic tools for creation and evaluation */
4/* of uniform b-splines */
5/* */
6/* Copyright 2015 - 2023 by Kay F. Jahnke */
7/* */
8/* Permission is hereby granted, free of charge, to any person */
9/* obtaining a copy of this software and associated documentation */
10/* files (the "Software"), to deal in the Software without */
11/* restriction, including without limitation the rights to use, */
12/* copy, modify, merge, publish, distribute, sublicense, and/or */
13/* sell copies of the Software, and to permit persons to whom the */
14/* Software is furnished to do so, subject to the following */
15/* conditions: */
16/* */
17/* The above copyright notice and this permission notice shall be */
18/* included in all copies or substantial portions of the */
19/* Software. */
20/* */
21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
23/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
24/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
25/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
26/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
27/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
28/* OTHER DEALINGS IN THE SOFTWARE. */
29/* */
30/************************************************************************/
31
32/// \file complex.cc
33///
34/// \brief demonstrate use of b-spline over std::complex data
35///
36/// vspline handles std::complex data like pairs of the complex
37/// type's value_type, and uses a vigra::TinyVector of two
38/// simdized value_types as the vectorized type.
39/// use examples.sh to compile with g++ and clang++, and all
40/// available SIMD back-ends:
41/// ./examples.sh complex.cc
42
43#include <iostream>
44#include <iomanip>
45#include <assert.h>
46#include <complex>
47#include <vspline/multithread.h>
48#include <vspline/vspline.h>
49
50int main ( int argc , char * argv[] )
51{
52 // nicely formatted output
53
54 std::cout << std::fixed << std::showpoint
55 << std::showpos << std::setprecision(6) ;
56
57 // create default b-spline over 100 values
58
60
61 // get a vigra::MultiArrayView to the spline's 'core'. This is the
62 // area corresponding with the original data and is filled with zero.
63
64 auto v1 = bsp.core ;
65
66 // we only set one single value in the middle of the array
67
68 v1 [ 50 ] = std::complex<float> ( 3.3 , 2.2 ) ;
69
70 // now we convert the original data to b-spline coefficients
71 // by calling prefilter()
72
73 bsp.prefilter() ;
74
75 // and create an evaluator over the spline. Here we pass three
76 // template arguments to the evaluator's type declaration:
77 // - float for the 'incoming type' (coordinates)
78 // - std::complex<float> for the 'outgoing type' (values)
79 // - 4 for the vector width, just for this example
80
82
83 // create the evalator
84
85 auto ev = ev_type ( bsp ) ;
86
87 // now we evaluate the spline in the region around the single
88 // nonzero value in the input data and print argument and result
89
90 float in ;
91 std::complex<float> out ;
92
93 for ( int k = -12 ; k < 13 ; k++ )
94 {
95 in = 50.0 + k * 0.1 ;
96
97 // use ev's eval() method:
98 ev.eval ( in , out ) ;
99 std::cout << "1. ev(" << in << ") = " << out << std::endl ;
100
101 // alternatively, use ev as a callable
102 std::cout << "2. ev(" << in << ") = " << ev(in) << std::endl ;
103
104 // ditto, but feed immediates. note we're passing float explicitly
105 std::cout << "3. ev(" << in << ") = " << ev(50.0f + k * 0.1f) << std::endl ;
106 }
107
108 // repeat the example evaluation with vector data
109
110 for ( int k = -12 ; k < 13 ; k++ )
111 {
112 // feed the evaluator with vectors. Note how we obtain the
113 // type of vectorized data the evaluator will accept from
114 // the evaluator, by querying for it's 'in_v' type.
115 // in_v will be a vigra::TinyVector of two SIMD vectors,
116 // where the type of the SIMD vectors depends on the SIMD
117 // back-end. For simplicity's sake, we initialize the
118 // vectorized argument to a uniform value.
119 // Note how in the output, the different SIMD back-ends
120 // produce visibly different output.
121
122 typename ev_type::in_v vk ( 50.0 + k * 0.1 ) ;
123
124 std::cout << "ev(" << vk << ") = " << ev(vk) << std::endl ;
125 }
126}
vspline::evaluator< coordinate_type, float > ev_type
Definition: ca_correct.cc:121
class evaluator encodes evaluation of a spline-like object. This is a generalization of b-spline eval...
Definition: eval.h:1718
int main(int argc, char *argv[])
Definition: complex.cc:50
code to distribute the processing of bulk data to several threads
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
Definition: bspline.h:499
view_type core
Definition: bspline.h:566
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....
Definition: bspline.h:815
vector_traits< coordinate_type, vsize >::type in_v
vectorized in_type and out_type. vspline::vector_traits supplies these types so that multidimensional...
includes all headers from vspline (most of them indirectly)