1 /* =======================================================================
2 * @author: Leonardo Florez-Valencia
3 * @email: florez-l@javeriana.edu.co
4 * =======================================================================
7 #ifndef __ivq__ITK__IsoImageSlicer__h__
8 #define __ivq__ITK__IsoImageSlicer__h__
10 #include <itkAffineTransform.h>
11 #include <itkExtractImageFilter.h>
13 #include <itkImageToImageFilter.h>
14 #include <itkInterpolateImageFunction.h>
15 #include <itkResampleImageFilter.h>
16 #include <itkVectorResampleImageFilter.h>
17 #include <itkVectorInterpolateImageFunction.h>
25 template< class _TSlicer, class _TInterpolateFunction >
27 : public itk::ImageToImageFilter< typename _TSlicer::InputImageType, itk::Image< typename _TSlicer::InputImageType::PixelType, _TSlicer::ImageDimension - 1 > >
31 typedef BaseImageSlicer Self;
32 typedef _TSlicer TSlicer;
33 typedef _TInterpolateFunction TInterpolateFunction;
34 typedef typename TSlicer::InputImageType TImage;
35 typedef typename TInterpolateFunction::CoordRepType TScalar;
36 typedef typename TImage::PixelType TPixel;
39 Dim = TImage::ImageDimension,
40 SliceDim = TImage::ImageDimension - 1
42 typedef itk::Image< TPixel, Self::SliceDim > TSliceImage;
45 typedef itk::ImageToImageFilter< TImage, TSliceImage > Superclass;
46 typedef itk::SmartPointer< Self > Pointer;
47 typedef itk::SmartPointer< const Self > ConstPointer;
50 typedef itk::ExtractImageFilter< TImage, TSliceImage > TCollapsor;
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;
59 typedef itk::AffineTransform< TScalar, Self::Dim > TTransform;
60 typedef typename TTransform::MatrixType TMatrix;
61 typedef typename TTransform::OffsetType TVector;
65 itkTypeMacro( BaseImageSlicer, itkImageToImageFilter );
67 itkBooleanMacro( SizeFromMaximum );
68 itkBooleanMacro( SizeFromMinimum );
69 itkBooleanMacro( SpacingFromMaximum );
70 itkBooleanMacro( SpacingFromMinimum );
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 );
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 );
91 virtual unsigned long GetMTime( ) const override;
93 const TInterpolateFunction* GetInterpolator( ) const;
94 const TMatrix& GetRotation( ) const;
95 const TVector& GetTranslation( ) const;
97 void SetInterpolator( TInterpolateFunction* f );
99 template< class _TOtherMatrix >
100 void SetRotation( const _TOtherMatrix& r );
102 template< class _TOtherVector >
103 void SetTranslation( const _TOtherVector& t );
105 void SetSize( TScalar s );
109 virtual ~BaseImageSlicer( );
111 virtual void GenerateOutputInformation( ) override; // TODO { }
112 virtual void GenerateInputRequestedRegion( ) override;
113 virtual void GenerateData( ) override;
116 // Purposely not implemented
117 BaseImageSlicer( const Self& );
118 void operator=( const Self& );
121 typename TSlicer::Pointer m_Slicer;
122 typename TCollapsor::Pointer m_Collapsor;
123 typename TTransform::Pointer m_Transform;
125 TPixel m_DefaultValue;
128 bool m_SizeFromMaximum;
129 bool m_SizeFromMinimum;
131 TSpacingValue m_Spacing;
132 bool m_SpacingFromMaximum;
133 bool m_SpacingFromMinimum;
140 // -------------------------------------------------------------------------
141 #define ivq_ITK_DefineIsoImageSlicer( name, R, F ) \
142 template< class _TImage, class _TScalar = double > \
144 : public ivq::ITK::BaseImageSlicer< R< _TImage, _TImage, _TScalar >, F< _TImage, _TScalar > > \
147 typedef ivq::ITK::BaseImageSlicer< R< _TImage, _TImage, _TScalar >, F< _TImage, _TScalar > > Superclass; \
149 typedef itk::SmartPointer< Self > Pointer; \
150 typedef itk::SmartPointer< const Self > ConstPointer; \
152 itkNewMacro( Self ); \
153 itkTypeMacro( ivq::ITK::name, ivq::ITK::BaseSlicer ); \
155 name( ) : Superclass( ) { } \
156 virtual ~name( ) { } \
158 name( const Self& ); \
159 void operator=( const Self& ); \
166 ivq_ITK_DefineIsoImageSlicer(
168 itk::ResampleImageFilter,
169 itk::InterpolateImageFunction
171 ivq_ITK_DefineIsoImageSlicer(
172 VectorIsoImageSlicer,
173 itk::VectorResampleImageFilter,
174 itk::VectorInterpolateImageFunction
181 // -------------------------------------------------------------------------
182 template< class _TSlicer, class _TInterpolateFunction >
183 template< class _TOtherMatrix >
184 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
185 SetRotation( const _TOtherMatrix& r )
188 for( unsigned int i = 0; i < Self::Dim; ++i )
189 for( unsigned int j = 0; j < Self::Dim; ++j )
190 rotation[ i ][ j ] = r[ i ][ j ];
191 this->m_Transform->SetMatrix( rotation );
195 // -------------------------------------------------------------------------
196 template< class _TSlicer, class _TInterpolateFunction >
197 template< class _TOtherVector >
198 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
199 SetTranslation( const _TOtherVector& t )
202 for( unsigned int i = 0; i < Self::Dim; ++i )
204 this->m_Transform->SetOffset( off );
208 #ifndef ITK_MANUAL_INSTANTIATION
209 # include <ivq/ITK/IsoImageSlicer.hxx>
210 #endif // ITK_MANUAL_INSTANTIATION
212 #endif // __ivq__ITK__IsoImageSlicer__h__