20 #ifndef MIRTK_BinaryVoxelFunction_H 21 #define MIRTK_BinaryVoxelFunction_H 23 #include "mirtk/VoxelFunction.h" 25 #include "mirtk/NeighborhoodOffsets.h" 26 #include "mirtk/InterpolateImageFunction.h" 52 namespace mirtk {
namespace BinaryVoxelFunction {
65 template <
class T1,
class T2>
66 void operator ()(
const T1 *in, T2 *out) { *out = *in; }
68 template <
class TImage,
class T1,
class T2>
69 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
71 this->operator ()(in, out);
74 template <
class T1,
class T2>
75 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
77 this->operator ()(in, out);
91 template <
class T1,
class T2>
92 void operator ()(
const T1 *in, T2 *out)
94 *out =
static_cast<T2
>(
static_cast<double>(*out) +
static_cast<double>(*in));
97 template <
class TImage,
class T1,
class T2>
98 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
100 this->operator ()(in, out);
103 template <
class T1,
class T2>
104 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
106 this->operator ()(in, out);
116 template <
class T1,
class T2>
117 void operator ()(
const T1 *in, T2 *out)
119 *out =
static_cast<T2
>(
static_cast<double>(*out) -
static_cast<double>(*in));
122 template <
class TImage,
class T1,
class T2>
123 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
125 this->operator ()(in, out);
128 template <
class T1,
class T2>
129 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
131 this->operator ()(in, out);
141 template <
class T1,
class T2>
142 void operator ()(
const T1 *in, T2 *out)
144 *out =
static_cast<T2
>(
static_cast<double>(*out) *
static_cast<double>(*in));
147 template <
class TImage,
class T1,
class T2>
148 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
150 this->operator ()(in, out);
153 template <
class T1,
class T2>
154 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
156 this->operator ()(in, out);
166 template <
class T1,
class T2>
167 void operator ()(
const T1 *in, T2 *out)
169 double divisor =
static_cast<double>(*in);
171 *out =
static_cast<T2
>(0);
173 *out =
static_cast<T2
>(
static_cast<double>(*out) / divisor);
177 template <
class TImage,
class T1,
class T2>
178 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
180 this->operator ()(in, out);
183 template <
class T1,
class T2>
184 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
186 this->operator ()(in, out);
206 void operator ()(
int i,
int j,
int k,
int,
const T *in, T *out)
214 for (
int n = 0; n < _Offsets.Size(); ++n) {
215 ptr2offset = in + _Offsets(n);
216 if (*ptr2offset < value) value = *ptr2offset;
234 void operator ()(
int i,
int j,
int k,
int,
const T *in, T *out)
242 for (
int n = 0; n < _Offsets.Size(); ++n) {
243 ptr2offset = in + _Offsets(n);
244 if (*ptr2offset > value) value = *ptr2offset;
263 SSD(
SSD &o) : value(o.value) {}
265 void split(
const SSD &) { value = .0; }
266 void join (
const SSD &rhs) { value += rhs.value; }
268 template <
class T1,
class T2>
269 void operator ()(
const T1 *in1,
const T2 *in2)
271 double diff =
static_cast<double>(*in1) -
static_cast<double>(*in2);
272 value += diff * diff;
275 template <
class TImage,
class T1,
class T2>
276 void operator ()(
const TImage&,
int,
const T1 *in, T2 *out)
278 this->operator ()(in, out);
281 template <
class T1,
class T2>
282 void operator ()(
int,
int,
int,
int,
const T1 *in, T2 *out)
284 this->operator ()(in, out);
294 template <
class TReal,
class TInterpolator = InterpolateImageFunction>
303 _y(d2->
X() * d2->
Y())
308 void operator()(
int i,
int j,
int k,
int,
const TReal *d2, TReal *dout)
311 double x1 = i, y1 = j, z1 = k;
312 _D2->ImageToWorld(x1, y1, z1);
313 double x2 = x1 + d2[_x];
double x = x2;
314 double y2 = y1 + d2[_y];
double y = y2;
315 _D1 ->WorldToImage(x, y, z1);
316 _D1Interpolator->Evaluate (d, x, y, z1);
319 dout[_x] =
static_cast<TReal
>(x2 - x1);
320 dout[_y] =
static_cast<TReal
>(y2 - y1);
325 TInterpolator *_D1Interpolator;
328 static const int _x = 0;
334 template <
class TReal,
class TInterpolator = InterpolateImageFunction>
343 _y(d2->
X() * d2->
Y() * d2->
Z()),
349 void operator()(
int i,
int j,
int k,
int,
const TReal *d2, TReal *dout)
352 double x1 = i, y1 = j, z1 = k;
353 _D2->ImageToWorld(x1, y1, z1);
354 double x2 = x1 + d2[_x];
double x = x2;
355 double y2 = y1 + d2[_y];
double y = y2;
356 double z2 = z1 + d2[_z];
double z = z2;
357 _D1 ->WorldToImage(x, y, z);
358 _D1Interpolator->Evaluate (d, x, y, z);
362 dout[_x] =
static_cast<TReal
>(x2 - x1);
363 dout[_y] =
static_cast<TReal
>(y2 - y1);
364 dout[_z] =
static_cast<TReal
>(z2 - z1);
369 TInterpolator *_D1Interpolator;
372 static const int _x = 0;
Compose two 2D displacement fields: D = D1 ° D2.
const ImageAttributes * _Domain
Compose two 3D displacement fields: D = D1 ° D2.
void join(VoxelFunction &)
Join results.
int Y() const
Returns the number of voxels in the y-direction.
int X() const
Returns the number of voxels in the x-direction.
void split(VoxelFunction &)
bool IsBoundary(int) const
Whether voxel index is at boundary of finite image domain.
int Z() const
Returns the number of voxels in the z-direction.