ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkAffineTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkAffineTransform_h
19 #define itkAffineTransform_h
20 
22 #include <iostream>
23 
24 
25 namespace itk
26 {
98 
99 template<
100  typename TParametersValueType = double,
101  unsigned int NDimensions = 3 >
102 // Number of dimensions in the input space
103 class ITK_TEMPLATE_EXPORT AffineTransform:
104  public MatrixOffsetTransformBase< TParametersValueType, NDimensions, NDimensions>
105 {
106 public:
109  typedef MatrixOffsetTransformBase< TParametersValueType,
110  NDimensions,
111  NDimensions > Superclass;
112 
115 
118 
120  itkNewMacro(Self);
121 
123  itkStaticConstMacro(InputSpaceDimension, unsigned int, NDimensions);
124  itkStaticConstMacro(OutputSpaceDimension, unsigned int, NDimensions);
125  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
126  itkStaticConstMacro( ParametersDimension, unsigned int,
127  NDimensions *( NDimensions + 1 ) );
129 
131  typedef typename Superclass::ParametersType ParametersType;
132  typedef typename Superclass::FixedParametersType FixedParametersType;
133  typedef typename Superclass::JacobianType JacobianType;
134  typedef typename Superclass::ScalarType ScalarType;
135  typedef typename Superclass::InputPointType InputPointType;
136  typedef typename Superclass::OutputPointType OutputPointType;
137  typedef typename Superclass::InputVectorType InputVectorType;
138  typedef typename Superclass::OutputVectorType OutputVectorType;
139  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
140  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
141  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
142  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
143  typedef typename Superclass::MatrixType MatrixType;
144  typedef typename Superclass::InverseMatrixType InverseMatrixType;
145  typedef typename Superclass::CenterType CenterType;
146  typedef typename Superclass::OffsetType OffsetType;
147  typedef typename Superclass::TranslationType TranslationType;
148 
151  typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
152  typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
153 
160  void Translate(const OutputVectorType & offset, bool pre = 0);
161 
173  void Scale(const OutputVectorType & factor, bool pre = 0);
174 
175  void Scale(const TParametersValueType & factor, bool pre = 0);
176 
192  void Rotate(int axis1, int axis2, TParametersValueType angle, bool pre = 0);
194 
208  void Rotate2D(TParametersValueType angle, bool pre = 0);
209 
223  void Rotate3D(const OutputVectorType & axis, TParametersValueType angle, bool pre = 0);
224 
236  void Shear(int axis1, int axis2, TParametersValueType coef, bool pre = 0);
237 
239  bool GetInverse(Self *inverse) const;
240 
242  virtual InverseTransformBasePointer GetInverseTransform() const ITK_OVERRIDE;
243 
252  itkLegacyMacro(InputPointType BackTransform(const OutputPointType & point) const);
253  itkLegacyMacro(InputVectorType BackTransform(const OutputVectorType & vector) const);
254  itkLegacyMacro(InputVnlVectorType BackTransform( const OutputVnlVectorType & vector) const);
255  itkLegacyMacro(InputCovariantVectorType BackTransform( const OutputCovariantVectorType & vector) const);
257 
267  itkLegacyMacro(InputPointType BackTransformPoint(const OutputPointType & point) const);
268 
280  ScalarType Metric(const Self *other) const;
281 
285  ScalarType Metric() const;
286 
287 protected:
295  AffineTransform(const MatrixType & matrix,
296  const OutputVectorType & offset);
297  AffineTransform(unsigned int paramDims);
298  AffineTransform();
300 
302  virtual ~AffineTransform() ITK_OVERRIDE;
303 
305  void PrintSelf(std::ostream & s, Indent indent) const ITK_OVERRIDE;
306 
307 private:
308 
309  AffineTransform(const Self & other);
310  const Self & operator=(const Self &);
311 }; //class AffineTransform
312 
313 #if !defined(ITK_LEGACY_REMOVE)
314 
315 template<typename TParametersValueType, unsigned int NDimensions>
316 inline
319 {
320  itkWarningMacro(
321  << "BackTransform(): This method is slated to be removed "
322  << "from ITK. Instead, please use GetInverse() to generate an inverse "
323  << "transform and then perform the transform using that inverted transform.");
324  return this->GetInverseMatrix() * vect;
325 }
327 
329 template<typename TParametersValueType, unsigned int NDimensions>
330 inline
332 AffineTransform<TParametersValueType, NDimensions>::BackTransform(const OutputVnlVectorType & vect) const
333 {
334  itkWarningMacro(
335  << "BackTransform(): This method is slated to be removed "
336  << "from ITK. Instead, please use GetInverse() to generate an inverse "
337  << "transform and then perform the transform using that inverted transform.");
338  return this->GetInverseMatrix() * vect;
339 }
341 
343 template<typename TParametersValueType, unsigned int NDimensions>
344 inline
345 typename AffineTransform<TParametersValueType, NDimensions>::InputCovariantVectorType
346 AffineTransform<TParametersValueType, NDimensions>::BackTransform(const OutputCovariantVectorType & vec) const
347 {
348  itkWarningMacro(
349  << "BackTransform(): This method is slated to be removed "
350  << "from ITK. Instead, please use GetInverse() to generate an inverse "
351  << "transform and then perform the transform using that inverted transform.");
352 
353  InputCovariantVectorType result; // Converted vector
354 
355  for ( unsigned int i = 0; i < NDimensions; i++ )
356  {
358  for ( unsigned int j = 0; j < NDimensions; j++ )
359  {
360  result[i] += this->GetMatrix()[j][i] * vec[j]; // Direct matrix transposed
361  }
362  }
363  return result;
364 }
365 
367 template<typename TParametersValueType, unsigned int NDimensions>
368 inline
369 typename AffineTransform<TParametersValueType, NDimensions>::InputPointType
370 AffineTransform<TParametersValueType, NDimensions>::BackTransformPoint(const OutputPointType & point) const
371 {
372  return this->BackTransform(point);
373 }
374 
376 template<typename TParametersValueType, unsigned int NDimensions>
377 inline
378 typename AffineTransform<TParametersValueType, NDimensions>::InputPointType
379 AffineTransform<TParametersValueType, NDimensions>::BackTransform(const OutputPointType & point) const
380 {
381  itkWarningMacro(
382  << "BackTransform(): This method is slated to be removed "
383  << "from ITK. Instead, please use GetInverse() to generate an inverse "
384  << "transform and then perform the transform using that inverted transform.");
385  InputPointType result; // Converted point
386  ScalarType temp[NDimensions];
387  unsigned int i, j;
389 
390  for ( j = 0; j < NDimensions; j++ )
391  {
392  temp[j] = point[j] - this->GetOffset()[j];
393  }
394 
395  for ( i = 0; i < NDimensions; i++ )
396  {
397  result[i] = 0.0;
398  for ( j = 0; j < NDimensions; j++ )
399  {
400  result[i] += this->GetInverseMatrix()[i][j] * temp[j];
401  }
402  }
403  return result;
404 }
405 #endif
406 } // namespace itk
407 
408 #ifndef ITK_MANUAL_INSTANTIATION
409 #include "itkAffineTransform.hxx"
410 #endif
411 
412 #endif /* itkAffineTransform_h */
Superclass::InputCovariantVectorType InputCovariantVectorType
Superclass::MatrixType MatrixType
Light weight base class for most itk classes.
Superclass::TranslationType TranslationType
SmartPointer< const Self > ConstPointer
Matrix and Offset transformation of a vector space (e.g. space coordinates)
Superclass::InputVnlVectorType InputVnlVectorType
Superclass::OutputVnlVectorType OutputVnlVectorType
Superclass::JacobianType JacobianType
Superclass::ParametersType ParametersType
Superclass::InputVectorType InputVectorType
Superclass::OutputVectorType OutputVectorType
Superclass::CenterType CenterType
SmartPointer< Self > Pointer
Superclass::InverseMatrixType InverseMatrixType
Superclass::OffsetType OffsetType
InverseTransformBaseType::Pointer InverseTransformBasePointer
Superclass::OutputCovariantVectorType OutputCovariantVectorType
Superclass::FixedParametersType FixedParametersType
Superclass::OutputPointType OutputPointType
MatrixOffsetTransformBase< TParametersValueType, NDimensions, NDimensions > Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Superclass::ScalarType ScalarType
Superclass::InputPointType InputPointType
Superclass::InverseTransformBaseType InverseTransformBaseType