1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef __clitkMultipleBSplineDeformableTransform_h
19 #define __clitkMultipleBSplineDeformableTransform_h
21 #include <clitkBSplineDeformableTransform.h>
23 #include <itkNearestNeighborInterpolateImageFunction.h>
30 class TCoordRep = double,
31 unsigned int NInputDimensions = 3,
32 unsigned int NOutputDimensions = 3 >
33 class ITK_EXPORT MultipleBSplineDeformableTransform : public itk::Transform< TCoordRep, NInputDimensions, NOutputDimensions >
37 //====================================================================
39 //====================================================================
40 typedef MultipleBSplineDeformableTransform<TCoordRep, NInputDimensions, NOutputDimensions> Self;
41 typedef itk::Transform<TCoordRep, NInputDimensions, NOutputDimensions> Superclass;
42 typedef itk::SmartPointer<Self> Pointer;
43 typedef itk::SmartPointer<const Self> ConstPointer;
45 /** New macro for creation of through the object factory.*/
48 /** Run-time type information (and related methods). */
49 itkTypeMacro( MultipleBSplineDeformableTransform, Transform );
51 /** Dimension of the domain space. */
52 itkStaticConstMacro(OutputDimension, unsigned int, NOutputDimensions);
54 /** Dimension of the input model. */
55 itkStaticConstMacro(InputDimension, unsigned int, NInputDimensions);
57 /** Standard scalar type for this class. */
58 typedef typename Superclass::ScalarType ScalarType;
60 /** Standard parameters container. */
61 typedef typename Superclass::ParametersType ParametersType;
62 #if ITK_VERSION_MAJOR >= 4
63 typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
66 /** Standard Jacobian container. */
67 typedef typename Superclass::JacobianType JacobianType;
69 /** Standard vector type for this class. */
70 typedef itk::Vector<TCoordRep,
71 InputDimension> InputVectorType;
72 typedef itk::Vector<TCoordRep,
73 OutputDimension> OutputVectorType;
75 /** Standard covariant vector type for this class. */
76 typedef itk::CovariantVector<TCoordRep,
77 InputDimension> InputCovariantVectorType;
78 typedef itk::CovariantVector<TCoordRep,
79 OutputDimension> OutputCovariantVectorType;
81 /** Standard vnl_vector type for this class. */
82 typedef vnl_vector_fixed<TCoordRep,
83 InputDimension> InputVnlVectorType;
84 typedef vnl_vector_fixed<TCoordRep,
85 OutputDimension> OutputVnlVectorType;
87 /** Standard coordinate point type for this class. */
88 typedef itk::Point<TCoordRep,
89 InputDimension> InputPointType;
90 typedef itk::Point<TCoordRep,
91 OutputDimension> OutputPointType;
93 //JV Parameters as images with OutputDimension number of components per Pixel
94 typedef typename ParametersType::ValueType ParametersValueType;
95 typedef typename itk::Vector<ParametersValueType, OutputDimension> PixelType;
96 typedef itk::Image<PixelType, InputDimension> CoefficientImageType;
97 typedef typename CoefficientImageType::Pointer CoefficientImagePointer;
99 /** Typedefs for specifying the extend to the grid. */
100 typedef itk::ImageRegion<InputDimension> RegionType;
101 typedef typename RegionType::IndexType IndexType;
102 typedef typename RegionType::SizeType SizeType;
103 typedef typename CoefficientImageType::SpacingType SpacingType;
104 typedef typename CoefficientImageType::DirectionType DirectionType;
105 typedef typename CoefficientImageType::PointType OriginType;
106 typedef itk::ContinuousIndex<TCoordRep, InputDimension> ContinuousIndexType;
108 /** Typedef of the bulk transform. */
109 typedef itk::Transform<ScalarType, InputDimension, OutputDimension> BulkTransformType;
110 typedef BulkTransformType* BulkTransformPointer;
112 typedef itk::Image< unsigned char, InputDimension> ImageLabelType;
113 typedef ImageLabelType* ImageLabelPointer;
114 //typedef typename ImageLabelType::Pointer ImageLabelPointer;
116 typedef itk::NearestNeighborInterpolateImageFunction<ImageLabelType, TCoordRep> ImageLabelInterpolator;
117 typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer;
119 void SetLabels(ImageLabelPointer labels);
120 ImageLabelPointer GetLabels() {return m_labels;}
122 itkGetMacro(nLabels, unsigned);
124 void SetSplineOrder(const unsigned int & splineOrder);
125 void SetSplineOrders(const SizeType & splineOrders);
127 itkGetMacro( SplineOrders, SizeType );
128 itkGetConstMacro( SplineOrders, SizeType );
131 void SetLUTSamplingFactor(const int & samplingFactor);
132 void SetLUTSamplingFactors(const SizeType & samplingFactors);
134 itkGetMacro( LUTSamplingFactors, SizeType );
135 itkGetConstMacro( LUTSamplingFactors,SizeType );
138 void SetParameters(const ParametersType & parameters);
140 void SetFixedParameters(const ParametersType & parameters);
142 void SetParametersByValue(const ParametersType & parameters);
146 /** Get the Transformation Parameters. */
147 virtual const ParametersType& GetParameters(void) const;
149 /** Get the Transformation Fixed Parameters. */
150 virtual const ParametersType& GetFixedParameters(void) const;
152 // The coefficientImage
153 virtual const std::vector<CoefficientImagePointer>& GetCoefficientImages() const;
154 virtual void SetCoefficientImages(std::vector<CoefficientImagePointer>& images);
156 /** This method specifies the region over which the grid resides. */
157 virtual void SetGridRegion( const RegionType& region );
159 itkGetMacro( GridRegion, RegionType );
160 itkGetConstMacro( GridRegion, RegionType );
163 /** This method specifies the grid spacing or resolution. */
164 virtual void SetGridSpacing( const SpacingType& spacing );
166 itkGetMacro( GridSpacing, SpacingType );
167 itkGetConstMacro( GridSpacing, SpacingType );
170 /** This method specifies the grid directions . */
171 virtual void SetGridDirection( const DirectionType & spacing );
173 itkGetMacro( GridDirection, DirectionType );
174 itkGetConstMacro( GridDirection, DirectionType );
177 /** This method specifies the grid origin. */
178 virtual void SetGridOrigin( const OriginType& origin );
180 itkGetMacro( GridOrigin, OriginType );
181 itkGetConstMacro( GridOrigin, OriginType );
184 // Set the bulk transform, real pointer
185 void SetBulkTransform(BulkTransformPointer b);
186 BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;}
188 /** Transform points by a BSpline deformable transformation. */
189 OutputPointType TransformPoint(const InputPointType &point ) const;
191 // JV added for just the deformable part, without bulk
192 OutputPointType DeformablyTransformPoint(const InputPointType &point ) const;
194 /** Method to transform a vector -
195 * not applicable for this type of transform. */
196 virtual OutputVectorType TransformVector(const InputVectorType &) const
198 itkExceptionMacro(<< "Method not applicable for deformable transform." );
199 return OutputVectorType();
202 /** Method to transform a vnl_vector -
203 * not applicable for this type of transform */
204 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
206 itkExceptionMacro(<< "Method not applicable for deformable transform. ");
207 return OutputVnlVectorType();
210 /** Method to transform a CovariantVector -
211 * not applicable for this type of transform */
212 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
214 itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
215 return OutputCovariantVectorType();
218 /** Compute the Jacobian Matrix of the transformation at one point */
219 #if ITK_VERSION_MAJOR >= 4
220 virtual void ComputeJacobianWithRespectToParameters (const InputPointType &p, JacobianType &jacobian) const;
221 virtual void ComputeJacobianWithRespectToPosition (const InputPointType &p, JacobianType &jacobian) const
223 itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented for " << this->GetNameOfClass() );
226 virtual const JacobianType& GetJacobian(const InputPointType &point ) const;
229 /** Return the number of parameters that completely define the Transfom */
230 #if ITK_VERSION_MAJOR >= 4
231 virtual NumberOfParametersType GetNumberOfParameters(void) const;
233 virtual unsigned int GetNumberOfParameters(void) const;
236 /** Return the number of parameters per dimension */
237 unsigned int GetNumberOfParametersPerDimension(void) const;
239 virtual bool IsLinear() const { return false; }
241 typedef clitk::BSplineDeformableTransform<TCoordRep,InputDimension, OutputDimension > TransformType;
243 const std::vector<typename TransformType::Pointer> &GetTransforms() { return m_trans; }
247 void PrintSelf(std::ostream &os, itk::Indent indent) const;
249 MultipleBSplineDeformableTransform();
250 virtual ~MultipleBSplineDeformableTransform();
252 void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const;
255 MultipleBSplineDeformableTransform(const Self&); //purposely not implemented
256 void operator=(const Self&); //purposely not implemented
258 /** The bulk transform. */
259 BulkTransformPointer m_BulkTransform;
261 /** Jacobian as OutputDimension number of images. */
262 typedef typename JacobianType::ValueType JacobianValueType;
263 typedef typename itk::Vector<JacobianValueType,OutputDimension> JacobianPixelType;
264 typedef itk::Image<JacobianPixelType, OutputDimension> JacobianImageType;
265 typename JacobianImageType::Pointer m_JacobianImage[OutputDimension];
266 typedef itk::ImageRegionIterator<JacobianImageType> IteratorType;
268 /** Keep a pointer to the input parameters. */
269 const ParametersType * m_InputParametersPointer;
271 /** Internal parameters buffer. */
272 ParametersType m_InternalParametersBuffer;
274 unsigned int m_nLabels;
275 ImageLabelPointer m_labels;
276 ImageLabelInterpolatorPointer m_labelInterpolator;
277 std::vector<typename TransformType::Pointer> m_trans;
278 std::vector<ParametersType> m_parameters;
279 mutable std::vector<CoefficientImagePointer> m_CoefficientImages;
280 mutable int m_LastJacobian;
281 #if ITK_VERSION_MAJOR >= 4
282 mutable JacobianType m_SharedDataBSplineJacobian;
286 // FIXME it seems not used
287 bool InsideValidRegion( const ContinuousIndexType& index ) const;
293 # include "clitkMultipleBSplineDeformableTransform.txx"
296 #endif // __clitkMultipleBSplineDeformableTransform_h