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 typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
64 /** Standard Jacobian container. */
65 typedef typename Superclass::JacobianType JacobianType;
67 /** Standard vector type for this class. */
68 typedef itk::Vector<TCoordRep,
69 InputDimension> InputVectorType;
70 typedef itk::Vector<TCoordRep,
71 OutputDimension> OutputVectorType;
73 /** Standard covariant vector type for this class. */
74 typedef itk::CovariantVector<TCoordRep,
75 InputDimension> InputCovariantVectorType;
76 typedef itk::CovariantVector<TCoordRep,
77 OutputDimension> OutputCovariantVectorType;
79 /** Standard vnl_vector type for this class. */
80 typedef vnl_vector_fixed<TCoordRep,
81 InputDimension> InputVnlVectorType;
82 typedef vnl_vector_fixed<TCoordRep,
83 OutputDimension> OutputVnlVectorType;
85 /** Standard coordinate point type for this class. */
86 typedef itk::Point<TCoordRep,
87 InputDimension> InputPointType;
88 typedef itk::Point<TCoordRep,
89 OutputDimension> OutputPointType;
91 //JV Parameters as images with OutputDimension number of components per Pixel
92 typedef typename ParametersType::ValueType ParametersValueType;
93 typedef typename itk::Vector<ParametersValueType, OutputDimension> PixelType;
94 typedef itk::Image<PixelType, InputDimension> CoefficientImageType;
95 typedef typename CoefficientImageType::Pointer CoefficientImagePointer;
97 /** Typedefs for specifying the extend to the grid. */
98 typedef itk::ImageRegion<InputDimension> RegionType;
99 typedef typename RegionType::IndexType IndexType;
100 typedef typename RegionType::SizeType SizeType;
101 typedef typename CoefficientImageType::SpacingType SpacingType;
102 typedef typename CoefficientImageType::DirectionType DirectionType;
103 typedef typename CoefficientImageType::PointType OriginType;
104 typedef itk::ContinuousIndex<TCoordRep, InputDimension> ContinuousIndexType;
106 /** Typedef of the bulk transform. */
107 typedef itk::Transform<ScalarType, InputDimension, OutputDimension> BulkTransformType;
108 typedef BulkTransformType* BulkTransformPointer;
110 typedef itk::Image< unsigned char, InputDimension> ImageLabelType;
111 typedef ImageLabelType* ImageLabelPointer;
112 //typedef typename ImageLabelType::Pointer ImageLabelPointer;
114 typedef itk::NearestNeighborInterpolateImageFunction<ImageLabelType, TCoordRep> ImageLabelInterpolator;
115 typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer;
117 void SetLabels(ImageLabelPointer labels);
118 ImageLabelPointer GetLabels() {return m_labels;}
120 itkGetMacro(nLabels, unsigned);
122 void SetSplineOrder(const unsigned int & splineOrder);
123 void SetSplineOrders(const SizeType & splineOrders);
125 itkGetMacro( SplineOrders, SizeType );
126 itkGetConstMacro( SplineOrders, SizeType );
129 void SetLUTSamplingFactor(const int & samplingFactor);
130 void SetLUTSamplingFactors(const SizeType & samplingFactors);
132 itkGetMacro( LUTSamplingFactors, SizeType );
133 itkGetConstMacro( LUTSamplingFactors,SizeType );
136 void SetParameters(const ParametersType & parameters);
138 void SetFixedParameters(const ParametersType & parameters);
140 void SetParametersByValue(const ParametersType & parameters);
144 /** Get the Transformation Parameters. */
145 virtual const ParametersType& GetParameters(void) const;
147 /** Get the Transformation Fixed Parameters. */
148 virtual const ParametersType& GetFixedParameters(void) const;
150 // The coefficientImage
151 virtual const std::vector<CoefficientImagePointer>& GetCoefficientImages() const;
152 virtual void SetCoefficientImages(std::vector<CoefficientImagePointer>& images);
154 /** This method specifies the region over which the grid resides. */
155 virtual void SetGridRegion( const RegionType& region );
157 itkGetMacro( GridRegion, RegionType );
158 itkGetConstMacro( GridRegion, RegionType );
161 /** This method specifies the grid spacing or resolution. */
162 virtual void SetGridSpacing( const SpacingType& spacing );
164 itkGetMacro( GridSpacing, SpacingType );
165 itkGetConstMacro( GridSpacing, SpacingType );
168 /** This method specifies the grid directions . */
169 virtual void SetGridDirection( const DirectionType & spacing );
171 itkGetMacro( GridDirection, DirectionType );
172 itkGetConstMacro( GridDirection, DirectionType );
175 /** This method specifies the grid origin. */
176 virtual void SetGridOrigin( const OriginType& origin );
178 itkGetMacro( GridOrigin, OriginType );
179 itkGetConstMacro( GridOrigin, OriginType );
182 // Set the bulk transform, real pointer
183 void SetBulkTransform(BulkTransformPointer b);
184 BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;}
186 /** Transform points by a BSpline deformable transformation. */
187 OutputPointType TransformPoint(const InputPointType &point ) const;
189 // JV added for just the deformable part, without bulk
190 OutputPointType DeformablyTransformPoint(const InputPointType &point ) const;
192 /** Method to transform a vector -
193 * not applicable for this type of transform. */
194 virtual OutputVectorType TransformVector(const InputVectorType &) const
196 itkExceptionMacro(<< "Method not applicable for deformable transform." );
197 return OutputVectorType();
200 /** Method to transform a vnl_vector -
201 * not applicable for this type of transform */
202 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
204 itkExceptionMacro(<< "Method not applicable for deformable transform. ");
205 return OutputVnlVectorType();
208 /** Method to transform a CovariantVector -
209 * not applicable for this type of transform */
210 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
212 itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
213 return OutputCovariantVectorType();
216 /** Compute the Jacobian Matrix of the transformation at one point */
217 virtual void ComputeJacobianWithRespectToParameters (const InputPointType &p, JacobianType &jacobian) const;
218 virtual void ComputeJacobianWithRespectToPosition (const InputPointType &p, JacobianType &jacobian) const
220 itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented for " << this->GetNameOfClass() );
223 /** Return the number of parameters that completely define the Transfom */
224 virtual NumberOfParametersType GetNumberOfParameters(void) const;
226 /** Return the number of parameters per dimension */
227 unsigned int GetNumberOfParametersPerDimension(void) const;
229 virtual bool IsLinear() const { return false; }
231 typedef clitk::BSplineDeformableTransform<TCoordRep,InputDimension, OutputDimension > TransformType;
233 const std::vector<typename TransformType::Pointer> &GetTransforms() { return m_trans; }
237 void PrintSelf(std::ostream &os, itk::Indent indent) const;
239 MultipleBSplineDeformableTransform();
240 virtual ~MultipleBSplineDeformableTransform();
242 void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const;
245 MultipleBSplineDeformableTransform(const Self&); //purposely not implemented
246 void operator=(const Self&); //purposely not implemented
248 /** The bulk transform. */
249 BulkTransformPointer m_BulkTransform;
251 /** Jacobian as OutputDimension number of images. */
252 typedef typename JacobianType::ValueType JacobianValueType;
253 typedef typename itk::Vector<JacobianValueType,OutputDimension> JacobianPixelType;
254 typedef itk::Image<JacobianPixelType, OutputDimension> JacobianImageType;
255 typename JacobianImageType::Pointer m_JacobianImage[OutputDimension];
256 typedef itk::ImageRegionIterator<JacobianImageType> IteratorType;
258 /** Keep a pointer to the input parameters. */
259 const ParametersType * m_InputParametersPointer;
261 /** Internal parameters buffer. */
262 ParametersType m_InternalParametersBuffer;
264 unsigned int m_nLabels;
265 ImageLabelPointer m_labels;
266 ImageLabelInterpolatorPointer m_labelInterpolator;
267 std::vector<typename TransformType::Pointer> m_trans;
268 std::vector<ParametersType> m_parameters;
269 mutable std::vector<CoefficientImagePointer> m_CoefficientImages;
270 mutable int m_LastJacobian;
271 mutable JacobianType m_SharedDataBSplineJacobian;
274 // FIXME it seems not used
275 bool InsideValidRegion( const ContinuousIndexType& index ) const;
280 #ifndef ITK_MANUAL_INSTANTIATION
281 # include "clitkMultipleBSplineDeformableTransform.txx"
284 #endif // __clitkMultipleBSplineDeformableTransform_h