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