![]() |
ITK
4.2.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 00196 virtual OutputPointType TransformPoint(const InputPointType &) const = 0; 00197 00199 virtual OutputVectorType TransformVector(const InputVectorType &) const 00200 { 00201 itkExceptionMacro( "TransformVector(const InputVectorType &)" 00202 "is unimplemented for " << this->GetNameOfClass() ); 00203 } 00204 00209 virtual OutputVectorType TransformVector( 00210 const InputVectorType & vector, 00211 const InputPointType & point ) const; 00212 00214 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const 00215 { 00216 itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is " 00217 "unimplemented for " << this->GetNameOfClass() ); 00218 } 00219 00224 virtual OutputVnlVectorType TransformVector( 00225 const InputVnlVectorType & vector, 00226 const InputPointType & point ) const; 00227 00229 virtual OutputVectorPixelType TransformVector( 00230 const InputVectorPixelType & itkNotUsed(vector) ) const 00231 { 00232 itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is " 00233 "unimplemented for " << this->GetNameOfClass() ); 00234 } 00235 00240 virtual OutputVectorPixelType TransformVector( 00241 const InputVectorPixelType & vector, 00242 const InputPointType & point ) const; 00243 00245 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const 00246 { 00247 itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is " 00248 "unimplemented for " << this->GetNameOfClass() ); 00249 } 00250 00256 virtual OutputCovariantVectorType TransformCovariantVector( 00257 const InputCovariantVectorType & vector, 00258 const InputPointType & point ) const; 00259 00260 00262 virtual OutputVectorPixelType TransformCovariantVector( 00263 const InputVectorPixelType & itkNotUsed(vector) ) const 00264 { 00265 itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)" 00266 "is unimplemented for " << this->GetNameOfClass() ); 00267 } 00268 00274 virtual OutputVectorPixelType TransformCovariantVector( 00275 const InputVectorPixelType & vector, 00276 const InputPointType & point ) const; 00277 00279 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00280 const InputDiffusionTensor3DType & itkNotUsed(tensor) ) 00281 const 00282 { 00283 itkExceptionMacro( 00284 "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is " 00285 "unimplemented for " << this->GetNameOfClass() ); 00286 } 00287 00293 virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( 00294 const InputDiffusionTensor3DType & tensor, 00295 const InputPointType & point ) const; 00296 00298 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00299 const InputVectorPixelType & itkNotUsed(tensor) ) const 00300 { 00301 itkExceptionMacro( 00302 "TransformDiffusionTensor( const InputVectorPixelType & ) is " 00303 "unimplemented for " << this->GetNameOfClass() ); 00304 } 00305 00306 virtual OutputVectorPixelType TransformDiffusionTensor3D( 00307 const InputVectorPixelType & tensor, 00308 const InputPointType & point ) const; 00309 00315 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00316 const InputSymmetricSecondRankTensorType & tensor, 00317 const InputPointType & point ) const; 00318 00320 virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( 00321 const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const 00322 { 00323 itkExceptionMacro( 00324 "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is " 00325 "unimplemented for " << this->GetNameOfClass() ); 00326 } 00327 00329 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00330 const InputVectorPixelType & itkNotUsed(tensor) ) const 00331 { 00332 itkExceptionMacro( 00333 "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is " 00334 "unimplemented for " << this->GetNameOfClass() ); 00335 } 00336 00343 virtual OutputVectorPixelType TransformSymmetricSecondRankTensor( 00344 const InputVectorPixelType & tensor, 00345 const InputPointType & point ) const; 00346 00354 virtual void SetParameters(const ParametersType &) = 0; 00355 00363 virtual void SetParametersByValue(const ParametersType & p) 00364 { 00365 this->SetParameters(p); 00366 } 00367 00369 virtual const ParametersType & GetParameters(void) const 00370 { 00371 return m_Parameters; 00372 } 00373 00375 virtual void SetFixedParameters(const ParametersType &) = 0; 00376 00378 virtual const ParametersType & GetFixedParameters(void) const 00379 { 00380 return m_FixedParameters; 00381 } 00382 00393 virtual void UpdateTransformParameters( DerivativeType & update, TScalarType factor = 1.0 ); 00394 00403 virtual NumberOfParametersType GetNumberOfLocalParameters(void) const 00404 { 00405 return this->GetNumberOfParameters(); 00406 } 00407 00409 virtual NumberOfParametersType GetNumberOfParameters(void) const 00410 { 00411 return this->m_Parameters.Size(); 00412 } 00413 00422 bool GetInverse( Self *itkNotUsed(inverseTransform) ) const 00423 { 00424 return false; 00425 } 00426 00433 virtual InverseTransformBasePointer GetInverseTransform() const 00434 { 00435 return NULL; 00436 } 00437 00439 virtual std::string GetTransformTypeAsString() const; 00440 00456 virtual bool IsLinear() const 00457 { 00458 return false; 00459 } 00460 00464 virtual bool HasLocalSupport() const 00465 { 00466 return false; 00467 } 00468 #ifdef ITKV3_COMPATIBILITY 00469 00481 virtual const JacobianType & GetJacobian(const InputPointType & x) const 00482 { 00483 this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian); 00484 return m_SharedLocalJacobian; 00485 } 00487 00488 #endif 00489 00524 virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const 00525 { 00526 itkExceptionMacro( 00527 "ComputeJacobianWithRespectToParamters( InputPointType, JacobianType" 00528 " is unimplemented for " << this->GetNameOfClass() ); 00529 } 00531 00532 00538 virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const 00539 { 00540 itkExceptionMacro( 00541 "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType" 00542 " is unimplemented for " << this->GetNameOfClass() ); 00543 } 00544 00545 00551 virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const; 00552 00553 protected: 00559 virtual typename LightObject::Pointer InternalClone() const; 00560 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
1.7.6.1