20 #ifndef MIRTK_ExtrapolateImageFunction_H 21 #define MIRTK_ExtrapolateImageFunction_H 23 #include "mirtk/ExtrapolationMode.h" 24 #include "mirtk/Vector.h" 25 #include "mirtk/VoxelCast.h" 26 #include "mirtk/BaseImage.h" 27 #include "mirtk/ImageFunction.h" 99 virtual bool IsForeground(
int,
int,
int = 0,
int = 0)
const;
105 double Evaluate(
double,
double,
double = 0,
double = 0)
const;
108 virtual double Evaluate(
double,
double,
double = 0,
double = 0);
117 virtual double GetAsDouble(
int,
int,
int = 0,
int = 0)
const = 0;
149 template <
class TImage>
178 const TImage * = NULL);
187 const ImageType *Input()
const;
196 VoxelType
Get(
int)
const;
199 virtual VoxelType
Get(
int,
int,
int = 0,
int = 0)
const = 0;
202 VoxelType operator ()(
int)
const;
205 VoxelType operator ()(
int,
int,
int = 0,
int = 0)
const;
212 double GetAsDouble(
int,
int,
int = 0,
int = 0)
const;
240 template <
class TImage>
291 virtual void TransformIndex(
int &idx,
int max)
const = 0;
294 void TransformX(
int &)
const;
297 void TransformY(
int &)
const;
300 void TransformZ(
int &)
const;
303 virtual void TransformT(
int &l)
const;
306 void TransformX(
int &,
int)
const;
309 void TransformY(
int &,
int)
const;
312 void TransformZ(
int &,
int)
const;
315 virtual void TransformT(
int &l,
int c)
const;
321 void Transform(
int &,
int &,
int &)
const;
324 void Transform(
int &,
int &,
int &,
int &)
const;
330 virtual bool IsForeground(
int,
int,
int = 0,
int = 0)
const;
336 virtual VoxelType
Get(
int,
int,
int = 0,
int = 0)
const;
345 #define mirtkExtrapolatorMacro(clsname, mode) \ 346 mirtkObjectMacro(clsname); \ 349 inline virtual enum ExtrapolationMode ExtrapolationMode() const \ 352 inline static enum ExtrapolationMode ExtrapolationType() \ 357 #define mirtkGenericExtrapolatorMacro(clsname, mode) \ 358 mirtkExtrapolatorMacro(clsname, mode); \ 361 typedef TImage ImageType; \ 363 typedef typename ImageType::VoxelType VoxelType; \ 365 typedef typename ImageType::RealType RealType; \ 367 using GenericExtrapolateImageFunction<TImage>::Get; \ 377 return Input()->Attributes();
413 return Input()->XSize();
419 return Input()->YSize();
425 return Input()->ZSize();
431 return Input()->TSize();
438 return this->
GetAsDouble(static_cast<int>(round(x)),
439 static_cast<int>(round(y)),
440 static_cast<int>(round(z)),
441 static_cast<int>(round(t)));
455 return this->_DefaultValue;
462 Input()->IndexToVoxel(idx, i, j, k, l);
471 v =
Vector(
N(), this->_DefaultValue);
486 Input()->IndexToVoxel(idx, i, j, k, l);
501 if (!this->Input()->HasBackgroundValue())
return true;
502 const double value = this->
GetAsDouble(i, j, k, l);
503 const double bg = this->Input()->GetBackgroundValueAsDouble();
504 return (value != bg && (!
IsNaN(value) || !
IsNaN(bg)));
512 template <
class TImage>
519 template <
class TImage>
526 template <
class TImage>
530 ExtrapolateImageFunction::Input(dynamic_cast<const ImageType *>(input));
531 if (input && !this->_Input) {
532 cerr << this->
NameOfClass() <<
"::Input: Invalid input image type" << endl;
538 template <
class TImage>
541 return reinterpret_cast<const TImage *
>(this->_Input);
545 template <
class TImage>
552 if (!dynamic_cast<const ImageType *>(this->_Input)) {
553 cerr << this->
NameOfClass() <<
"::Initialize: Invalid input image type" << endl;
559 template <
class TImage>
564 return voxel_cast<
VoxelType>(this->_DefaultValue);
568 template <
class TImage>
573 Input()->IndexToVoxel(idx, i, j, k, l);
574 return this->
Get(i, j, k, l);
578 template <
class TImage>
582 return this->
Get(idx);
586 template <
class TImage>
591 return this->
Get(i, j, k, l);
595 template <
class TImage>
599 return voxel_cast<
double>(this->
Get(i, j, k, l));
603 template <
class TImage>
607 v = voxel_cast<
Vector>(this->
Get(i, j, k, l));
615 template <
class TImage>
618 _xmax(0), _ymax(0), _zmax(0), _tmax(0)
623 template <
class TImage>
629 template <
class TImage>
635 _xmax = this->X() - 1;
636 _ymax = this->Y() - 1;
637 _zmax = this->Z() - 1;
638 _tmax = this->T() - 1;
642 template <
class TImage>
645 this->TransformIndex(i, _xmax);
649 template <
class TImage>
652 this->TransformIndex(j, _ymax);
656 template <
class TImage>
659 this->TransformIndex(k, _zmax);
663 template <
class TImage>
666 this->TransformIndex(l, _tmax);
670 template <
class TImage>
674 this->TransformIndex(i, _xmax);
678 template <
class TImage>
682 this->TransformIndex(j, _ymax);
686 template <
class TImage>
690 this->TransformIndex(k, _zmax);
694 template <
class TImage>
698 this->TransformIndex(l, _tmax);
702 template <
class TImage>
710 template <
class TImage>
719 template <
class TImage>
729 template <
class TImage>
734 return this->Input()->IsForeground(i, j, k, l);
738 template <
class TImage>
743 return this->Input()->Get(i, j, k, l);
753 #include "mirtk/ConstExtrapolateImageFunction.h" 754 #include "mirtk/ConstExtrapolateImageFunctionWithPeriodicTime.h" 755 #include "mirtk/NearestNeighborExtrapolateImageFunction.h" 756 #include "mirtk/RepeatExtrapolateImageFunction.h" 757 #include "mirtk/MirrorExtrapolateImageFunction.h" 767 template <
class TImage>
774 case Extrapolation_None: { p = NULL;
break; }
779 case Extrapolation_ConstWithPeriodicTime:
783 cerr <<
"GenericExtrapolateImageFunction::New: Unknown extrapolation mode: " << mode << endl;
786 if (p) p->
Input(image);
793 #endif // MIRTK_ExtrapolateImageFunction_H
string Get(const ParameterList ¶ms, string name)
Get parameter value from parameters list.
virtual void Initialize()
MIRTKCU_API bool IsNaN(double x)
Check if floating point value is not a number (NaN)
ExtrapolationMode
Image extrapolation modes.
virtual const char * NameOfClass() const =0
Get name of class, which this object is an instance of.
void Transform(Array< T > &values, UnaryOperation op)
Apply unary operation for each array element in-place.