]> Creatis software - clitk.git/blob - registration/clitkMultipleBSplineDeformableTransform.h
Debug RTStruct conversion with empty struc
[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     typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
63
64     /** Standard Jacobian container. */
65     typedef typename Superclass::JacobianType JacobianType;
66
67     /** Standard vector type for this class. */
68     typedef itk::Vector<TCoordRep,
69                         InputDimension> InputVectorType;
70     typedef itk::Vector<TCoordRep,
71                         OutputDimension> OutputVectorType;
72
73     /** Standard covariant vector type for this class. */
74     typedef itk::CovariantVector<TCoordRep,
75                                  InputDimension> InputCovariantVectorType;
76     typedef itk::CovariantVector<TCoordRep,
77                                  OutputDimension> OutputCovariantVectorType;
78
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;
84
85     /** Standard coordinate point type for this class. */
86     typedef itk::Point<TCoordRep,
87                        InputDimension> InputPointType;
88     typedef itk::Point<TCoordRep,
89                        OutputDimension> OutputPointType;
90
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;
96
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;
105
106     /** Typedef of the bulk transform. */
107     typedef itk::Transform<ScalarType, InputDimension, OutputDimension> BulkTransformType;
108     typedef BulkTransformType*                  BulkTransformPointer;
109
110     typedef itk::Image< unsigned char, InputDimension>   ImageLabelType;
111     typedef ImageLabelType* ImageLabelPointer;
112     //typedef typename ImageLabelType::Pointer ImageLabelPointer;
113
114     typedef itk::NearestNeighborInterpolateImageFunction<ImageLabelType, TCoordRep> ImageLabelInterpolator;
115     typedef typename ImageLabelInterpolator::Pointer ImageLabelInterpolatorPointer;
116
117     void SetLabels(ImageLabelPointer labels);
118     ImageLabelPointer GetLabels() {return m_labels;}
119
120     itkGetMacro(nLabels, unsigned);
121
122     void SetSplineOrder(const unsigned int &  splineOrder);
123     void SetSplineOrders(const SizeType &  splineOrders);
124     /*
125     itkGetMacro( SplineOrders, SizeType );
126     itkGetConstMacro( SplineOrders, SizeType );
127     */
128
129     void SetLUTSamplingFactor(const int &  samplingFactor);
130     void SetLUTSamplingFactors(const SizeType &  samplingFactors);
131     /*
132     itkGetMacro( LUTSamplingFactors, SizeType );
133     itkGetConstMacro( LUTSamplingFactors,SizeType );
134     */
135
136     void SetParameters(const ParametersType & parameters);
137
138     void SetFixedParameters(const ParametersType & parameters);
139
140     void SetParametersByValue(const ParametersType & parameters);
141
142     void SetIdentity();
143
144     /** Get the Transformation Parameters. */
145     virtual const ParametersType& GetParameters(void) const;
146
147     /** Get the Transformation Fixed Parameters. */
148     virtual const ParametersType& GetFixedParameters(void) const;
149
150     // The coefficientImage
151     virtual const std::vector<CoefficientImagePointer>& GetCoefficientImages() const;
152     virtual void SetCoefficientImages(std::vector<CoefficientImagePointer>& images);
153
154     /** This method specifies the region over which the grid resides. */
155     virtual void SetGridRegion( const RegionType& region );
156     /*
157     itkGetMacro( GridRegion, RegionType );
158     itkGetConstMacro( GridRegion, RegionType );
159     */
160
161     /** This method specifies the grid spacing or resolution. */
162     virtual void SetGridSpacing( const SpacingType& spacing );
163     /*
164     itkGetMacro( GridSpacing, SpacingType );
165     itkGetConstMacro( GridSpacing, SpacingType );
166     */
167
168     /** This method specifies the grid directions . */
169     virtual void SetGridDirection( const DirectionType & spacing );
170     /*
171     itkGetMacro( GridDirection, DirectionType );
172     itkGetConstMacro( GridDirection, DirectionType );
173     */
174
175     /** This method specifies the grid origin. */
176     virtual void SetGridOrigin( const OriginType& origin );
177     /*
178     itkGetMacro( GridOrigin, OriginType );
179     itkGetConstMacro( GridOrigin, OriginType );
180     */
181
182     // Set the bulk transform, real pointer
183     void SetBulkTransform(BulkTransformPointer b);
184     BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;}
185
186     /** Transform points by a BSpline deformable transformation. */
187     OutputPointType  TransformPoint(const InputPointType  &point ) const;
188
189     // JV added for just the deformable part, without bulk
190     OutputPointType  DeformablyTransformPoint(const InputPointType  &point ) const;
191
192     /** Method to transform a vector -
193      *  not applicable for this type of transform. */
194     virtual OutputVectorType TransformVector(const InputVectorType &) const
195     {
196       itkExceptionMacro(<< "Method not applicable for deformable transform." );
197       return OutputVectorType();
198     }
199
200     /** Method to transform a vnl_vector -
201      *  not applicable for this type of transform */
202     virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
203     {
204       itkExceptionMacro(<< "Method not applicable for deformable transform. ");
205       return OutputVnlVectorType();
206     }
207
208     /** Method to transform a CovariantVector -
209      *  not applicable for this type of transform */
210     virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
211     {
212       itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
213       return OutputCovariantVectorType();
214     }
215
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
219     {
220       itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented for " << this->GetNameOfClass() );
221     }
222
223     /** Return the number of parameters that completely define the Transfom */
224     virtual NumberOfParametersType GetNumberOfParameters(void) const;
225
226     /** Return the number of parameters per dimension */
227     unsigned int GetNumberOfParametersPerDimension(void) const;
228
229     virtual bool IsLinear() const { return false; }
230
231     typedef  clitk::BSplineDeformableTransform<TCoordRep,InputDimension, OutputDimension > TransformType;
232
233     const std::vector<typename TransformType::Pointer> &GetTransforms() { return m_trans; }
234
235   protected:
236
237     void PrintSelf(std::ostream &os, itk::Indent indent) const;
238
239     MultipleBSplineDeformableTransform();
240     virtual ~MultipleBSplineDeformableTransform();
241
242     void TransformPointToContinuousIndex( const InputPointType & point, ContinuousIndexType & index ) const;
243
244   private:
245     MultipleBSplineDeformableTransform(const Self&); //purposely not implemented
246     void operator=(const Self&); //purposely not implemented
247
248     /** The bulk transform. */
249     BulkTransformPointer  m_BulkTransform;
250
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;
257
258     /** Keep a pointer to the input parameters. */
259     const ParametersType *  m_InputParametersPointer;
260
261     /** Internal parameters buffer. */
262     ParametersType          m_InternalParametersBuffer;
263
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;
272
273     void InitJacobian();
274     // FIXME it seems not used
275     bool InsideValidRegion( const ContinuousIndexType& index ) const;
276   };
277
278 }  // namespace clitk
279
280 #ifndef ITK_MANUAL_INSTANTIATION
281 # include "clitkMultipleBSplineDeformableTransform.txx"
282 #endif
283
284 #endif // __clitkMultipleBSplineDeformableTransform_h