]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx
3f566e5834cbdc2df323037c65ba27f02d408d41
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / ExtractSliceImageFilter.cxx
1 #include "ExtractSliceImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkExtractImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::ExtractSliceImageFilter::
8 ExtractSliceImageFilter( )
9   : Superclass( )
10 {
11   this->_AddInput( "Input" );
12   this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
13
14   this->m_Parameters->ConfigureAsUint( "Axis" );
15   this->m_Parameters->ConfigureAsInt( "Slice" );
16
17   this->m_Parameters->SetUint( "Axis", 0 );
18   this->m_Parameters->SetInt( "Slice", 0 );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::BasicFilters::ExtractSliceImageFilter::
23 ~ExtractSliceImageFilter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
29 _GenerateData( )
30 {
31   cpPlugins::Interface::Image* image =
32     this->GetInput< cpPlugins::Interface::Image >( "Input" );
33   if( image == NULL )
34     return( "ExtractSliceImageFilter: No input image." );
35
36   itk::DataObject* itk_image = NULL;
37   std::string r = "";
38 /*
39   cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
40   else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
41   else*/ r = "ExtractSliceImageFilter: Input image type not supported.";
42   return( r );
43 }
44
45 // -------------------------------------------------------------------------
46 template< class I >
47 std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
48 _GD0( itk::DataObject* image )
49 {
50   return( this->_RealGD< I, I >( image ) );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class I, class O >
55 inline std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
56 _RealGD( itk::DataObject* image )
57 {
58   typedef itk::ExtractImageFilter< I, O > _F;
59   typedef typename O::PixelType _OP;
60
61   // Get parameters
62   int axis = this->m_Parameters->GetUint( "Axis" );
63   int slice = this->m_Parameters->GetInt( "Slice" );
64
65   // Compute region
66   I* img = dynamic_cast< I* >( image );
67   typename I::RegionType region = img->GetRequestedRegion( );
68   typename I::SizeType size = region.GetSize( );
69   typename I::IndexType index = region.GetIndex( );
70   size[ axis ] = 1;
71   index[ axis ] = slice;
72   region.SetSize( size );
73   region.SetIndex( index );
74
75   // Configure filter
76   _F* filter = this->_CreateITK< _F >( );
77   filter->SetInput( img );
78   filter->SetExtractionRegion( region );
79   filter->SetDirectionCollapseToIdentity( );
80   filter->Update( );
81
82   // Connect output
83   cpPlugins::Interface::Image* out =
84     this->GetOutput< cpPlugins::Interface::Image >( "Output" );
85   if( out != NULL )
86   {
87     out->SetITK< O >( filter->GetOutput( ) );
88     return( "" );
89   }
90   else
91     return( "ExtractSliceImageFilter: output not correctly created." );
92 }
93
94 // eof - $RCSfile$