ITK
4.0.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkTransform_h 00019 #define __itkTransform_h 00020 00021 #include "itkTransformBase.h" 00022 #include "itkVector.h" 00023 #include "itkSymmetricSecondRankTensor.h" 00024 #include "itkDiffusionTensor3D.h" 00025 #include "itkVariableLengthVector.h" 00026 #include "vnl/vnl_vector_fixed.h" 00027 #include "itkMatrix.h" 00028 00029 namespace itk 00030 { 00079 template <class TScalarType, 00080 unsigned int NInputDimensions = 3, 00081 unsigned int NOutputDimensions = 3> 00082 class ITK_EXPORT Transform : public TransformBase 00083 { 00084 public: 00086 typedef Transform Self; 00087 typedef TransformBase Superclass; 00088 typedef SmartPointer<Self> Pointer; 00089 typedef SmartPointer<const Self> ConstPointer; 00090 00092 itkTypeMacro(Transform, TransformBase); 00093 00095 itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions); 00096 itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions); 00098 00100 unsigned int GetInputSpaceDimension(void) const 00101 { 00102 return NInputDimensions; 00103 } 00104 00106 unsigned int GetOutputSpaceDimension(void) const 00107 { 00108 return NOutputDimensions; 00109 } 00110 00112 typedef TScalarType ScalarType; 00113 00115 typedef typename Superclass::ParametersType ParametersType; 00116 typedef typename Superclass::ParametersValueType ParametersValueType; 00117 typedef Array<ParametersValueType> DerivativeType; 00118 00120 typedef Array2D<ParametersValueType> JacobianType; 00121 00123 typedef Vector<TScalarType, NInputDimensions> InputVectorType; 00124 typedef Vector<TScalarType, NOutputDimensions> OutputVectorType; 00125 00128 typedef VariableLengthVector<TScalarType> InputVectorPixelType; 00129 typedef VariableLengthVector<TScalarType> OutputVectorPixelType; 00130 00131 /* Standard symmetric second rank tenosr type for this class */ 00132 typedef SymmetricSecondRankTensor<TScalarType,NInputDimensions> 00133 InputSymmetricSecondRankTensorType; 00134 typedef SymmetricSecondRankTensor<TScalarType,NOutputDimensions> 00135 OutputSymmetricSecondRankTensorType; 00136 00137 /* Standard tensor type for this class */ 00138 typedef DiffusionTensor3D<TScalarType> InputDiffusionTensor3DType; 00139 typedef DiffusionTensor3D<TScalarType> OutputDiffusionTensor3DType; 00140 00142 typedef CovariantVector<TScalarType, NInputDimensions> 00143 InputCovariantVectorType; 00144 typedef CovariantVector<TScalarType, NOutputDimensions> 00145 OutputCovariantVectorType; 00146 00148 typedef vnl_vector_fixed<TScalarType, NInputDimensions> InputVnlVectorType; 00149 typedef vnl_vector_fixed<TScalarType, NOutputDimensions> 00150 OutputVnlVectorType; 00151 00153 typedef Point<TScalarType, NInputDimensions> InputPointType; 00154 typedef Point<TScalarType, NOutputDimensions> OutputPointType; 00155 00158 typedef Transform< 00159 TScalarType, NOutputDimensions, NInputDimensions> InverseTransformBaseType; 00160 00161 typedef typename InverseTransformBaseType::Pointer 00162 InverseTransformBasePointer; 00163 00164 typedef Matrix<TScalarType, 00165 itkGetStaticConstMacro(OutputSpaceDimension), 00166 itkGetStaticConstMacro(InputSpaceDimension)> MatrixType; 00167 00168 typedef Matrix<double, 00169 itkGetStaticConstMacro(OutputSpaceDimension), 00170 itkGetStaticConstMacro(OutputSpaceDimension)> 00171 OutputDirectionMatrix; 00172 typedef Matrix<double, 00173 itkGetStaticConstMacro(InputSpaceDimension), 00174 itkGetStaticConstMacro(InputSpaceDimension)> 00175 InputDirectionMatrix; 00176 typedef Matrix<double, 00177 itkGetStaticConstMacro(OutputSpaceDimension), 00178 itkGetStaticConstMacro(InputSpaceDimension)> 00179 DirectionChangeMatrix; 00180 00181 typedef Superclass::NumberOfParametersType NumberOfParametersType; 00182 00183 #if 0 00184 // this method is currently undocummented, untested and broken when input and output dimensions are 00185 // not the same 00186 void SetDirectionChange( const OutputDirectionMatrix fixedDir, const InputDirectionMatrix movingDir ); 00187 #endif 00188 00189 void SetDirectionChangeMatrix( const DirectionChangeMatrix & changeDir ) 00190 { 00191 m_DirectionChange = changeDir; this->Modified(); 00192 } 00193 00194 DirectionChangeMatrix GetDirectionChangeMatrix( void ) const 00195 { 00196 return m_DirectionChange; 00197 } 00198 00203 virtual OutputPointType TransformPoint(const InputPointType &) const = 0; 00204 00206 virtual OutputVectorType TransformVector(const InputVectorType &) const 00207 { 00208 itkExceptionMacro( "TransformVector(const InputVectorType &)" 00209 "is unimplemented for " << this->GetNameOfClass() ); 00210 } 00211 00216 virtual OutputVectorType TransformVector( 00217 const InputVectorType & vector, 00218 const InputPointType & point ) const; 00219 00221 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const 00222 { 00223 itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is " 00224 "unimplemented for " << this->GetNameOfClass() ); 00225 } 00226 00231 virtual OutputVnlVectorType TransformVector( 00232 const InputVnlVectorType & vector, 00233 const InputPointType & point ) const; 00234 00236 virtual OutputVectorPixelType TransformVector( 00237 const InputVectorPixelType & itkNotUsed(vector) ) const 00238 { 00239 itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is " 00240 "unimplemented for " << this->GetNameOfClass() ); 00241 } 00242 00247 virtual OutputVectorPixelType TransformVector( 00248 const InputVectorPixelType & vector, 00249 const InputPointType & point ) const; 00250 00252 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const 00253 { 00254 itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is " 00255 "unimplemented for " << this->GetNameOfClass() ); 00256 } 00257 00263 virtual OutputCovariantVectorType TransformCovariantVector( 00264 const InputCovariantVectorType & vector, 00265 const InputPointType & point ) const; 00266 00267 00269 virtual OutputVectorPixelType TransformCovariantVector( 00270 const InputVectorPixelType & itkNotUsed(vector) ) const 00271 { 00272 itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)" 00273 "is unimplemented for " << this->GetNameOfClass() ); 00274 } 00275 00281 virtual OutputVectorPixelType TransformCovariantVector( 00282 const InputVectorPixelType & vector, 00283 const InputPointType & point ) const; 00284 00286 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00287 const InputDiffusionTensor3DType & itkNotUsed(tensor) ) 00288 const 00289 { 00290 itkExceptionMacro( 00291 "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is " 00292 "unimplemented for " << this->GetNameOfClass() ); 00293 } 00294 00300 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00301 const InputDiffusionTensor3DType & tensor, 00302 const InputPointType & point ) const; 00303 00305 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00306 const InputVectorPixelType & itkNotUsed(tensor) ) const 00307 { 00308 itkExceptionMacro( 00309 "TransformDiffusionTensor( const InputVectorPixelType & ) is " 00310 "unimplemented for " << this->GetNameOfClass() ); 00311 } 00312 00313 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00314 const InputVectorPixelType & tensor, 00315 const InputPointType & point ) const; 00316 00322 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00323 const InputSymmetricSecondRankTensorType & tensor, 00324 const InputPointType & point ) const; 00325 00327 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00328 const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const 00329 { 00330 itkExceptionMacro( 00331 "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is " 00332 "unimplemented for " << this->GetNameOfClass() ); 00333 } 00334 00336 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00337 const InputVectorPixelType & itkNotUsed(tensor) ) const 00338 { 00339 itkExceptionMacro( 00340 "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is " 00341 "unimplemented for " << this->GetNameOfClass() ); 00342 } 00343 00350 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00351 const InputVectorPixelType & tensor, 00352 const InputPointType & point ) const; 00353 00361 virtual void SetParameters(const ParametersType &) = 0; 00362 00370 virtual void SetParametersByValue(const ParametersType & p) 00371 { 00372 this->SetParameters(p); 00373 } 00374 00376 virtual const ParametersType & GetParameters(void) const 00377 { 00378 return m_Parameters; 00379 } 00380 00382 virtual void SetFixedParameters(const ParametersType &) = 0; 00383 00385 virtual const ParametersType & GetFixedParameters(void) const 00386 { 00387 return m_FixedParameters; 00388 } 00389 00400 virtual void UpdateTransformParameters( DerivativeType & update, TScalarType factor = 1.0 ); 00401 00410 virtual NumberOfParametersType GetNumberOfLocalParameters(void) const 00411 { 00412 return this->GetNumberOfParameters(); 00413 } 00414 00416 virtual NumberOfParametersType GetNumberOfParameters(void) const 00417 { 00418 return this->m_Parameters.Size(); 00419 } 00420 00429 bool GetInverse( Self *itkNotUsed(inverseTransform) ) const 00430 { 00431 return false; 00432 } 00433 00440 virtual InverseTransformBasePointer GetInverseTransform() const 00441 { 00442 return NULL; 00443 } 00444 00446 virtual std::string GetTransformTypeAsString() const; 00447 00463 virtual bool IsLinear() const 00464 { 00465 return false; 00466 } 00467 00471 virtual bool HasLocalSupport() const 00472 { 00473 return false; 00474 } 00475 #ifdef ITKV3_COMPATIBILITY 00476 00488 virtual const JacobianType & GetJacobian(const InputPointType & x) const 00489 { 00490 this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian); 00491 return m_SharedLocalJacobian; 00492 } 00494 00495 #endif 00496 00531 virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const 00532 { 00533 itkExceptionMacro( 00534 "ComputeJacobianWithRespectToParamters( InputPointType, JacobianType" 00535 " is unimplemented for " << this->GetNameOfClass() ); 00536 } 00538 00539 00545 virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const 00546 { 00547 itkExceptionMacro( 00548 "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType" 00549 " is unimplemented for " << this->GetNameOfClass() ); 00550 } 00551 00552 00558 virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const; 00559 00560 protected: 00561 Transform(); 00562 Transform(NumberOfParametersType NumberOfParameters); 00563 virtual ~Transform() 00564 { 00565 } 00566 00567 mutable ParametersType m_Parameters; 00568 mutable ParametersType m_FixedParameters; 00569 00570 OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation( 00571 const InputDiffusionTensor3DType, const JacobianType ) const; 00572 00573 #ifdef ITKV3_COMPATIBILITY 00574 // This is only needed to provide the old interface that returns a reference to the Jacobian. 00575 // It is NOT thread-safe and should be avoided whenever possible. 00576 mutable JacobianType m_SharedLocalJacobian; 00577 #endif 00578 00579 mutable DirectionChangeMatrix m_DirectionChange; 00580 private: 00581 Transform(const Self &); // purposely not implemented 00582 void operator=(const Self &); // purposely not implemented 00583 00584 template <typename TType> 00585 std::string GetTransformTypeAsString(TType *) const 00586 { 00587 std::string rval("other"); 00588 00589 return rval; 00590 } 00591 00592 std::string GetTransformTypeAsString(float *) const 00593 { 00594 std::string rval("float"); 00595 00596 return rval; 00597 } 00598 00599 std::string GetTransformTypeAsString(double *) const 00600 { 00601 std::string rval("double"); 00602 00603 return rval; 00604 } 00605 00606 }; 00607 } // end namespace itk 00608 00609 // Define instantiation macro for this template. 00610 #define ITK_TEMPLATE_Transform(_, EXPORT, TypeX, TypeY) \ 00611 namespace itk \ 00612 { \ 00613 _( 3 ( class EXPORT Transform<ITK_TEMPLATE_3 TypeX> ) ) \ 00614 namespace Templates \ 00615 { \ 00616 typedef Transform<ITK_TEMPLATE_3 TypeX> Transform##TypeY; \ 00617 } \ 00618 } 00619 00620 #if ITK_TEMPLATE_EXPLICIT 00621 #include "Templates/itkTransform+-.h" 00622 #endif 00623 00624 #if ITK_TEMPLATE_TXX 00625 #include "itkTransform.hxx" 00626 #endif 00627 00628 #endif 00629