ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkScaleTransform.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 __itkScaleTransform_h
19 #define __itkScaleTransform_h
20 
21 #include <iostream>
23 #include "itkMacro.h"
24 #include "itkMatrix.h"
25 
26 namespace itk
27 {
41 template <
42  class TScalarType = float, // Type for cordinate representation type (float or
43  // double)
44  unsigned int NDimensions = 3>
45 // Number of dimensions
46 // class ITK_EXPORT ScaleTransform:public Transform< TScalarType,
47 class ITK_EXPORT ScaleTransform : public MatrixOffsetTransformBase<TScalarType,
48  NDimensions,
49  NDimensions>
50 {
51 public:
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(ScaleTransform, 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 
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 
102  typedef typename Superclass::MatrixType MatrixType;
103 
108  void SetParameters(const ParametersType & parameters);
109 
114  const ParametersType & GetParameters(void) const;
115 
119  virtual void SetFixedParameters(const ParametersType &)
120  {
121  }
122 
124  virtual const ParametersType & GetFixedParameters(void) const;
125 
127  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & point, JacobianType & j) const;
128 
133  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jac) const;
134 
143  void SetScale(const ScaleType & scale)
144  {
145  m_Scale = scale; this->ComputeMatrix(); this->Modified();
146  }
147 
148  virtual void ComputeMatrix(void);
149 
151  void Compose(const Self *other, bool pre = false);
152 
156  void Scale(const ScaleType & scale, bool pre = false);
157 
162  OutputPointType TransformPoint(const InputPointType & point) const;
163 
164  using Superclass::TransformVector;
165  OutputVectorType TransformVector(const InputVectorType & vector) const;
166 
167  OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
168 
169  using Superclass::TransformCovariantVector;
170  OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const;
171 
176  inline InputPointType BackTransform(const OutputPointType & point) const;
177 
178  inline InputVectorType BackTransform(const OutputVectorType & vector) const;
179 
180  inline InputVnlVectorType BackTransform(const OutputVnlVectorType & vector) const;
181 
182  inline InputCovariantVectorType BackTransform(const OutputCovariantVectorType & vector) const;
183 
188  bool GetInverse(Self *inverse) const;
189 
191  virtual InverseTransformBasePointer GetInverseTransform() const;
192 
196  void SetIdentity(void)
197  {
198  m_Scale.Fill(1.0);
199  }
200 
202  itkSetMacro(Center, InputPointType);
203  itkGetConstReferenceMacro(Center, InputPointType);
205 
207  itkGetConstReferenceMacro(Scale, ScaleType);
208 
214  virtual bool IsLinear() const
215  {
216  return true;
217  }
218 protected:
219 
221  ScaleTransform();
222 
224  ~ScaleTransform();
225 
227  void PrintSelf(std::ostream & os, Indent indent) const;
228 
229 private:
230  ScaleTransform(const Self & other); // purposely not implemented
231  const Self & operator=(const Self &); // purposely not implemented
232 
233  ScaleType m_Scale; // Scales of the transformation
234 
235  InputPointType m_Center; // Scaling center
237 }; // class ScaleTransform
238 
239 // Back transform a point
240 template <class ScalarType, unsigned int NDimensions>
241 inline
244 {
245  InputPointType result;
246 
247  for( unsigned int i = 0; i < SpaceDimension; i++ )
248  {
249  result[i] = ( point[i] + m_Center[i] ) / m_Scale[i] - m_Center[i];
250  }
251  return result;
252 }
253 
254 // Back transform a vector
255 template <class ScalarType, unsigned int NDimensions>
256 inline
259 {
260  InputVectorType result;
261 
262  for( unsigned int i = 0; i < SpaceDimension; i++ )
263  {
264  result[i] = vect[i] / m_Scale[i];
265  }
266  return result;
267 }
268 
269 // Back transform a vnl_vector
270 template <class ScalarType, unsigned int NDimensions>
271 inline
274 {
275  InputVnlVectorType result;
276 
277  for( unsigned int i = 0; i < SpaceDimension; i++ )
278  {
279  result[i] = vect[i] / m_Scale[i];
280  }
281  return result;
282 }
283 
284 // Back Transform a CovariantVector
285 template <class ScalarType, unsigned int NDimensions>
286 inline
289 {
290  // Covariant Vectors are scaled by the inverse
292 
293  for( unsigned int i = 0; i < SpaceDimension; i++ )
294  {
295  result[i] = vect[i] * m_Scale[i];
296  }
297  return result;
298 }
299 
300 } // namespace itk
301 
302 // Define instantiation macro for this template.
303 #define ITK_TEMPLATE_ScaleTransform(_, EXPORT, TypeX, TypeY) \
304  namespace itk \
305  { \
306  _( 2 ( class EXPORT ScaleTransform<ITK_TEMPLATE_2 TypeX> ) ) \
307  namespace Templates \
308  { \
309  typedef ScaleTransform<ITK_TEMPLATE_2 TypeX> ScaleTransform##TypeY; \
310  } \
311  }
312 
313 #if ITK_TEMPLATE_EXPLICIT
314 #include "Templates/itkScaleTransform+-.h"
315 #endif
316 
317 #if ITK_TEMPLATE_TXX
318 #include "itkScaleTransform.hxx"
319 #endif
320 
321 #endif /* __itkScaleTransform_h */
322