+#include "ExtractSliceImageFilter.h"
+#include <cpPlugins/Interface/Image.h>
+
+#include <itkExtractImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::ExtractSliceImageFilter::
+ExtractSliceImageFilter( )
+ : Superclass( )
+{
+ this->m_ClassName = "cpPlugins::BasicFilters::ExtractSliceImageFilter";
+ this->m_ClassCategory = "ImageToImageFilter";
+ this->SetNumberOfInputs( 1 );
+ this->SetNumberOfOutputs( 1 );
+ this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+
+ using namespace cpPlugins::Interface;
+ this->m_DefaultParameters.Configure( Parameters::Int, "Axis" );
+ this->m_DefaultParameters.Configure( Parameters::Int, "Slice" );
+ this->m_DefaultParameters.SetValueAsInt( "Axis", 0 );
+ this->m_DefaultParameters.SetValueAsInt( "Slice", 0 );
+ this->m_Parameters = this->m_DefaultParameters;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::ExtractSliceImageFilter::
+~ExtractSliceImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
+_GenerateData( )
+{
+ cpPlugins::Interface::Image* image =
+ this->GetInput< cpPlugins::Interface::Image >( 0 );
+ if( image == NULL )
+ return( "ExtractSliceImageFilter: No input image." );
+
+ itk::DataObject* itk_image = NULL;
+ std::string r = "";
+ cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
+ else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _GD0 );
+ else r = "ExtractSliceImageFilter: Input image type not supported.";
+ return( r );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
+_GD0( itk::DataObject* image )
+{
+ return( this->_RealGD< I, I >( image ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+inline std::string cpPlugins::BasicFilters::ExtractSliceImageFilter::
+_RealGD( itk::DataObject* image )
+{
+ typedef itk::ExtractImageFilter< I, O > _F;
+ typedef typename O::PixelType _OP;
+
+ // Get parameters
+ int axis = this->m_Parameters.GetValueAsInt( "Axis" );
+ int slice = this->m_Parameters.GetValueAsInt( "Slice" );
+
+ std::cout << "HOLA: " << slice << std::endl;
+
+
+ // Compute region
+ I* img = dynamic_cast< I* >( image );
+ typename I::RegionType region = img->GetRequestedRegion( );
+ typename I::SizeType size = region.GetSize( );
+ typename I::IndexType index = region.GetIndex( );
+ size[ axis ] = 1;
+ index[ axis ] = slice;
+ region.SetSize( size );
+ region.SetIndex( index );
+
+ std::cout << "HOLA-: " << region << std::endl;
+
+ // Configure filter
+ _F* filter = this->_CreateITK< _F >( );
+ filter->SetInput( img );
+ filter->SetExtractionRegion( region );
+ filter->SetDirectionCollapseToIdentity( );
+ filter->Update( );
+
+ // Connect output
+ cpPlugins::Interface::Image* out =
+ this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ if( out != NULL )
+ {
+ out->SetITK< O >( filter->GetOutput( ) );
+ return( "" );
+ }
+ else
+ return( "ExtractSliceImageFilter: output not correctly created." );
+}
+
+// eof - $RCSfile$