]> Creatis software - cpPlugins.git/blob - lib/ivq/ITK/ExtractNativeSlicesImageFilter.hxx
...
[cpPlugins.git] / lib / ivq / ITK / ExtractNativeSlicesImageFilter.hxx
1 // =======================================================================
2 // @author: Leonardo Florez-Valencia
3 // @email: florez-l@javeriana.edu.co
4 // =======================================================================
5 #ifndef __ivq__ITK__ExtractNativeSlicesImageFilter__hxx__
6 #define __ivq__ITK__ExtractNativeSlicesImageFilter__hxx__
7
8 #include <itkExtractImageFilter.h>
9
10 // -------------------------------------------------------------------------
11 template< class _TImage >
12 ivq::ITK::ExtractNativeSlicesImageFilter< _TImage >::
13 ExtractNativeSlicesImageFilter( )
14   : Superclass( ),
15     m_Direction( 0 )
16 {
17   ivqITKInputConfigureMacro( Input, TImage );
18   ivqITKOutputConfigureMacro( Output, TSlicesVector );
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TImage >
23 ivq::ITK::ExtractNativeSlicesImageFilter< _TImage >::
24 ~ExtractNativeSlicesImageFilter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TImage >
30 void ivq::ITK::ExtractNativeSlicesImageFilter< _TImage >::
31 GenerateData( )
32 {
33   typedef itk::ExtractImageFilter< TImabe, TSlice > _TExtract;
34
35   if( this->m_Direction >= Self::ImageDimension )
36     itkExceptionMacro( << "Invalid direction: " << this->m_Direction );
37
38   // Some values
39   const TImage* input = this->GetInput( );
40   TSlicesVector* output = this->GetOutput( );
41   typename TImage::RegionType region = input->GetRequestedRegion( );
42   typename TImage::IndexType regionIndex = region.GetIndex( );
43   typename TImage::SizeType sliceSize = region.GetSize( );
44   unsigned int numSlices = sliceSize[ this->m_Direction ];
45   sliceSize[ this->m_Direction ] = 0;
46
47   // Extract all slices
48   output->Get( ).clear( );
49   for( unsigned int i = 0; i < numSlices; ++i )
50   {
51     // Prepare extraction region
52     typename TImage::IndexType sliceIndex = regionIndex;
53     sliceIndex[ this->m_Direction ] += i;
54     typename TImage::RegionType sliceRegion( sliceIndex, sliceSize );
55
56     // Extract slice
57     typename _TExtract::Pointer extract = _TExtract::New( );
58     extract->SetInput( input );
59     extract->SetExtractionRegion( sliceRegion );
60     extract->SetDirectionCollapseToIdentity( );
61     extract->Update( );
62     typename TSlice::Pointer slice = extract->GetOutput( );
63     slice->DisconnectPipeline( );
64     output->Get( ).push_back( slice );
65
66   } // rof
67 }
68
69 #endif // __ivq__ITK__ExtractNativeSlicesImageFilter__hxx__
70 // eof - $RCSfile$