ITK
4.1.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 itkCloneMacro(Self); 00101 00103 unsigned int GetInputSpaceDimension(void) const 00104 { 00105 return NInputDimensions; 00106 } 00107 00109 unsigned int GetOutputSpaceDimension(void) const 00110 { 00111 return NOutputDimensions; 00112 } 00113 00115 typedef TScalarType ScalarType; 00116 00118 typedef typename Superclass::ParametersType ParametersType; 00119 typedef typename Superclass::ParametersValueType ParametersValueType; 00120 typedef Array<ParametersValueType> DerivativeType; 00121 00123 typedef Array2D<ParametersValueType> JacobianType; 00124 00126 typedef Vector<TScalarType, NInputDimensions> InputVectorType; 00127 typedef Vector<TScalarType, NOutputDimensions> OutputVectorType; 00128 00131 typedef VariableLengthVector<TScalarType> InputVectorPixelType; 00132 typedef VariableLengthVector<TScalarType> OutputVectorPixelType; 00133 00134 /* Standard symmetric second rank tenosr type for this class */ 00135 typedef SymmetricSecondRankTensor<TScalarType,NInputDimensions> 00136 InputSymmetricSecondRankTensorType; 00137 typedef SymmetricSecondRankTensor<TScalarType,NOutputDimensions> 00138 OutputSymmetricSecondRankTensorType; 00139 00140 /* Standard tensor type for this class */ 00141 typedef DiffusionTensor3D<TScalarType> InputDiffusionTensor3DType; 00142 typedef DiffusionTensor3D<TScalarType> OutputDiffusionTensor3DType; 00143 00145 typedef CovariantVector<TScalarType, NInputDimensions> 00146 InputCovariantVectorType; 00147 typedef CovariantVector<TScalarType, NOutputDimensions> 00148 OutputCovariantVectorType; 00149 00151 typedef vnl_vector_fixed<TScalarType, NInputDimensions> InputVnlVectorType; 00152 typedef vnl_vector_fixed<TScalarType, NOutputDimensions> 00153 OutputVnlVectorType; 00154 00156 typedef Point<TScalarType, NInputDimensions> InputPointType; 00157 typedef Point<TScalarType, NOutputDimensions> OutputPointType; 00158 00161 typedef Transform< 00162 TScalarType, NOutputDimensions, NInputDimensions> InverseTransformBaseType; 00163 00164 typedef typename InverseTransformBaseType::Pointer 00165 InverseTransformBasePointer; 00166 00167 typedef Matrix<TScalarType, 00168 itkGetStaticConstMacro(OutputSpaceDimension), 00169 itkGetStaticConstMacro(InputSpaceDimension)> MatrixType; 00170 00171 typedef Matrix<double, 00172 itkGetStaticConstMacro(OutputSpaceDimension), 00173 itkGetStaticConstMacro(OutputSpaceDimension)> 00174 OutputDirectionMatrix; 00175 typedef Matrix<double, 00176 itkGetStaticConstMacro(InputSpaceDimension), 00177 itkGetStaticConstMacro(InputSpaceDimension)> 00178 InputDirectionMatrix; 00179 typedef Matrix<double, 00180 itkGetStaticConstMacro(OutputSpaceDimension), 00181 itkGetStaticConstMacro(InputSpaceDimension)> 00182 DirectionChangeMatrix; 00183 00184 typedef Superclass::NumberOfParametersType NumberOfParametersType; 00185 00186 #if 0 00187 // this method is currently undocummented, untested and broken when input and output dimensions are 00188 // not the same 00189 void SetDirectionChange( const OutputDirectionMatrix fixedDir, const InputDirectionMatrix movingDir ); 00190 #endif 00191 00192 void SetDirectionChangeMatrix( const DirectionChangeMatrix & changeDir ) 00193 { 00194 m_DirectionChange = changeDir; this->Modified(); 00195 } 00196 00197 DirectionChangeMatrix GetDirectionChangeMatrix( void ) const 00198 { 00199 return m_DirectionChange; 00200 } 00201 00206 virtual OutputPointType TransformPoint(const InputPointType &) const = 0; 00207 00209 virtual OutputVectorType TransformVector(const InputVectorType &) const 00210 { 00211 itkExceptionMacro( "TransformVector(const InputVectorType &)" 00212 "is unimplemented for " << this->GetNameOfClass() ); 00213 } 00214 00219 virtual OutputVectorType TransformVector( 00220 const InputVectorType & vector, 00221 const InputPointType & point ) const; 00222 00224 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const 00225 { 00226 itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is " 00227 "unimplemented for " << this->GetNameOfClass() ); 00228 } 00229 00234 virtual OutputVnlVectorType TransformVector( 00235 const InputVnlVectorType & vector, 00236 const InputPointType & point ) const; 00237 00239 virtual OutputVectorPixelType TransformVector( 00240 const InputVectorPixelType & itkNotUsed(vector) ) const 00241 { 00242 itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is " 00243 "unimplemented for " << this->GetNameOfClass() ); 00244 } 00245 00250 virtual OutputVectorPixelType TransformVector( 00251 const InputVectorPixelType & vector, 00252 const InputPointType & point ) const; 00253 00255 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const 00256 { 00257 itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is " 00258 "unimplemented for " << this->GetNameOfClass() ); 00259 } 00260 00266 virtual OutputCovariantVectorType TransformCovariantVector( 00267 const InputCovariantVectorType & vector, 00268 const InputPointType & point ) const; 00269 00270 00272 virtual OutputVectorPixelType TransformCovariantVector( 00273 const InputVectorPixelType & itkNotUsed(vector) ) const 00274 { 00275 itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)" 00276 "is unimplemented for " << this->GetNameOfClass() ); 00277 } 00278 00284 virtual OutputVectorPixelType TransformCovariantVector( 00285 const InputVectorPixelType & vector, 00286 const InputPointType & point ) const; 00287 00289 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00290 const InputDiffusionTensor3DType & itkNotUsed(tensor) ) 00291 const 00292 { 00293 itkExceptionMacro( 00294 "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is " 00295 "unimplemented for " << this->GetNameOfClass() ); 00296 } 00297 00303 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00304 const InputDiffusionTensor3DType & tensor, 00305 const InputPointType & point ) const; 00306 00308 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00309 const InputVectorPixelType & itkNotUsed(tensor) ) const 00310 { 00311 itkExceptionMacro( 00312 "TransformDiffusionTensor( const InputVectorPixelType & ) is " 00313 "unimplemented for " << this->GetNameOfClass() ); 00314 } 00315 00316 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00317 const InputVectorPixelType & tensor, 00318 const InputPointType & point ) const; 00319 00325 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00326 const InputSymmetricSecondRankTensorType & tensor, 00327 const InputPointType & point ) const; 00328 00330 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00331 const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const 00332 { 00333 itkExceptionMacro( 00334 "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is " 00335 "unimplemented for " << this->GetNameOfClass() ); 00336 } 00337 00339 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00340 const InputVectorPixelType & itkNotUsed(tensor) ) const 00341 { 00342 itkExceptionMacro( 00343 "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is " 00344 "unimplemented for " << this->GetNameOfClass() ); 00345 } 00346 00353 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00354 const InputVectorPixelType & tensor, 00355 const InputPointType & point ) const; 00356 00364 virtual void SetParameters(const ParametersType &) = 0; 00365 00373 virtual void SetParametersByValue(const ParametersType & p) 00374 { 00375 this->SetParameters(p); 00376 } 00377 00379 virtual const ParametersType & GetParameters(void) const 00380 { 00381 return m_Parameters; 00382 } 00383 00385 virtual void SetFixedParameters(const ParametersType &) = 0; 00386 00388 virtual const ParametersType & GetFixedParameters(void) const 00389 { 00390 return m_FixedParameters; 00391 } 00392 00403 virtual void UpdateTransformParameters( DerivativeType & update, TScalarType factor = 1.0 ); 00404 00413 virtual NumberOfParametersType GetNumberOfLocalParameters(void) const 00414 { 00415 return this->GetNumberOfParameters(); 00416 } 00417 00419 virtual NumberOfParametersType GetNumberOfParameters(void) const 00420 { 00421 return this->m_Parameters.Size(); 00422 } 00423 00432 bool GetInverse( Self *itkNotUsed(inverseTransform) ) const 00433 { 00434 return false; 00435 } 00436 00443 virtual InverseTransformBasePointer GetInverseTransform() const 00444 { 00445 return NULL; 00446 } 00447 00449 virtual std::string GetTransformTypeAsString() const; 00450 00466 virtual bool IsLinear() const 00467 { 00468 return false; 00469 } 00470 00474 virtual bool HasLocalSupport() const 00475 { 00476 return false; 00477 } 00478 #ifdef ITKV3_COMPATIBILITY 00479 00491 virtual const JacobianType & GetJacobian(const InputPointType & x) const 00492 { 00493 this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian); 00494 return m_SharedLocalJacobian; 00495 } 00497 00498 #endif 00499 00534 virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const 00535 { 00536 itkExceptionMacro( 00537 "ComputeJacobianWithRespectToParamters( InputPointType, JacobianType" 00538 " is unimplemented for " << this->GetNameOfClass() ); 00539 } 00541 00542 00548 virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const 00549 { 00550 itkExceptionMacro( 00551 "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType" 00552 " is unimplemented for " << this->GetNameOfClass() ); 00553 } 00554 00555 00561 virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const; 00562 00563 protected: 00569 virtual typename LightObject::Pointer InternalClone() const; 00570 00571 Transform(); 00572 Transform(NumberOfParametersType NumberOfParameters); 00573 virtual ~Transform() 00574 { 00575 } 00576 00577 mutable ParametersType m_Parameters; 00578 mutable ParametersType m_FixedParameters; 00579 00580 OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation( 00581 const InputDiffusionTensor3DType, const JacobianType ) const; 00582 00583 #ifdef ITKV3_COMPATIBILITY 00584 // This is only needed to provide the old interface that returns a reference to the Jacobian. 00585 // It is NOT thread-safe and should be avoided whenever possible. 00586 mutable JacobianType m_SharedLocalJacobian; 00587 #endif 00588 00589 mutable DirectionChangeMatrix m_DirectionChange; 00590 private: 00591 Transform(const Self &); // purposely not implemented 00592 void operator=(const Self &); // purposely not implemented 00593 00594 template <typename TType> 00595 std::string GetTransformTypeAsString(TType *) const 00596 { 00597 std::string rval("other"); 00598 00599 return rval; 00600 } 00601 00602 std::string GetTransformTypeAsString(float *) const 00603 { 00604 std::string rval("float"); 00605 00606 return rval; 00607 } 00608 00609 std::string GetTransformTypeAsString(double *) const 00610 { 00611 std::string rval("double"); 00612 00613 return rval; 00614 } 00615 00616 }; 00617 } // end namespace itk 00618 00619 // Define instantiation macro for this template. 00620 #define ITK_TEMPLATE_Transform(_, EXPORT, TypeX, TypeY) \ 00621 namespace itk \ 00622 { \ 00623 _( 3 ( class EXPORT Transform<ITK_TEMPLATE_3 TypeX> ) ) \ 00624 namespace Templates \ 00625 { \ 00626 typedef Transform<ITK_TEMPLATE_3 TypeX> Transform##TypeY; \ 00627 } \ 00628 } 00629 00630 #if ITK_TEMPLATE_EXPLICIT 00631 #include "Templates/itkTransform+-.h" 00632 #endif 00633 00634 #if ITK_TEMPLATE_TXX 00635 #include "itkTransform.hxx" 00636 #endif 00637 00638 #endif 00639