36 #ifndef __itkLegendrePolynomialTransform_h
37 #define __itkLegendrePolynomialTransform_h
44 #include <itkTransform.h>
45 #include <itkExceptionObject.h>
50 #include <Core/ITKCommon/Transform/itkInverseTransform.h>
53 #include <vnl/algo/vnl_svd.h>
80 template <
class TScalar =
double,
unsigned int N = 2 >
82 public Transform<TScalar, 2, 2>
87 typedef SmartPointer<Self> Pointer;
88 typedef SmartPointer<const Self> ConstPointer;
90 typedef Transform<TScalar, 2, 2> Superclass;
95 typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
98 itkStaticConstMacro(Degree,
unsigned int, N);
101 itkStaticConstMacro(CoefficientsPerDimension,
103 ((N + 1) * (N + 2)) / 2);
106 itkStaticConstMacro(ParameterVectorLength,
120 itkStaticConstMacro(InputSpaceDimension,
unsigned int, 2);
121 itkStaticConstMacro(OutputSpaceDimension,
unsigned int, 2);
127 typedef typename Superclass::ParametersType ParametersType;
128 typedef typename Superclass::JacobianType JacobianType;
130 typedef typename Superclass::InputPointType InputPointType;
131 typedef typename Superclass::OutputPointType OutputPointType;
134 virtual OutputPointType TransformPoint(
const InputPointType & x)
const;
139 InputPointType BackTransformPoint(
const OutputPointType & y)
const;
142 virtual void SetFixedParameters(
const ParametersType & params)
143 { this->m_FixedParameters = params; }
146 virtual const ParametersType & GetFixedParameters()
const
147 {
return this->m_FixedParameters; }
150 virtual void SetParameters(
const ParametersType & params)
151 { this->m_Parameters = params; }
154 virtual const ParametersType & GetParameters()
const
155 {
return this->m_Parameters; }
158 virtual NumberOfParametersType GetNumberOfParameters()
const
159 {
return ParameterVectorLength; }
163 virtual void ComputeJacobianWithRespectToParameters(
const InputPointType &, JacobianType & )
const;
166 virtual InverseTransformBasePointer GetInverseTransform()
const
168 typedef InverseTransform<Self> InvTransformType;
169 typename InvTransformType::Pointer inv = InvTransformType::New();
170 inv->SetForwardTransform(
this);
171 return inv.GetPointer();
182 const double Xmax = 0.0,
183 const double Ymax = 0.0)
185 double & uc_ = this->m_FixedParameters[0];
186 double & vc_ = this->m_FixedParameters[1];
187 double & xmax_ = this->m_FixedParameters[2];
188 double & ymax_ = this->m_FixedParameters[3];
189 double & a00_ = this->m_Parameters[index_a(0, 0)];
190 double & b00_ = this->m_Parameters[index_b(0, 0)];
193 double xc = (x_min + x_max) / 2.0;
194 double yc = (y_min + y_max) / 2.0;
199 if (Xmax != 0.0 && Ymax != 0.0)
206 const double w = x_max - x_min;
207 const double h = y_max - y_min;
220 void setup_translation(
221 const double tx_Xmax = 0.0,
222 const double ty_Ymax = 0.0)
225 double & uc_ = this->m_FixedParameters[0];
226 double & vc_ = this->m_FixedParameters[1];
243 void eval(
const std::vector<ScalarType> & x,
244 std::vector<ScalarType> & F,
245 std::vector<std::vector<ScalarType> > & J)
const;
249 void setup_linear_system(
const unsigned int start_with_degree,
250 const unsigned int degrees_covered,
251 const std::vector<InputPointType> & uv,
252 const std::vector<OutputPointType> & xy,
253 vnl_matrix<double> & M,
254 vnl_vector<double> & bx,
255 vnl_vector<double> & by)
const;
259 void solve_for_parameters(
const unsigned int start_with_degree,
260 const unsigned int degrees_covered,
261 const std::vector<InputPointType> & uv,
262 const std::vector<OutputPointType> & xy,
263 ParametersType & params)
const;
265 inline void solve_for_parameters(
const unsigned int start_with_degree,
266 const unsigned int degrees_covered,
267 const std::vector<InputPointType> & uv,
268 const std::vector<OutputPointType> & xy)
270 ParametersType params = GetParameters();
271 solve_for_parameters(start_with_degree,
276 SetParameters(params);
281 inline static unsigned int
282 count_coefficients(
const unsigned int start_with_degree,
283 const unsigned int degrees_covered)
286 index_a(0, start_with_degree + degrees_covered) -
287 index_a(0, start_with_degree);
291 inline const double & GetUc()
const
292 {
return this->m_FixedParameters[0]; }
294 inline const double & GetVc()
const
295 {
return this->m_FixedParameters[1]; }
298 inline const double & GetXmax()
const
299 {
return this->m_FixedParameters[2]; }
301 inline const double & GetYmax()
const
302 {
return this->m_FixedParameters[3]; }
305 static void setup_shared_params_mask(
bool shared, std::vector<bool> & mask)
307 mask.assign(ParameterVectorLength, shared);
308 mask[index_a(0, 0)] =
false;
309 mask[index_b(0, 0)] =
false;
314 inline static unsigned int index_a(
const unsigned int & j,
315 const unsigned int & k)
316 {
return j + ((j + k) * (j + k + 1)) / 2; }
318 inline static unsigned int index_b(
const unsigned int & j,
319 const unsigned int & k)
320 {
return CoefficientsPerDimension + index_a(j, k); }
323 std::string GetTransformTypeAsString()
const
325 std::string base = Superclass::GetTransformTypeAsString();
326 std::ostringstream name;
327 name << base <<
'_' << N;
332 LegendrePolynomialTransform();
335 void PrintSelf(std::ostream & s, Indent indent)
const;
339 LegendrePolynomialTransform(
const Self & other);
340 const Self & operator = (
const Self & t);
343 inline const double & a(
const unsigned int & j,
344 const unsigned int & k)
const
345 {
return this->m_Parameters[index_a(j, k)]; }
347 inline const double & b(
const unsigned int & j,
348 const unsigned int & k)
const
349 {
return this->m_Parameters[index_b(j, k)]; }
356 #ifndef ITK_MANUAL_INSTANTIATION
357 #include <Core/ITKCommon/Transform/itkLegendrePolynomialTransform.txx>
364 template <
class transform_t>
365 typename transform_t::Pointer
366 setup_transform(
const itk::Point<double, 2> & bbox_min,
367 const itk::Point<double, 2> & bbox_max)
369 double w = bbox_max[0] - bbox_min[0];
370 double h = bbox_max[1] - bbox_min[1];
371 double Umax = w / 2.0;
372 double Vmax = h / 2.0;
374 typename transform_t::Pointer t = transform_t::New();
375 t->setup(bbox_min[0],
389 template <
class transform_t,
class image_t>
390 typename transform_t::Pointer
391 setup_transform(
const image_t * image)
393 typedef typename image_t::IndexType index_t;
399 typename image_t::PointType origin;
400 image->TransformIndexToPhysicalPoint(i00, origin);
406 typename image_t::PointType spacing;
407 image->TransformIndexToPhysicalPoint(i11, spacing);
408 spacing[0] -= origin[0];
409 spacing[1] -= origin[1];
411 typename image_t::SizeType sz =
412 image->GetLargestPossibleRegion().GetSize();
414 typename image_t::PointType bbox_min = origin;
415 typename image_t::PointType bbox_max;
416 bbox_max[0] = bbox_min[0] + spacing[0] * double(sz[0]);
417 bbox_max[1] = bbox_min[1] + spacing[1] * double(sz[1]);
419 return setup_transform<transform_t>(bbox_min, bbox_max);
423 #endif // __itkLegendrePolynomialTransform_h
Definition: itkNormalizeImageFilterWithMask.h:48