ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkTranslationTransform.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 __itkTranslationTransform_h
19 #define __itkTranslationTransform_h
20 
21 #include <iostream>
22 #include "itkTransform.h"
23 #include "itkMacro.h"
24 #include "itkMatrix.h"
25 
26 namespace itk
27 {
43 template <
44  class TScalarType = double, // Data type for scalars (float or
45  // double)
46  unsigned int NDimensions = 3>
47 // Number of dimensions
48 class ITK_EXPORT TranslationTransform :
49  public Transform<TScalarType, NDimensions, NDimensions>
50 {
51 public:
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(TranslationTransform, Transform);
63 
65  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
66  itkStaticConstMacro(ParametersDimension, unsigned int, NDimensions);
68 
70  typedef typename Superclass::ScalarType ScalarType;
71 
73  typedef typename Superclass::ParametersType ParametersType;
74 
76  typedef typename Superclass::JacobianType JacobianType;
77 
79  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
80 
84 
88 
90  typedef vnl_vector_fixed<TScalarType, NDimensions> InputVnlVectorType;
91  typedef vnl_vector_fixed<TScalarType, NDimensions> OutputVnlVectorType;
92 
96 
99  typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
100  typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
101 
104  const OutputVectorType & GetOffset(void) const
105  {
106  return m_Offset;
107  }
108 
111  void SetParameters(const ParametersType & parameters);
112 
114  virtual const ParametersType & GetParameters(void) const;
115 
119  void SetOffset(const OutputVectorType & offset)
120  {
121  m_Offset = offset; return;
122  }
123 
125  void Compose(const Self *other, bool pre = 0);
126 
131  void Translate(const OutputVectorType & offset, bool pre = 0);
132 
137  OutputPointType TransformPoint(const InputPointType & point) const;
138 
139  using Superclass::TransformVector;
140  OutputVectorType TransformVector(const InputVectorType & vector) const;
141 
142  OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
143 
144  using Superclass::TransformCovariantVector;
145  OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const;
146 
150  inline InputPointType BackTransform(const OutputPointType & point) const;
151 
152  inline InputVectorType BackTransform(const OutputVectorType & vector) const;
153 
154  inline InputVnlVectorType BackTransform(const OutputVnlVectorType & vector) const;
155 
156  inline InputCovariantVectorType BackTransform(const OutputCovariantVectorType & vector) const;
157 
162  bool GetInverse(Self *inverse) const;
163 
165  virtual InverseTransformBasePointer GetInverseTransform() const;
166 
168  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & point, JacobianType & j) const;
169 
174  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jac) const;
175 
177  void SetIdentity(void);
178 
180  virtual NumberOfParametersType GetNumberOfParameters(void) const
181  {
182  return NDimensions;
183  }
184 
190  virtual bool IsLinear() const
191  {
192  return true;
193  }
194 
198  virtual void SetFixedParameters(const ParametersType &)
199  {
200  }
201 
205  virtual const ParametersType & GetFixedParameters(void) const
206  {
207  this->m_FixedParameters.SetSize(0);
208  return this->m_FixedParameters;
209  }
211 
212 protected:
216  void PrintSelf(std::ostream & os, Indent indent) const;
217 
218 private:
219  TranslationTransform(const Self &); // purposely not implemented
220  void operator=(const Self &); // purposely not implemented
221 
223  OutputVectorType m_Offset; // Offset of the transformation
224 }; // class TranslationTransform
225 
226 // Back transform a point
227 template <class TScalarType, unsigned int NDimensions>
228 inline
231 {
232  return point - m_Offset;
233 }
234 
235 // Back transform a vector
236 template <class TScalarType, unsigned int NDimensions>
237 inline
240 {
241  return vect;
242 }
243 
244 // Back transform a vnl_vector
245 template <class TScalarType, unsigned int NDimensions>
246 inline
249 {
250  return vect;
251 }
252 
253 // Back Transform a CovariantVector
254 template <class TScalarType, unsigned int NDimensions>
255 inline
258 {
259  return vect;
260 }
261 
262 } // namespace itk
263 
264 // Define instantiation macro for this template.
265 #define ITK_TEMPLATE_TranslationTransform(_, EXPORT, TypeX, TypeY) \
266  namespace itk \
267  { \
268  _( 2 ( class EXPORT TranslationTransform<ITK_TEMPLATE_2 TypeX> ) ) \
269  namespace Templates \
270  { \
271  typedef TranslationTransform<ITK_TEMPLATE_2 TypeX> TranslationTransform##TypeY; \
272  } \
273  }
274 
275 #if ITK_TEMPLATE_EXPLICIT
276 #include "Templates/itkTranslationTransform+-.h"
277 #endif
278 
279 #if ITK_TEMPLATE_TXX
280 #include "itkTranslationTransform.hxx"
281 #endif
282 
283 #endif /* __itkTranslationTransform_h */
284