]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 17 Apr 2016 23:02:11 +0000 (18:02 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 17 Apr 2016 23:02:11 +0000 (18:02 -0500)
lib/cpPlugins_Instances/ScalarImagesBaseFilters.i
plugins/cpPluginsImageFilters/CastImageFilter.cxx [new file with mode: 0644]
plugins/cpPluginsImageFilters/CastImageFilter.h [new file with mode: 0644]

index 48209381bc452b21d2d15ae54b663c706fe03531..5b5ebb5aac263284ca557be9acc7799780a3e5b7 100644 (file)
@@ -9,6 +9,9 @@ d #itk_filters=ImageToImage;InPlaceImage
 
 i cpPlugins_Instances/ScalarImages.h
 t itk{#itk_filters}Filter.h
+t itkCastImageFilter.h
+t itkImageAlgorithm.h
+t itkUnaryFunctorImageFilter.h
 
 * =====================
 * = Base filter types =
@@ -17,4 +20,10 @@ c itk::{#itk_filters}Filter< itk::Image< #inputs, #dims >, itk::Image< #outputs,
 c itk::{#itk_filters}Filter< itk::Image< #pixels, 3 >, itk::Image< #pixels, 2 > >
 c itk::{#itk_filters}Filter< itk::Image< #pixels, 2 >, itk::Image< #pixels, 3 > >
 
+* ==================
+* = Simple filters =
+* ==================
+
+c itk::CastImageFilter< itk::Image< #inputs, #dims >, itk::Image< #outputs, #dims > >
+
 * eof - $RCSfile$
diff --git a/plugins/cpPluginsImageFilters/CastImageFilter.cxx b/plugins/cpPluginsImageFilters/CastImageFilter.cxx
new file mode 100644 (file)
index 0000000..0743b2a
--- /dev/null
@@ -0,0 +1,93 @@
+#include <cpPluginsImageFilters/CastImageFilter.h>
+#include <cpPlugins/Image.h>
+#include <cpPlugins_Instances/ScalarImagesBaseFilters.h>
+
+// -------------------------------------------------------------------------
+cpPluginsImageFilters::CastImageFilter::
+CastImageFilter( )
+  : Superclass( )
+{
+  this->_AddInput( "Input" );
+  this->_AddOutput< cpPlugins::Image >( "Output" );
+
+  std::vector< std::string > choices;
+  choices.push_back( "char" );
+  choices.push_back( "short" );
+  choices.push_back( "int" );
+  choices.push_back( "long" );
+  choices.push_back( "uchar" );
+  choices.push_back( "ushort" );
+  choices.push_back( "uint" );
+  choices.push_back( "ulong" );
+  choices.push_back( "float" );
+  choices.push_back( "double" );
+  this->m_Parameters.ConfigureAsChoices( "CastType", choices );
+  this->m_Parameters.SetSelectedChoice( "CastType", "uchar" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageFilters::CastImageFilter::
+~CastImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageFilters::CastImageFilter::
+_GenerateData( )
+{
+  auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
+  cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 1 );
+  else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 2 );
+  else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
+  else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 4 );
+  else this->_Error( "No valid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage >
+void cpPluginsImageFilters::CastImageFilter::
+_GD0( _TInputImage* image )
+{
+  auto out = this->m_Parameters.GetSelectedChoice( "CastType" );
+  if( out == "char" )
+    this->_GD1< _TInputImage, char >( image );
+  else if( out == "short" )
+    this->_GD1< _TInputImage, short >( image );
+  else if( out == "int" )
+    this->_GD1< _TInputImage, int >( image );
+  else if( out == "long" )
+    this->_GD1< _TInputImage, long >( image );
+  else if( out == "float" )
+    this->_GD1< _TInputImage, float >( image );
+  else if( out == "double" )
+    this->_GD1< _TInputImage, double >( image );
+  else if( out == "uchar" )
+    this->_GD1< _TInputImage, unsigned char >( image );
+  else if( out == "ushort" )
+    this->_GD1< _TInputImage, unsigned short >( image );
+  else if( out == "uint" )
+    this->_GD1< _TInputImage, unsigned int >( image );
+  else if( out == "ulong" )
+    this->_GD1< _TInputImage, unsigned long >( image );
+  else
+    this->_Error( "Invalid output casting type." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputPixel >
+void cpPluginsImageFilters::CastImageFilter::
+_GD1( _TInputImage* image )
+{
+  typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage;
+  typedef itk::CastImageFilter< _TInputImage, _TOutputImage > _TFilter;
+
+  // Configure filter
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( image );
+  filter->Update( );
+
+  // Connect output
+  this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/cpPluginsImageFilters/CastImageFilter.h b/plugins/cpPluginsImageFilters/CastImageFilter.h
new file mode 100644 (file)
index 0000000..d9760b0
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+#define __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+
+#include <plugins/cpPluginsImageFilters/cpPluginsImageFilters_Export.h>
+#include <cpPlugins/ProcessObject.h>
+
+namespace cpPluginsImageFilters
+{
+  /**
+   */
+  class cpPluginsImageFilters_EXPORT CastImageFilter
+    : public cpPlugins::ProcessObject
+  {
+  public:
+    typedef CastImageFilter      Self;
+    typedef cpPlugins::ProcessObject        Superclass;
+    typedef itk::SmartPointer< Self >       Pointer;
+    typedef itk::SmartPointer< const Self > ConstPointer;
+
+  public:
+    itkNewMacro( Self );
+    itkTypeMacro( CastImageFilter, cpPlugins::ProcessObject );
+    cpPlugins_Id_Macro( CastImageFilter, ImageFilters );
+
+  protected:
+    CastImageFilter( );
+    virtual ~CastImageFilter( );
+
+    virtual void _GenerateData( ) ITK_OVERRIDE;
+
+    template< class _TInputImage >
+      inline void _GD0( _TInputImage* image );
+
+    template< class _TInputImage, class _TOutputPixel >
+      inline void _GD1( _TInputImage* image );
+
+  private:
+    // Purposely not implemented
+    CastImageFilter( const Self& );
+    Self& operator=( const Self& );
+  };
+
+} // ecapseman
+
+#endif // __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+
+// eof - $RCSfile$