20 #ifndef MIRTK_InterpolateImageFunction_H 21 #define MIRTK_InterpolateImageFunction_H 23 #include "mirtk/InterpolationMode.h" 24 #include "mirtk/Point.h" 25 #include "mirtk/Vector.h" 26 #include "mirtk/Voxel.h" 27 #include "mirtk/VoxelCast.h" 28 #include "mirtk/BaseImage.h" 29 #include "mirtk/GenericImage.h" 30 #include "mirtk/ImageFunction.h" 31 #include "mirtk/UnaryVoxelFunction.h" 33 #include "mirtk/ExtrapolateImageFunction.h" 57 mirtkPublicAttributeMacro(
int, NumberOfDimensions);
73 double _x1, _y1, _z1, _t1, _x2, _y2, _z2, _t2;
168 double XSize()
const;
171 double YSize()
const;
174 double ZSize()
const;
177 double TSize()
const;
208 void Inside(
double &,
double &,
209 double &,
double &)
const;
213 void Inside(
double &,
double &,
double &,
214 double &,
double &,
double &)
const;
218 void Inside(
double &,
double &,
double &,
double &,
219 double &,
double &,
double &,
double &)
const;
226 virtual void BoundingBox(
double,
double,
int &,
int &,
230 virtual void BoundingBox(
double,
double,
double,
int &,
int &,
int &,
231 int &,
int &,
int &)
const;
234 virtual void BoundingBox(
double,
double,
double,
double,
235 int &,
int &,
int &,
int &,
236 int &,
int &,
int &,
int &)
const;
240 bool IsInside(
double,
double)
const;
244 bool IsInside(
double,
double,
double)
const;
248 bool IsInside(
double,
double,
double,
double)
const;
264 bool IsOutside(
double,
double,
double)
const;
268 bool IsOutside(
double,
double,
double,
double)
const;
288 bool IsForeground(
double,
double,
double,
double)
const;
306 virtual double EvaluateInside(
double,
double,
double = 0,
double = 0)
const = 0;
309 virtual double EvaluateOutside(
double,
double,
double = 0,
double = 0)
const = 0;
318 double Evaluate(
double,
double,
double = 0,
double = 0)
const;
339 double Evaluate(
double,
double,
double = 0,
double = 0);
378 virtual void EvaluateInside(
double *,
double,
double,
double = 0,
int = 1)
const;
381 virtual void EvaluateOutside(
double *,
double,
double,
double = 0,
int = 1)
const;
390 void Evaluate(
double *,
double,
double,
double = 0,
int = 1)
const;
450 void Evaluate(
Vector &,
double,
double,
double = 0,
double = 0)
const;
485 template <
class TVoxel>
558 template <
class TImage>
568 typedef TImage ImageType;
569 typedef typename ImageType::VoxelType VoxelType;
570 typedef typename ImageType::RealType RealType;
571 typedef typename ImageType::RealScalarType Real;
589 const TImage * = NULL);
602 const TImage * = NULL);
611 const ImageType *
Input()
const;
639 virtual VoxelType GetInside(
double,
double,
double = 0,
double = 0)
const = 0;
642 virtual VoxelType GetOutside(
double,
double,
double = 0,
double = 0)
const = 0;
653 virtual VoxelType GetWithPaddingInside(
double,
double,
double = 0,
double = 0)
const = 0;
660 virtual VoxelType GetWithPaddingOutside(
double,
double,
double = 0,
double = 0)
const = 0;
667 VoxelType GetWithPadding(
double,
double,
double = 0,
double = 0)
const;
676 VoxelType
Get(
double,
double,
double = 0,
double = 0)
const;
679 VoxelType operator ()(
double,
double,
double = 0,
double = 0)
const;
689 virtual double EvaluateInside(
double,
double,
double = 0,
double = 0)
const;
692 virtual double EvaluateOutside(
double,
double,
double = 0,
double = 0)
const;
717 virtual void EvaluateInside(
double *,
double,
double,
double = 0,
int = 1)
const;
720 virtual void EvaluateOutside(
double *,
double,
double,
double = 0,
int = 1)
const;
775 #define mirtkInterpolatorMacro(clsname, mode) \ 776 mirtkObjectMacro(clsname); \ 779 inline virtual enum InterpolationMode InterpolationMode() const \ 782 inline static enum InterpolationMode InterpolationType() \ 787 #define mirtkGenericInterpolatorTypes(superclsname) \ 789 typedef superclsname<TImage> Superclass; \ 790 typedef typename Superclass::ImageType ImageType; \ 791 typedef typename Superclass::VoxelType VoxelType; \ 792 typedef typename Superclass::RealType RealType; \ 793 typedef typename Superclass::Real Real; \ 794 typedef typename Superclass::ExtrapolatorType ExtrapolatorType; \ 798 #define mirtkGenericInterpolatorMacro(clsname, mode) \ 799 mirtkInterpolatorMacro(clsname, mode); \ 800 mirtkGenericInterpolatorTypes(GenericInterpolateImageFunction); \ 814 this->_Input =
const_cast<BaseImage *
>(input);
868 return this->_Input->Attributes();
874 return this->_Input->X();
880 return this->_Input->Y();
886 return this->_Input->Z();
892 return this->_Input->T();
898 return this->_Input->XSize();
904 return this->_Input->YSize();
910 return this->_Input->ZSize();
916 return this->_Input->TSize();
922 this->_Input->WorldToImage(x, y);
928 this->_Input->WorldToImage(x, y, z);
934 this->_Input->WorldToImage(p);
940 this->_Input->WorldToImage(v);
946 this->_Input->ImageToWorld(x, y);
952 this->_Input->ImageToWorld(x, y, z);
958 this->_Input->ImageToWorld(p);
964 this->_Input->ImageToWorld(v);
973 double &x2,
double &y2)
const 981 double &x2,
double &y2,
double &z2)
const 983 x1 =
_x1, y1 = _y1, z1 = _z1;
984 x2 = _x2, y2 = _y2, z2 = _z2;
989 double &x2,
double &y2,
double &z2,
double &t2)
const 991 x1 =
_x1, y1 = _y1, z1 = _z1, t1 = _t1;
992 x2 = _x2, y2 = _y2, z2 = _z2, t2 = _t2;
998 int &i2,
int &j2)
const 1006 int &i1,
int &j1,
int &k1,
1007 int &i2,
int &j2,
int &k2)
const 1009 if (this->NumberOfDimensions() >= 3) {
1022 int &i1,
int &j1,
int &k1,
int &l1,
1023 int &i2,
int &j2,
int &k2,
int &l2)
const 1025 if (this->NumberOfDimensions() >= 4) {
1030 }
else if (this->NumberOfDimensions() == 3) {
1046 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2);
1052 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2) && (_z1 <= z && z <= _z2);
1058 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2) && (_z1 <= z && z <= _z2) && (_t1 <= t && t <= _t2);
1114 int i1, j1, k1, i2, j2, k2;
1122 int i1, j1, k1, l1, i2, j2, k2, l2;
1123 BoundingBox(x, y, z, t, i1, j1, k1, l1, i2, j2, k2, l2);
1172 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1180 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1201 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1209 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1236 template <
class TVoxel>
1242 ParallelForEachVoxel(output.
Attributes(), output, eval);
1244 }
else if (output.
N() == 1) {
1246 ParallelForEachVoxel(output.
Attributes(), output, eval);
1250 ParallelForEachVoxel(output.
Attributes(), output, eval);
1262 Throw(ERR_NotImplemented, __FUNCTION__,
"Not implemented");
1269 Throw(ERR_NotImplemented, __FUNCTION__,
"Not implemented");
1284 Throw(ERR_NotImplemented, __FUNCTION__,
"Not implemented");
1291 Throw(ERR_NotImplemented, __FUNCTION__,
"Not implemented");
1311 template <
class TImage>
1314 return reinterpret_cast<const TImage *
>(this->_Input);
1318 template <
class TImage>
1326 template <
class TImage>
1338 template <
class TImage>
1339 inline typename TImage::VoxelType
1341 ::Get(
double x,
double y,
double z,
double t)
const 1343 if (
IsInside(x, y, z, t))
return this->GetInside (x, y, z, t);
1344 else return this->GetOutside(x, y, z, t);
1348 template <
class TImage>
1349 inline typename TImage::VoxelType
1353 if (
IsInside(x, y, z, t))
return this->GetWithPaddingInside (x, y, z, t);
1354 else return this->GetWithPaddingOutside(x, y, z, t);
1358 template <
class TImage>
1362 return this->
Get(x, y, z, t);
1366 template <
class TImage>
1370 return voxel_cast<
double>(this->GetInside(x, y, z, t));
1374 template <
class TImage>
1378 return voxel_cast<
double>(this->GetOutside(x, y, z, t));
1382 template <
class TImage>
1386 return voxel_cast<
double>(this->GetWithPaddingInside(x, y, z, t));
1390 template <
class TImage>
1394 return voxel_cast<
double>(this->GetWithPaddingOutside(x, y, z, t));
1398 template <
class TImage>
1402 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1403 (*v) = voxel_cast<
double>(this->GetInside(x, y, z, static_cast<double>(t)));
1408 template <
class TImage>
1412 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1413 (*v) = voxel_cast<
double>(this->GetOutside(x, y, z, static_cast<double>(t)));
1418 template <
class TImage>
1422 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1423 (*v) = voxel_cast<
double>(this->GetWithPaddingInside(x, y, z, static_cast<double>(t)));
1428 template <
class TImage>
1432 for (
int t = 0; t <
Input()->
T(); ++t, v += vt) {
1433 (*v) = voxel_cast<
double>(this->GetWithPaddingOutside(x, y, z, static_cast<double>(t)));
1438 template <
class TImage>
1442 v = voxel_cast<
Vector>(this->GetInside(x, y, z, t));
1446 template <
class TImage>
1450 v = voxel_cast<
Vector>(this->GetOutside(x, y, z, t));
1454 template <
class TImage>
1458 v = voxel_cast<
Vector>(this->GetWithPaddingInside(x, y, z, t));
1462 template <
class TImage>
1466 v = voxel_cast<
Vector>(this->GetWithPaddingOutside(x, y, z, t));
1472 #endif // MIRTK_InterpolateImageFunction_H virtual void BoundingInterval(double, int &, int &) const =0
void WorldToImage(double &, double &) const
Convert world coordinates (in mm) to image location (in pixels)
bool IsBoundingBoxInsideForeground(int, int, int, int) const
Whether all voxels within a 2D bounding region are inside foreground region.
void EvaluateJacobian(Matrix &, double, double, double=0, double=NaN) const
virtual ~InterpolateImageFunction()
Destructor.
const ImageAttributes & Attributes() const
Gets the image attributes.
MIRTKCU_API bool IsZero(double a, double tol=1e-12)
Determine equality of a floating point number with zero.
string Get(const ParameterList ¶ms, string name)
Get parameter value from parameters list.
enum ExtrapolationMode ExtrapolationMode() const
Get extrapolation mode used by this interpolator.
const ImageType * Input() const
Get input image.
ExtrapolateImageFunction * _InfiniteInput
bool _InfiniteInputOwner
Whether infinite discrete image was instantiated by this image function.
virtual void Initialize()
double _x
x coordinate of Point
int X() const
Image size along x axis.
virtual void BoundingBox(double, double, int &, int &, int &, int &) const
Returns discrete boundaries of local 2D image region needed for interpolation.
int Z() const
Image size along z axis.
const ImageAttributes & Attributes() const
Lattice attributes.
double Evaluate(double, double, double=0, double=0) const
VoxelType GetWithPadding(double, double, double=0, double=0) const
int T() const
Image size along t axis.
int Y() const
Image size along y axis.
virtual enum InterpolationMode InterpolationMode() const =0
Get interpolation mode corresponding to this interpolator.
double TSize() const
Image spacing along t axis.
Interpolate scalar or vector image.
virtual double EvaluateInside(double, double, double=0, double=0) const =0
InterpolationMode
Image interpolation modes.
int N() const
Number of vector components per voxel.
bool IsInside(double, double) const
virtual void EvaluateJacobianWithPaddingOutside(Matrix &, double, double, double=0, double=NaN) const
VoxelType operator()(double, double, double=0, double=0) const
Evaluate generic image at an arbitrary location (in pixels)
virtual double EvaluateWithPaddingInside(double, double, double=0, double=0) const
void EvaluateJacobianWithPadding(Matrix &, double, double, double=0, double=NaN) const
virtual void EvaluateJacobianWithPaddingInside(Matrix &, double, double, double=0, double=NaN) const
double ZSize() const
Image spacing along z axis.
virtual double EvaluateWithPaddingOutside(double, double, double=0, double=0) const
virtual void EvaluateJacobianInside(Matrix &, double, double, double=0, double=NaN) const
void Inside(double &, double &, double &, double &) const
double YSize() const
Image spacing along y axis.
virtual double EvaluateOutside(double, double, double=0, double=0) const
Evaluate scalar image at an arbitrary location (in pixels)
bool IsOutside(double, double) const
virtual double EvaluateWithPaddingInside(double, double, double=0, double=0) const =0
InterpolateImageFunction()
Default constructor.
virtual void EvaluateJacobianOutside(Matrix &, double, double, double=0, double=NaN) const
ExtrapolationMode
Image extrapolation modes.
virtual double EvaluateWithPaddingOutside(double, double, double=0, double=0) const =0
void Throw(ErrorType err, const char *func, Args... args) const
virtual double EvaluateInside(double, double, double=0, double=0) const
double TSize() const
Returns the size of a voxel in the t-direction.
Interpolate scalar image.
ExtrapolateImageFunction * Extrapolator()
int T() const
Returns the number of voxels in the t-direction.
VoxelType Get(double, double, double=0, double=0) const
bool IsForeground(double, double) const
static InterpolateImageFunction * New(enum InterpolationMode=Interpolation_Default, const BaseImage *=NULL)
Construct interpolator with default infinite extension of input image.
double XSize() const
Image spacing along x axis.
ExtrapolatorType * Extrapolator()
double _z
z coordinate of Point
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
void ImageToWorld(double &, double &) const
Convert image location (in pixels) to world coordinates (in mm)
double _y
y coordinate of Point
Interpolate multi-channel image (3D+c)
const BaseImage * Input() const
Get input image.
virtual double EvaluateOutside(double, double, double=0, double=0) const =0
Evaluate scalar image at an arbitrary location (in pixels)
double EvaluateWithPadding(double, double, double=0, double=0) const