From: Leonardo Flórez-Valencia Date: Fri, 17 Feb 2017 22:21:40 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~7 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=cpPlugins.git;a=commitdiff_plain;h=31650ba6c437b0cd635307695f533592ce1c5ff3 ... --- diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ba1a41a..72feba3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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 index 0000000..11cda00 --- /dev/null +++ b/plugins/ITKRasterFilters/ITKRasterFilters.i @@ -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 index 0000000..2332714 --- /dev/null +++ b/plugins/ITKRasterFilters/RasterImageFilter.cxx @@ -0,0 +1,145 @@ +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +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 index 0000000..f9e6f0d --- /dev/null +++ b/plugins/ITKRasterFilters/RasterImageFilter.h @@ -0,0 +1,44 @@ +#ifndef __cpPluginsITKRasterFilters__RasterImageFilter__h__ +#define __cpPluginsITKRasterFilters__RasterImageFilter__h__ + +#include +#include + +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$