]> Creatis software - cpPlugins.git/commitdiff
RescaleIntensity filter added.
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Thu, 29 Sep 2016 20:19:19 +0000 (15:19 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Thu, 29 Sep 2016 20:19:19 +0000 (15:19 -0500)
CMakeLists.txt
lib/Instances/cpPlugins_Images.i
lib/cpBaseQtApplication/MainWindow.cxx
lib/cpPlugins/Interface/Plugins.cxx
plugins/CMakeLists.txt
plugins/ImageGenericFilters/RescaleIntensityImageFilter.cxx [new file with mode: 0644]
plugins/ImageGenericFilters/RescaleIntensityImageFilter.h [new file with mode: 0644]
plugins/ImageSources/RandomImageSource.cxx [new file with mode: 0644]
plugins/ImageSources/RandomImageSource.h [new file with mode: 0644]

index 85fe564e12faa23b5818b28e1ece42a5ee791f34..8fb53f6c4ee6fed45b598d5d650dcba9ceca975c 100644 (file)
@@ -1,4 +1,4 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
 
 ## ========================
 ## == Project definition ==
index fd3781b709555627e8afd1a6839fb92fccff1429..140d90cb2dd28f950436d5908b891601ff62fc5e 100644 (file)
@@ -31,7 +31,7 @@ c itk::ImportImageContainer< unsigned long, itk::FixedArray< #pixels#, #process_
 c itk::ImportImageContainer< unsigned long, itk::Offset< #process_dims# > >
 
 c itk::Image$Base;Region$< #process_dims# >
-c itk::Image< #pixels#, #process_dims# >
+c itk::Image< $bool;#pixels#$, #process_dims# >
 c itk::Image< itk::#colors#< #pixels# >, #process_dims# >
 c itk::Image< std::complex< #reals# >, #process_dims# >
 c itk::Image< itk::#vectors#< #reals#, #process_dims# >, #process_dims# >
index 67a3844aaa3641fdf40cbef029ace9cce8fd1a2d..8e1abab90018474c27aec881ea7ae4888c7018b3 100644 (file)
@@ -70,7 +70,6 @@ MainWindow( int argc, char* argv[], QApplication* app, QWidget* parent )
 
   // Get the plugins interface
   this->m_Plugins = TPlugins::New( );
-  try { this->m_Plugins->AddEnvironments( env.str( ) ); } catch( ... ) { }
   try { this->m_Plugins->OpenEnvironments( env.str( ) ); } catch( ... ) { }
   try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { }
   this->updateEnvironment( );
index 3e68371f1faa31fc9a99c8b73b44d616f6332a4c..b5f9269809b4f5f86f3f4350073e47c914e0d332 100644 (file)
@@ -91,17 +91,7 @@ AddEnvironments( const std::string& new_environment )
     std::stringstream dir;
     dir << cpExtensions::CanonicalPath( *i );
     if( dir.str( ) != "" )
-    {
-      if( !cpExtensions::IsPathSeparator( dir.str( ).back( ) ) )
-        dir << cpExtensions_PATH_SEPARATOR;
-      std::stringstream name;
-      name << dir.str( ) << cpPlugins_CONFIG;
-      std::ifstream check( name.str( ).c_str( ), std::ifstream::binary );
-      if( check )
-        this->m_Paths.insert( dir.str( ) );
-      check.close( );
-
-    } // fi
+      this->m_Paths.insert( dir.str( ) );
 
   } // rof
 }
@@ -162,45 +152,59 @@ LoadEnvironments( )
 void cpPlugins::Interface::Plugins::
 SaveEnvironments( const std::string& dir ) const
 {
-  if( this->m_Paths.size( ) > 0 )
-  {
-    std::stringstream buffer;
-    auto i = this->m_Paths.begin( );
-    for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
-      buffer << *i << std::endl;
+  std::stringstream buffer;
+  for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
+    buffer << *i << std::endl;
 
-    std::stringstream fname;
-    fname << dir;
-    if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
-      fname << cpExtensions_PATH_SEPARATOR;
-    fname << cpPlugins_PATHS;
-    if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
-      throw std::runtime_error( "Error writing environment file." );
-  }
-  else
-    throw std::runtime_error( "No paths to save." );
+  std::stringstream fname;
+  fname << dir;
+  if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
+    fname << cpExtensions_PATH_SEPARATOR;
+  fname << cpPlugins_PATHS;
+  if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
+    throw std::runtime_error( "Error writing environment file." );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Plugins::
 OpenEnvironments( const std::string& dir )
 {
-  std::stringstream fname;
-  fname << dir;
-  if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
-    fname << cpExtensions_PATH_SEPARATOR;
-  fname << cpPlugins_PATHS;
-  std::string buffer;
-  if( cpExtensions::Read( buffer, fname.str( ) ) )
+  std::vector< std::string > tokens;
+  cpExtensions::Tokenize( tokens, dir, cpPlugins_ENV_SEPARATOR );
+  for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt )
   {
-    std::istringstream input( buffer );
-    std::stringstream paths;
-    for( std::string line; std::getline( input, line ); )
-      paths << line << cpPlugins_ENV_SEPARATOR;
-    this->AddEnvironments( paths.str( ) );
-  }
-  else
-    throw std::runtime_error( "Error opening environment file." );
+    std::stringstream fname;
+    fname << *tIt;
+    if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
+      fname << cpExtensions_PATH_SEPARATOR;
+    fname << cpPlugins_PATHS;
+    std::string buffer;
+    if( cpExtensions::Read( buffer, fname.str( ) ) )
+    {
+      std::istringstream input( buffer );
+      std::stringstream paths;
+      for( std::string line; std::getline( input, line ); )
+        paths << line << cpPlugins_ENV_SEPARATOR;
+      this->AddEnvironments( paths.str( ) );
+    }
+    else
+    {
+      bool success = true;
+      try
+      {
+        this->LoadDirectory( dir );
+      }
+      catch( ... )
+      {
+        success = false;
+
+      } // yrt
+      if( success )
+        this->AddEnvironments( dir );
+
+    } // fi
+
+  } // rof
 }
 
 // -------------------------------------------------------------------------
@@ -425,13 +429,22 @@ Plugins( )
   if( p != NULL )
     str << p << cpPlugins_ENV_SEPARATOR;
   str << ".";
-  this->AddEnvironments( str.str( ) );
+  this->OpenEnvironments( str.str( ) );
 
   // Try to read locally defined paths
-  std::vector< std::string > tokens;
-  cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
-  for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
-    this->OpenEnvironments( *t );
+  /* TODO
+     std::vector< std::string > tokens;
+     cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
+     for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
+     {
+     try
+     {
+     this->OpenEnvironments( *t );
+     }
+     catch( ... ) { }
+
+     } // rof
+  */
 }
 
 // -------------------------------------------------------------------------
index a985afe2d71242d385b560241f834228ef76b817..cbf2528277fb86ceae88a28bab9dfcc2292296ae 100644 (file)
@@ -11,6 +11,7 @@ SET(
   ImageGenericFilters
   ImageGradientFilters
   ImageMeshFilters
+  ImageSources
   ImageThresholdFilters
   IO
   MeshFilters
diff --git a/plugins/ImageGenericFilters/RescaleIntensityImageFilter.cxx b/plugins/ImageGenericFilters/RescaleIntensityImageFilter.cxx
new file mode 100644 (file)
index 0000000..01ccdbc
--- /dev/null
@@ -0,0 +1,54 @@
+#include <plugins/ImageGenericFilters/RescaleIntensityImageFilter.h>
+#include <cpPlugins/DataObjects/Image.h>
+
+#include <itkRescaleIntensityImageFilter.h>
+#include <itkRescaleIntensityImageFilter.hxx>
+#include <itkUnaryFunctorImageFilter.hxx>
+#include <itkMinimumMaximumImageCalculator.hxx>
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::RescaleIntensityImageFilter::
+RescaleIntensityImageFilter( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
+  this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
+
+  this->m_Parameters.ConfigureAsReal( "OutputMinimum" );
+  this->m_Parameters.ConfigureAsReal( "OutputMaximum" );
+
+  this->m_Parameters.SetReal( "OutputMinimum", 0 );
+  this->m_Parameters.SetReal( "OutputMaximum", 1 );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::RescaleIntensityImageFilter::
+~RescaleIntensityImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageGenericFilters::RescaleIntensityImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
+  else this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPluginsImageGenericFilters::RescaleIntensityImageFilter::
+_GD0( _TImage* input )
+{
+  typedef itk::RescaleIntensityImageFilter< _TImage > _TFilter;
+
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( input );
+  filter->SetOutputMinimum( this->m_Parameters.GetReal( "OutputMinimum" ) );
+  filter->SetOutputMaximum( this->m_Parameters.GetReal( "OutputMaximum" ) );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ImageGenericFilters/RescaleIntensityImageFilter.h b/plugins/ImageGenericFilters/RescaleIntensityImageFilter.h
new file mode 100644 (file)
index 0000000..d04ee48
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __cpPluginsImageGenericFilters__RescaleIntensityImageFilter__h__
+#define __cpPluginsImageGenericFilters__RescaleIntensityImageFilter__h__
+
+#include <plugins/cpPluginsImageGenericFilters_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsImageGenericFilters
+{
+  /**
+   */
+  class cpPluginsImageGenericFilters_EXPORT RescaleIntensityImageFilter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      RescaleIntensityImageFilter,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageFilters
+      );
+
+  protected:
+    template< class _TImage >
+      inline void _GD0( _TImage* input );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsImageGenericFilters__RescaleIntensityImageFilter__h__
+
+// eof - $RCSfile$
diff --git a/plugins/ImageSources/RandomImageSource.cxx b/plugins/ImageSources/RandomImageSource.cxx
new file mode 100644 (file)
index 0000000..b0ef6c4
--- /dev/null
@@ -0,0 +1,108 @@
+#include <plugins/ImageSources/RandomImageSource.h>
+#include <cpPlugins/DataObjects/Image.h>
+
+#include <itkRandomImageSource.h>
+#include <itkRandomImageSource.hxx>
+
+// -------------------------------------------------------------------------
+cpPluginsImageSources::RandomImageSource::
+RandomImageSource( )
+  : Superclass( )
+{
+  this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
+
+  this->m_Parameters.ConfigureAsUintList( "Size" );
+  this->m_Parameters.ConfigureAsRealList( "Spacing" );
+
+  std::vector< std::string > pixels;
+  pixels.push_back( "char" );
+  pixels.push_back( "short" );
+  pixels.push_back( "int" );
+  pixels.push_back( "long" );
+  pixels.push_back( "uchar" );
+  pixels.push_back( "ushort" );
+  pixels.push_back( "uint" );
+  pixels.push_back( "ulong" );
+  pixels.push_back( "float" );
+  pixels.push_back( "double" );
+  this->m_Parameters.ConfigureAsChoices( "PixelType", pixels );
+  this->m_Parameters.SetSelectedChoice( "PixelType", "uchar" );
+
+  std::vector< std::string > dims;
+  dims.push_back( "1" );
+  dims.push_back( "2" );
+  dims.push_back( "3" );
+  dims.push_back( "4" );
+  this->m_Parameters.ConfigureAsChoices( "Dimension", dims );
+  this->m_Parameters.SetSelectedChoice( "Dimension", "2" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageSources::RandomImageSource::
+~RandomImageSource( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageSources::RandomImageSource::
+_GenerateData( )
+{
+  auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" );
+  if     ( pixel == "char"   ) this->_GD0< char >( );
+  else if( pixel == "short"  ) this->_GD0< short >( );
+  else if( pixel == "int"    ) this->_GD0< int >( );
+  else if( pixel == "long"   ) this->_GD0< long >( );
+  else if( pixel == "uchar"  ) this->_GD0< unsigned char >( );
+  else if( pixel == "ushort" ) this->_GD0< unsigned short >( );
+  else if( pixel == "uint"   ) this->_GD0< unsigned int >( );
+  else if( pixel == "ulong"  ) this->_GD0< unsigned long >( );
+  else if( pixel == "float"  ) this->_GD0< float >( );
+  else if( pixel == "double" ) this->_GD0< double >( );
+  else this->_Error( "Invalid pixel type." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel >
+void cpPluginsImageSources::RandomImageSource::
+_GD0( )
+{
+  auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" );
+  if     ( dim == "1" ) this->_GD1< _TPixel, 1 >( );
+  else if( dim == "2" ) this->_GD1< _TPixel, 2 >( );
+  else if( dim == "3" ) this->_GD1< _TPixel, 3 >( );
+  else if( dim == "4" ) this->_GD1< _TPixel, 4 >( );
+  else this->_Error( "Invalid dimension." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+void cpPluginsImageSources::RandomImageSource::
+_GD1( )
+{
+  typedef itk::Image< _TPixel, _VDim >      _TImage;
+  typedef itk::RandomImageSource< _TImage > _TFilter;
+
+  auto size = this->m_Parameters.GetUintList( "Size" );
+  auto spacing = this->m_Parameters.GetRealList( "Spacing" );
+  if( size.size( ) < _VDim )
+    this->_Error( "Invalid size." );
+  if( spacing.size( ) < _VDim )
+    this->_Error( "Invalid spacing." );
+
+  typename _TImage::SizeType out_size;
+  typename _TImage::SpacingType out_spac;
+  for( unsigned int i = 0; i < _VDim; ++i )
+  {
+    out_size[ i ] = size[ i ];
+    out_spac[ i ] = spacing[ i ];
+
+  } // rof
+
+  _TFilter* filter = this->_CreateITK< _TFilter >( );
+  filter->SetSize( out_size );
+  filter->SetSpacing( out_spac );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ImageSources/RandomImageSource.h b/plugins/ImageSources/RandomImageSource.h
new file mode 100644 (file)
index 0000000..ad9b581
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __cpPluginsImageSources__RandomImageSource__h__
+#define __cpPluginsImageSources__RandomImageSource__h__
+
+#include <plugins/cpPluginsImageSources_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsImageSources
+{
+  /**
+   */
+  class cpPluginsImageSources_EXPORT RandomImageSource
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      RandomImageSource,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageSources
+      );
+
+  protected:
+    template< class _TPixel >
+    inline void _GD0( );
+
+    template< class _TPixel, unsigned int _VDim >
+    inline void _GD1( );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsImageSources__RandomImageSource__h__
+
+// eof - $RCSfile$