vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
Classes | Namespaces
convolve.h File Reference

separable convolution of nD arrays More...

#include "common.h"
#include "extrapolate.h"
#include "filter.h"

Go to the source code of this file.

Classes

struct  vspline::fir_filter_specs
 fir_filter_specs holds the parameters for a filter performing a convolution along a single axis. In vspline, the place where the specifications for a filter are fixed and the place where it is finally created are far apart: the filter is created in the separate worker threads. So this structure serves as a vehicle to transport the arguments. Note the specification of 'headroom': this allows for non-symmetrical and even kernels. When applying the kernel to obtain output[i], the kernel is applied to input [ i - headroom ] , ... , input [ i - headroom + ksize - 1 ] More...
 
struct  vspline::fir_filter< in_type, out_type, _math_type >
 class fir_filter provides the 'solve' routine which convolves a 1D signal with selectable extrapolation. Here, the convolution kernel is applied to the incoming signal and the result is written to the specified output location. Note that this operation can be done in-place, but input and output may also be different. While most of the time this routine will be invoked by class convolve (below), it is also directly used by the specialized code for 1D filtering. Note how we conveniently inherit from the specs class. This also enables us to use an instance of fir_filter or class convolve as specs argument to create further filters with the same arguments. More...
 
struct  vspline::convolve< _vtype, _math_ele_type, _vsize >
 class convolve provides the combination of class fir_filter above with a vector-friendly buffer. Calling code provides information about what should be buffered, the data are sucked into the buffer, filtered, and moved back from there. The operation is orchestrated by the code in filter.h, which is also used to 'wield' the b-spline prefilter. Both operations are sufficiently similar to share the wielding code. More...
 

Namespaces

namespace  vspline
 

Detailed Description

separable convolution of nD arrays

This file provides the core filtering code for convolution, which can be used by itself to filter 1D arrays, or is used with the 'wielding' code in filter.h to filter nD arrays. The latter use is what's used throughout most of vspline, since it provides automatic multithreading and vectorization by buffering the data and applying the 1D code to the buffer.

The implementation of convolution in this file can safely operate in-place. The actual convolution operation is done using a small kernel-sized circular buffer, which is multiplied with an adequately shifted and rotated representation of the kernel. This is done avoiding conditionals as best as possible. The 1D data are extrapolated with one of the boundary condition codes known to class extrapolator (see extrapolate.h). This is done transparently by putting extrapolated data into the small circular buffer where this is needed.

The code is trivial insofar as it only uses indexed assignments, addition and multiplication. So it can operate on a wide variety of data types, prominently among them SIMD vector types.

Note how I use the kernel front-to-back, in the same forward sequence as the data it is applied to. This is contrary to the normal convention of using the kernel values back-to-front. Inside vspline, where only symmetrical kernels are used, this makes no difference, but when vpline's convolution code is used for other convolutions, this has to be kept in mind.

Definition in file convolve.h.