ITK  4.6.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 TScalar = double, // Data type for scalars
101  // (e.g. float or double)
102  unsigned int NDimensions = 3 >
103 // Number of dimensions in the input space
105  public MatrixOffsetTransformBase< TScalar, NDimensions, NDimensions >
106 {
107 public:
110  typedef MatrixOffsetTransformBase< TScalar,
111  NDimensions,
112  NDimensions > Superclass;
113 
116 
119 
121  itkNewMacro(Self);
122 
124  itkStaticConstMacro(InputSpaceDimension, unsigned int, NDimensions);
125  itkStaticConstMacro(OutputSpaceDimension, unsigned int, NDimensions);
126  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
127  itkStaticConstMacro( ParametersDimension, unsigned int,
128  NDimensions *( NDimensions + 1 ) );
130 
148 
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 TScalar & factor, bool pre = 0);
176 
192  void Rotate(int axis1, int axis2, TScalar angle, bool pre = 0);
194 
208  void Rotate2D(TScalar angle, bool pre = 0);
209 
223  void Rotate3D(const OutputVectorType & axis, TScalar angle, bool pre = 0);
224 
236  void Shear(int axis1, int axis2, TScalar coef, bool pre = 0);
237 
239  bool GetInverse(Self *inverse) const;
240 
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(void) const;
286 
287 protected:
295  AffineTransform(const MatrixType & matrix,
296  const OutputVectorType & offset);
297  AffineTransform(unsigned int paramDims);
298  AffineTransform();
300 
302  virtual ~AffineTransform();
303 
305  void PrintSelf(std::ostream & s, Indent indent) const;
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 TScalar, unsigned int NDimensions >
316 inline
318 AffineTransform< TScalar, NDimensions >::BackTransform(const OutputVectorType & vect) const
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 TScalar, unsigned int NDimensions >
330 inline
331 typename AffineTransform< TScalar, NDimensions >::InputVnlVectorType
332 AffineTransform< TScalar, 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 TScalar, unsigned int NDimensions >
344 inline
345 typename AffineTransform< TScalar, NDimensions >::InputCovariantVectorType
346 AffineTransform< TScalar, 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 TScalar, unsigned int NDimensions >
368 inline
369 typename AffineTransform< TScalar, NDimensions >::InputPointType
370 AffineTransform< TScalar, NDimensions >::BackTransformPoint(const OutputPointType & point) const
371 {
372  return this->BackTransform(point);
373 }
374 
376 template< typename TScalar, unsigned int NDimensions >
377 inline
378 typename AffineTransform< TScalar, NDimensions >::InputPointType
379 AffineTransform< TScalar, 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::InputVnlVectorType InputVnlVectorType
Light weight base class for most itk classes.
Superclass::ScalarType ScalarType
InverseTransformBaseType::Pointer InverseTransformBasePointer
Vector< TScalar, itkGetStaticConstMacro(InputSpaceDimension)> InputVectorType
Superclass::ParametersType ParametersType
Superclass::OutputPointType OutputPointType
void Rotate2D(TScalar angle, bool pre=0)
void PrintSelf(std::ostream &s, Indent indent) const
Matrix and Offset transformation of a vector space (e.g. space coordinates)
Superclass::InputVectorType InputVectorType
vnl_vector_fixed< TScalar, itkGetStaticConstMacro(OutputSpaceDimension)> OutputVnlVectorType
Matrix< TScalar, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> MatrixType
Superclass::InputPointType InputPointType
static const unsigned int OutputSpaceDimension
Vector< TScalar, itkGetStaticConstMacro(OutputSpaceDimension)> OutputVectorType
Superclass::JacobianType JacobianType
Superclass::InputCovariantVectorType InputCovariantVectorType
Superclass::InverseTransformBaseType InverseTransformBaseType
void Scale(const OutputVectorType &factor, bool pre=0)
void Translate(const OutputVectorType &offset, bool pre=0)
SmartPointer< const Self > ConstPointer
static const ScalarType Zero
Matrix< TScalar, itkGetStaticConstMacro(InputSpaceDimension), itkGetStaticConstMacro(OutputSpaceDimension)> InverseMatrixType
Superclass::InverseMatrixType InverseMatrixType
vnl_vector_fixed< TScalar, itkGetStaticConstMacro(InputSpaceDimension)> InputVnlVectorType
ScalarType Metric(void) const
Point< TScalar, itkGetStaticConstMacro(InputSpaceDimension)> InputPointType
static const unsigned int SpaceDimension
Superclass::OutputCovariantVectorType OutputCovariantVectorType
CovariantVector< TScalar, itkGetStaticConstMacro(OutputSpaceDimension)> OutputCovariantVectorType
Superclass::OutputVnlVectorType OutputVnlVectorType
Superclass::OffsetType OffsetType
Point< TScalar, itkGetStaticConstMacro(OutputSpaceDimension)> OutputPointType
MatrixOffsetTransformBase< TScalar, NDimensions, NDimensions > Superclass
static const unsigned int ParametersDimension
CovariantVector< TScalar, itkGetStaticConstMacro(InputSpaceDimension)> InputCovariantVectorType
SmartPointer< Self > Pointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkLegacyMacro(InputPointType BackTransform(const OutputPointType &point) const)
void Rotate3D(const OutputVectorType &axis, TScalar angle, bool pre=0)
virtual InverseTransformBasePointer GetInverseTransform() const
Superclass::TranslationType TranslationType
void Rotate(int axis1, int axis2, TScalar angle, bool pre=0)
virtual ~AffineTransform()
bool GetInverse(Self *inverse) const
const Self & operator=(const Self &)
Superclass::MatrixType MatrixType
Superclass::OutputVectorType OutputVectorType
void Shear(int axis1, int axis2, TScalar coef, bool pre=0)
static const unsigned int InputSpaceDimension
Superclass::CenterType CenterType