| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkScaleTransform.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:47 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
|
| 18 |
|
#ifndef __itkScaleTransform_h |
| 19 |
|
#define __itkScaleTransform_h |
| 20 |
|
|
| 21 |
|
#include <iostream> |
| 22 |
|
#include "itkTransform.h" |
| 23 |
|
#include "itkExceptionObject.h" |
| 24 |
|
#include "itkMatrix.h" |
| 25 |
|
|
| 26 |
|
namespace itk |
| 27 |
|
{ |
| 28 |
|
|
| 29 |
|
/** \brief Scale transformation of a vector space (e.g. space coordinates) |
| 30 |
|
* |
| 31 |
|
* The same functionality could be obtained by using the Affine tranform, |
| 32 |
|
* but with a large difference in performace since the affine transform will |
| 33 |
|
* use a matrix multiplication using a diagonal matrix. |
| 34 |
|
* |
| 35 |
|
* \ingroup Transforms |
| 36 |
|
*/ |
| 37 |
|
template < |
| 38 |
LEN |
class TScalarType=float, // Type for cordinate representation type (float or double) |
| 39 |
|
unsigned int NDimensions=3 > // Number of dimensions |
| 40 |
MCM |
class ITK_EXPORT ScaleTransform : public Transform< TScalarType, |
| 41 |
|
NDimensions, |
| 42 |
|
NDimensions > |
| 43 |
|
{ |
| 44 |
|
public: |
| 45 |
|
/** Standard class typedefs. */ |
| 46 |
|
typedef ScaleTransform Self; |
| 47 |
TDA |
typedef Transform< TScalarType, NDimensions, NDimensions > Superclass; |
| 48 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 49 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 50 |
|
|
| 51 |
|
/** New macro for creation of through a smart pointer. */ |
| 52 |
|
itkNewMacro( Self ); |
| 53 |
|
|
| 54 |
|
/** Run-time type information (and related methods). */ |
| 55 |
|
itkTypeMacro( ScaleTransform, Transform ); |
| 56 |
|
|
| 57 |
|
/** Dimension of the domain space. */ |
| 58 |
|
itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions); |
| 59 |
|
itkStaticConstMacro(ParametersDimension, unsigned int, NDimensions); |
| 60 |
|
|
| 61 |
|
/** Scalar type. */ |
| 62 |
|
typedef typename Superclass::ScalarType ScalarType; |
| 63 |
|
|
| 64 |
|
/** Parameters type. */ |
| 65 |
|
typedef typename Superclass::ParametersType ParametersType; |
| 66 |
|
|
| 67 |
|
/** Jacobian type. */ |
| 68 |
|
typedef typename Superclass::JacobianType JacobianType; |
| 69 |
|
|
| 70 |
|
/** Standard vector type for this class. */ |
| 71 |
LEN |
typedef FixedArray<TScalarType, itkGetStaticConstMacro(SpaceDimension)> ScaleType; |
| 72 |
|
|
| 73 |
|
/** Standard vector type for this class. */ |
| 74 |
LEN |
typedef Vector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputVectorType; |
| 75 |
LEN |
typedef Vector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputVectorType; |
| 76 |
|
|
| 77 |
|
/** Standard covariant vector type for this class. */ |
| 78 |
LEN |
typedef CovariantVector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputCovariantVectorType; |
| 79 |
LEN |
typedef CovariantVector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputCovariantVectorType; |
| 80 |
|
|
| 81 |
|
/** Standard vnl_vector type for this class. */ |
| 82 |
LEN |
typedef vnl_vector_fixed<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputVnlVectorType; |
| 83 |
LEN |
typedef vnl_vector_fixed<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputVnlVectorType; |
| 84 |
|
|
| 85 |
|
/** Standard coordinate point type for this class. */ |
| 86 |
LEN |
typedef Point<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputPointType; |
| 87 |
LEN |
typedef Point<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputPointType; |
| 88 |
|
|
| 89 |
|
/** Set parameters. This method sets the parameters for the transform value |
| 90 |
|
* specified by the user. The parameters are organized as scale[i] = |
| 91 |
LEN |
* parameter[i]. That means that in 3D the scale parameters for the coordinates |
| 92 |
|
* {x,y,z} are {parameter[0], parameter[1], parameter[2]} respectively */ |
| 93 |
|
void SetParameters(const ParametersType & parameters); |
| 94 |
|
|
| 95 |
|
/** Get the parameters that uniquely define the transform This is typically |
| 96 |
LEN |
* used by optimizers during the process of image registration. The parameters |
| 97 |
|
* are organized as {scale X, scale Y, scale Z } = { parameter[0], |
| 98 |
IND |
**** parameter[1], parameter[2] } respectively */ |
| 99 |
|
const ParametersType & GetParameters( void ) const; |
| 100 |
|
|
| 101 |
|
/** Get the Jacobian matrix. */ |
| 102 |
|
const JacobianType & GetJacobian( const InputPointType & point ) const; |
| 103 |
|
|
| 104 |
|
/** Set the factors of an Scale Transform |
| 105 |
|
* This method sets the factors of an ScaleTransform to a |
| 106 |
|
* value specified by the user. |
| 107 |
|
* This method cannot be done with SetMacro because itk::Array has not an |
| 108 |
|
* operator== defined. The array of scales correspond in order to the factors |
| 109 |
|
* to be applied to each one of the coordinaates. For example, in 3D, |
| 110 |
|
* scale[0] corresponds to X, scale[1] corresponds to Y and scale[2] |
| 111 |
|
* corresponds to Z.*/ |
| 112 |
|
void SetScale( const ScaleType & scale ) |
| 113 |
|
{ this->Modified(); m_Scale = scale; } |
| 114 |
|
|
| 115 |
|
/** Compose with another ScaleTransform. */ |
| 116 |
|
void Compose(const Self * other, bool pre=false); |
| 117 |
|
|
| 118 |
|
/** Compose this transform transformation with another scaling. |
| 119 |
|
* The pre argument is irrelevant here since scale transforms are commutative, |
| 120 |
|
* pre and postcomposition are therefore equivalent. */ |
| 121 |
|
void Scale(const ScaleType & scale, bool pre=false ); |
| 122 |
|
|
| 123 |
|
/** Transform by a scale transformation |
| 124 |
|
* This method applies the scale transform given by self to a |
| 125 |
|
* given point or vector, returning the transformed point or |
| 126 |
|
* vector. */ |
| 127 |
|
OutputPointType TransformPoint(const InputPointType &point ) const; |
| 128 |
|
OutputVectorType TransformVector(const InputVectorType &vector) const; |
| 129 |
|
OutputVnlVectorType TransformVector(const InputVnlVectorType &vector) const; |
| 130 |
|
OutputCovariantVectorType TransformCovariantVector( |
| 131 |
|
const InputCovariantVectorType &vector) const; |
| 132 |
|
|
| 133 |
|
/** Back transform by a scale transformation |
| 134 |
|
* This method finds the point or vector that maps to a given |
| 135 |
|
* point or vector under the scale transformation defined by |
| 136 |
|
* self. If no such point exists, an exception is thrown. */ |
| 137 |
|
inline InputPointType BackTransform(const OutputPointType &point ) const; |
| 138 |
|
inline InputVectorType BackTransform(const OutputVectorType &vector) const; |
| 139 |
LEN |
inline InputVnlVectorType BackTransform(const OutputVnlVectorType &vector) const; |
| 140 |
|
inline InputCovariantVectorType BackTransform( |
| 141 |
LEN |
const OutputCovariantVectorType &vector) const; |
| 142 |
|
|
| 143 |
|
/** Find inverse of a scale transformation |
| 144 |
|
* This method creates and returns a new ScaleTransform object |
| 145 |
|
* which is the inverse of self. If self is not invertible, |
| 146 |
|
* false is returned. */ |
| 147 |
|
bool GetInverse(Self* inverse) const; |
| 148 |
|
|
| 149 |
|
/** Set the transformation to an Identity |
| 150 |
|
* |
| 151 |
|
* This sets all the scales to 1.0 */ |
| 152 |
|
void SetIdentity( void ) |
| 153 |
|
{ m_Scale.Fill( 1.0 ); } |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
/** Set/Get the center used as fixed point for the scaling */ |
| 157 |
|
itkSetMacro( Center, InputPointType ); |
| 158 |
|
itkGetConstReferenceMacro( Center, InputPointType ); |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
/** Get access to scale values */ |
| 162 |
|
itkGetConstReferenceMacro( Scale, ScaleType ); |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
protected: |
| 166 |
|
/** Construct an ScaleTransform object. */ |
| 167 |
|
ScaleTransform(); |
| 168 |
|
|
| 169 |
|
/** Destroy an ScaleTransform object. */ |
| 170 |
|
~ScaleTransform(); |
| 171 |
|
|
| 172 |
|
/** Print contents of an ScaleTransform */ |
| 173 |
|
void PrintSelf(std::ostream &os, Indent indent) const; |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
private: |
| 177 |
|
ScaleTransform(const Self & other); //purposely not implemented |
| 178 |
|
const Self & operator=( const Self & ); //purposely not implemented |
| 179 |
|
|
| 180 |
|
ScaleType m_Scale; // Scales of the transformation |
| 181 |
|
|
| 182 |
|
InputPointType m_Center; // Scaling center |
| 183 |
|
|
| 184 |
|
}; //class ScaleTransform |
| 185 |
|
|
| 186 |
|
} // namespace itk |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 190 |
|
#include "itkScaleTransform.txx" |
| 191 |
|
#endif |
| 192 |
|
|
| 193 |
|
#endif /* __itkScaleTransform_h */ |
| 194 |
|
|