20 #ifndef MIRTK_LinearImageGradientFunction_HXX 21 #define MIRTK_LinearImageGradientFunction_HXX 23 #include "mirtk/Math.h" 24 #include "mirtk/LinearImageGradientFunction.h" 25 #include "mirtk/ImageGradientFunction.hxx" 26 #include "mirtk/LinearInterpolateImageFunction.hxx" 37 template <
class TImage>
44 template <
class TImage>
51 template <
class TImage>
55 Superclass::Initialize(coeff);
58 switch (this->NumberOfDimensions()) {
61 this->_z2 =
fdec(this->Input()->Z() - 1.5);
64 this->_y2 =
fdec(this->Input()->Y() - 1.5);
66 this->_x2 =
fdec(this->Input()->X() - 1.5);
70 _ContinuousImage.Input(this->Input());
71 _ContinuousImage.Initialize(coeff);
79 template <
class TImage>
83 i =
ifloor(x - .5), I = i + 2;
91 template <
class TImage>
97 val.
_x = _ContinuousImage.GetInside(x + .5, y, z, t) -
98 _ContinuousImage.GetInside(x - .5, y, z, t);
99 val.
_y = _ContinuousImage.GetInside(x, y + .5, z, t) -
100 _ContinuousImage.GetInside(x, y - .5, z, t);
105 template <
class TImage>
113 a = _ContinuousImage.GetWithPaddingInside(x - .5, y, z, t);
114 if (a == _ContinuousImage.DefaultValue())
return this->DefaultValue();
115 b = _ContinuousImage.GetWithPaddingInside(x + .5, y, z, t);
116 if (b == _ContinuousImage.DefaultValue())
return this->DefaultValue();
119 a = _ContinuousImage.GetWithPaddingInside(x, y - .5, z, t);
120 if (a == _ContinuousImage.DefaultValue())
return this->DefaultValue();
121 b = _ContinuousImage.GetWithPaddingInside(x, y + .5, z, t);
122 if (b == _ContinuousImage.DefaultValue())
return this->DefaultValue();
129 template <
class TImage>
135 val.
_x = _ContinuousImage.GetInside(x + .5, y, z, t) -
136 _ContinuousImage.GetInside(x - .5, y, z, t);
137 val.
_y = _ContinuousImage.GetInside(x, y + .5, z, t) -
138 _ContinuousImage.GetInside(x, y - .5, z, t);
139 val.
_z = _ContinuousImage.GetInside(x, y, z + .5, t) -
140 _ContinuousImage.GetInside(x, y, z - .5, t);
145 template <
class TImage>
153 a = _ContinuousImage.GetWithPaddingInside(x - .5, y, z, t);
154 if (a == _ContinuousImage.DefaultValue())
return this->DefaultValue();
155 b = _ContinuousImage.GetWithPaddingInside(x + .5, y, z, t);
156 if (b == _ContinuousImage.DefaultValue())
return this->DefaultValue();
159 a = _ContinuousImage.GetWithPaddingInside(x, y - .5, z, t);
160 if (a == _ContinuousImage.DefaultValue())
return this->DefaultValue();
161 b = _ContinuousImage.GetWithPaddingInside(x, y + .5, z, t);
162 if (b == _ContinuousImage.DefaultValue())
return this->DefaultValue();
165 a = _ContinuousImage.GetWithPaddingInside(x, y, z - .5, t);
166 if (a == _ContinuousImage.DefaultValue())
return this->DefaultValue();
167 b = _ContinuousImage.GetWithPaddingInside(x, y, z + .5, t);
168 if (b == _ContinuousImage.DefaultValue())
return this->DefaultValue();
175 template <
class TImage>
180 switch (this->NumberOfDimensions()) {
181 case 2:
return GetInside2D(x, y, z, t);
182 default:
return GetInside3D(x, y, z, t);
187 template <
class TImage>
192 return this->DefaultValue();
196 template <
class TImage>
201 switch (this->NumberOfDimensions()) {
202 case 2:
return GetWithPaddingInside2D(x, y, z, t);
203 default:
return GetWithPaddingInside3D(x, y, z, t);
208 template <
class TImage>
213 return this->DefaultValue();
219 #endif // MIRTK_LinearImageGradientFunction_HXX GradientType GetInside3D(double, double, double=0, double=0) const
Get gradient of given 3D image without handling boundary conditions.
virtual GradientType GetWithPaddingInside(double, double, double=0, double=0) const
Evaluate generic image gradient without handling boundary conditions.
virtual ~GenericLinearImageGradientFunction()
Destructor.
GenericLinearImageGradientFunction()
Default constructor.
MIRTKCU_API int ifloor(T x)
Round floating-point value to next smaller integer and cast to int.
virtual GradientType GetInside(double, double, double=0, double=0) const
MIRTKCU_API double fdec(double f)
virtual void Initialize(bool=false)
Initialize interpolation function.
virtual GradientType GetOutside(double, double, double=0, double=0) const
GradientType GetWithPaddingInside2D(double, double, double=0, double=0) const
virtual void BoundingInterval(double, int &, int &) const
virtual GradientType GetWithPaddingOutside(double, double, double=0, double=0) const
GradientType GetWithPaddingInside3D(double, double, double=0, double=0) const
GradientType GetInside2D(double, double, double=0, double=0) const
Get gradient of given 2D image without handling boundary conditions.