20 #ifndef MIRTK_NaryVoxelFunction_H    21 #define MIRTK_NaryVoxelFunction_H    23 #include "mirtk/VoxelFunction.h"    24 #include "mirtk/BaseImage.h"    25 #include "mirtk/InterpolateImageFunction.h"    39 namespace NaryVoxelFunction {
    48 template <
class TInterpolator = InterpolateImageFunction>
    56   static const int _x = 0; 
    62     _VelocityField(v->Input()),
    63     _VelocityInterpolator (v),
    65     _dt(t / _NumberOfSteps),
    66     _y(_VelocityField->GetX() * _VelocityField->GetY())
    70   void operator ()(
int i, 
int j, 
int k, 
int, T *d)
    73     double x1 = i, y1 = j, z1 = k;
    75     double x2 = x1, y2 = y1;
    77       x = x2, y = y2, z = z1;
    79       _VelocityInterpolator->Evaluate(v, x, y, z);
    83     d[
_x] = 
static_cast<T
>(x2 - x1);
    84     d[
_y] = 
static_cast<T
>(y2 - y1);
    88   void operator ()(
int i, 
int j, 
int k, 
int, 
const T *din, T *dout)
    91     double x1 = i, y1 = j, z1 = k;
    93     double x2 = x1 + din[
_x];
    94     double y2 = y1 + din[
_y];
    96       x = x2, y = y2, z = z1;
    98       _VelocityInterpolator->Evaluate(v, x, y, z);
   102     dout[
_x] = 
static_cast<T
>(x2 - x1);
   103     dout[
_y] = 
static_cast<T
>(y2 - y1);
   109 template <
class TInterpolator = InterpolateImageFunction>
   117   static const int _x = 0; 
   123     _VelocityField(v->Input()),
   124     _VelocityInterpolator (v),
   126     _dt(t / _NumberOfSteps),
   127     _y(_VelocityField->X() * _VelocityField->Y() * _VelocityField->Z()),
   132   void operator ()(
int i, 
int j, 
int k, 
int, T *d)
   134     double x, y, z, v[3];
   135     double x1 = i, y1 = j, z1 = k;
   137     double x2 = x1, y2 = y1, z2 = z1;
   139       x = x2, y = y2, z = z2;
   141       _VelocityInterpolator->Evaluate(v, x, y, z);
   146     d[
_x] = 
static_cast<T
>(x2 - x1);
   147     d[
_y] = 
static_cast<T
>(y2 - y1);
   148     d[_z] = 
static_cast<T
>(z2 - z1);
   152   void operator ()(
int i, 
int j, 
int k, 
int, 
const T *din, T *dout)
   154     double x, y, z, v[3];
   155     double x1 = i, y1 = j, z1 = k;
   157     double x2 = x1 + din[
_x];
   158     double y2 = y1 + din[
_y];
   159     double z2 = z1 + din[_z];
   161       x = x2, y = y2, z = z2;
   163       _VelocityInterpolator->Evaluate(v, x, y, z);
   168     dout[
_x] = 
static_cast<T
>(x2 - x1);
   169     dout[
_y] = 
static_cast<T
>(y2 - y1);
   170     dout[_z] = 
static_cast<T
>(z2 - z1);
   178   const double *_Weight;
   180   template <
class TImage, 
class T>
   181   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, T *out)
   183     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b));
   186   template <
class TImage, 
class T>
   187   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, 
const T *c, T *out)
   189     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b) + _Weight[2] * (*c));
   192   template <
class TImage, 
class T>
   193   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, 
const T *c, 
const T *d, T *out)
   195     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b) + _Weight[2] * (*c) + _Weight[3] * (*d));
   198   template <
class TImage, 
class T>
   199   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, 
const T *c, 
const T *d, 
const T *e, T *out)
   201     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b) + _Weight[2] * (*c) + _Weight[3] * (*d) + _Weight[4] * (*e));
   204   template <
class TImage, 
class T>
   205   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, 
const T *c, 
const T *d, 
const T *e, 
const T *f, T *out)
   207     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b) + _Weight[2] * (*c) + _Weight[3] * (*d) + _Weight[4] * (*e) + _Weight[5] * (*f));
   210   template <
class TImage, 
class T>
   211   void operator()(
const TImage &, 
int, 
const T *a, 
const T *b, 
const T *c, 
const T *d, 
const T *e, 
const T *f, 
const T *g, T *out)
   213     (*out) = 
static_cast<T
>(_Weight[0] * (*a) + _Weight[1] * (*b) + _Weight[2] * (*c) + _Weight[3] * (*d) + _Weight[4] * (*e) + _Weight[5] * (*f) + _Weight[6] * (*g));
   221   template <
class TImage, 
class T>
   222   void operator()(
const TImage &, 
int, 
const T *v, 
const T *d, T *out)
   224     (*out) = (*v) + (*d);
   227   template <
class TImage, 
class T>
   228   void operator()(
const TImage &, 
int, 
const T *v, 
const T *d, 
const T *l1, T *out)
   230     (*out) = 
static_cast<T
>((*v) + (*d) + (*l1) / 2.0);
   233   template <
class TImage, 
class T>
   234   void operator()(
const TImage &, 
int, 
const T *v, 
const T *d, 
const T *l1, 
const T *l2, T *out)
   236     (*out) = 
static_cast<T
>((*v) + (*d) + (*l1) / 2.0 + (*l2) / 12.0);
   239   template <
class TImage, 
class T>
   240   void operator()(
const TImage &, 
int, 
const T *v, 
const T *d, 
const T *l1, 
const T *l2, 
const T *l3, T *out)
   242     (*out) = 
static_cast<T
>((*v) + (*d) + (*l1) / 2.0 + (*l2) / 12.0 - (*l3) / 12.0);
   245   template <
class TImage, 
class T>
   246   void operator()(
const TImage &, 
int, 
const T *v, 
const T *d, 
const T *l1, 
const T *l2, 
const T *l3, 
const T *l4, T *out)
   248     (*out) = 
static_cast<T
>((*v) + (*d) + (*l1) / 2.0 + (*l2) / 12.0 - (*l3) / 12.0 - (*l4) / 24.0);
   256   template <
class TImage, 
class T>
   257   void operator()(
const TImage &, 
int, 
const T *d, 
const T *l1, T *out)
   259     (*out) = 
static_cast<T
>((*d) + (*l1) / 2.0);
   262   template <
class TImage, 
class T>
   263   void operator()(
const TImage &, 
int, 
const T *d, 
const T *l1, 
const T *l2, T *out)
   265     (*out) = 
static_cast<T
>((*d) + (*l1) / 2.0 + (*l2) / 12.0);
   268   template <
class TImage, 
class T>
   269   void operator()(
const TImage &, 
int, 
const T *d, 
const T *l1, 
const T *l2, 
const T *l3, T *out)
   271     (*out) = 
static_cast<T
>((*d) + (*l1) / 2.0 + (*l2) / 12.0 - (*l3) / 12.0);
   274   template <
class TImage, 
class T>
   275   void operator()(
const TImage &, 
int, 
const T *d, 
const T *l1, 
const T *l2, 
const T *l3, 
const T *l4, T *out)
   277     (*out) = 
static_cast<T
>((*d) + (*l1) / 2.0 + (*l2) / 12.0 - (*l3) / 12.0 - (*l4) / 24.0);
   284 #endif // MIRTK_NaryVoxelFunction_H static const int _x
Offset of x component. 
int _z
Offset of y and z components. 
double _dt
Temporal step length. 
void WorldToImage(double &, double &) const
World to image coordinate conversion with two doubles. 
const BaseImage * _VelocityField
Velocity field. 
int _NumberOfSteps
Number of integration steps. 
int _y
Offset of y component. 
double _dt
Temporal step length. 
int _NumberOfSteps
Number of integration steps. 
Compute voxel-wise weighted sum. 
Voxel function for exponentiation of 2D velocity field. 
void ImageToWorld(double &, double &) const
Image to world coordinate conversion with two doubles. 
TInterpolator * _VelocityInterpolator
Velocity field interpolator. 
const BaseImage * _VelocityField
Velocity field. 
Evaluate velocity update using Baker-Campbell-Hausdorff (BCH) formula. 
TInterpolator * _VelocityInterpolator
Velocity field interpolator. 
Voxel function for exponentiation of 3D velocity field.