]> Creatis software - cpPlugins.git/commitdiff
Maurer signed distance filter added.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 18 Jan 2016 23:04:14 +0000 (18:04 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 18 Jan 2016 23:04:14 +0000 (18:04 -0500)
appli/bash/cpPlugins_createHost.cxx
lib/cpPlugins/Interface/ParametersQtDialog.cxx
lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.h [new file with mode: 0644]

index 6f8214d1bb828c1f0f0d9b0f11d92a21dce4aa7e..4f46211900df09edbd6c78ff9c12555582947db0 100644 (file)
@@ -54,7 +54,7 @@ int main( int argc, char* argv[] )
 
   output_code << "#include <Pluma/Connector.hpp>" << 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
index 3df62ee731aa417a959b043eafebffde64ad42e9..731fc77a120a9bd371c4b44a2e1dd02e4a328b76 100644 (file)
@@ -10,6 +10,7 @@
 #include <vtkRenderWindowInteractor.h>
 
 #include <QCheckBox>
+#include <QComboBox>
 #include <QDoubleSpinBox>
 #include <QFileDialog>
 #include <QHBoxLayout>
@@ -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 (file)
index 0000000..c8740cd
--- /dev/null
@@ -0,0 +1,112 @@
+#include "SignedMaurerDistanceMapImageFilter.h"
+#include <cpPlugins/Interface/Image.h>
+
+#include <itkSignedMaurerDistanceMapImageFilter.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..2d87c76
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef __CPPLUGINS__PLUGINS__SIGNEDMAURERDISTANCEMAPIMAGEFILTER__H__
+#define __CPPLUGINS__PLUGINS__SIGNEDMAURERDISTANCEMAPIMAGEFILTER__H__
+
+#include <cpPlugins/BasicFilters/cpPluginsBasicFilters_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+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$