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