1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
6 #define __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__
8 #include <cpExtensions/Config.h>
9 #include <itkAffineTransform.h>
10 #include <itkExtractImageFilter.h>
12 #include <itkImageToImageFilter.h>
13 #include <itkInterpolateImageFunction.h>
14 #include <itkResampleImageFilter.h>
15 #include <itkVectorResampleImageFilter.h>
16 #include <itkVectorInterpolateImageFunction.h>
18 namespace cpExtensions
24 template< class R, class I >
26 : public itk::ImageToImageFilter< typename R::InputImageType, itk::Image< typename R::InputImageType::PixelType, R::ImageDimension - 1 > >
30 typedef BaseImageSlicer Self;
32 typedef I TInterpolateFunction;
33 typedef typename R::InputImageType TImage;
34 typedef typename I::CoordRepType TScalar;
35 typedef typename TImage::PixelType TPixel;
38 Dim = TImage::ImageDimension,
39 SliceDim = TImage::ImageDimension - 1
41 typedef itk::Image< TPixel, Self::SliceDim > TSliceImage;
44 typedef itk::ImageToImageFilter< TImage, TSliceImage > Superclass;
45 typedef itk::SmartPointer< Self > Pointer;
46 typedef itk::SmartPointer< const Self > ConstPointer;
49 typedef itk::ExtractImageFilter< TImage, TSliceImage > TCollapsor;
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;
58 typedef itk::AffineTransform< TScalar, Self::Dim > TTransform;
59 typedef typename TTransform::MatrixType TMatrix;
60 typedef typename TTransform::OffsetType TVector;
64 itkTypeMacro( BaseImageSlicer, itkImageToImageFilter );
66 itkBooleanMacro( SizeFromMaximum );
67 itkBooleanMacro( SizeFromMinimum );
68 itkBooleanMacro( SpacingFromMaximum );
69 itkBooleanMacro( SpacingFromMinimum );
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 );
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 );
90 virtual unsigned long GetMTime( ) const cpExtensions_OVERRIDE;
92 const TInterpolateFunction* GetInterpolator( ) const;
93 const TMatrix& GetRotation( ) const;
94 const TVector& GetTranslation( ) const;
96 void SetInterpolator( TInterpolateFunction* f );
99 void SetRotation( const M& r );
102 void SetTranslation( const V& t );
103 void SetSize( TScalar s );
107 virtual ~BaseImageSlicer( );
109 virtual void GenerateOutputInformation( ) cpExtensions_OVERRIDE; // TODO { }
110 virtual void GenerateInputRequestedRegion( ) cpExtensions_OVERRIDE;
111 virtual void GenerateData( ) cpExtensions_OVERRIDE;
114 // Purposely not implemented
115 BaseImageSlicer( const Self& );
116 void operator=( const Self& );
119 typename TSlicer::Pointer m_Slicer;
120 typename TCollapsor::Pointer m_Collapsor;
121 typename TTransform::Pointer m_Transform;
123 TPixel m_DefaultValue;
126 bool m_SizeFromMaximum;
127 bool m_SizeFromMinimum;
129 TSpacingValue m_Spacing;
130 bool m_SpacingFromMaximum;
131 bool m_SpacingFromMinimum;
138 // -------------------------------------------------------------------------
139 #define CPPLUGINS_DEFINE_ISOIMAGESLICER( name, R, F ) \
140 template< class I, class S = double > \
142 : public BaseImageSlicer< R< I, I, S >, F< I, S > > \
145 typedef BaseImageSlicer< R< I, I, S >, F< I, S > > Superclass; \
147 typedef itk::SmartPointer< Self > Pointer; \
148 typedef itk::SmartPointer< const Self > ConstPointer; \
150 itkNewMacro( Self ); \
151 itkTypeMacro( name, BaseSlicer ); \
153 name( ) : Superclass( ) { } \
154 virtual ~name( ) { } \
156 name( const Self& ); \
157 void operator=( const Self& ); \
160 namespace cpExtensions
164 CPPLUGINS_DEFINE_ISOIMAGESLICER(
166 itk::ResampleImageFilter,
167 itk::InterpolateImageFunction
169 CPPLUGINS_DEFINE_ISOIMAGESLICER(
170 VectorIsoImageSlicer,
171 itk::VectorResampleImageFilter,
172 itk::VectorInterpolateImageFunction
179 #ifndef ITK_MANUAL_INSTANTIATION
180 # include <cpExtensions/Algorithms/IsoImageSlicer.hxx>
181 #endif // ITK_MANUAL_INSTANTIATION
183 #endif // __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__H__