]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Algorithms/IsoImageSlicer.h
...
[cpPlugins.git] / lib / cpPlugins / Extensions / Algorithms / IsoImageSlicer.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
7
8 #include <itkAffineTransform.h>
9 #include <itkExtractImageFilter.h>
10 #include <itkImage.h>
11 #include <itkImageToImageFilter.h>
12 #include <itkInterpolateImageFunction.h>
13 #include <itkResampleImageFilter.h>
14 #include <itkVectorResampleImageFilter.h>
15 #include <itkVectorInterpolateImageFunction.h>
16
17 namespace cpPlugins
18 {
19   namespace Extensions
20   {
21     namespace Algorithms
22     {
23       /**
24        */
25       template< class R, class I >
26       class BaseImageSlicer
27         : public itk::ImageToImageFilter< typename R::InputImageType, itk::Image< typename R::InputImageType::PixelType, R::ImageDimension - 1 > >
28       {
29       public:
30         // Basic types
31         typedef BaseImageSlicer            Self;
32         typedef R                          TSlicer;
33         typedef I                          TInterpolateFunction;
34         typedef typename R::InputImageType TImage;
35         typedef typename I::CoordRepType   TScalar;
36         typedef typename TImage::PixelType TPixel;
37         enum
38         {
39           Dim      = TImage::ImageDimension,
40           SliceDim = TImage::ImageDimension - 1
41         };
42         typedef itk::Image< TPixel, Self::SliceDim > TSliceImage;
43
44         // itk types
45         typedef itk::ImageToImageFilter< TImage, TSliceImage > Superclass;
46         typedef itk::SmartPointer< Self >                      Pointer;
47         typedef itk::SmartPointer< const Self >                ConstPointer;
48
49         // Internal filters
50         typedef itk::ExtractImageFilter< TImage, TSliceImage > TCollapsor;
51
52         // Various types
53         typedef typename TImage::IndexType   TIndex;
54         typedef typename TImage::RegionType  TRegion;
55         typedef typename TImage::SizeType    TSize;
56         typedef typename TImage::SpacingType TSpacing;
57         typedef typename TSpacing::ValueType TSpacingValue;
58
59         typedef itk::AffineTransform< TScalar, Self::Dim > TTransform;
60         typedef typename TTransform::MatrixType            TMatrix;
61         typedef typename TTransform::OffsetType            TVector;
62
63       public:
64         itkNewMacro( Self );
65         itkTypeMacro( BaseImageSlicer, itkImageToImageFilter );
66
67         itkBooleanMacro( SizeFromMaximum );
68         itkBooleanMacro( SizeFromMinimum );
69         itkBooleanMacro( SpacingFromMaximum );
70         itkBooleanMacro( SpacingFromMinimum );
71
72         itkGetConstObjectMacro( Transform, TTransform );
73         itkGetConstMacro( DefaultValue, TPixel );
74         itkGetConstMacro( Size, TVector );
75         itkGetConstMacro( SizeFromMaximum, bool );
76         itkGetConstMacro( SizeFromMinimum, bool );
77         itkGetConstMacro( Spacing, TSpacingValue );
78         itkGetConstMacro( SpacingFromMaximum, bool );
79         itkGetConstMacro( SpacingFromMinimum, bool );
80
81         itkSetObjectMacro( Transform, TTransform );
82         itkSetMacro( Size, TVector );
83         itkSetMacro( DefaultValue, TPixel );
84         itkSetMacro( SizeFromMaximum, bool );
85         itkSetMacro( SizeFromMinimum, bool );
86         itkSetMacro( Spacing, TSpacingValue );
87         itkSetMacro( SpacingFromMaximum, bool );
88         itkSetMacro( SpacingFromMinimum, bool );
89
90       public:
91         virtual unsigned long GetMTime( ) const;
92
93         const TInterpolateFunction* GetInterpolator( ) const;
94         const TMatrix& GetRotation( ) const;
95         const TVector& GetTranslation( ) const;
96
97         void SetInterpolator( TInterpolateFunction* f );
98
99         template< class M >
100         void SetRotation( const M& r );
101
102         template< class V >
103         void SetTranslation( const V& t );
104         void SetSize( TScalar s );
105
106       protected:
107         BaseImageSlicer( );
108         virtual ~BaseImageSlicer( );
109
110         virtual void GenerateOutputInformation( ); // TODO { }
111         virtual void GenerateInputRequestedRegion( );
112         virtual void GenerateData( );
113
114       private:
115         // Purposely not implemented
116         BaseImageSlicer( const Self& );
117         void operator=( const Self& );
118
119       protected:
120         typename TSlicer::Pointer    m_Slicer;
121         typename TCollapsor::Pointer m_Collapsor;
122         typename TTransform::Pointer m_Transform;
123
124         TPixel m_DefaultValue;
125
126         TVector m_Size;
127         bool    m_SizeFromMaximum;
128         bool    m_SizeFromMinimum;
129
130         TSpacingValue m_Spacing;
131         bool          m_SpacingFromMaximum;
132         bool          m_SpacingFromMinimum;
133       };
134
135     } // ecapseman
136
137   } // ecapseman
138
139 } // ecapseman
140
141 // -------------------------------------------------------------------------
142 #define CPPLUGINS_DEFINE_ISOIMAGESLICER( name, R, F )                   \
143   template< class I, class S = double >                                 \
144   class name                                                            \
145     : public BaseImageSlicer< R< I, I, S >, F< I, S > >                 \
146   {                                                                     \
147   public:                                                               \
148     typedef BaseImageSlicer< R< I, I, S >, F< I, S > > Superclass;      \
149     typedef name                                       Self;            \
150     typedef itk::SmartPointer< Self >                  Pointer;         \
151     typedef itk::SmartPointer< const Self >            ConstPointer;    \
152   public:                                                               \
153     itkNewMacro( Self );                                                \
154     itkTypeMacro( name, BaseSlicer );                                   \
155   protected:                                                            \
156     name( ) : Superclass( ) { }                                         \
157     virtual ~name( ) { }                                                \
158   private:                                                              \
159     name( const Self& );                                                \
160     void operator=( const Self& );                                      \
161   };
162
163 namespace cpPlugins
164 {
165   namespace Extensions
166   {
167     namespace Algorithms
168     {
169       CPPLUGINS_DEFINE_ISOIMAGESLICER(
170         IsoImageSlicer,
171         itk::ResampleImageFilter,
172         itk::InterpolateImageFunction
173         );
174       CPPLUGINS_DEFINE_ISOIMAGESLICER(
175         VectorIsoImageSlicer,
176         itk::VectorResampleImageFilter,
177         itk::VectorInterpolateImageFunction
178         );
179
180     } // ecapseman
181
182   } // ecapseman
183
184 } // ecapseman
185
186 #include <cpPlugins/Extensions/Algorithms/IsoImageSlicer.hxx>
187
188 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
189
190 // eof - $RCSfile$