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://oncora1.lyon.fnclcc.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;
63 /** Standard Jacobian container. */
64 typedef typename Superclass::JacobianType JacobianType;
66 /** Standard vector type for this class. */
67 typedef itk::Vector<TCoordRep,
68 InputDimension> InputVectorType;
69 typedef itk::Vector<TCoordRep,
70 OutputDimension> OutputVectorType;
72 /** Standard covariant vector type for this class. */
73 typedef itk::CovariantVector<TCoordRep,
74 InputDimension> InputCovariantVectorType;
75 typedef itk::CovariantVector<TCoordRep,
76 OutputDimension> OutputCovariantVectorType;
78 /** Standard vnl_vector type for this class. */
79 typedef vnl_vector_fixed<TCoordRep,
80 InputDimension> InputVnlVectorType;
81 typedef vnl_vector_fixed<TCoordRep,
82 OutputDimension> OutputVnlVectorType;
84 /** Standard coordinate point type for this class. */
85 typedef itk::Point<TCoordRep,
86 InputDimension> InputPointType;
87 typedef itk::Point<TCoordRep,
88 OutputDimension> OutputPointType;
90 //JV Parameters as images with OutputDimension number of components per Pixel
91 typedef typename ParametersType::ValueType ParametersValueType;
92 typedef typename itk::Vector<ParametersValueType, OutputDimension> PixelType;
93 typedef itk::Image<PixelType, InputDimension> CoefficientImageType;
94 typedef typename CoefficientImageType::Pointer CoefficientImagePointer;
96 /** Typedefs for specifying the extend to the grid. */
97 typedef itk::ImageRegion<InputDimension> RegionType;
98 typedef typename RegionType::IndexType IndexType;
99 typedef typename RegionType::SizeType SizeType;
100 typedef typename CoefficientImageType::SpacingType SpacingType;
101 typedef typename CoefficientImageType::DirectionType DirectionType;
102 typedef typename CoefficientImageType::PointType OriginType;
103 typedef itk::ContinuousIndex<TCoordRep, InputDimension> ContinuousIndexType;
105 /** Typedef of the bulk transform. */
106 typedef itk::Transform<ScalarType, InputDimension, OutputDimension> BulkTransformType;
107 typedef BulkTransformType* BulkTransformPointer;
109 typedef itk::Image< unsigned char, InputDimension> ImageLabelType;
110 typedef ImageLabelType* ImageLabelPointer;
111 //typedef typename ImageLabelType::Pointer ImageLabelPointer;
113 typedef itk::NearestNeighborInterpolateImageFunction<ImageLabelType, TCoordRep> ImageLabelInterpolator;
114 typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer;
116 void SetLabels(ImageLabelPointer labels);
117 ImageLabelPointer GetLabels() {return m_labels;}
119 itkGetMacro(nLabels, unsigned);
121 void SetSplineOrder(const unsigned int & splineOrder);
122 void SetSplineOrders(const SizeType & splineOrders);
124 itkGetMacro( SplineOrders, SizeType );
125 itkGetConstMacro( SplineOrders, SizeType );
128 void SetLUTSamplingFactor(const int & samplingFactor);
129 void SetLUTSamplingFactors(const SizeType & samplingFactors);
131 itkGetMacro( LUTSamplingFactors, SizeType );
132 itkGetConstMacro( LUTSamplingFactors,SizeType );
135 void SetParameters(const ParametersType & parameters);
137 void SetFixedParameters(const ParametersType & parameters);
139 void SetParametersByValue(const ParametersType & parameters);
143 /** Get the Transformation Parameters. */
144 virtual const ParametersType& GetParameters(void) const;
146 /** Get the Transformation Fixed Parameters. */
147 virtual const ParametersType& GetFixedParameters(void) const;
149 // The coefficientImage
150 virtual const std::vector<CoefficientImagePointer>& GetCoefficientImages() const;
151 virtual void SetCoefficientImages(std::vector<CoefficientImagePointer>& images);
153 /** This method specifies the region over which the grid resides. */
154 virtual void SetGridRegion( const RegionType& region );
156 itkGetMacro( GridRegion, RegionType );
157 itkGetConstMacro( GridRegion, RegionType );
160 /** This method specifies the grid spacing or resolution. */
161 virtual void SetGridSpacing( const SpacingType& spacing );
163 itkGetMacro( GridSpacing, SpacingType );
164 itkGetConstMacro( GridSpacing, SpacingType );
167 /** This method specifies the grid directions . */
168 virtual void SetGridDirection( const DirectionType & spacing );
170 itkGetMacro( GridDirection, DirectionType );
171 itkGetConstMacro( GridDirection, DirectionType );
174 /** This method specifies the grid origin. */
175 virtual void SetGridOrigin( const OriginType& origin );
177 itkGetMacro( GridOrigin, OriginType );
178 itkGetConstMacro( GridOrigin, OriginType );
181 // Set the bulk transform, real pointer
182 void SetBulkTransform(BulkTransformPointer b);
183 BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;}
185 /** Transform points by a BSpline deformable transformation. */
186 OutputPointType TransformPoint(const InputPointType &point ) const;
188 // JV added for just the deformable part, without bulk
189 OutputPointType DeformablyTransformPoint(const InputPointType &point ) const;
191 /** Method to transform a vector -
192 * not applicable for this type of transform. */
193 virtual OutputVectorType TransformVector(const InputVectorType &) const
195 itkExceptionMacro(<< "Method not applicable for deformable transform." );
196 return OutputVectorType();
199 /** Method to transform a vnl_vector -
200 * not applicable for this type of transform */
201 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
203 itkExceptionMacro(<< "Method not applicable for deformable transform. ");
204 return OutputVnlVectorType();
207 /** Method to transform a CovariantVector -
208 * not applicable for this type of transform */
209 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
211 itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
212 return OutputCovariantVectorType();
215 /** Compute the Jacobian Matrix of the transformation at one point */
216 virtual const JacobianType& GetJacobian(const InputPointType &point ) const;
218 /** Return the number of parameters that completely define the Transfom */
219 virtual unsigned int GetNumberOfParameters(void) const;
221 /** Return the number of parameters per dimension */
222 unsigned int GetNumberOfParametersPerDimension(void) const;
224 virtual bool IsLinear() const { return false; }
226 typedef clitk::BSplineDeformableTransform<TCoordRep,InputDimension, OutputDimension > TransformType;
230 void PrintSelf(std::ostream &os, itk::Indent indent) const;
232 MultipleBSplineDeformableTransform();
233 virtual ~MultipleBSplineDeformableTransform();
235 void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const;
238 MultipleBSplineDeformableTransform(const Self&); //purposely not implemented
239 void operator=(const Self&); //purposely not implemented
241 /** The bulk transform. */
242 BulkTransformPointer m_BulkTransform;
244 /** Jacobian as OutputDimension number of images. */
245 typedef typename JacobianType::ValueType JacobianValueType;
246 typedef typename itk::Vector<JacobianValueType,OutputDimension> JacobianPixelType;
247 typedef itk::Image<JacobianPixelType, OutputDimension> JacobianImageType;
248 typename JacobianImageType::Pointer m_JacobianImage[OutputDimension];
249 typedef itk::ImageRegionIterator<JacobianImageType> IteratorType;
251 /** Keep a pointer to the input parameters. */
252 const ParametersType * m_InputParametersPointer;
254 /** Internal parameters buffer. */
255 ParametersType m_InternalParametersBuffer;
257 unsigned int m_nLabels;
258 ImageLabelPointer m_labels;
259 ImageLabelInterpolatorPointer m_labelInterpolator;
260 std::vector<typename TransformType::Pointer> m_trans;
261 std::vector<ParametersType> m_parameters;
262 mutable std::vector<CoefficientImagePointer> m_CoefficientImages;
263 mutable int m_LastJacobian;
266 // FIXME it seems not used
267 bool InsideValidRegion( const ContinuousIndexType& index ) const;
273 # include "clitkMultipleBSplineDeformableTransform.txx"
276 #endif // __clitkMultipleBSplineDeformableTransform_h