ITK  4.6.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  typename TScalar = float, // Type for cordinate representation type (float or
43  // double)
44  unsigned int NDimensions = 3>
45 // Number of dimensions
46 // class ScaleTransform:public Transform< TScalar,
47 class ScaleTransform : public MatrixOffsetTransformBase< TScalar,
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 
71 
74 
77 
80 
84 
88 
90  typedef vnl_vector_fixed<TScalar, NDimensions> InputVnlVectorType;
91  typedef vnl_vector_fixed<TScalar, NDimensions> OutputVnlVectorType;
92 
96 
100  typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
101 
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 
165  OutputVectorType TransformVector(const InputVectorType & vector) const;
166 
168 
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 
183 
188  bool GetInverse(Self *inverse) const;
189 
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 
219 protected:
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 <typename 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 <typename 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 <typename 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 <typename 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 #ifndef ITK_MANUAL_INSTANTIATION
303 #include "itkScaleTransform.hxx"
304 #endif
305 
306 #endif /* __itkScaleTransform_h */
const ParametersType & GetParameters(void) const
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &vector) const
Light weight base class for most itk classes.
static const unsigned int ParametersDimension
void Compose(const Self *other, bool pre=false)
InverseTransformBaseType::Pointer InverseTransformBasePointer
Superclass::MatrixType MatrixType
void SetParameters(const ParametersType &parameters)
Matrix and Offset transformation of a vector space (e.g. space coordinates)
virtual InverseTransformBasePointer GetInverseTransform() const
SmartPointer< const Self > ConstPointer
virtual void ComputeMatrix(void)
void Scale(const ScaleType &scale, bool pre=false)
const Self & operator=(const Self &)
void SetScale(const ScaleType &scale)
virtual const ParametersType & GetFixedParameters(void) const
Matrix< TScalar, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> MatrixType
bool GetInverse(Self *inverse) const
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &vector) const
OutputVectorType TransformVector(const InputVectorType &vector) const
InputPointType BackTransform(const OutputPointType &point) const
Superclass::InverseTransformBaseType InverseTransformBaseType
CovariantVector< TScalar, NDimensions > OutputCovariantVectorType
void Fill(const ValueType &)
Point< TScalar, NDimensions > OutputPointType
ParametersType m_FixedParameters
static const unsigned int SpaceDimension
Vector< TScalar, NDimensions > InputVectorType
SmartPointer< Self > Pointer
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
OutputVectorType TransformVector(const InputVectorType &vector) const
Superclass::ScalarType ScalarType
MatrixOffsetTransformBase< TScalar, NDimensions, NDimensions > Superclass
Point< TScalar, NDimensions > InputPointType
virtual void Modified() const
Vector< TScalar, NDimensions > OutputVectorType
Superclass::JacobianType JacobianType
Scale transformation of a vector space (e.g. space coordinates)
virtual bool IsLinear() const
vnl_vector_fixed< TScalar, NDimensions > InputVnlVectorType
vnl_vector_fixed< TScalar, NDimensions > OutputVnlVectorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
OutputPointType TransformPoint(const InputPointType &point) const
InputPointType m_Center
void PrintSelf(std::ostream &os, Indent indent) const
CovariantVector< TScalar, NDimensions > InputCovariantVectorType
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &x, JacobianType &jac) const
A templated class holding a n-Dimensional covariant vector.
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &point, JacobianType &j) const
virtual void SetFixedParameters(const ParametersType &)
Superclass::ParametersType ParametersType
FixedArray< TScalar, NDimensions > ScaleType