]> Creatis software - cpPlugins.git/commitdiff
CastImageFilter added.
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Thu, 10 Nov 2016 17:14:04 +0000 (12:14 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Thu, 10 Nov 2016 17:14:04 +0000 (12:14 -0500)
plugins/ImageGenericFilters/CastImageFilter.cxx [new file with mode: 0644]
plugins/ImageGenericFilters/CastImageFilter.h [new file with mode: 0644]

diff --git a/plugins/ImageGenericFilters/CastImageFilter.cxx b/plugins/ImageGenericFilters/CastImageFilter.cxx
new file mode 100644 (file)
index 0000000..31626a5
--- /dev/null
@@ -0,0 +1,78 @@
+#include <ImageGenericFilters/CastImageFilter.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Image_Demanglers.h>
+
+#include <itkCastImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::CastImageFilter::
+CastImageFilter( )
+  : Superclass( )
+{
+  typedef cpPlugins::DataObjects::Image _TImage;
+  this->_ConfigureInput< _TImage >( "Input", true, false );
+  this->_ConfigureOutput< _TImage >( "Output" );
+  this->m_Parameters.ConfigureAsScalarTypesChoices( "CastType" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::CastImageFilter::
+~CastImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageGenericFilters::CastImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput >
+void cpPluginsImageGenericFilters::CastImageFilter::
+_GD0( _TInput* input )
+{
+  std::string out_res =
+    this->m_Parameters.GetSelectedChoice( "CastType" );
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+  if( out_res == "char" ) this->_GD1< _TInput, char >( input );
+  if( out_res == "uchar" ) this->_GD1< _TInput, unsigned char >( input );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+  if( out_res == "short" ) this->_GD1< _TInput, short >( input );
+  if( out_res == "ushort" ) this->_GD1< _TInput, unsigned short >( input );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+  if( out_res == "int" ) this->_GD1< _TInput, int >( input );
+  if( out_res == "uint" ) this->_GD1< _TInput, unsigned int >( input );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+  if( out_res == "long" ) this->_GD1< _TInput, long >( input );
+  if( out_res == "ulong" ) this->_GD1< _TInput, unsigned long >( input );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#ifdef cpPlugins_CONFIG_REAL_TYPES_float
+  if( out_res == "float" ) this->_GD1< _TInput, float >( input );
+#endif // cpPlugins_CONFIG_REAL_TYPES_float
+#ifdef cpPlugins_CONFIG_REAL_TYPES_double
+  if( out_res == "double" ) this->_GD1< _TInput, double >( input );
+#endif // cpPlugins_CONFIG_REAL_TYPES_double
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutputPixel >
+void cpPluginsImageGenericFilters::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/ImageGenericFilters/CastImageFilter.h b/plugins/ImageGenericFilters/CastImageFilter.h
new file mode 100644 (file)
index 0000000..3ce8f80
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __cpPluginsImageGenericFilters__CastImageFilter__h__
+#define __cpPluginsImageGenericFilters__CastImageFilter__h__
+
+#include <cpPluginsImageGenericFilters_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsImageGenericFilters
+{
+  /**
+   */
+  class cpPluginsImageGenericFilters_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 // __cpPluginsImageGenericFilters__CastImageFilter__h__
+
+// eof - $RCSfile$