X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FBasicFilters%2FCPRFilter.cxx;fp=lib%2FcpPlugins%2FPlugins%2FBasicFilters%2FCPRFilter.cxx;h=21dcbab574a8c1f0649872b35d73aec9b0b2ba5e;hb=dea0e89b762a27b1e4088f3d03b5169ca63a227f;hp=0000000000000000000000000000000000000000;hpb=ec34dab45f184bf8147b610e6e36e90b46dd8f14;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/BasicFilters/CPRFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/CPRFilter.cxx new file mode 100644 index 0000000..21dcbab --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/CPRFilter.cxx @@ -0,0 +1,103 @@ +#include "CPRFilter.h" +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::CPRFilter:: +CPRFilter( ) + : Superclass( ) +{ + this->_AddInput( "InputImage", true ); + this->_AddInput( "InputAxis", true ); + this->_AddInput( "Interpolator", false ); + this->_AddOutput< cpPlugins::Interface::Image >( "Output" ); + + this->m_Parameters->ConfigureAsUint( "NumberOfSlices" ); + this->m_Parameters->ConfigureAsReal( "SliceRadius" ); + std::vector< std::string > choices; + choices.push_back( "float" ); + choices.push_back( "double" ); + this->m_Parameters->ConfigureAsChoices( "ScalarType", choices ); + + this->m_Parameters->SetUint( "NumberOfSlices", 0 ); + this->m_Parameters->SetReal( "SliceRadius", 10 ); + this->m_Parameters->SetSelectedChoice( "ScalarType", "float" ); +} + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::CPRFilter:: +~CPRFilter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::BasicFilters::CPRFilter:: +_GenerateData( ) +{ + auto image = + this->GetInputData< cpPlugins::Interface::Image >( "InputImage" ); + if( image == NULL ) + return( "CPRFilter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); + else r = "CPRFilter: Input image type not supported."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::BasicFilters::CPRFilter:: +_GD0( itk::DataObject* dobj ) +{ + I* image = dynamic_cast< I* >( dobj ); + + auto choice = this->m_Parameters->GetSelectedChoice( "ScalarType" ); + if( choice == "float" ) + return( this->_GD1< I, float >( image ) ); + else if( choice == "double" ) + return( this->_GD1< I, double >( image ) ); + else + return( "CPRFilter: Scalar type not supported." ); +} + +// ------------------------------------------------------------------------- +template< class I, class S > +std::string cpPlugins::BasicFilters::CPRFilter:: +_GD1( I* image ) +{ + typedef cpExtensions::Algorithms::CPRFilter< I, S > _Filter; + typedef itk::PolyLineParametricPath< I::ImageDimension > _Path; + typedef itk::InterpolateImageFunction< I, S > _Interpolator; + + auto axis = + this->GetInputData< cpPlugins::Interface::PolyLineParametricPath >( + "InputAxis" + )->GetITK< _Path >( ); + auto w_int = + this->GetInputData< cpPlugins::Interface::DataObject >( "Interpolator" ); + _Interpolator* interpolator = NULL; + if( w_int != NULL ) + interpolator = w_int->GetITK< _Interpolator >( ); + + // Configure filter + _Filter* filter = this->_CreateITK< _Filter >( ); + filter->SetInput( image ); + filter->SetAxis( axis ); + if( interpolator != NULL ) + filter->SetInterpolator( interpolator ); + filter->SetNumberOfSlices( this->m_Parameters->GetUint( "NumberOfSlices" ) ); + filter->SetSliceRadius( this->m_Parameters->GetReal( "SliceRadius" ) ); + filter->Update( ); + + // Assign output + auto out = + this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + out->SetITK< I >( filter->GetOutput( ) ); + return( "" ); +} + +// eof - $RCSfile$