]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 17 Feb 2017 22:21:40 +0000 (17:21 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 17 Feb 2017 22:21:40 +0000 (17:21 -0500)
plugins/CMakeLists.txt
plugins/ITKRasterFilters/ITKRasterFilters.i [new file with mode: 0644]
plugins/ITKRasterFilters/RasterImageFilter.cxx [new file with mode: 0644]
plugins/ITKRasterFilters/RasterImageFilter.h [new file with mode: 0644]

index ba1a41a3cc95d64615ea2d28a162d589c565fc2e..72feba3b6afb679df2d40cb8a318d6643812fa00 100644 (file)
@@ -23,6 +23,7 @@ SET(
   ITKSeparableFilters
   ITKSliceFilters
   ITKUnaryFunctorFilters
+  ITKRasterFilters
   cpExtensions
   )
 
diff --git a/plugins/ITKRasterFilters/ITKRasterFilters.i b/plugins/ITKRasterFilters/ITKRasterFilters.i
new file mode 100644 (file)
index 0000000..11cda00
--- /dev/null
@@ -0,0 +1,9 @@
+header #define ITK_MANUAL_INSTANTIATION
+
+tinclude itkTriangleMeshToBinaryImageFilter:h|hxx
+tinclude cpExtensions/Algorithms/RasterContourFilter:h|hxx
+
+instances itk::TriangleMeshToBinaryImageFilter< itk::Mesh< #real_types#, 3 >, itk::Image< #scalar_types#, 3 > >
+instances cpExtensions::Algorithms::RasterContourFilter< itk::Image< #scalar_types#, 2 > >
+
+** eof - $RCSfile$
diff --git a/plugins/ITKRasterFilters/RasterImageFilter.cxx b/plugins/ITKRasterFilters/RasterImageFilter.cxx
new file mode 100644 (file)
index 0000000..2332714
--- /dev/null
@@ -0,0 +1,145 @@
+#include <ITKRasterFilters/RasterImageFilter.h>
+#include <cpInstances/DataObjects/Image.h>
+#include <cpInstances/DataObjects/Mesh.h>
+
+#include <itkTriangleMeshToBinaryImageFilter.h>
+#include <cpExtensions/Algorithms/RasterContourFilter.h>
+
+// -------------------------------------------------------------------------
+cpPluginsITKRasterFilters::RasterImageFilter::
+RasterImageFilter( )
+  : Superclass( )
+{
+  typedef cpInstances::DataObjects::Mesh  _TMesh;
+  typedef cpInstances::DataObjects::Image _TImage;
+
+  this->_ConfigureInput< _TMesh >( "Input", true, false );
+  this->_ConfigureInput< _TImage >( "TemplateImage", false, false );
+  this->_ConfigureOutput< _TImage >( "Output" );
+
+  this->m_Parameters.ConfigureAsReal( "InsideValue", 1 );
+  this->m_Parameters.ConfigureAsReal( "OutsideValue", 0 );
+  this->m_Parameters.ConfigureAsScalarTypesChoices( "OutputPixelType" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsITKRasterFilters::RasterImageFilter::
+~RasterImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsITKRasterFilters::RasterImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Mesh_Meshes_1( o, _GD0_2D, 2 )
+    cpPlugins_Demangle_Mesh_Meshes_1( o, _GD0_3D, 3 )
+    this->_Error( "Invalid input image dimension." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TMesh >
+void cpPluginsITKRasterFilters::RasterImageFilter::
+_GD0_2D( _TMesh* mesh )
+{
+  std::string p_type =
+    this->m_Parameters.GetSelectedChoice( "OutputPixelType" );
+  if( p_type == "char" ) this->_GD1_2D< _TMesh, char >( mesh );
+  else if( p_type == "short" ) this->_GD1_2D< _TMesh, short >( mesh );
+  else if( p_type == "int" ) this->_GD1_2D< _TMesh, int >( mesh );
+  else if( p_type == "long" ) this->_GD1_2D< _TMesh, long >( mesh );
+  else if( p_type == "uchar" ) this->_GD1_2D< _TMesh, unsigned char >( mesh );
+  else if( p_type == "ushort" ) this->_GD1_2D< _TMesh, unsigned short >( mesh );
+  else if( p_type == "uint" ) this->_GD1_2D< _TMesh, unsigned int >( mesh );
+  else if( p_type == "ulong" ) this->_GD1_2D< _TMesh, unsigned long >( mesh );
+  else if( p_type == "float" ) this->_GD1_2D< _TMesh, float >( mesh );
+  else if( p_type == "double" ) this->_GD1_2D< _TMesh, double >( mesh );
+}
+
+// -------------------------------------------------------------------------
+template< class _TMesh, class _TPixelType >
+void cpPluginsITKRasterFilters::RasterImageFilter::
+_GD1_2D( _TMesh* mesh )
+{
+  typedef itk::Image< _TPixelType, 2 > _TImage;
+  typedef typename _TImage::Superclass _TBaseImage;
+  typedef cpExtensions::Algorithms::RasterContourFilter< _TImage > _TFilter;
+
+  // Configure filter
+  _TFilter* filter = this->_CreateITK< _TFilter >( );
+  filter->SetInsideValue( this->m_Parameters.GetReal( "InsideValue" ) );
+  filter->SetOutsideValue( this->m_Parameters.GetReal( "OutsideValue" ) );
+  filter->SetTemplate( this->GetInputData< _TBaseImage >( "TemplateImage" ) );
+  filter->ClearPoints( );
+  for( unsigned long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
+    filter->AddPoint( mesh->GetPoint( i ) );
+
+  // Execute and connect output
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TMesh >
+void cpPluginsITKRasterFilters::RasterImageFilter::
+_GD0_3D( _TMesh* mesh )
+{
+  std::string p_type =
+    this->m_Parameters.GetSelectedChoice( "OutputPixelType" );
+  if( p_type == "char" ) this->_GD1_3D< _TMesh, char >( mesh );
+  else if( p_type == "short" ) this->_GD1_3D< _TMesh, short >( mesh );
+  else if( p_type == "int" ) this->_GD1_3D< _TMesh, int >( mesh );
+  else if( p_type == "long" ) this->_GD1_3D< _TMesh, long >( mesh );
+  else if( p_type == "uchar" ) this->_GD1_3D< _TMesh, unsigned char >( mesh );
+  else if( p_type == "ushort" ) this->_GD1_3D< _TMesh, unsigned short >( mesh );
+  else if( p_type == "uint" ) this->_GD1_3D< _TMesh, unsigned int >( mesh );
+  else if( p_type == "ulong" ) this->_GD1_3D< _TMesh, unsigned long >( mesh );
+  else if( p_type == "float" ) this->_GD1_3D< _TMesh, float >( mesh );
+  else if( p_type == "double" ) this->_GD1_3D< _TMesh, double >( mesh );
+}
+
+// -------------------------------------------------------------------------
+template< class _TMesh, class _TPixelType >
+void cpPluginsITKRasterFilters::RasterImageFilter::
+_GD1_3D( _TMesh* mesh )
+{
+  typedef itk::Image< _TPixelType, 3 > _TImage;
+  typedef typename _TImage::Superclass _TBaseImage;
+  typedef itk::TriangleMeshToBinaryImageFilter< _TMesh, _TImage > _TFilter;
+
+  // Create filter
+  _TFilter* filter = this->_CreateITK< _TFilter >( );
+
+  // Compute bounding box
+  typename _TImage::DirectionType direction;
+  typename _TImage::PointType origin;
+  typename _TImage::SizeType size;
+  typename _TImage::SpacingType spac;
+  auto t_image = this->GetInputData< _TBaseImage >( "TemplateImage" );
+  if( t_image == NULL )
+  {
+  }
+  else
+  {
+    direction = t_image->GetDirection( );
+    origin = t_image->GetOrigin( );
+    size = t_image->GetLargestPossibleRegion( ).GetSize( );
+    spac = t_image->GetSpacing( );
+
+  } // fi
+
+  // Configure filter
+  filter->SetDirection( direction );
+  filter->SetOrigin( origin );
+  filter->SetSize( size );
+  filter->SetSpacing( spac );
+  filter->SetInsideValue( this->m_Parameters.GetReal( "InsideValue" ) );
+  filter->SetOutsideValue( this->m_Parameters.GetReal( "OutsideValue" ) );
+
+  // Execute and connect output
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ITKRasterFilters/RasterImageFilter.h b/plugins/ITKRasterFilters/RasterImageFilter.h
new file mode 100644 (file)
index 0000000..f9e6f0d
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef __cpPluginsITKRasterFilters__RasterImageFilter__h__
+#define __cpPluginsITKRasterFilters__RasterImageFilter__h__
+
+#include <cpPlugins_ITKRasterFilters_Export.h>
+#include <cpPlugins/Pipeline/ProcessObject.h>
+
+namespace cpPluginsITKRasterFilters
+{
+  /**
+   */
+  class cpPlugins_ITKRasterFilters_EXPORT RasterImageFilter
+    : public cpPlugins::Pipeline::ProcessObject
+  {
+    cpPluginsObject(
+      RasterImageFilter,
+      cpPlugins::Pipeline::ProcessObject,
+      MeshToImageFilters
+      );
+
+  protected:
+    template< class _TMesh >
+    inline void _GD0_2D( _TMesh* mesh );
+
+    template< class _TMesh, class _TPixelType >
+    inline void _GD1_2D( _TMesh* mesh );
+
+    template< class _TMesh >
+    inline void _GD0_3D( _TMesh* mesh );
+
+    template< class _TMesh, class _TPixelType >
+    inline void _GD1_3D( _TMesh* mesh );
+
+
+    /* TODO
+       template< class _TImage, class _TScalar >
+       inline void _GD1( _TImage* image );
+    */
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsITKRasterFilters__RasterImageFilter__h__
+
+// eof - $RCSfile$