]> Creatis software - clitk.git/blob - registration/clitkMultipleBSplineDeformableTransform.h
changes in license header
[clitk.git] / registration / clitkMultipleBSplineDeformableTransform.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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
20
21 #include <clitkBSplineDeformableTransform.h>
22
23 #include <itkNearestNeighborInterpolateImageFunction.h>
24
25 #include <vector>
26
27 namespace clitk
28 {
29   template <
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 >
34   {
35   public:
36
37     //====================================================================
38     // Typedefs
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;
44
45     /** New macro for creation of through the object factory.*/
46     itkNewMacro( Self );
47
48     /** Run-time type information (and related methods). */
49     itkTypeMacro( MultipleBSplineDeformableTransform, Transform );
50
51     /** Dimension of the domain space. */
52     itkStaticConstMacro(OutputDimension, unsigned int, NOutputDimensions);
53
54     /** Dimension of the input model. */
55     itkStaticConstMacro(InputDimension, unsigned int, NInputDimensions);
56
57     /** Standard scalar type for this class. */
58     typedef typename Superclass::ScalarType ScalarType;
59
60     /** Standard parameters container. */
61     typedef typename Superclass::ParametersType ParametersType;
62
63     /** Standard Jacobian container. */
64     typedef typename Superclass::JacobianType JacobianType;
65
66     /** Standard vector type for this class. */
67     typedef itk::Vector<TCoordRep,
68                         InputDimension> InputVectorType;
69     typedef itk::Vector<TCoordRep,
70                         OutputDimension> OutputVectorType;
71
72     /** Standard covariant vector type for this class. */
73     typedef itk::CovariantVector<TCoordRep,
74                                  InputDimension> InputCovariantVectorType;
75     typedef itk::CovariantVector<TCoordRep,
76                                  OutputDimension> OutputCovariantVectorType;
77
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;
83
84     /** Standard coordinate point type for this class. */
85     typedef itk::Point<TCoordRep,
86                        InputDimension> InputPointType;
87     typedef itk::Point<TCoordRep,
88                        OutputDimension> OutputPointType;
89
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;
95
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;
104
105     /** Typedef of the bulk transform. */
106     typedef itk::Transform<ScalarType, InputDimension, OutputDimension> BulkTransformType;
107     typedef BulkTransformType*                  BulkTransformPointer;
108
109     typedef itk::Image< unsigned char, InputDimension>   ImageLabelType;
110     typedef ImageLabelType* ImageLabelPointer;
111     //typedef typename ImageLabelType::Pointer ImageLabelPointer;
112
113     typedef itk::NearestNeighborInterpolateImageFunction<ImageLabelType, TCoordRep> ImageLabelInterpolator;
114     typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer;
115
116     void SetLabels(ImageLabelPointer labels);
117     ImageLabelPointer GetLabels() {return m_labels;}
118
119     itkGetMacro(nLabels, unsigned);
120
121     void SetSplineOrder(const unsigned int &  splineOrder);
122     void SetSplineOrders(const SizeType &  splineOrders);
123     /*
124     itkGetMacro( SplineOrders, SizeType );
125     itkGetConstMacro( SplineOrders, SizeType );
126     */
127
128     void SetLUTSamplingFactor(const int &  samplingFactor);
129     void SetLUTSamplingFactors(const SizeType &  samplingFactors);
130     /*
131     itkGetMacro( LUTSamplingFactors, SizeType );
132     itkGetConstMacro( LUTSamplingFactors,SizeType );
133     */
134
135     void SetParameters(const ParametersType & parameters);
136
137     void SetFixedParameters(const ParametersType & parameters);
138
139     void SetParametersByValue(const ParametersType & parameters);
140
141     void SetIdentity();
142
143     /** Get the Transformation Parameters. */
144     virtual const ParametersType& GetParameters(void) const;
145
146     /** Get the Transformation Fixed Parameters. */
147     virtual const ParametersType& GetFixedParameters(void) const;
148
149     // The coefficientImage
150     virtual const std::vector<CoefficientImagePointer>& GetCoefficientImages() const;
151     virtual void SetCoefficientImages(std::vector<CoefficientImagePointer>& images);
152
153     /** This method specifies the region over which the grid resides. */
154     virtual void SetGridRegion( const RegionType& region );
155     /*
156     itkGetMacro( GridRegion, RegionType );
157     itkGetConstMacro( GridRegion, RegionType );
158     */
159
160     /** This method specifies the grid spacing or resolution. */
161     virtual void SetGridSpacing( const SpacingType& spacing );
162     /*
163     itkGetMacro( GridSpacing, SpacingType );
164     itkGetConstMacro( GridSpacing, SpacingType );
165     */
166
167     /** This method specifies the grid directions . */
168     virtual void SetGridDirection( const DirectionType & spacing );
169     /*
170     itkGetMacro( GridDirection, DirectionType );
171     itkGetConstMacro( GridDirection, DirectionType );
172     */
173
174     /** This method specifies the grid origin. */
175     virtual void SetGridOrigin( const OriginType& origin );
176     /*
177     itkGetMacro( GridOrigin, OriginType );
178     itkGetConstMacro( GridOrigin, OriginType );
179     */
180
181     // Set the bulk transform, real pointer
182     void SetBulkTransform(BulkTransformPointer b);
183     BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;}
184
185     /** Transform points by a BSpline deformable transformation. */
186     OutputPointType  TransformPoint(const InputPointType  &point ) const;
187
188     // JV added for just the deformable part, without bulk
189     OutputPointType  DeformablyTransformPoint(const InputPointType  &point ) const;
190
191     /** Method to transform a vector -
192      *  not applicable for this type of transform. */
193     virtual OutputVectorType TransformVector(const InputVectorType &) const
194     {
195       itkExceptionMacro(<< "Method not applicable for deformable transform." );
196       return OutputVectorType();
197     }
198
199     /** Method to transform a vnl_vector -
200      *  not applicable for this type of transform */
201     virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
202     {
203       itkExceptionMacro(<< "Method not applicable for deformable transform. ");
204       return OutputVnlVectorType();
205     }
206
207     /** Method to transform a CovariantVector -
208      *  not applicable for this type of transform */
209     virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
210     {
211       itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
212       return OutputCovariantVectorType();
213     }
214
215     /** Compute the Jacobian Matrix of the transformation at one point */
216     virtual const JacobianType& GetJacobian(const InputPointType  &point ) const;
217
218     /** Return the number of parameters that completely define the Transfom */
219     virtual unsigned int GetNumberOfParameters(void) const;
220
221     /** Return the number of parameters per dimension */
222     unsigned int GetNumberOfParametersPerDimension(void) const;
223
224     virtual bool IsLinear() const { return false; }
225
226     typedef  clitk::BSplineDeformableTransform<TCoordRep,InputDimension, OutputDimension > TransformType;
227
228   protected:
229
230     void PrintSelf(std::ostream &os, itk::Indent indent) const;
231
232     MultipleBSplineDeformableTransform();
233     virtual ~MultipleBSplineDeformableTransform();
234
235     void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const;
236
237   private:
238     MultipleBSplineDeformableTransform(const Self&); //purposely not implemented
239     void operator=(const Self&); //purposely not implemented
240
241     /** The bulk transform. */
242     BulkTransformPointer  m_BulkTransform;
243
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;
250
251     /** Keep a pointer to the input parameters. */
252     const ParametersType *  m_InputParametersPointer;
253
254     /** Internal parameters buffer. */
255     ParametersType          m_InternalParametersBuffer;
256
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;
264
265     void InitJacobian();
266     // FIXME it seems not used
267     bool InsideValidRegion( const ContinuousIndexType& index ) const;
268   };
269
270 }  // namespace clitk
271
272 #if ITK_TEMPLATE_TXX
273 # include "clitkMultipleBSplineDeformableTransform.txx"
274 #endif
275
276 #endif // __clitkMultipleBSplineDeformableTransform_h