29 #ifndef __itkGridTransform_h
30 #define __itkGridTransform_h
37 #include <itkTransform.h>
38 #include <itkExceptionObject.h>
39 #include <itkIdentityTransform.h>
44 #include <Core/ITKCommon/Transform/itkDiscontinuousTransform.h>
58 typedef SmartPointer<Self> Pointer;
59 typedef SmartPointer<const Self> ConstPointer;
61 typedef Transform<double, 2, 2> Superclass;
66 typedef InverseTransformBaseType::Pointer InverseTransformBasePointer;
82 typedef Superclass::ParametersType ParametersType;
83 typedef Superclass::JacobianType JacobianType;
85 typedef Superclass::InputPointType InputPointType;
86 typedef Superclass::OutputPointType OutputPointType;
89 virtual OutputPointType TransformPoint(
const InputPointType & x)
const
95 uv[0] = (x[0] - transform_.tile_min_[0]) / transform_.tile_ext_[0];
96 uv[1] = (x[1] - transform_.tile_min_[1]) / transform_.tile_ext_[1];
97 transform_.transform_inv(uv, y);
101 transform_.transform(x, y);
102 y[0] *= transform_.tile_ext_[0];
103 y[1] *= transform_.tile_ext_[1];
104 y[0] += transform_.tile_min_[0];
105 y[1] += transform_.tile_min_[1];
111 y[0] = std::numeric_limits<double>::max();
121 InputPointType BackTransformPoint(
const OutputPointType & y)
const
126 transform_.transform(y, x);
127 x[0] *= transform_.tile_ext_[0];
128 x[1] *= transform_.tile_ext_[1];
129 x[0] += transform_.tile_min_[0];
130 x[1] += transform_.tile_min_[1];
135 uv[0] = (y[0] - transform_.tile_min_[0]) / transform_.tile_ext_[0];
136 uv[1] = (y[1] - transform_.tile_min_[1]) / transform_.tile_ext_[1];
137 transform_.transform_inv(uv, x);
143 x[0] = std::numeric_limits<double>::max();
151 virtual void SetFixedParameters(
const ParametersType & params)
152 { this->m_FixedParameters = params; }
155 virtual const ParametersType & GetFixedParameters()
const
157 ParametersType params = this->m_FixedParameters;
159 params[1] = transform_.rows_;
160 params[2] = transform_.cols_;
161 params[3] = transform_.tile_min_[0];
162 params[4] = transform_.tile_min_[1];
163 params[5] = transform_.tile_ext_[0];
164 params[6] = transform_.tile_ext_[1];
167 GridTransform * fake =
const_cast<GridTransform *
>(
this);
168 fake->m_FixedParameters = params;
169 return this->m_FixedParameters;
173 virtual void SetParameters(
const ParametersType & params)
175 this->m_Parameters = params;
177 size_t rows = int(this->m_FixedParameters[1]);
178 size_t cols = int(this->m_FixedParameters[2]);
181 tile_min[0] = this->m_FixedParameters[3];
182 tile_min[1] = this->m_FixedParameters[4];
185 tile_max[0] = tile_min[0] + this->m_FixedParameters[5];
186 tile_max[1] = tile_min[1] + this->m_FixedParameters[6];
188 std::vector<pnt2d_t> xy((rows + 1) * (cols + 1));
190 unsigned int num_points = xy.size();
192 if (2 * num_points != params.size())
194 itkExceptionMacro(<<
"xy size does not match number of parameters");
197 for (
unsigned int i = 0; i < num_points; i++)
199 xy[i][0] = params[i * 2];
200 xy[i][1] = params[i * 2 + 1];
203 transform_.setup(rows,
211 virtual const ParametersType & GetParameters()
const
213 ParametersType params(GetNumberOfParameters());
214 unsigned int num_pts = params.size() / 2;
215 unsigned int num_cols = (transform_.cols_ + 1);
216 for (
unsigned int i = 0; i < num_pts; i++)
218 unsigned int row = i / num_cols;
219 unsigned int col = i % num_cols;
221 const pnt2d_t & xy = transform_.vertex(row, col).xy_;
222 unsigned int idx = 2 * i;
224 params[idx + 1] = xy[1];
228 GridTransform * fake =
const_cast<GridTransform *
>(
this);
229 fake->m_Parameters = params;
230 return this->m_Parameters;
234 virtual NumberOfParametersType GetNumberOfParameters(
void)
const
235 {
return 2 * transform_.grid_.mesh_.size(); }
238 virtual InverseTransformBasePointer GetInverseTransform()
const
240 GridTransform::Pointer inv = GridTransform::New();
241 inv->setup(transform_, !is_inverse());
242 return inv.GetPointer();
247 const bool & is_inverse =
false)
249 transform_ = transform;
251 GetFixedParameters();
253 this->m_FixedParameters[0] = is_inverse ? 1.0 : 0.0;
257 inline bool is_inverse()
const
258 {
return this->m_FixedParameters[0] != 0.0; }
295 ComputeJacobianWithRespectToParameters(
const InputPointType &point, JacobianType &jacobian )
const
303 double Su = transform_.tile_ext_[0];
304 double Sv = transform_.tile_ext_[1];
308 jacobian.SetSize(2, GetNumberOfParameters());
310 if (transform_.jacobian(point, idx, jac))
312 for (
unsigned int i = 0; i < 3; i++)
314 unsigned int addr = idx[i] * 2;
315 jacobian(0, addr) = Su * jac[i * 2];
316 jacobian(0, addr + 1) = Su * jac[i * 2 + 1];
317 jacobian(1, addr) = Sv * jac[i * 2 + 6];
318 jacobian(1, addr + 1) = Sv * jac[i * 2 + 7];
328 this->m_FixedParameters.SetSize(7);
331 this->m_FixedParameters[0] = 0.0;
334 this->m_FixedParameters[1] = 0.0;
335 this->m_FixedParameters[2] = 0.0;
338 this->m_FixedParameters[3] = std::numeric_limits<double>::max();
339 this->m_FixedParameters[4] = this->m_FixedParameters[3];
340 this->m_FixedParameters[5] = -(this->m_FixedParameters[3]);
341 this->m_FixedParameters[6] = -(this->m_FixedParameters[3]);
346 GridTransform(
const Self & other);
347 const Self & operator = (
const Self & t);
358 #endif // __itkGridTransform_h
Definition: itkNormalizeImageFilterWithMask.h:48