]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx
ff14aa429538a5c5acec2236ff8b48fa0b819bd3
[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->m_ClassName = "cpPlugins::BasicFilters::ExtractSliceImageFilter";
12   this->m_ClassCategory = "ImageToImageFilter";
13   this->SetNumberOfInputs( 1 );
14   this->SetNumberOfOutputs( 1 );
15   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
16
17   using namespace cpPlugins::Interface;
18   this->m_DefaultParameters.Configure( Parameters::Int, "Axis" );
19   this->m_DefaultParameters.Configure( Parameters::Int, "Slice" );
20   this->m_DefaultParameters.SetValueAsInt( "Axis", 0 );
21   this->m_DefaultParameters.SetValueAsInt( "Slice", 0 );
22   this->m_Parameters = this->m_DefaultParameters;
23 }
24
25 // -------------------------------------------------------------------------
26 cpPlugins::BasicFilters::ExtractSliceImageFilter::
27 ~ExtractSliceImageFilter( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
33 _GenerateData( )
34 {
35   cpPlugins::Interface::Image* image =
36     this->GetInput< cpPlugins::Interface::Image >( 0 );
37   if( image == NULL )
38     return( "ExtractSliceImageFilter: No input image." );
39
40   itk::DataObject* itk_image = NULL;
41   std::string r = "";
42   cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
43   else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
44   else r = "ExtractSliceImageFilter: Input image type not supported.";
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
51 _GD0( itk::DataObject* image )
52 {
53   return( this->_RealGD< I, I >( image ) );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class I, class O >
58 inline std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
59 _RealGD( itk::DataObject* image )
60 {
61   typedef itk::ExtractImageFilter< I, O > _F;
62   typedef typename O::PixelType _OP;
63
64   // Get parameters
65   int axis = this->m_Parameters.GetValueAsInt( "Axis" );
66   int slice = this->m_Parameters.GetValueAsInt( "Slice" );
67
68   std::cout << "HOLA: " << slice << std::endl;
69
70
71   // Compute region
72   I* img = dynamic_cast< I* >( image );
73   typename I::RegionType region = img->GetRequestedRegion( );
74   typename I::SizeType size = region.GetSize( );
75   typename I::IndexType index = region.GetIndex( );
76   size[ axis ] = 1;
77   index[ axis ] = slice;
78   region.SetSize( size );
79   region.SetIndex( index );
80
81   std::cout << "HOLA-: " << region << std::endl;
82
83   // Configure filter
84   _F* filter = this->_CreateITK< _F >( );
85   filter->SetInput( img );
86   filter->SetExtractionRegion( region );
87   filter->SetDirectionCollapseToIdentity( );
88   filter->Update( );
89
90   // Connect output
91   cpPlugins::Interface::Image* out =
92     this->GetOutput< cpPlugins::Interface::Image >( 0 );
93   if( out != NULL )
94   {
95     out->SetITK< O >( filter->GetOutput( ) );
96     return( "" );
97   }
98   else
99     return( "ExtractSliceImageFilter: output not correctly created." );
100 }
101
102 // eof - $RCSfile$