/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ #ifndef __clitkMultipleBSplineDeformableTransform_h #define __clitkMultipleBSplineDeformableTransform_h #include #include #include namespace clitk { template < class TCoordRep = double, unsigned int NInputDimensions = 3, unsigned int NOutputDimensions = 3 > class ITK_EXPORT MultipleBSplineDeformableTransform : public itk::Transform< TCoordRep, NInputDimensions, NOutputDimensions > { public: //==================================================================== // Typedefs //==================================================================== typedef MultipleBSplineDeformableTransform Self; typedef itk::Transform Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; /** New macro for creation of through the object factory.*/ itkNewMacro( Self ); /** Run-time type information (and related methods). */ itkTypeMacro( MultipleBSplineDeformableTransform, Transform ); /** Dimension of the domain space. */ itkStaticConstMacro(OutputDimension, unsigned int, NOutputDimensions); /** Dimension of the input model. */ itkStaticConstMacro(InputDimension, unsigned int, NInputDimensions); /** Standard scalar type for this class. */ typedef typename Superclass::ScalarType ScalarType; /** Standard parameters container. */ typedef typename Superclass::ParametersType ParametersType; typedef typename Superclass::NumberOfParametersType NumberOfParametersType; /** Standard Jacobian container. */ typedef typename Superclass::JacobianType JacobianType; /** Standard vector type for this class. */ typedef itk::Vector InputVectorType; typedef itk::Vector OutputVectorType; /** Standard covariant vector type for this class. */ typedef itk::CovariantVector InputCovariantVectorType; typedef itk::CovariantVector OutputCovariantVectorType; /** Standard vnl_vector type for this class. */ typedef vnl_vector_fixed InputVnlVectorType; typedef vnl_vector_fixed OutputVnlVectorType; /** Standard coordinate point type for this class. */ typedef itk::Point InputPointType; typedef itk::Point OutputPointType; //JV Parameters as images with OutputDimension number of components per Pixel typedef typename ParametersType::ValueType ParametersValueType; typedef typename itk::Vector PixelType; typedef itk::Image CoefficientImageType; typedef typename CoefficientImageType::Pointer CoefficientImagePointer; /** Typedefs for specifying the extend to the grid. */ typedef itk::ImageRegion RegionType; typedef typename RegionType::IndexType IndexType; typedef typename RegionType::SizeType SizeType; typedef typename CoefficientImageType::SpacingType SpacingType; typedef typename CoefficientImageType::DirectionType DirectionType; typedef typename CoefficientImageType::PointType OriginType; typedef itk::ContinuousIndex ContinuousIndexType; /** Typedef of the bulk transform. */ typedef itk::Transform BulkTransformType; typedef BulkTransformType* BulkTransformPointer; typedef itk::Image< unsigned char, InputDimension> ImageLabelType; typedef ImageLabelType* ImageLabelPointer; //typedef typename ImageLabelType::Pointer ImageLabelPointer; typedef itk::NearestNeighborInterpolateImageFunction ImageLabelInterpolator; typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer; void SetLabels(ImageLabelPointer labels); ImageLabelPointer GetLabels() {return m_labels;} itkGetMacro(nLabels, unsigned); void SetSplineOrder(const unsigned int & splineOrder); void SetSplineOrders(const SizeType & splineOrders); /* itkGetMacro( SplineOrders, SizeType ); itkGetConstMacro( SplineOrders, SizeType ); */ void SetLUTSamplingFactor(const int & samplingFactor); void SetLUTSamplingFactors(const SizeType & samplingFactors); /* itkGetMacro( LUTSamplingFactors, SizeType ); itkGetConstMacro( LUTSamplingFactors,SizeType ); */ void SetParameters(const ParametersType & parameters); void SetFixedParameters(const ParametersType & parameters); void SetParametersByValue(const ParametersType & parameters); void SetIdentity(); /** Get the Transformation Parameters. */ virtual const ParametersType& GetParameters(void) const; /** Get the Transformation Fixed Parameters. */ virtual const ParametersType& GetFixedParameters(void) const; // The coefficientImage virtual const std::vector& GetCoefficientImages() const; virtual void SetCoefficientImages(std::vector& images); /** This method specifies the region over which the grid resides. */ virtual void SetGridRegion( const RegionType& region ); /* itkGetMacro( GridRegion, RegionType ); itkGetConstMacro( GridRegion, RegionType ); */ /** This method specifies the grid spacing or resolution. */ virtual void SetGridSpacing( const SpacingType& spacing ); /* itkGetMacro( GridSpacing, SpacingType ); itkGetConstMacro( GridSpacing, SpacingType ); */ /** This method specifies the grid directions . */ virtual void SetGridDirection( const DirectionType & spacing ); /* itkGetMacro( GridDirection, DirectionType ); itkGetConstMacro( GridDirection, DirectionType ); */ /** This method specifies the grid origin. */ virtual void SetGridOrigin( const OriginType& origin ); /* itkGetMacro( GridOrigin, OriginType ); itkGetConstMacro( GridOrigin, OriginType ); */ // Set the bulk transform, real pointer void SetBulkTransform(BulkTransformPointer b); BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;} /** Transform points by a BSpline deformable transformation. */ OutputPointType TransformPoint(const InputPointType &point ) const; // JV added for just the deformable part, without bulk OutputPointType DeformablyTransformPoint(const InputPointType &point ) const; /** Method to transform a vector - * not applicable for this type of transform. */ virtual OutputVectorType TransformVector(const InputVectorType &) const { itkExceptionMacro(<< "Method not applicable for deformable transform." ); return OutputVectorType(); } /** Method to transform a vnl_vector - * not applicable for this type of transform */ virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const { itkExceptionMacro(<< "Method not applicable for deformable transform. "); return OutputVnlVectorType(); } /** Method to transform a CovariantVector - * not applicable for this type of transform */ virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const { itkExceptionMacro(<< "Method not applicable for deformable transfrom. "); return OutputCovariantVectorType(); } /** Compute the Jacobian Matrix of the transformation at one point */ virtual void ComputeJacobianWithRespectToParameters (const InputPointType &p, JacobianType &jacobian) const; virtual void ComputeJacobianWithRespectToPosition (const InputPointType &p, JacobianType &jacobian) const { itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented for " << this->GetNameOfClass() ); } /** Return the number of parameters that completely define the Transfom */ virtual NumberOfParametersType GetNumberOfParameters(void) const; /** Return the number of parameters per dimension */ unsigned int GetNumberOfParametersPerDimension(void) const; virtual bool IsLinear() const { return false; } typedef clitk::BSplineDeformableTransform TransformType; const std::vector &GetTransforms() { return m_trans; } protected: void PrintSelf(std::ostream &os, itk::Indent indent) const; MultipleBSplineDeformableTransform(); virtual ~MultipleBSplineDeformableTransform(); void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const; private: MultipleBSplineDeformableTransform(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented /** The bulk transform. */ BulkTransformPointer m_BulkTransform; /** Jacobian as OutputDimension number of images. */ typedef typename JacobianType::ValueType JacobianValueType; typedef typename itk::Vector JacobianPixelType; typedef itk::Image JacobianImageType; typename JacobianImageType::Pointer m_JacobianImage[OutputDimension]; typedef itk::ImageRegionIterator IteratorType; /** Keep a pointer to the input parameters. */ const ParametersType * m_InputParametersPointer; /** Internal parameters buffer. */ ParametersType m_InternalParametersBuffer; unsigned int m_nLabels; ImageLabelPointer m_labels; ImageLabelInterpolatorPointer m_labelInterpolator; std::vector m_trans; std::vector m_parameters; mutable std::vector m_CoefficientImages; mutable int m_LastJacobian; mutable JacobianType m_SharedDataBSplineJacobian; void InitJacobian(); // FIXME it seems not used bool InsideValidRegion( const ContinuousIndexType& index ) const; }; } // namespace clitk #ifndef ITK_MANUAL_INSTANTIATION # include "clitkMultipleBSplineDeformableTransform.txx" #endif #endif // __clitkMultipleBSplineDeformableTransform_h