--- /dev/null
+#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$