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 __itkBSplineBaseTransform_h 00019 #define __itkBSplineBaseTransform_h 00020 00021 #include <iostream> 00022 #include "itkTransform.h" 00023 #include "itkImage.h" 00024 #include "itkBSplineInterpolationWeightFunction.h" 00025 00026 namespace itk 00027 { 00033 template <class TScalarType = double, unsigned int NDimensions = 3, 00034 unsigned int VSplineOrder = 3> 00035 class ITK_EXPORT BSplineBaseTransform : 00036 public Transform<TScalarType, NDimensions, NDimensions> 00037 { 00038 public: 00040 typedef BSplineBaseTransform Self; 00041 typedef Transform<TScalarType, NDimensions, NDimensions> Superclass; 00042 typedef SmartPointer<Self> Pointer; 00043 typedef SmartPointer<const Self> ConstPointer; 00044 00046 itkTypeMacro( BSplineBaseTransform, Transform ); 00047 00049 itkStaticConstMacro( SpaceDimension, unsigned int, NDimensions ); 00050 00052 itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder ); 00053 00055 itkCloneMacro(Self); 00056 00058 typedef typename Superclass::ScalarType ScalarType; 00059 00061 typedef typename Superclass::ParametersType ParametersType; 00062 00064 typedef typename Superclass::JacobianType JacobianType; 00065 00067 typedef typename Superclass::NumberOfParametersType NumberOfParametersType; 00068 00070 typedef Vector<TScalarType, itkGetStaticConstMacro( SpaceDimension )> InputVectorType; 00071 typedef Vector<TScalarType, itkGetStaticConstMacro( SpaceDimension )> OutputVectorType; 00073 00075 typedef CovariantVector<TScalarType, itkGetStaticConstMacro( SpaceDimension )> InputCovariantVectorType; 00076 typedef CovariantVector<TScalarType, itkGetStaticConstMacro( SpaceDimension )> OutputCovariantVectorType; 00078 00080 typedef vnl_vector_fixed<TScalarType, SpaceDimension> InputVnlVectorType; 00081 typedef vnl_vector_fixed<TScalarType, SpaceDimension> OutputVnlVectorType; 00082 00084 typedef Point <TScalarType, itkGetStaticConstMacro( SpaceDimension )> InputPointType; 00085 typedef Point <TScalarType, itkGetStaticConstMacro( SpaceDimension )> OutputPointType; 00087 00107 void SetParameters( const ParametersType & parameters ); 00108 00131 virtual void SetFixedParameters( const ParametersType & parameters ) = 0; 00133 00150 void SetParametersByValue( const ParametersType & parameters ); 00151 00160 void SetIdentity(); 00161 00163 virtual const ParametersType & GetParameters() const; 00164 00166 virtual const ParametersType & GetFixedParameters() const; 00167 00169 typedef typename ParametersType::ValueType ParametersValueType; 00170 typedef Image<ParametersValueType, itkGetStaticConstMacro( SpaceDimension )> ImageType; 00171 typedef typename ImageType::Pointer ImagePointer; 00172 typedef FixedArray<ImagePointer, NDimensions> CoefficientImageArray; 00173 00185 virtual void SetCoefficientImages( const CoefficientImageArray & images ) = 0; 00186 00188 const CoefficientImageArray GetCoefficientImages() const 00189 { 00190 return this->m_CoefficientImages; 00191 } 00192 00193 typedef typename Superclass::DerivativeType DerivativeType; 00194 00205 virtual void UpdateTransformParameters( DerivativeType & update, TScalarType factor = 1.0 ); 00206 00208 typedef ImageRegion<itkGetStaticConstMacro( SpaceDimension )> RegionType; 00209 00210 typedef typename RegionType::IndexType IndexType; 00211 typedef typename RegionType::SizeType SizeType; 00212 typedef typename ImageType::SpacingType SpacingType; 00213 typedef typename ImageType::DirectionType DirectionType; 00214 typedef typename ImageType::PointType OriginType; 00215 00217 OutputPointType TransformPoint( const InputPointType & point ) const; 00218 00220 typedef BSplineInterpolationWeightFunction<ScalarType, 00221 itkGetStaticConstMacro( SpaceDimension ), 00222 itkGetStaticConstMacro( SplineOrder )> WeightsFunctionType; 00223 00224 typedef typename WeightsFunctionType::WeightsType WeightsType; 00225 typedef typename WeightsFunctionType::ContinuousIndexType ContinuousIndexType; 00226 00228 typedef Array<unsigned long> ParameterIndexArrayType; 00229 00238 virtual void TransformPoint( const InputPointType & inputPoint, OutputPointType & outputPoint, 00239 WeightsType & weights, ParameterIndexArrayType & indices, bool & inside ) const = 0; 00240 00242 unsigned long GetNumberOfWeights() const 00243 { 00244 return m_WeightsFunction->GetNumberOfWeights(); 00245 } 00246 00249 using Superclass::TransformVector; 00250 virtual OutputVectorType TransformVector( const InputVectorType & ) const 00251 { 00252 itkExceptionMacro( << "Method not applicable for deformable transform." ); 00253 return OutputVectorType(); 00254 } 00256 00259 virtual OutputVnlVectorType TransformVector( const InputVnlVectorType & ) const 00260 { 00261 itkExceptionMacro( << "Method not applicable for deformable transform. " ); 00262 return OutputVnlVectorType(); 00263 } 00265 00268 using Superclass::TransformCovariantVector; 00269 virtual OutputCovariantVectorType TransformCovariantVector( 00270 const InputCovariantVectorType & ) const 00271 { 00272 itkExceptionMacro( << "Method not applicable for deformable transfrom. " ); 00273 return OutputCovariantVectorType(); 00274 } 00276 00278 void ComputeJacobianFromBSplineWeightsWithRespectToPosition( 00279 const InputPointType &, WeightsType &, ParameterIndexArrayType & ) const; 00280 00281 virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const = 0; 00282 00283 virtual void ComputeJacobianWithRespectToPosition( const InputPointType &, JacobianType & ) const 00284 { 00285 itkExceptionMacro( << "ComputeJacobianWithRespectToPosition not yet implemented " 00286 "for " << this->GetNameOfClass() ); 00287 } 00288 00290 virtual NumberOfParametersType GetNumberOfParameters() const = 0; 00291 00293 virtual NumberOfParametersType GetNumberOfParametersPerDimension() const = 0; 00294 00300 virtual bool IsLinear() const 00301 { 00302 return false; 00303 } 00304 00305 unsigned int GetNumberOfAffectedWeights() const; 00306 00307 typedef typename ImageType::SpacingType PhysicalDimensionsType; 00308 typedef typename ImageType::PixelType PixelType; 00309 00310 typedef SizeType MeshSizeType; 00311 00312 00313 protected: 00315 void PrintSelf( std::ostream & os, Indent indent ) const; 00316 00317 BSplineBaseTransform(); 00318 virtual ~BSplineBaseTransform(); 00319 00321 itkSetObjectMacro( WeightsFunction, WeightsFunctionType ); 00322 00324 itkGetObjectMacro( WeightsFunction, WeightsFunctionType ); 00325 00327 void WrapAsImages(); 00328 00329 protected: 00331 void SetFixedParametersFromTransformDomainInformation() const; 00332 00334 virtual void SetFixedParametersGridSizeFromTransformDomainInformation() const = 0; 00335 00337 virtual void SetFixedParametersGridOriginFromTransformDomainInformation() const = 0; 00338 00340 virtual void SetFixedParametersGridSpacingFromTransformDomainInformation() const = 0; 00341 00343 virtual void SetFixedParametersGridDirectionFromTransformDomainInformation() const = 0; 00344 00346 virtual void SetCoefficientImageInformationFromFixedParameters() =0; 00347 00349 virtual bool InsideValidRegion( ContinuousIndexType & ) const = 0; 00350 00351 // NOTE: There is a natural duality between the 00352 // two representations of of the coefficients 00353 // whereby the m_InternalParametersBuffer is 00354 // needed to fit into the optimization framework 00355 // and the m_CoefficientImages is needed for 00356 // the Jacobian computations. This implementation 00357 // is an attempt to remove as much redundancy as possible 00358 // and share as much information between the two 00359 // instances as possible. 00360 // 00365 CoefficientImageArray m_CoefficientImages; 00366 00368 const ParametersType *m_InputParametersPointer; 00369 00371 ParametersType m_InternalParametersBuffer; 00372 00373 00375 typename WeightsFunctionType::Pointer m_WeightsFunction; 00376 00377 private: 00378 BSplineBaseTransform( const Self & ); // purposely not implemented 00379 void operator=( const Self & ); // purposely not implemented 00380 00381 CoefficientImageArray ArrayOfImagePointerGeneratorHelper() const; 00382 }; // class BSplineBaseTransform 00383 } // namespace itk 00384 00385 // Define instantiation macro for this template. 00386 #define ITK_TEMPLATE_BSplineBaseTransform(_, EXPORT, TypeX, TypeY) \ 00387 namespace itk \ 00388 { \ 00389 _( 3 ( class EXPORT BSplineBaseTransform<ITK_TEMPLATE_3 TypeX> ) ) \ 00390 namespace Templates \ 00391 { \ 00392 typedef BSplineBaseTransform<ITK_TEMPLATE_3 TypeX> \ 00393 BSplineBaseTransform##TypeY; \ 00394 } \ 00395 } 00396 00397 #if ITK_TEMPLATE_EXPLICIT 00398 // template < class TScalarType, unsigned int NDimensions, unsigned int 00399 // VSplineOrder > 00400 // const unsigned int itk::BSplineBaseTransform<TScalarType, 00401 // NDimensions, VSplineOrder >::SpaceDimension; 00402 // template < class TScalarType, unsigned int NDimensions, unsigned int 00403 // VSplineOrder > 00404 // const unsigned int itk::BSplineBaseTransform<TScalarType, 00405 // NDimensions, VSplineOrder >::SplineOrder; 00406 #include "Templates/itkBSplineBaseTransform+-.h" 00407 #endif 00408 00409 #if ITK_TEMPLATE_TXX 00410 #include "itkBSplineBaseTransform.hxx" 00411 #endif 00412 00413 #endif /* __itkBSplineBaseTransform_h */ 00414