]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/IsoImageSlicer.h
9e7e3ecc040a713b11063a31d17579095bb57374
[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 cpExtensions_OVERRIDE;
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( ) cpExtensions_OVERRIDE; // TODO { }
109       virtual void GenerateInputRequestedRegion( ) cpExtensions_OVERRIDE;
110       virtual void GenerateData( ) cpExtensions_OVERRIDE;
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 // -------------------------------------------------------------------------
138 #define CPPLUGINS_DEFINE_ISOIMAGESLICER( name, R, F )                   \
139   template< class I, class S = double >                                 \
140   class name                                                            \
141     : public BaseImageSlicer< R< I, I, S >, F< I, S > >                 \
142   {                                                                     \
143   public:                                                               \
144     typedef BaseImageSlicer< R< I, I, S >, F< I, S > > Superclass;      \
145     typedef name                                       Self;            \
146     typedef itk::SmartPointer< Self >                  Pointer;         \
147     typedef itk::SmartPointer< const Self >            ConstPointer;    \
148   public:                                                               \
149     itkNewMacro( Self );                                                \
150     itkTypeMacro( name, BaseSlicer );                                   \
151   protected:                                                            \
152     name( ) : Superclass( ) { }                                         \
153     virtual ~name( ) { }                                                \
154   private:                                                              \
155     name( const Self& );                                                \
156     void operator=( const Self& );                                      \
157   };
158
159 namespace cpExtensions
160 {
161   namespace Algorithms
162   {
163     CPPLUGINS_DEFINE_ISOIMAGESLICER(
164       IsoImageSlicer,
165       itk::ResampleImageFilter,
166       itk::InterpolateImageFunction
167       );
168     CPPLUGINS_DEFINE_ISOIMAGESLICER(
169       VectorIsoImageSlicer,
170       itk::VectorResampleImageFilter,
171       itk::VectorInterpolateImageFunction
172       );
173
174   } // ecapseman
175
176 } // ecapseman
177
178 #ifndef ITK_MANUAL_INSTANTIATION
179 #include <cpExtensions/Algorithms/IsoImageSlicer.hxx>
180 #endif // ITK_MANUAL_INSTANTIATION
181
182 #endif // __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
183
184 // eof - $RCSfile$