20 #ifndef MIRTK_ImageGradientFunction_H 21 #define MIRTK_ImageGradientFunction_H 23 #include "mirtk/Object.h" 24 #include "mirtk/Matrix.h" 25 #include "mirtk/Vector3D.h" 26 #include "mirtk/BaseImage.h" 27 #include "mirtk/InterpolationMode.h" 28 #include "mirtk/ExtrapolationMode.h" 29 #include "mirtk/ExtrapolateImageFunction.h" 62 mirtkPublicAttributeMacro(
bool, WrtWorld);
65 mirtkPublicAttributeMacro(
double, DefaultValue);
71 mirtkPublicAttributeMacro(
int, NumberOfDimensions);
96 double _x1, _y1, _z1, _t1, _x2, _y2, _z2, _t2;
180 void Inside(
double &,
double &,
181 double &,
double &)
const;
185 void Inside(
double &,
double &,
double &,
186 double &,
double &,
double &)
const;
190 void Inside(
double &,
double &,
double &,
double &,
191 double &,
double &,
double &,
double &)
const;
198 virtual void BoundingBox(
double,
double,
int &,
int &,
202 virtual void BoundingBox(
double,
double,
double,
int &,
int &,
int &,
203 int &,
int &,
int &)
const;
206 virtual void BoundingBox(
double,
double,
double,
double,
207 int &,
int &,
int &,
int &,
208 int &,
int &,
int &,
int &)
const;
212 bool IsInside(
double,
double)
const;
216 bool IsInside(
double,
double,
double)
const;
220 bool IsInside(
double,
double,
double,
double)
const;
228 bool IsOutside(
double,
double,
double)
const;
232 bool IsOutside(
double,
double,
double,
double)
const;
244 bool IsForeground(
double,
double,
double,
double)
const;
254 virtual GradientType
GetInside(
double,
double,
double = 0,
double = 0)
const = 0;
257 virtual GradientType
GetOutside(
double,
double,
double = 0,
double = 0)
const = 0;
266 GradientType
Get(
double,
double,
double = 0,
double = 0)
const;
291 GradientType
GetWithPadding(
double,
double,
double = 0,
double = 0)
const;
294 GradientType
operator ()(
double,
double,
double = 0,
double = 0)
const;
310 virtual void EvaluateInside(
double *,
double,
double,
double = 0,
int = 1)
const;
316 virtual void EvaluateOutside(
double *,
double,
double,
double = 0,
int = 1)
const;
328 void Evaluate(
double *,
double,
double,
double = 0,
int = 1)
const;
390 template <
class TImage>
400 typedef TImage ImageType;
401 typedef typename ImageType::VoxelType VoxelType;
402 typedef GradientType::ComponentType Real;
420 const TImage * = NULL);
433 const TImage * = NULL);
442 const ImageType *
Input()
const;
469 #define mirtkGradientInterpolatorMacro(clsname, mode) \ 470 mirtkObjectMacro(clsname); \ 473 inline virtual enum InterpolationMode InterpolationMode() const \ 476 inline static enum InterpolationMode InterpolationType() \ 481 #define mirtkGenericGradientInterpolatorTypes(superclsname) \ 483 typedef superclsname<TImage> Superclass; \ 484 typedef typename Superclass::ImageType ImageType; \ 485 typedef typename Superclass::VoxelType VoxelType; \ 486 typedef typename Superclass::Real Real; \ 487 typedef typename Superclass::ExtrapolatorType ExtrapolatorType; \ 488 typedef typename Superclass::GradientType GradientType; \ 492 #define mirtkGenericGradientInterpolatorMacro(clsname, mode) \ 493 mirtkGradientInterpolatorMacro(clsname, mode); \ 494 mirtkGenericGradientInterpolatorTypes(GenericImageGradientFunction); \ 587 double &x2,
double &y2)
const 595 double &x2,
double &y2,
double &z2)
const 597 x1 =
_x1, y1 = _y1, z1 = _z1;
598 x2 = _x2, y2 = _y2, z2 = _z2;
603 double &x2,
double &y2,
double &z2,
double &t2)
const 605 x1 =
_x1, y1 = _y1, z1 = _z1, t1 = _t1;
606 x2 = _x2, y2 = _y2, z2 = _z2, t2 = _t2;
612 int &i2,
int &j2)
const 620 int &i1,
int &j1,
int &k1,
621 int &i2,
int &j2,
int &k2)
const 623 if (this->NumberOfDimensions() >= 3) {
636 int &i1,
int &j1,
int &k1,
int &l1,
637 int &i2,
int &j2,
int &k2,
int &l2)
const 639 if (this->NumberOfDimensions() >= 4) {
644 }
else if (this->NumberOfDimensions() == 3) {
660 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2);
666 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2) && (_z1 <= z && z <= _z2);
672 return (
_x1 <= x && x <= _x2) && (_y1 <= y && y <= _y2) && (_z1 <= z && z <= _z2) && (_t1 <= t && t <= _t2);
704 int i1, j1, k1, i2, j2, k2;
712 int i1, j1, k1, l1, i2, j2, k2, l2;
713 BoundingBox(x, y, z, t, i1, j1, k1, l1, i2, j2, k2, l2);
741 return this->
Get(x, y, z, t);
767 ::Evaluate(
double *v,
double x,
double y,
double z,
int vt)
const 807 template <
class TImage>
810 return reinterpret_cast<const TImage *
>(this->
_Input);
814 template <
class TImage>
822 template <
class TImage>
832 #endif // MIRTK_ImageGradientFunction_H bool IsOutside(double, double) const
virtual void EvaluateOutside(double *, double, double, double=0, int=1) const
bool IsBoundingBoxInsideForeground(int, int, int, int) const
Whether all voxels within a 2D bounding region are inside foreground region.
const ImageType * Input() const
Get input image.
GradientType operator()(double, double, double=0, double=0) const
Evaluate image gradient at an arbitrary location (in pixels)
virtual ~ImageGradientFunction()
Destructor.
ExtrapolatorType * Extrapolator()
GradientType _VoxelSize
Image resolution.
void WorldToImage(double &, double &) const
World to image coordinate conversion with two doubles.
virtual enum InterpolationMode InterpolationMode() const =0
Get interpolation mode corresponding to this image gradient function.
GradientType GetWithPadding(double, double, double=0, double=0) const
virtual void EvaluateWithPaddingOutside(double *, double, double, double=0, int=1) const
bool _InfiniteInputOwner
Whether infinite discrete image was instantiated by this image function.
virtual void BoundingInterval(double, int &, int &) const =0
void EvaluateWithPadding(double *, double, double, double=0, int=1) const
virtual GradientType GetInside(double, double, double=0, double=0) const =0
ExtrapolateImageFunction * Extrapolator()
virtual void BoundingBox(double, double, int &, int &, int &, int &) const
Returns discrete boundaries of local 2D image region needed for interpolation.
InterpolationMode
Image interpolation modes.
static ImageGradientFunction * New(enum InterpolationMode, const BaseImage *=NULL)
Construct image gradient function with default infinite extension of input image. ...
double GetTOrigin() const
Get temporal origin of input image.
void Evaluate(double *, double, double, double=0, int=1) const
bool IsInside(double, double) const
double GetTOrigin() const
Get temporal origin.
enum ExtrapolationMode ExtrapolationMode() const
Get extrapolation mode used by this interpolator.
virtual GradientType GetWithPaddingInside(double, double, double=0, double=0) const =0
ImageGradientFunction()
Default constructor.
virtual void EvaluateWithPaddingInside(double *, double, double, double=0, int=1) const
void Inside(double &, double &, double &, double &) const
ExtrapolateImageFunction * _InfiniteInput
ExtrapolationMode
Image extrapolation modes.
void ImageGradientToWorld(GradientType &) const
Orient and scale image gradient by world to image matrix.
virtual void Initialize(bool coeff=false)
static int Rows()
Number of vector components.
const BaseImage * Input() const
Get input image.
bool IsForeground(double, double) const
virtual void EvaluateInside(double *, double, double, double=0, int=1) const
virtual GradientType GetOutside(double, double, double=0, double=0) const =0
Evaluate generic image gradient at an arbitrary location (in pixels)
virtual GradientType GetWithPaddingOutside(double, double, double=0, double=0) const =0
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
GradientType Get(double, double, double=0, double=0) const
Matrix _Orientation
Image orientation matrix.
BaseImage * _Input
Input image for filter.
void WorldToImage(double &, double &) const
Convert world coordinates to image location (in pixels)
Vector3D< double > GradientType
Type of interpolated gradient vectors.