40 #ifndef __itkMeshTransform_h
41 #define __itkMeshTransform_h
48 #include <itkTransform.h>
49 #include <itkExceptionObject.h>
50 #include <itkIdentityTransform.h>
55 #include <Core/ITKCommon/Transform/itkDiscontinuousTransform.h>
69 typedef SmartPointer<Self> Pointer;
70 typedef SmartPointer<const Self> ConstPointer;
72 typedef Transform<double, 2, 2> Superclass;
77 typedef InverseTransformBaseType::Pointer InverseTransformBasePointer;
93 typedef Superclass::ParametersType ParametersType;
94 typedef Superclass::JacobianType JacobianType;
96 typedef Superclass::InputPointType InputPointType;
97 typedef Superclass::OutputPointType OutputPointType;
100 virtual OutputPointType TransformPoint(
const InputPointType & x)
const
103 if ( transform_.grid_.cols_ == 0 || transform_.grid_.cols_ == 0 )
109 else if (is_inverse())
112 uv[0] = (x[0] - transform_.tile_min_[0]) / transform_.tile_ext_[0];
113 uv[1] = (x[1] - transform_.tile_min_[1]) / transform_.tile_ext_[1];
114 transform_.transform_inv(uv, y);
118 transform_.transform(x, y);
119 y[0] *= transform_.tile_ext_[0];
120 y[1] *= transform_.tile_ext_[1];
121 y[0] += transform_.tile_min_[0];
122 y[1] += transform_.tile_min_[1];
128 y[0] = std::numeric_limits<double>::max();
138 InputPointType BackTransformPoint(
const OutputPointType & y)
const
143 transform_.transform(y, x);
144 x[0] *= transform_.tile_ext_[0];
145 x[1] *= transform_.tile_ext_[1];
146 x[0] += transform_.tile_min_[0];
147 x[1] += transform_.tile_min_[1];
152 uv[0] = (y[0] - transform_.tile_min_[0]) / transform_.tile_ext_[0];
153 uv[1] = (y[1] - transform_.tile_min_[1]) / transform_.tile_ext_[1];
154 transform_.transform_inv(uv, x);
160 x[0] = std::numeric_limits<double>::max();
168 virtual void SetFixedParameters(
const ParametersType & params)
169 { this->m_FixedParameters = params; }
172 const ParametersType & GetFixedParameters()
const
174 ParametersType params = this->m_FixedParameters;
177 params[1] = transform_.grid_.rows_;
178 params[2] = transform_.grid_.cols_;
181 params[3] = transform_.tile_min_[0];
182 params[4] = transform_.tile_min_[1];
183 params[5] = transform_.tile_ext_[0];
184 params[6] = transform_.tile_ext_[1];
187 params[7] = transform_.grid_.mesh_.size();
190 MeshTransform * fake =
const_cast<MeshTransform *
>(
this);
191 fake->m_FixedParameters = params;
192 return this->m_FixedParameters;
196 virtual void SetParameters(
const ParametersType & params)
198 this->m_Parameters = params;
200 std::size_t accel_grid_rows = std::size_t(this->m_FixedParameters[1]);
201 std::size_t accel_grid_cols = std::size_t(this->m_FixedParameters[2]);
204 tile_min[0] = this->m_FixedParameters[3];
205 tile_min[1] = this->m_FixedParameters[4];
208 tile_max[0] = tile_min[0] + this->m_FixedParameters[5];
209 tile_max[1] = tile_min[1] + this->m_FixedParameters[6];
211 const std::size_t num_points = std::size_t(this->m_FixedParameters[7]);
212 std::vector<pnt2d_t> uv(num_points);
213 std::vector<pnt2d_t> xy(num_points);
215 for (
unsigned int i = 0; i < num_points; i++)
217 const std::size_t idx = i * 4;
219 uv[i][0] = params[idx + 0];
220 uv[i][1] = params[idx + 1];
221 xy[i][0] = params[idx + 2];
222 xy[i][1] = params[idx + 3];
225 transform_.setup(tile_min,
234 virtual const ParametersType & GetParameters()
const
236 ParametersType params(GetNumberOfParameters());
238 const std::size_t num_points = transform_.grid_.mesh_.size();
239 for (std::size_t i = 0; i < num_points; i++)
241 const vertex_t & vx = transform_.grid_.mesh_[i];
242 const std::size_t idx = i * 4;
244 params[idx + 0] = vx.uv_[0];
245 params[idx + 1] = vx.uv_[1];
246 params[idx + 2] = vx.xy_[0];
247 params[idx + 3] = vx.xy_[1];
251 MeshTransform * fake =
const_cast<MeshTransform *
>(
this);
252 fake->m_Parameters = params;
253 return this->m_Parameters;
257 virtual NumberOfParametersType GetNumberOfParameters(
void)
const
258 {
return 4 * transform_.grid_.mesh_.size(); }
261 virtual InverseTransformBasePointer GetInverseTransform()
const
263 MeshTransform::Pointer inv = MeshTransform::New();
264 inv->setup(transform_, !is_inverse());
265 return inv.GetPointer();
270 const bool & is_inverse =
false)
272 transform_ = transform;
274 GetFixedParameters();
276 this->m_FixedParameters[0] = is_inverse ? 1.0 : 0.0;
280 inline bool is_inverse()
const
281 {
return this->m_FixedParameters[0] != 0.0; }
318 ComputeJacobianWithRespectToParameters(
const InputPointType &point, JacobianType &jacobian )
const
326 double Su = transform_.tile_ext_[0];
327 double Sv = transform_.tile_ext_[1];
331 jacobian.SetSize(2, GetNumberOfParameters());
333 if (transform_.jacobian(point, idx, jac))
335 for (
unsigned int i = 0; i < 3; i++)
337 unsigned int addr = idx[i] * 2;
338 jacobian(0, addr) = Su * jac[i * 2];
339 jacobian(0, addr + 1) = Su * jac[i * 2 + 1];
340 jacobian(1, addr) = Sv * jac[i * 2 + 6];
341 jacobian(1, addr + 1) = Sv * jac[i * 2 + 7];
351 this->m_FixedParameters.SetSize(8);
354 this->m_FixedParameters[0] = 0.0;
357 this->m_FixedParameters[1] = 0.0;
358 this->m_FixedParameters[2] = 0.0;
361 this->m_FixedParameters[3] = std::numeric_limits<double>::max();
362 this->m_FixedParameters[4] = this->m_FixedParameters[3];
363 this->m_FixedParameters[5] = -(this->m_FixedParameters[3]);
364 this->m_FixedParameters[6] = -(this->m_FixedParameters[3]);
367 this->m_FixedParameters[7] = 0.0;
372 MeshTransform(
const Self & other);
373 const Self & operator = (
const Self & t);
384 #endif // __itkMeshTransform_h
Definition: itkNormalizeImageFilterWithMask.h:48
Definition: itkDiscontinuousTransform.h:56