From: Leonardo Flórez-Valencia Date: Wed, 23 Nov 2016 13:40:56 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~38 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=90bfa498079cf3d7de0d8ad0ec63154b767c1bc7;p=cpPlugins.git ... --- diff --git a/appli/CMakeLists.txt b/appli/CMakeLists.txt index b1e3af3..7daf319 100644 --- a/appli/CMakeLists.txt +++ b/appli/CMakeLists.txt @@ -1,4 +1,4 @@ -SUBDIRS(bash examples PipelineEditor) +SUBDIRS(bash plugins examples PipelineEditor) ## eof - $RCSfile$ diff --git a/appli/plugins/CMakeLists.txt b/appli/plugins/CMakeLists.txt new file mode 100644 index 0000000..d9f331f --- /dev/null +++ b/appli/plugins/CMakeLists.txt @@ -0,0 +1,19 @@ +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/lib + ${PROJECT_BINARY_DIR}/lib + ) +SET( + _plugins_APPS + ExecutePipeline + ) +FOREACH(_app ${_plugins_APPS}) + ADD_EXECUTABLE(cpPlugins_plugins_${_app} ${_app}) + TARGET_LINK_LIBRARIES(cpPlugins_plugins_${_app} cpPlugins) + SET( + cpPlugins_plugins_${_app}_APP cpPlugins_plugins_${_app} + CACHE INTERNAL "bash program cpPlugins_plugins_${_app}" + ) +ENDFOREACH(_app) + + +## eof - $RCSfile$ diff --git a/appli/plugins/ExecutePipeline.cxx b/appli/plugins/ExecutePipeline.cxx new file mode 100644 index 0000000..128583d --- /dev/null +++ b/appli/plugins/ExecutePipeline.cxx @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +int main( int argc, char* argv[] ) +{ + // Manage inputs + if( argc < 2 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " workspace [parameters]" << std::endl; + return( 1 ); + + } // fi + + // Create interface and load library + cpPlugins::Interface::Plugins::Pointer interface = + cpPlugins::Interface::Plugins::New( ); + try + { + interface->GuessPlugins( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + // Workspace + cpPlugins::Interface::Workspace::Pointer workspace = + cpPlugins::Interface::Workspace::New( ); + try + { + workspace->Load( argv[ 1 ] ); + } + catch( std::exception& err ) + { + std::cerr + << "Error loading workspace \"" << argv[ 1 ] + << "\": " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + // Read parameters + for( int i = 2; i < argc; ++i ) + { + std::vector< std::string > tokens; + cpPlugins::Tokenize( tokens, argv[ i ], "@=" ); + if( tokens.size( ) == 3 ) + { + auto filter = workspace->GetFilter( tokens[ 1 ] ); + if( filter != NULL ) + { + auto params = filter->GetParameters( ); + params->SetString( tokens[ 0 ], tokens[ 2 ], true ); + + } // fi + + } // fi + + } // rof + + // Execute filter + workspace->PrintExecutionOn( ); + try + { + workspace->Update( ); + } + catch( std::exception& err ) + { + std::cerr << std::endl << "********************************" << std::endl; + std::cerr << "Error caught: " << err.what( ) << std::endl; + std::cerr << "********************************" << std::endl; + return( 1 ); + + } // yrt + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/cpInstances/UnaryFunctorFilters.i b/lib/cpInstances/UnaryFunctorFilters.i index 7ae9eb3..55e0a69 100644 --- a/lib/cpInstances/UnaryFunctorFilters.i +++ b/lib/cpInstances/UnaryFunctorFilters.i @@ -3,15 +3,17 @@ header #define ITK_MANUAL_INSTANTIATION define all_ints=#int_types#;#uint_types# define in_scalars=#scalar_pixels# define out_scalars=#scalar_pixels# +define filters=AbsImageFilter;NotImageFilter tinclude itkUnaryFunctorImageFilter:h|hxx tinclude itkInvertIntensityImageFilter:h|hxx tinclude itkBinaryThresholdImageFilter:h|hxx tinclude itkCastImageFilter:h|hxx -cinclude itkNotImageFilter.h +cinclude itk#filters#.h instances itk::UnaryFunctorImageFilter< itk::Image< #all_ints#, #process_dims# >, itk::Image< #all_ints#, #process_dims# >, itk::Functor::NOT< #all_ints#, #all_ints# > > +instances itk::UnaryFunctorImageFilter< itk::Image< #scalar_pixels#, #process_dims# >, itk::Image< #scalar_pixels#, #process_dims# >, itk::Functor::Abs< #scalar_pixels#, #scalar_pixels# > > instances itk::CastImageFilter< itk::Image< #in_scalars#, #process_dims# >, itk::Image< #out_scalars#, #process_dims# > > diff --git a/plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx new file mode 100644 index 0000000..1249a4f --- /dev/null +++ b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx @@ -0,0 +1,46 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpPluginsITKUnaryFunctorFilters::AbsImageFilter:: +AbsImageFilter( ) + : Superclass( ) +{ + typedef cpInstances::Image _TImage; + + this->_ConfigureInput< _TImage >( "Input", true, false ); + this->_ConfigureOutput< _TImage >( "Output" ); +} + +// ------------------------------------------------------------------------- +cpPluginsITKUnaryFunctorFilters::AbsImageFilter:: +~AbsImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsITKUnaryFunctorFilters::AbsImageFilter:: +_GenerateData( ) +{ + auto o = this->GetInputData( "Input" ); + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpPluginsITKUnaryFunctorFilters::AbsImageFilter:: +_GD0( _TImage* image ) +{ + typedef itk::AbsImageFilter< _TImage, _TImage > _TFilter; + + // Configure filter + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ITKUnaryFunctorFilters/AbsImageFilter.h b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.h new file mode 100644 index 0000000..8d03b10 --- /dev/null +++ b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.h @@ -0,0 +1,29 @@ +#ifndef __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__ +#define __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__ + +#include +#include + +namespace cpPluginsITKUnaryFunctorFilters +{ + /** + */ + class cpPluginsITKUnaryFunctorFilters_EXPORT AbsImageFilter + : public cpPlugins::BaseObjects::ProcessObject + { + cpPluginsObject( + AbsImageFilter, + cpPlugins::BaseObjects::ProcessObject, + ImageFilters + ); + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + }; + +} // ecapseman + +#endif // __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__ + +// eof - $RCSfile$ diff --git a/plugins/VTKFilters/MarchingCubes.cxx b/plugins/VTKFilters/MarchingCubes.cxx new file mode 100644 index 0000000..b8a7866 --- /dev/null +++ b/plugins/VTKFilters/MarchingCubes.cxx @@ -0,0 +1,64 @@ +#include +#include +#include + +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsVTKFilters::MarchingCubes:: +MarchingCubes( ) + : Superclass( ) +{ + this->_ConfigureInput< cpInstances::Image >( "Input", true, false ); + this->_ConfigureOutput< cpInstances::Mesh >( "Output" ); + this->m_Parameters.ConfigureAsRealList( "Thresholds" ); +} + +// ------------------------------------------------------------------------- +cpPluginsVTKFilters::MarchingCubes:: +~MarchingCubes( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsVTKFilters::MarchingCubes:: +_GenerateData( ) +{ + // Get input + auto image = this->GetInput( "Input" ); + vtkImageData* vtk_image = image->GetVTK< vtkImageData >( ); + if( vtk_image == NULL ) + this->_Error( "Input does not have a valid VTK conversion." ); + + std::vector< double > values = + this->m_Parameters.GetRealList( "Thresholds" ); + vtkPolyData* pd = NULL; + if( vtk_image->GetDataDimension( ) == 2 ) + { + vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( ); + ms->SetInputData( vtk_image ); + for( unsigned int i = 0; i < values.size( ); ++i ) + ms->SetValue( i, values[ i ] ); + ms->Update( ); + pd = ms->GetOutput( ); + } + else if( vtk_image->GetDataDimension( ) == 3 ) + { + vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( ); + mc->ComputeNormalsOff( ); + mc->SetInputData( vtk_image ); + for( unsigned int i = 0; i < values.size( ); ++i ) + mc->SetValue( i, values[ i ] ); + mc->Update( ); + pd = mc->GetOutput( ); + } + else + this->_Error( "Input data does not have a valid dimension." ); + + // Connect output + this->GetOutput( "Output" )->SetVTK( pd ); +} + +// eof - $RCSfile$ diff --git a/plugins/VTKFilters/MarchingCubes.h b/plugins/VTKFilters/MarchingCubes.h new file mode 100644 index 0000000..fe29362 --- /dev/null +++ b/plugins/VTKFilters/MarchingCubes.h @@ -0,0 +1,25 @@ +#ifndef __cpPluginsVTKFilters__MarchingCubes__h__ +#define __cpPluginsVTKFilters__MarchingCubes__h__ + +#include +#include + +namespace cpPluginsVTKFilters +{ + /** + */ + class cpPluginsVTKFilters_EXPORT MarchingCubes + : public cpPlugins::BaseObjects::ProcessObject + { + cpPluginsObject( + MarchingCubes, + cpPlugins::BaseObjects::ProcessObject, + ImageToMeshFilters + ); + }; + +} // ecapseman + +#endif // __cpPluginsVTKFilters__MarchingCubes__h__ + +// eof - $RCSfile$