From 80ac2c55630c2a345a2102f0be86843147a398cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Mon, 5 Dec 2016 19:09:59 -0500 Subject: [PATCH] ... --- .../DataStructures/FourierSeriesContour.cxx | 22 ++-- .../DataStructures/FourierSeriesContour.h | 26 ++--- lib/cpInstances/CMakeLists.txt | 13 ++- lib/cpInstances/ITKImageInterpolators.i | 5 + lib/cpPlugins/BaseObjects/Parameters.cxx | 3 + plugins/CMakeLists.txt | 6 + .../BSplineInterpolateImageFunction.cxx | 62 ++++++++++ .../BSplineInterpolateImageFunction.h | 38 ++++++ .../InterpolateImageFunction.cxx | 23 ++++ .../InterpolateImageFunction.h | 50 ++++++++ .../LinearInterpolateImageFunction.cxx | 58 ++++++++++ .../LinearInterpolateImageFunction.h | 38 ++++++ plugins/ITKSliceFilters/CPRImageFilter.cxx | 61 ++++++---- plugins/ITKSliceFilters/ITKSliceFilters.i | 7 ++ .../IsoResampleImageFilter.cxx | 109 ++++++++++++++++++ .../ITKSliceFilters/IsoResampleImageFilter.h | 32 +++++ 16 files changed, 505 insertions(+), 48 deletions(-) create mode 100644 plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.cxx create mode 100644 plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.h create mode 100644 plugins/ITKImageInterpolators/InterpolateImageFunction.cxx create mode 100644 plugins/ITKImageInterpolators/InterpolateImageFunction.h create mode 100644 plugins/ITKImageInterpolators/LinearInterpolateImageFunction.cxx create mode 100644 plugins/ITKImageInterpolators/LinearInterpolateImageFunction.h create mode 100644 plugins/ITKSliceFilters/ITKSliceFilters.i create mode 100644 plugins/ITKSliceFilters/IsoResampleImageFilter.cxx create mode 100644 plugins/ITKSliceFilters/IsoResampleImageFilter.h diff --git a/lib/cpExtensions/DataStructures/FourierSeriesContour.cxx b/lib/cpExtensions/DataStructures/FourierSeriesContour.cxx index 989b0bc..679f216 100644 --- a/lib/cpExtensions/DataStructures/FourierSeriesContour.cxx +++ b/lib/cpExtensions/DataStructures/FourierSeriesContour.cxx @@ -26,7 +26,7 @@ template< class _TScalar > _TScalar cpExtensions::DataStructures::FourierSeriesContour< _TScalar >:: GetArea( ) const { - S a = TScalar( 0 ); + TScalar a = TScalar( 0 ); int q = this->GetNumberOfHarmonics( ); typename Self::const_iterator i = this->begin( ); for( int l = -q; i != this->end( ); ++i, ++l ) @@ -403,7 +403,7 @@ operator&( const _TScalar& phase ) const int q = this->GetNumberOfHarmonics( ); typename Self::const_iterator i = this->begin( ); for( int l = -q; i != this->end( ); ++i, ++l ) - res.push_back( *i * std::polar( S( 1 ), S( l ) * phase ) ); + res.push_back( *i * std::polar( TScalar( 1 ), TScalar( l ) * phase ) ); return( res ); } @@ -416,7 +416,7 @@ operator&=( const _TScalar& phase ) int q = this->GetNumberOfHarmonics( ); typename Self::iterator i = this->begin( ); for( int l = -q; i != this->end( ); ++i, ++l ) - *i *= std::polar( S( 1 ), S( l ) * phase ); + *i *= std::polar( TScalar( 1 ), TScalar( l ) * phase ); return( *this ); } @@ -473,8 +473,8 @@ GetPhase( const _TScalar& w ) const // 1.1. Roughly sample phases for( unsigned int s = 0; s < _samples; ++s ) { - S w = TScalar( s ) * _angleOff; - S a = std::arg( contour._Z( w, 0 ) ); + TScalar w = TScalar( s ) * _angleOff; + TScalar a = std::arg( contour._Z( w, 0 ) ); function.push_back( std::pair< TScalar, TScalar >( w, a ) ); if( a < minA ) { @@ -545,7 +545,7 @@ Sample( std::vector< TPoint >& p, const unsigned long& s ) const static const TScalar _2pi = TScalar( 2 ) * TScalar( vnl_math::pi ); TScalar off = _2pi / TScalar( s - 1 ); for( unsigned int w = 0; w < s; ++w ) - p.push_back( ( *this )( S( w ) * off ) ); + p.push_back( ( *this )( TScalar( w ) * off ) ); } // ------------------------------------------------------------------------- @@ -571,8 +571,12 @@ GetEllipse( int l, _TScalar& a, _TScalar& b, _TScalar& t, _TScalar& p ) const { zp /= np; zn /= nn; - t = std::real( std::log( zp * zn ) / TComplex( TScalar( 0 ), S( 2 ) ) ); - p = std::real( std::log( zp / zn ) / TComplex( TScalar( 0 ), S( 2 * l ) ) ); + t = std::real( + std::log( zp * zn ) / TComplex( TScalar( 0 ), TScalar( 2 ) ) + ); + p = std::real( + std::log( zp / zn ) / TComplex( TScalar( 0 ), TScalar( 2 * l ) ) + ); } else { @@ -623,7 +627,7 @@ template< class _TScalar > void cpExtensions::DataStructures::FourierSeriesContour< _TScalar >:: _DFT( const std::vector< TComplex >& p, unsigned int q ) { - static const S _2pi = TScalar( 2 ) * TScalar( vnl_math::pi ); + static const TScalar _2pi = TScalar( 2 ) * TScalar( vnl_math::pi ); this->SetNumberOfHarmonics( q ); *this *= TScalar( 0 ); diff --git a/lib/cpExtensions/DataStructures/FourierSeriesContour.h b/lib/cpExtensions/DataStructures/FourierSeriesContour.h index 56ad853..3590549 100644 --- a/lib/cpExtensions/DataStructures/FourierSeriesContour.h +++ b/lib/cpExtensions/DataStructures/FourierSeriesContour.h @@ -19,33 +19,33 @@ namespace cpExtensions * */ template< class _TScalar > - class cpExtensions_EXPORT FourierSeries + class cpExtensions_EXPORT FourierSeriesContour : public std::deque< std::complex< _TScalar > > { public: - typedef FourierSeries Self; - typedef _TScalar TScalar; - typedef itk::Matrix< S, 2, 2 > TMatrix; - typedef itk::Point< S, 2 > TPoint; - typedef typename TPoint::VectorType TVector; - typedef std::complex< S > TComplex; - typedef std::deque< TComplex > Superclass; + typedef FourierSeriesContour Self; + typedef _TScalar TScalar; + typedef itk::Matrix< TScalar, 2, 2 > TMatrix; + typedef itk::Point< TScalar, 2 > TPoint; + typedef typename TPoint::VectorType TVector; + typedef std::complex< TScalar > TComplex; + typedef std::deque< TComplex > Superclass; public: - FourierSeries( unsigned int q = 1 ); + FourierSeriesContour( unsigned int q = 1 ); template< class _TScalar2 > - FourierSeries( const FourierSeries< _TScalar2 >& o ); + FourierSeriesContour( const FourierSeriesContour< _TScalar2 >& o ); template< class _TIterator > - FourierSeries( + FourierSeriesContour( const _TIterator& b, const _TIterator& e, unsigned int q ); - virtual ~FourierSeries( ); + virtual ~FourierSeriesContour( ); template< class _TScalar2 > - Self& operator=( const FourierSeries< _TSCalar2 >& o ); + Self& operator=( const FourierSeriesContour< _TScalar2 >& o ); bool operator==( const Self& o ) const { return( false ); } bool operator!=( const Self& o ) const { return( true ); } diff --git a/lib/cpInstances/CMakeLists.txt b/lib/cpInstances/CMakeLists.txt index ece1f31..031e960 100644 --- a/lib/cpInstances/CMakeLists.txt +++ b/lib/cpInstances/CMakeLists.txt @@ -25,7 +25,6 @@ CreateLib( ${CMAKE_CURRENT_SOURCE_DIR}/ITKMeshes.i ${CMAKE_CURRENT_SOURCE_DIR}/ITKPaths.i ${CMAKE_CURRENT_SOURCE_DIR}/ITKTransforms.i - ${CMAKE_CURRENT_SOURCE_DIR}/ITKImageInterpolators.i ) TARGET_LINK_LIBRARIES( ${_pfx}ITKDataObjects @@ -43,6 +42,16 @@ TARGET_LINK_LIBRARIES( ${_pfx}ITKDataObjects ) +CreateLib( + ${_pfx}ITKImageInterpolators + SHARED + ${CMAKE_CURRENT_SOURCE_DIR}/ITKImageInterpolators.i + ) +TARGET_LINK_LIBRARIES( + ${_pfx}ITKImageInterpolators + ${_pfx}ITKBaseImageFilters + ) + CreateLib( ${_pfx}ITKBaseImageFilters SHARED @@ -79,6 +88,7 @@ CreateLib( TARGET_LINK_LIBRARIES( cpPluginsDataObjects cpPlugins + cpExtensions ${_pfx}ITKBaseImageFilters ) @@ -91,6 +101,7 @@ SET( ${_pfx}ITKBaseObjects ${_pfx}ITKDataObjects ${_pfx}ITKImageIterators + ${_pfx}ITKImageInterpolators ${_pfx}ITKBaseImageFilters CACHE INTERNAL "All valid instances." FORCE ) diff --git a/lib/cpInstances/ITKImageInterpolators.i b/lib/cpInstances/ITKImageInterpolators.i index caaff5d..c6c5f9c 100644 --- a/lib/cpInstances/ITKImageInterpolators.i +++ b/lib/cpInstances/ITKImageInterpolators.i @@ -17,4 +17,9 @@ instances itk::#interp#InterpolateImageFunction< itk::Image< #scalar_types#, #pd instances itk::VectorLinearInterpolateImageFunction< itk::Image< itk::#v#< #i_real#, #pdims# >, #pdims# >, #o_real# > +tinclude itkBSplineDecompositionImageFilter:h|hxx +tinclude itkBSplineInterpolateImageFunction:h|hxx +instances itk::BSplineInterpolateImageFunction< itk::Image< #scalar_types#, #pdims# >, #real_types#, #real_types# > +instances itk::BSplineDecompositionImageFilter< itk::Image< #scalar_types#, #pdims# >, itk::Image< #real_types#, #pdims# > > + ** eof - $RCSfile$ diff --git a/lib/cpPlugins/BaseObjects/Parameters.cxx b/lib/cpPlugins/BaseObjects/Parameters.cxx index cfb5f83..4025461 100644 --- a/lib/cpPlugins/BaseObjects/Parameters.cxx +++ b/lib/cpPlugins/BaseObjects/Parameters.cxx @@ -200,6 +200,7 @@ ConfigureAsRealTypesChoices( const std::string& name ) choices.push_back( "float" ); choices.push_back( "double" ); this->ConfigureAsChoices( name, choices ); + this->SetSelectedChoice( name, "float" ); } // ------------------------------------------------------------------------- @@ -216,6 +217,7 @@ ConfigureAsIntTypesChoices( const std::string& name ) choices.push_back( "long" ); choices.push_back( "ulong" ); this->ConfigureAsChoices( name, choices ); + this->SetSelectedChoice( name, "char" ); } // ------------------------------------------------------------------------- @@ -234,6 +236,7 @@ ConfigureAsScalarTypesChoices( const std::string& name ) choices.push_back( "float" ); choices.push_back( "double" ); this->ConfigureAsChoices( name, choices ); + this->SetSelectedChoice( name, "char" ); } // ------------------------------------------------------------------------- diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 53d00f8..9a44ffb 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -20,6 +20,8 @@ SET( ITKSeparableFilters ITKMorphology ITKParaMorphology + ITKSliceFilters + ITKImageInterpolators cpExtensions ) @@ -68,5 +70,9 @@ TARGET_LINK_LIBRARIES( cpPluginsITKMorphology cpPluginsITKUnaryFunctorFilters ) +TARGET_LINK_LIBRARIES( + cpPluginsITKSliceFilters + cpPluginsITKImageInterpolators + ) ## eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.cxx b/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.cxx new file mode 100644 index 0000000..49af74c --- /dev/null +++ b/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.cxx @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +BSplineInterpolateImageFunction( ) + : Superclass( ) +{ + this->m_Parameters.ConfigureAsUint( "SplineOrder", 3 ); + this->m_Parameters.ConfigureAsBool( "UseImageDirection", true ); +} + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +~BSplineInterpolateImageFunction( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +CreateInterpolator( + itk::LightObject* image, const std::string& precision_type + ) +{ + this->m_PrecisionType = precision_type; + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( image, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +void cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +_GD0( _TImage* image ) +{ + if( this->m_PrecisionType == "float" ) + this->_GD1< _TImage, float >( image ); + else if( this->m_PrecisionType == "double" ) + this->_GD1< _TImage, double >( image ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TScalar > +void cpPluginsITKImageInterpolators::BSplineInterpolateImageFunction:: +_GD1( _TImage* image ) +{ + typedef itk::BSplineInterpolateImageFunction< _TImage, _TScalar, _TScalar > _TFunction; + + auto function = this->_CreateITK< _TFunction >( ); + function->SetSplineOrder( this->m_Parameters.GetUint( "SplineOrder" ) ); + function->SetUseImageDirection( this->m_Parameters.GetBool( "UseImageDirection" ) ); + this->GetOutput( "Output" )->SetITK( function ); +} + +// eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.h b/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.h new file mode 100644 index 0000000..f227327 --- /dev/null +++ b/plugins/ITKImageInterpolators/BSplineInterpolateImageFunction.h @@ -0,0 +1,38 @@ +#ifndef __cpPluginsITKImageInterpolators__BSplineInterpolateImageFunction__h__ +#define __cpPluginsITKImageInterpolators__BSplineInterpolateImageFunction__h__ + +#include +#include + +namespace cpPluginsITKImageInterpolators +{ + /** + */ + class cpPluginsITKImageInterpolators_EXPORT BSplineInterpolateImageFunction + : public InterpolateImageFunction + { + cpPluginsObject( + BSplineInterpolateImageFunction, + InterpolateImageFunction, + ITKImageInterpolators + ); + + public: + virtual void CreateInterpolator( + itk::LightObject* image, + const std::string& precision_type + ) cpPlugins_OVERRIDE; + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + + template< class _TImage, class _TScalar > + inline void _GD1( _TImage* image ); + }; + +} // ecapseman + +#endif // __cpPluginsITKImageInterpolators__BSplineInterpolateImageFunction__h__ + +// eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/InterpolateImageFunction.cxx b/plugins/ITKImageInterpolators/InterpolateImageFunction.cxx new file mode 100644 index 0000000..8d85bc9 --- /dev/null +++ b/plugins/ITKImageInterpolators/InterpolateImageFunction.cxx @@ -0,0 +1,23 @@ +#include + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::InterpolateImageFunction:: +InterpolateImageFunction( ) + : Superclass( ) +{ + this->_ConfigureOutput< cpPlugins::BaseObjects::DataObject >( "Output" ); +} + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::InterpolateImageFunction:: +~InterpolateImageFunction( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsITKImageInterpolators::InterpolateImageFunction:: +_GenerateData( ) +{ +} + +// eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/InterpolateImageFunction.h b/plugins/ITKImageInterpolators/InterpolateImageFunction.h new file mode 100644 index 0000000..88b8b58 --- /dev/null +++ b/plugins/ITKImageInterpolators/InterpolateImageFunction.h @@ -0,0 +1,50 @@ +#ifndef __cpPluginsITKImageInterpolators__InterpolateImageFunction__h__ +#define __cpPluginsITKImageInterpolators__InterpolateImageFunction__h__ + +#include +#include + +namespace cpPluginsITKImageInterpolators +{ + /** + */ + class cpPluginsITKImageInterpolators_EXPORT InterpolateImageFunction + : public cpPlugins::BaseObjects::ProcessObject + { + public: + typedef InterpolateImageFunction Self; + typedef cpPlugins::BaseObjects::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkTypeMacro( BaseFilter, cpPlugins::BaseObjects::ProcessObject ); + cpPlugins_Id_Macro( InterpolateImageFunction, ImageInterpolators ); + + protected: + InterpolateImageFunction( ); + virtual ~InterpolateImageFunction( ); + + public: + virtual void CreateInterpolator( + itk::LightObject* image, + const std::string& precision_type + ) = 0; + + protected: + virtual void _GenerateData( ) cpPlugins_OVERRIDE; + + private: + // Purposely not implemented. + InterpolateImageFunction( const Self& other ); + Self& operator=( const Self& other ); + + protected: + std::string m_PrecisionType; + }; + +} // ecapseman + +#endif // __cpPluginsITKImageInterpolators__InterpolateImageFunction__h__ + +// eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.cxx b/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.cxx new file mode 100644 index 0000000..55a3c37 --- /dev/null +++ b/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.cxx @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +LinearInterpolateImageFunction( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +~LinearInterpolateImageFunction( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +CreateInterpolator( + itk::LightObject* image, const std::string& precision_type + ) +{ + this->m_PrecisionType = precision_type; + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( image, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +void cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +_GD0( _TImage* image ) +{ + if( this->m_PrecisionType == "float" ) + this->_GD1< _TImage, float >( image ); + else if( this->m_PrecisionType == "double" ) + this->_GD1< _TImage, double >( image ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TScalar > +void cpPluginsITKImageInterpolators::LinearInterpolateImageFunction:: +_GD1( _TImage* image ) +{ + typedef itk::LinearInterpolateImageFunction< _TImage, _TScalar > _TFunction; + + auto function = this->_CreateITK< _TFunction >( ); + this->GetOutput( "Output" )->SetITK( function ); +} + +// eof - $RCSfile$ diff --git a/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.h b/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.h new file mode 100644 index 0000000..6b3aabf --- /dev/null +++ b/plugins/ITKImageInterpolators/LinearInterpolateImageFunction.h @@ -0,0 +1,38 @@ +#ifndef __cpPluginsITKImageInterpolators__LinearInterpolateImageFunction__h__ +#define __cpPluginsITKImageInterpolators__LinearInterpolateImageFunction__h__ + +#include +#include + +namespace cpPluginsITKImageInterpolators +{ + /** + */ + class cpPluginsITKImageInterpolators_EXPORT LinearInterpolateImageFunction + : public InterpolateImageFunction + { + cpPluginsObject( + LinearInterpolateImageFunction, + InterpolateImageFunction, + ITKImageInterpolators + ); + + public: + virtual void CreateInterpolator( + itk::LightObject* image, + const std::string& precision_type + ) cpPlugins_OVERRIDE; + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + + template< class _TImage, class _TScalar > + inline void _GD1( _TImage* image ); + }; + +} // ecapseman + +#endif // __cpPluginsITKImageInterpolators__LinearInterpolateImageFunction__h__ + +// eof - $RCSfile$ diff --git a/plugins/ITKSliceFilters/CPRImageFilter.cxx b/plugins/ITKSliceFilters/CPRImageFilter.cxx index b2f14e4..9c22570 100644 --- a/plugins/ITKSliceFilters/CPRImageFilter.cxx +++ b/plugins/ITKSliceFilters/CPRImageFilter.cxx @@ -1,23 +1,28 @@ #include -#include -#include -#include -#include -#include +/* TODO + #include + #include + + #include + #include + #include +*/ // ------------------------------------------------------------------------- cpPluginsITKSliceFilters::CPRImageFilter:: CPRImageFilter( ) : Superclass( ) { - typedef cpInstances::Image _TImage; - typedef cpInstances::Simple3DCurve _TCurve; - this->_ConfigureInput< _TImage >( "Image", true, false ); - this->_ConfigureInput< _TCurve >( "Curve", true, false ); - this->_ConfigureOutput< _TImage >( "Output" ); + /* TODO + typedef cpInstances::Image _TImage; + typedef cpInstances::Simple3DCurve _TCurve; + this->_ConfigureInput< _TImage >( "Image", true, false ); + this->_ConfigureInput< _TCurve >( "Curve", true, false ); + this->_ConfigureOutput< _TImage >( "Output" ); - this->m_Parameters.ConfigureAsReal( "SliceRadius", 1 ); + this->m_Parameters.ConfigureAsReal( "SliceRadius", 1 ); + */ } // ------------------------------------------------------------------------- @@ -30,9 +35,11 @@ cpPluginsITKSliceFilters::CPRImageFilter:: void cpPluginsITKSliceFilters::CPRImageFilter:: _GenerateData( ) { - auto o = this->GetInputData( "Image" ); - cpPlugins_Demangle_Image_ScalarPixels_1( o, _GD0, 3 ) - this->_Error( "Invalid input image." ); + /* TODO + auto o = this->GetInputData( "Image" ); + cpPlugins_Demangle_Image_ScalarPixels_1( o, _GD0, 3 ) + this->_Error( "Invalid input image." ); + */ } // ------------------------------------------------------------------------- @@ -40,9 +47,11 @@ template< class _TImage > void cpPluginsITKSliceFilters::CPRImageFilter:: _GD0( _TImage* image ) { - auto o = this->GetInputData( "Curve" ); - cpPlugins_Demangle_Simple3DCurve_All_2( o, _GD1, image ) - this->_Error( "Invalid input curve." ); + /* TODO + auto o = this->GetInputData( "Curve" ); + cpPlugins_Demangle_Simple3DCurve_All_2( o, _GD1, image ) + this->_Error( "Invalid input curve." ); + */ } // ------------------------------------------------------------------------- @@ -50,14 +59,16 @@ template< class _TCurve, class _TImage > void cpPluginsITKSliceFilters::CPRImageFilter:: _GD1( _TCurve* curve, _TImage* image ) { - typedef cpExtensions::Algorithms::CPRImageFilter< _TImage, _TCurve > _TFilter; - - auto filter = this->_CreateITK< _TFilter >( ); - filter->SetInput( image ); - filter->SetCurve( curve ); - filter->SetSliceRadius( this->m_Parameters.GetReal( "SliceRadius" ) ); - filter->Update( ); - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + /* TODO + typedef cpExtensions::Algorithms::CPRImageFilter< _TImage, _TCurve > _TFilter; + + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); + filter->SetCurve( curve ); + filter->SetSliceRadius( this->m_Parameters.GetReal( "SliceRadius" ) ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + */ } // eof - $RCSfile$ diff --git a/plugins/ITKSliceFilters/ITKSliceFilters.i b/plugins/ITKSliceFilters/ITKSliceFilters.i new file mode 100644 index 0000000..c7966b4 --- /dev/null +++ b/plugins/ITKSliceFilters/ITKSliceFilters.i @@ -0,0 +1,7 @@ +header #define ITK_MANUAL_INSTANTIATION + +tinclude itkResampleImageFilter:h|hxx + +instances itk::ResampleImageFilter< itk::Image< #scalar_types#, #pdims# >, itk::Image< #scalar_types#, #pdims# >, #real_types#, #real_types# > + +** eof - $RCSfile$ diff --git a/plugins/ITKSliceFilters/IsoResampleImageFilter.cxx b/plugins/ITKSliceFilters/IsoResampleImageFilter.cxx new file mode 100644 index 0000000..77d56a6 --- /dev/null +++ b/plugins/ITKSliceFilters/IsoResampleImageFilter.cxx @@ -0,0 +1,109 @@ +#include +#include + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsITKSliceFilters::IsoResampleImageFilter:: +IsoResampleImageFilter( ) + : Superclass( ) +{ + this->_ConfigureInput< cpInstances::Image >( "Input", true, false ); + this->_ConfigureInput< cpPlugins::BaseObjects::DataObject >( "Interpolator", false, false ); + this->_ConfigureOutput< cpInstances::Image >( "Output" ); + + this->m_Parameters.ConfigureAsReal( "Scale", 1 ); + this->m_Parameters.ConfigureAsBool( "ScaleFromMinimumSpacing", true ); + this->m_Parameters.ConfigureAsRealTypesChoices( "PrecisionType" ); +} + +// ------------------------------------------------------------------------- +cpPluginsITKSliceFilters::IsoResampleImageFilter:: +~IsoResampleImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsITKSliceFilters::IsoResampleImageFilter:: +_GenerateData( ) +{ + auto o = this->GetInputData( "Input" ); + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpPluginsITKSliceFilters::IsoResampleImageFilter:: +_GD0( _TImage* image ) +{ + typedef cpPluginsITKImageInterpolators::InterpolateImageFunction _TInterpolator; + + std::string p_type = this->m_Parameters.GetSelectedChoice( "PrecisionType" ); + auto interpolator = dynamic_cast< _TInterpolator* >( + this->GetInput( "Interpolator" )->GetSource( ) + ); + if( interpolator != NULL ) + interpolator->CreateInterpolator( image, p_type ); + if ( p_type == "float" ) this->_GD1< _TImage, float >( image ); + else if( p_type == "double" ) this->_GD1< _TImage, double >( image ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TScalar > +void cpPluginsITKSliceFilters::IsoResampleImageFilter:: +_GD1( _TImage* image ) +{ + typedef itk::IdentityTransform< _TScalar, _TImage::ImageDimension > _TTransform; + typedef itk::ResampleImageFilter< _TImage, _TImage, _TScalar, _TScalar > _TFilter; + typedef typename _TFilter::InterpolatorType _TInterpolator; + + // Initial configuration + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); + + // Associate transform + typename _TTransform::Pointer transform = _TTransform::New( ); + transform->SetIdentity( ); + filter->SetTransform( transform ); + + // Compute new spacing + typename _TImage::SpacingType in_spac = image->GetSpacing( ); + double val_spac = in_spac[ 0 ]; + if( this->m_Parameters.GetBool( "ScaleFromMinimumSpacing" ) ) + for( unsigned int d = 1; d < _TImage::ImageDimension; ++d ) + val_spac = ( in_spac[ d ] < val_spac )? in_spac[ d ]: val_spac; + else + for( unsigned int d = 1; d < _TImage::ImageDimension; ++d ) + val_spac = ( in_spac[ d ] > val_spac )? in_spac[ d ]: val_spac; + val_spac *= this->m_Parameters.GetReal( "Scale" ); + typename _TImage::SpacingType out_spac; + out_spac.Fill( val_spac ); + filter->SetOutputSpacing( out_spac ); + + // Compute new size + typename _TImage::SizeType in_size = image->GetRequestedRegion( ).GetSize( ); + typename _TImage::SizeType out_size; + for( unsigned int d = 0; d < _TImage::ImageDimension; ++d ) + out_size[ d ] = ( unsigned long )( + double( in_size[ d ] ) * double( in_spac[ d ] ) / val_spac + ); + filter->SetSize( out_size ); + + // New origin + filter->SetOutputOrigin( image->GetOrigin( ) ); + + // Set interpolator + auto interpolator = this->GetInputData< _TInterpolator >( "Interpolator" ); + if( interpolator != NULL ) + filter->SetInterpolator( interpolator ); + + // Update + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ITKSliceFilters/IsoResampleImageFilter.h b/plugins/ITKSliceFilters/IsoResampleImageFilter.h new file mode 100644 index 0000000..49cd2c1 --- /dev/null +++ b/plugins/ITKSliceFilters/IsoResampleImageFilter.h @@ -0,0 +1,32 @@ +#ifndef __cpPluginsITKSliceFilters__IsoResampleImageFilter__h__ +#define __cpPluginsITKSliceFilters__IsoResampleImageFilter__h__ + +#include +#include + +namespace cpPluginsITKSliceFilters +{ + /** + */ + class cpPluginsITKSliceFilters_EXPORT IsoResampleImageFilter + : public cpPlugins::BaseObjects::ProcessObject + { + cpPluginsObject( + IsoResampleImageFilter, + cpPlugins::BaseObjects::ProcessObject, + ITKSliceFilters + ); + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + + template< class _TImage, class _TScalar > + inline void _GD1( _TImage* image ); + }; + +} // ecapseman + +#endif // __cpPluginsITKSliceFilters__IsoResampleImageFilter__h__ + +// eof - $RCSfile$ -- 2.45.0