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 __itkDisplacementFieldTransform_h 00019 #define __itkDisplacementFieldTransform_h 00020 00021 #include "itkTransform.h" 00022 00023 #include "itkImage.h" 00024 #include "itkMatrixOffsetTransformBase.h" 00025 #include "itkImageVectorOptimizerParametersHelper.h" 00026 #include "itkVectorInterpolateImageFunction.h" 00027 00028 namespace itk 00029 { 00030 00085 template 00086 <class TScalar, unsigned int NDimensions> 00087 class ITK_EXPORT DisplacementFieldTransform : 00088 public Transform<TScalar, NDimensions, NDimensions> 00089 { 00090 public: 00092 typedef DisplacementFieldTransform Self; 00093 typedef Transform<TScalar, NDimensions, NDimensions> Superclass; 00094 typedef SmartPointer<Self> Pointer; 00095 typedef SmartPointer<const Self> ConstPointer; 00096 00098 itkTypeMacro( DisplacementFieldTransform, Transform ); 00099 00101 itkNewMacro( Self ); 00102 00104 typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer; 00105 00107 typedef typename Superclass::ScalarType ScalarType; 00108 00110 typedef typename Superclass::ParametersType ParametersType; 00111 typedef typename Superclass::ParametersValueType ParametersValueType; 00112 00114 typedef typename Superclass::JacobianType JacobianType; 00115 00117 typedef typename Superclass::NumberOfParametersType NumberOfParametersType; 00118 00120 typedef typename Superclass::InputPointType InputPointType; 00121 typedef typename Superclass::OutputPointType OutputPointType; 00122 00124 typedef typename Superclass::InputVectorType InputVectorType; 00125 typedef typename Superclass::OutputVectorType OutputVectorType; 00126 00127 typedef typename Superclass::InputVectorPixelType InputVectorPixelType; 00128 typedef typename Superclass::OutputVectorPixelType OutputVectorPixelType; 00129 00131 typedef typename Superclass::InputCovariantVectorType 00132 InputCovariantVectorType; 00133 typedef typename Superclass::OutputCovariantVectorType 00134 OutputCovariantVectorType; 00135 00137 typedef typename Superclass::InputVnlVectorType InputVnlVectorType; 00138 typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType; 00139 00141 typedef typename Superclass::InputDiffusionTensor3DType 00142 InputDiffusionTensor3DType; 00143 typedef typename Superclass::OutputDiffusionTensor3DType 00144 OutputDiffusionTensor3DType; 00145 00147 typedef CovariantVector<ScalarType, InputDiffusionTensor3DType::Dimension> 00148 InputTensorEigenVectorType; 00149 typedef CovariantVector<ScalarType, OutputDiffusionTensor3DType::Dimension> 00150 OutputTensorEigenVectorType; 00151 00153 typedef typename Superclass::DerivativeType DerivativeType; 00154 00156 itkStaticConstMacro( Dimension, unsigned int, NDimensions ); 00157 00159 typedef Image<OutputVectorType, Dimension> DisplacementFieldType; 00160 typedef typename DisplacementFieldType::Pointer DisplacementFieldPointer; 00161 00162 typedef VectorInterpolateImageFunction 00163 <DisplacementFieldType, ScalarType> InterpolatorType; 00164 00166 typedef typename DisplacementFieldType::IndexType IndexType; 00167 typedef typename DisplacementFieldType::RegionType RegionType; 00168 typedef typename DisplacementFieldType::SizeType SizeType; 00169 typedef typename DisplacementFieldType::SpacingType SpacingType; 00170 typedef typename DisplacementFieldType::DirectionType DirectionType; 00171 typedef typename DisplacementFieldType::PointType PointType; 00172 typedef typename DisplacementFieldType::PixelType PixelType; 00173 00175 typedef ImageVectorOptimizerParametersHelper< 00176 ScalarType, 00177 OutputVectorType::Dimension, 00178 Dimension> 00179 OptimizerParametersHelperType; 00180 00182 itkGetObjectMacro( DisplacementField, DisplacementFieldType ); 00183 00187 virtual void SetDisplacementField( DisplacementFieldType* field ); 00188 00190 itkGetObjectMacro( InverseDisplacementField, DisplacementFieldType ); 00191 virtual void SetInverseDisplacementField( DisplacementFieldType * inverseDisplacementField ); 00193 00195 itkGetObjectMacro( Interpolator, InterpolatorType ); 00196 /* Create out own set accessor that assigns the displacement field */ 00197 virtual void SetInterpolator( InterpolatorType* interpolator ); 00199 00201 itkGetConstReferenceMacro( DisplacementFieldSetTime, unsigned long ); 00202 00205 virtual OutputPointType TransformPoint( const InputPointType& thisPoint ) 00206 const; 00207 00209 using Superclass::TransformVector; 00210 virtual OutputVectorType TransformVector(const InputVectorType &) const 00211 { 00212 itkExceptionMacro( "TransformVector(Vector) unimplemented, use " 00213 "TransformVector(Vector,Point)" ); 00214 } 00216 00217 virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) 00218 const 00219 { 00220 itkExceptionMacro( "TransformVector(Vector) unimplemented, use " 00221 "TransformVector(Vector,Point)" ); 00222 } 00223 00224 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const 00225 { 00226 itkExceptionMacro( "TransformVector(Vector) unimplemented, use " 00227 "TransformVector(Vector,Point)" ); 00228 } 00229 00231 using Superclass::TransformDiffusionTensor3D; 00232 OutputDiffusionTensor3DType TransformDiffusionTensor( 00233 const InputDiffusionTensor3DType & ) const 00234 { 00235 itkExceptionMacro( "TransformDiffusionTensor(Tensor) unimplemented, use " 00236 "TransformDiffusionTensor(Tensor,Point)" ); 00237 } 00239 00240 OutputVectorPixelType TransformDiffusionTensor(const InputVectorPixelType & ) 00241 const 00242 { 00243 itkExceptionMacro( "TransformDiffusionTensor(Tensor) unimplemented, use " 00244 "TransformDiffusionTensor(Tensor,Point)" ); 00245 } 00246 00248 using Superclass::TransformCovariantVector; 00249 virtual OutputCovariantVectorType TransformCovariantVector( 00250 const InputCovariantVectorType &) const 00251 { 00252 itkExceptionMacro( "TransformCovariantVector(CovariantVector) " 00253 "unimplemented, use TransformCovariantVector(CovariantVector,Point)" ); 00254 } 00256 00257 virtual OutputVectorPixelType TransformCovariantVector( 00258 const InputVectorPixelType &) const 00259 { 00260 itkExceptionMacro( "TransformCovariantVector(CovariantVector) " 00261 "unimplemented, use TransformCovariantVector(CovariantVector,Point)" ); 00262 } 00263 00266 virtual void SetParameters(const ParametersType & params) 00267 { 00268 if( &(this->m_Parameters) != ¶ms ) 00269 { 00270 if( params.Size() != this->m_Parameters.Size() ) 00271 { 00272 itkExceptionMacro("Input parameters size (" << params.Size() 00273 << ") does not match internal size (" 00274 << this->m_Parameters.Size() << ")."); 00275 } 00276 /* copy into existing object */ 00277 this->m_Parameters = params; 00278 this->Modified(); 00279 } 00280 } 00282 00292 virtual void SetFixedParameters( const ParametersType & ); 00293 00315 virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, 00316 JacobianType & j) const 00317 { 00318 j = this->m_IdentityJacobian; 00319 } 00321 00328 virtual void ComputeJacobianWithRespectToParameters(const IndexType &, 00329 JacobianType & j) const 00330 { 00331 j = this->m_IdentityJacobian; 00332 } 00333 00338 virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & j ) const; 00339 00344 virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & j ) const; 00345 00350 virtual void ComputeJacobianWithRespectToPosition(const IndexType & x, JacobianType & j ) const; 00351 00363 virtual void GetInverseJacobianOfForwardFieldWithRespectToPosition(const InputPointType & point, 00364 JacobianType & jacobian, 00365 bool useSVD = false ) 00366 const; 00367 00379 virtual void GetInverseJacobianOfForwardFieldWithRespectToPosition(const IndexType & index, JacobianType & jacobian, 00380 bool useSVD = false ) 00381 const; 00382 00383 virtual void UpdateTransformParameters( DerivativeType & update, ScalarType factor = 1.0 ); 00384 00386 bool GetInverse( Self *inverse ) const; 00387 00389 virtual InverseTransformBasePointer GetInverseTransform() const; 00390 00392 virtual bool IsLinear() const 00393 { 00394 return false; 00395 } 00396 00397 virtual NumberOfParametersType GetNumberOfLocalParameters(void) const 00398 { 00399 return Dimension; 00400 } 00401 00402 virtual bool HasLocalSupport() const 00403 { 00404 return true; 00405 } 00406 00407 protected: 00408 00409 DisplacementFieldTransform(); 00410 virtual ~DisplacementFieldTransform(); 00411 void PrintSelf( std::ostream& os, Indent indent ) const; 00412 00414 typename DisplacementFieldType::Pointer m_DisplacementField; 00415 typename DisplacementFieldType::Pointer m_InverseDisplacementField; 00416 00418 typename InterpolatorType::Pointer m_Interpolator; 00419 00422 unsigned long m_DisplacementFieldSetTime; 00423 00426 JacobianType m_IdentityJacobian; 00427 private: 00428 DisplacementFieldTransform( const Self & ); // purposely not implemented 00429 void operator=( const Self & ); // purposely not implemented 00431 00440 virtual void ComputeJacobianWithRespectToPositionInternal(const IndexType & index, JacobianType & jacobian, 00441 bool doInverseJacobian) const; 00442 00447 virtual void VerifyFixedParametersInformation(); 00448 00453 virtual void SetFixedParametersFromDisplacementField() const; 00454 00455 }; 00456 00457 } // end namespace itk 00458 00459 #if ITK_TEMPLATE_EXPLICIT 00460 #include "Templates/itkDisplacementFieldTransform+-.h" 00461 #endif 00462 00463 #if ITK_TEMPLATE_TXX 00464 #include "itkDisplacementFieldTransform.hxx" 00465 #endif 00466 00467 #endif // __itkDisplacementFieldTransform_h 00468