]> Creatis software - cpPlugins.git/commitdiff
Cast image filter added. ROI filter modified.
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 9 Dec 2016 20:58:18 +0000 (15:58 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 9 Dec 2016 20:58:18 +0000 (15:58 -0500)
lib/cpPlugins/BaseObjects/ProcessObject.cxx
plugins/ITKImageGenericFilters_1/CastImageFilter.cxx [new file with mode: 0644]
plugins/ITKImageGenericFilters_1/CastImageFilter.h [new file with mode: 0644]
plugins/ITKImageGenericFilters_1/RegionOfInterestImageFilter.cxx
plugins/ITKLevelSetFilters/LaplacianSegmentationLevelSetImageFilter.cxx

index 35b95ff643525bf900a30ed4fe8313eea3fa646a..457835e42a9a725012fdbd8e39c40535b619059e 100644 (file)
@@ -220,36 +220,44 @@ Update( )
 {
   // Force upstream updates
   bool update = ( this->m_LastExecutionTime < this->GetMTime( ) );
-  for( auto input : this->m_Inputs )
+  try
   {
-    for( unsigned int i = 0; i < input.second->Size( ); ++i )
+    for( auto input : this->m_Inputs )
     {
-      auto obj = input.second->Get( i );
-      if( obj != NULL )
+      for( unsigned int i = 0; i < input.second->Size( ); ++i )
       {
-        auto src = obj->GetSource( );
-        if( src != NULL )
+        auto obj = input.second->Get( i );
+        if( obj != NULL )
         {
-          src->Update( );
-          update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
+          auto src = obj->GetSource( );
+          if( src != NULL )
+          {
+            src->Update( );
+            update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
+
+          } // fi
+        }
+        else
+        {
+          if( input.second->IsRequired( ) )
+            this->_Error(
+              std::string( "Required input \"" ) + input.first +
+              std::string( "\" in filter \"" ) +
+              this->m_Name +
+              std::string( "\" is not valid." )
+              );
 
         } // fi
-      }
-      else
-      {
-        if( input.second->IsRequired( ) )
-          this->_Error(
-            std::string( "Required input \"" ) + input.first +
-            std::string( "\" in filter \"" ) +
-            this->m_Name +
-            std::string( "\" is not valid." )
-            );
 
-      } // fi
+      } // rof
 
     } // rof
+  }
+  catch( std::exception& err )
+  {
+    this->_Error( err.what( ) );
 
-  } // rof
+  } // yrt
 
   if( update || this->m_ExplicitExecution )
   {
@@ -266,22 +274,30 @@ Update( )
     } // fi
 
     // Execute filter's algorithm and keep information about time
-    auto t_start = cpPlugins_CHRONO;
-    this->_GenerateData( );
-    auto t_end = cpPlugins_CHRONO;
-    this->Modified( );
-    this->m_LastExecutionSpan = long( t_end - t_start );
-    this->m_LastExecutionTime = this->GetMTime( );
-
-    // End the message, if needed...
-    if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
+    try
     {
-      *( this->m_PrintExecutionStream )
-        << "done in "
-        << double( this->m_LastExecutionSpan ) / double( 1000 )
-        << " s." << std::endl;
+      auto t_start = cpPlugins_CHRONO;
+      this->_GenerateData( );
+      auto t_end = cpPlugins_CHRONO;
+      this->Modified( );
+      this->m_LastExecutionSpan = long( t_end - t_start );
+      this->m_LastExecutionTime = this->GetMTime( );
+
+      // End the message, if needed...
+      if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
+      {
+        *( this->m_PrintExecutionStream )
+          << "done in "
+          << double( this->m_LastExecutionSpan ) / double( 1000 )
+          << " s." << std::endl;
 
-    } // fi
+      } // fi
+    }
+    catch( std::exception& err )
+    {
+      this->_Error( err.what( ) );
+
+    } // yrt
 
   } // fi
 }
@@ -350,13 +366,9 @@ void cpPlugins::BaseObjects::ProcessObject::
 _Error( const std::string& error )
 {
   if( error != "" )
-  {
     itkExceptionMacro(
-      "Error: \"" << this->GetClassCategory( ) << "::" <<
-      this->GetClassName( ) << "\": " << error
+      "Error: \"" << this->m_Name << "\": " << error
       );
-
-  } // fi
 }
 
 // eof - $RCSfile$
diff --git a/plugins/ITKImageGenericFilters_1/CastImageFilter.cxx b/plugins/ITKImageGenericFilters_1/CastImageFilter.cxx
new file mode 100644 (file)
index 0000000..e01c475
--- /dev/null
@@ -0,0 +1,64 @@
+#include <ITKImageGenericFilters_1/CastImageFilter.h>
+#include <cpInstances/Image.h>
+
+#include <itkCastImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPluginsITKImageGenericFilters_1::CastImageFilter::
+CastImageFilter( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpInstances::Image >( "Input", true, false );
+  this->_ConfigureOutput< cpInstances::Image >( "Output" );
+  this->m_Parameters.ConfigureAsScalarTypesChoices( "OutputPixelType" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsITKImageGenericFilters_1::CastImageFilter::
+~CastImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsITKImageGenericFilters_1::CastImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput >
+void cpPluginsITKImageGenericFilters_1::CastImageFilter::
+_GD0( _TInput* input )
+{
+  std::string o_type =
+    this->m_Parameters.GetSelectedChoice( "OutputPixelType" );
+  if( o_type == "char" )        this->_GD1< _TInput, char >( input );
+  else if( o_type == "short" )  this->_GD1< _TInput, short >( input );
+  else if( o_type == "int" )    this->_GD1< _TInput, int >( input );
+  else if( o_type == "long" )   this->_GD1< _TInput, long >( input );
+  else if( o_type == "uchar" )  this->_GD1< _TInput, unsigned char >( input );
+  else if( o_type == "ushort" ) this->_GD1< _TInput, unsigned short >( input );
+  else if( o_type == "uint" )   this->_GD1< _TInput, unsigned int >( input );
+  else if( o_type == "ulong" )  this->_GD1< _TInput, unsigned long >( input );
+  else if( o_type == "float" )  this->_GD1< _TInput, float >( input );
+  else if( o_type == "double" ) this->_GD1< _TInput, double >( input );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutputPixel >
+void cpPluginsITKImageGenericFilters_1::CastImageFilter::
+_GD1( _TInput* input )
+{
+  typedef itk::Image< _TOutputPixel, _TInput::ImageDimension > _TOutput;
+  typedef itk::CastImageFilter< _TInput, _TOutput > _TFilter;
+
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( input );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ITKImageGenericFilters_1/CastImageFilter.h b/plugins/ITKImageGenericFilters_1/CastImageFilter.h
new file mode 100644 (file)
index 0000000..42da95b
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __cpPluginsITKImageGenericFilters_1__CastImageFilter__h__
+#define __cpPluginsITKImageGenericFilters_1__CastImageFilter__h__
+
+#include <cpPluginsITKImageGenericFilters_1_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsITKImageGenericFilters_1
+{
+  /**
+   */
+  class cpPluginsITKImageGenericFilters_1_EXPORT CastImageFilter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      CastImageFilter,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageFilters
+      );
+
+  protected:
+    template< class _TInput >
+    inline void _GD0( _TInput* input );
+
+    template< class _TInput, class _TOutputPixel >
+    inline void _GD1( _TInput* input );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsITKImageGenericFilters_1__CastImageFilter__h__
+
+// eof - $RCSfile$
index 61f2f58ef87049b4f72099e57d9e0c1e13c8a50e..32e57495310b980742f8bcd4c74d599e04e321d1 100644 (file)
@@ -63,7 +63,7 @@ _GD0( _TImage* input )
 
   _TSize size;
   for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
-    size[ d ] = i1[ d ] - i0[ d ] + 1;
+    size[ d ] = i1[ d ] - i0[ d ];
 
   _TRegion region;
   region.SetIndex( i0 );
index f9a36ea1c6d2ed9c3cdc638282cd58afd3e87c60..f1390d77f4a347755d2ebc0c393022d15a62b5ec 100644 (file)
@@ -31,7 +31,7 @@ _GenerateData( )
 {
   auto o = this->GetInputData( "Input" );
   cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
-    this->_Error( "Invalid input image dimension." );
+    this->_Error( "Invalid input image." );
 }
 
 // -------------------------------------------------------------------------