From: Leonardo Florez-Valencia Date: Mon, 18 Jan 2016 23:04:14 +0000 (-0500) Subject: Maurer signed distance filter added. X-Git-Tag: v0.1~266 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=4c53d95faa6a9ece8c1daa0e64df8d0007b0cfa4;p=cpPlugins.git Maurer signed distance filter added. --- diff --git a/appli/bash/cpPlugins_createHost.cxx b/appli/bash/cpPlugins_createHost.cxx index 6f8214d..4f46211 100644 --- a/appli/bash/cpPlugins_createHost.cxx +++ b/appli/bash/cpPlugins_createHost.cxx @@ -54,7 +54,7 @@ int main( int argc, char* argv[] ) output_code << "#include " << std::endl; for( int i = 3; i < argc; ++i ) - output_code << "#include \"" << argv[ i ] << "\"" << std::endl; + output_code << "#include <" << argv[ i ] << ">" << std::endl; output_code << std::endl << "PLUMA_CONNECTOR" << std::endl diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 3df62ee..731fc77 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -364,7 +365,21 @@ setParameters( Parameters* parameters ) case Parameters::PathNameList: break; case Parameters::Choices: - break; + { + QComboBox* v_choices = new QComboBox( this ); + v_choices->setObjectName( pIt->first.c_str( ) ); + + std::istringstream str0( pIt->second.second ); + std::string choices; + std::getline( str0, choices, '@' ); + std::istringstream str1( choices ); + std::string token; + int id = 0; + while( std::getline( str1, token, '#' ) ) + v_choices->insertItem( id++, token.c_str( ) ); + w_input = v_choices; + } + break; default: w_input = NULL; break; @@ -396,6 +411,9 @@ setParameters( Parameters* parameters ) ); this->m_ToolsLayout->addWidget( this->m_Buttons ); + // Update values + this->updateView( ); + return( true ); } @@ -499,7 +517,20 @@ updateParameters( ) case Parameters::PathNameList: break; case Parameters::Choices: - break; + { + QComboBox* v_choices = this->findChild< QComboBox* >( pName ); + if( v_choices != NULL ) + { + std::istringstream str_choices( pIt->second.second ); + std::string real_choices; + std::getline( str_choices, real_choices, '@' ); + pIt->second.second = + real_choices + "@" + + v_choices->currentText( ).toStdString( ); + + } // fi + } + break; default: break; } // hctiws @@ -590,7 +621,31 @@ updateView( ) case Parameters::PathNameList: break; case Parameters::Choices: - break; + { + QComboBox* v_choices = this->findChild< QComboBox* >( pName ); + if( v_choices != NULL ) + { + std::istringstream str_choices( pIt->second.second ); + std::string choices, real_choice; + std::getline( str_choices, choices, '@' ); + std::getline( str_choices, real_choice, '@' ); + std::istringstream str( choices ); + std::string token; + int id = -1, cont = 0; + while( std::getline( str, token, '#' ) ) + { + if( token == real_choice ) + id = cont; + cont++; + + } // elihw + + if( id > -1 ) + v_choices->setCurrentIndex( id ); + + } // fi + } + break; default: break; } // hctiws diff --git a/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx new file mode 100644 index 0000000..c8740cd --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx @@ -0,0 +1,112 @@ +#include "SignedMaurerDistanceMapImageFilter.h" +#include + +#include + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: +SignedMaurerDistanceMapImageFilter( ) + : Superclass( ) +{ + this->_AddInput( "Input" ); + this->_MakeOutput< cpPlugins::Interface::Image >( "Output" ); + + this->m_Parameters->ConfigureAsReal( "BackgroundValue" ); + this->m_Parameters->ConfigureAsBool( "InsideIsPositive" ); + this->m_Parameters->ConfigureAsBool( "SquaredDistance" ); + this->m_Parameters->ConfigureAsBool( "UseImageSpacing" ); + + std::vector< std::string > choices; + choices.push_back( "float" ); + choices.push_back( "double" ); + this->m_Parameters->ConfigureAsChoices( "OutputResolution", choices ); + + this->m_Parameters->SetReal( "BackgroundValue", 0 ); + this->m_Parameters->SetBool( "InsideIsPositive", true ); + this->m_Parameters->SetBool( "SquaredDistance", false ); + this->m_Parameters->SetBool( "UseImageSpacing", true ); + this->m_Parameters->SetSelectedChoice( "OutputResolution", "float" ); +} + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: +~SignedMaurerDistanceMapImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: +_GenerateData( ) +{ + cpPlugins::Interface::Image* image = + this->GetInput< cpPlugins::Interface::Image >( "Input" ); + if( image == NULL ) + return( "SignedMaurerDistanceMapImageFilter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); + else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); + else r = "SignedMaurerDistanceMapImageFilter: Input image type not supported."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: +_GD0( itk::DataObject* image ) +{ + std::string out_res = + this->m_Parameters->GetSelectedChoice( "OutputResolution" ); + if( out_res == "float" ) + return( + this->_RealGD< I, itk::Image< float, I::ImageDimension > >( + image + ) + ); + else if( out_res == "double" ) + return( + this->_RealGD< I, itk::Image< double, I::ImageDimension > >( + image + ) + ); + else + return( "SignedMaurerDistanceMapImageFilter: Output resolution not supported." ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +inline std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: +_RealGD( itk::DataObject* image ) +{ + typedef itk::SignedMaurerDistanceMapImageFilter< I, O > _F; + + // Get parameters + double back_value = this->m_Parameters->GetReal( "BackgroundValue" ); + bool pos_inside = this->m_Parameters->GetBool( "InsideIsPositive" ); + bool sqr_dist = this->m_Parameters->GetBool( "SquaredDistance" ); + bool use_spac = this->m_Parameters->GetBool( "UseImageSpacing" ); + + // Configure filter + _F* filter = this->_CreateITK< _F >( ); + filter->SetInput( dynamic_cast< I* >( image ) ); + filter->SetBackgroundValue( ( typename I::PixelType )( back_value ) ); + filter->SetInsideIsPositive( pos_inside ); + filter->SetSquaredDistance( sqr_dist ); + filter->SetUseImageSpacing( use_spac ); + + filter->Update( ); + + // Connect output + cpPlugins::Interface::Image* out = + this->GetOutput< cpPlugins::Interface::Image >( "Output" ); + if( out != NULL ) + { + out->SetITK< O >( filter->GetOutput( ) ); + return( "" ); + } + else + return( "SignedMaurerDistanceMapImageFilter: output not correctly created." ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.h new file mode 100644 index 0000000..2d87c76 --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.h @@ -0,0 +1,60 @@ +#ifndef __CPPLUGINS__PLUGINS__SIGNEDMAURERDISTANCEMAPIMAGEFILTER__H__ +#define __CPPLUGINS__PLUGINS__SIGNEDMAURERDISTANCEMAPIMAGEFILTER__H__ + +#include +#include + +namespace cpPlugins +{ + namespace BasicFilters + { + /** + */ + class cpPluginsBasicFilters_EXPORT SignedMaurerDistanceMapImageFilter + : public cpPlugins::Interface::ImageToImageFilter + { + public: + typedef SignedMaurerDistanceMapImageFilter Self; + typedef cpPlugins::Interface::ImageToImageFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( + SignedMaurerDistanceMapImageFilter, + cpPluginsInterfaceImageToImageFilter + ); + cpPlugins_Id_Macro( + cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter, + DistanceMapFilter + ); + + protected: + SignedMaurerDistanceMapImageFilter( ); + virtual ~SignedMaurerDistanceMapImageFilter( ); + + virtual std::string _GenerateData( ); + + template< class I > + inline std::string _GD0( itk::DataObject* image ); + + template< class I, class O > + inline std::string _RealGD( itk::DataObject* image ); + + private: + // Purposely not implemented + SignedMaurerDistanceMapImageFilter( const Self& ); + Self& operator=( const Self& ); + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( SignedMaurerDistanceMapImageFilter ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__SIGNEDMAURERDISTANCEMAPIMAGEFILTER__H__ + +// eof - $RCSfile$