From: Leonardo Flórez-Valencia Date: Wed, 22 Feb 2017 20:48:49 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~3 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=9af34b55ea1d60eef3608aede00f9ef5a16dccdf;p=cpPlugins.git ... --- diff --git a/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.h b/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.h index f699602..deb6b30 100644 --- a/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.h +++ b/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.h @@ -6,6 +6,7 @@ #define __cpExtensions__Algorithms__PolyLineParametricPathWriter__h__ #include +#include // ------------------------------------------------------------------------- namespace cpExtensions @@ -14,7 +15,7 @@ namespace cpExtensions { /** */ - template< class _TPolyLine > + template< class _TPolyLine, class _TImage = itk::Image< unsigned char, _TPolyLine::PathDimension > > class PolyLineParametricPathWriter : public itk::ProcessObject { @@ -38,6 +39,10 @@ namespace cpExtensions public: void SetInput( const _TPolyLine* input ); const _TPolyLine* GetInput( ); + + void SetImage( const _TImage* image ); + const _TImage* GetImage( ); + virtual void Update( ); protected: diff --git a/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.hxx b/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.hxx index 8e9db8e..d71c6e3 100644 --- a/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.hxx +++ b/lib/cpExtensions/Algorithms/PolyLineParametricPathWriter.hxx @@ -8,8 +8,8 @@ #include // ------------------------------------------------------------------------- -template< class _TPolyLine > -void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +template< class _TPolyLine, class _TImage > +void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: SetInput( const _TPolyLine* input ) { this->itk::ProcessObject::SetNthInput( @@ -18,9 +18,9 @@ SetInput( const _TPolyLine* input ) } // ------------------------------------------------------------------------- -template< class _TPolyLine > +template< class _TPolyLine, class _TImage > const _TPolyLine* -cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: GetInput( ) { return( @@ -31,8 +31,30 @@ GetInput( ) } // ------------------------------------------------------------------------- -template< class _TPolyLine > -void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +template< class _TPolyLine, class _TImage > +void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: +SetImage( const _TImage* image ) +{ + this->itk::ProcessObject::SetNthInput( + 1, const_cast< _TImage* >( image ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TPolyLine, class _TImage > +const _TImage* cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: +GetImage( ) +{ + return( + dynamic_cast< const _TImage* >( + this->itk::ProcessObject::GetInput( 1 ) + ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TPolyLine, class _TImage > +void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: Update( ) { _TPolyLine* input = const_cast< _TPolyLine* >( this->GetInput( ) ); @@ -47,8 +69,8 @@ Update( ) } // ------------------------------------------------------------------------- -template< class _TPolyLine > -cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +template< class _TPolyLine, class _TImage > +cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: PolyLineParametricPathWriter( ) : Superclass( ), m_FileName( "" ), @@ -58,21 +80,22 @@ PolyLineParametricPathWriter( ) } // ------------------------------------------------------------------------- -template< class _TPolyLine > -cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +template< class _TPolyLine, class _TImage > +cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: ~PolyLineParametricPathWriter( ) { } // ------------------------------------------------------------------------- -template< class _TPolyLine > -void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >:: +template< class _TPolyLine, class _TImage > +void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >:: GenerateData( ) { typedef typename _TPolyLine::TContinuousIndex _TContinuousIndex; // "Serialize" data const _TPolyLine* input = this->GetInput( ); + const _TImage* image = this->GetImage( ); unsigned int dim = _TPolyLine::PathDimension; std::stringstream buffer; long step = input->GetSize( ) / this->m_NumberOfPoints; @@ -102,6 +125,15 @@ GenerateData( ) buffer << idx[ 0 ]; for( unsigned int d = 1; d < dim; ++d ) buffer << " " << idx[ d ]; + if( image != NULL ) + { + typename _TImage::PointType pidx; + typename _TImage::IndexType iidx; + image->TransformContinuousIndexToPhysicalPoint( idx, pidx ); + image->TransformPhysicalPointToIndex( pidx, iidx ); + buffer << " " << image->GetPixel( iidx ); + + } // fi buffer << std::endl; } // rof diff --git a/lib/cpInstances/DataObjects/PolyLineParametricPath.cxx b/lib/cpInstances/DataObjects/PolyLineParametricPath.cxx index 488be38..623233f 100644 --- a/lib/cpInstances/DataObjects/PolyLineParametricPath.cxx +++ b/lib/cpInstances/DataObjects/PolyLineParametricPath.cxx @@ -1,7 +1,7 @@ #include // ------------------------------------------------------------------------- -void cpInstances::PolyLineParametricPath:: +void cpInstances::DataObjects::PolyLineParametricPath:: SetITK( itk::LightObject* o ) { this->Superclass::SetITK( o ); @@ -18,20 +18,20 @@ SetITK( itk::LightObject* o ) } // ------------------------------------------------------------------------- -void cpInstances::PolyLineParametricPath:: +void cpInstances::DataObjects::PolyLineParametricPath:: SetVTK( vtkObjectBase* o ) { } // ------------------------------------------------------------------------- -cpInstances::PolyLineParametricPath:: +cpInstances::DataObjects::PolyLineParametricPath:: PolyLineParametricPath( ) : Superclass( ) { } // ------------------------------------------------------------------------- -cpInstances::PolyLineParametricPath:: +cpInstances::DataObjects::PolyLineParametricPath:: ~PolyLineParametricPath( ) { } diff --git a/lib/cpInstances/DataObjects/PolyLineParametricPath.h b/lib/cpInstances/DataObjects/PolyLineParametricPath.h index 49e30a0..fff6b6b 100644 --- a/lib/cpInstances/DataObjects/PolyLineParametricPath.h +++ b/lib/cpInstances/DataObjects/PolyLineParametricPath.h @@ -10,36 +10,40 @@ class vtkPolyLineParametricPathData; namespace cpInstances { - /** - */ - class cpPluginsDataObjects_EXPORT PolyLineParametricPath - : public cpPlugins::Pipeline::DataObject + namespace DataObjects { - public: - typedef PolyLineParametricPath Self; - typedef cpPlugins::Pipeline::DataObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( PolyLineParametricPath, cpPlugins::Pipeline::DataObject ); - cpPlugins_Id_Macro( PolyLineParametricPath, Object ); - cpPlugins_Compatibility_Macro; - - public: - virtual void SetITK( itk::LightObject* o ) override; - virtual void SetVTK( vtkObjectBase* o ) override; - - protected: - PolyLineParametricPath( ); - virtual ~PolyLineParametricPath( ); - - private: - // Purposely not implemented - PolyLineParametricPath( const Self& ); - Self& operator=( const Self& ); - }; + /** + */ + class cpPluginsDataObjects_EXPORT PolyLineParametricPath + : public cpPlugins::Pipeline::DataObject + { + public: + typedef PolyLineParametricPath Self; + typedef cpPlugins::Pipeline::DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( PolyLineParametricPath, cpPlugins::Pipeline::DataObject ); + cpPlugins_Id_Macro( PolyLineParametricPath, Object ); + cpPlugins_Compatibility_Macro; + + public: + virtual void SetITK( itk::LightObject* o ) override; + virtual void SetVTK( vtkObjectBase* o ) override; + + protected: + PolyLineParametricPath( ); + virtual ~PolyLineParametricPath( ); + + private: + // Purposely not implemented + PolyLineParametricPath( const Self& ); + Self& operator=( const Self& ); + }; + + } // ecapseman } // ecapseman diff --git a/plugins/cpExtensions/PolyLineParametricPathToPolyData.cxx b/plugins/cpExtensions/PolyLineParametricPathToPolyData.cxx index cd69303..ff3a77e 100644 --- a/plugins/cpExtensions/PolyLineParametricPathToPolyData.cxx +++ b/plugins/cpExtensions/PolyLineParametricPathToPolyData.cxx @@ -10,7 +10,7 @@ cpPluginscpExtensions::PolyLineParametricPathToPolyData:: PolyLineParametricPathToPolyData( ) : Superclass( ) { - this->_ConfigureInput< cpInstances::PolyLineParametricPath >( + this->_ConfigureInput< cpInstances::DataObjects::PolyLineParametricPath >( "Input", true, false ); this->_ConfigureOutput< cpInstances::DataObjects::Mesh >( "Output" ); diff --git a/plugins/cpExtensions/PolyLineParametricPathToSimple3DCurve.cxx b/plugins/cpExtensions/PolyLineParametricPathToSimple3DCurve.cxx index 7b2b853..92a6d7a 100644 --- a/plugins/cpExtensions/PolyLineParametricPathToSimple3DCurve.cxx +++ b/plugins/cpExtensions/PolyLineParametricPathToSimple3DCurve.cxx @@ -11,7 +11,7 @@ cpPluginscpExtensions::PolyLineParametricPathToSimple3DCurve:: PolyLineParametricPathToSimple3DCurve( ) : Superclass( ) { - this->_ConfigureInput< cpInstances::PolyLineParametricPath >( + this->_ConfigureInput< cpInstances::DataObjects::PolyLineParametricPath >( "Input", true, false ); this->_ConfigureOutput< cpInstances::DataObjects::Simple3DCurve >( "Output" ); diff --git a/plugins/cpExtensions/PolyLineParametricPathWriter.cxx b/plugins/cpExtensions/PolyLineParametricPathWriter.cxx index 7ee1be3..400d3eb 100644 --- a/plugins/cpExtensions/PolyLineParametricPathWriter.cxx +++ b/plugins/cpExtensions/PolyLineParametricPathWriter.cxx @@ -1,6 +1,8 @@ #include +#include #include +#include #include #include #include @@ -32,7 +34,8 @@ cpPluginscpExtensions::PolyLineParametricPathWriter:: PolyLineParametricPathWriter( ) : Superclass( ) { - this->_ConfigureInput< cpInstances::PolyLineParametricPath >( "Input", true, false ); + this->_ConfigureInput< cpInstances::DataObjects::PolyLineParametricPath >( "Input", true, false ); + this->_ConfigureInput< cpInstances::DataObjects::Image >( "Image", false, false ); this->m_Parameters.ConfigureAsSaveFileName( "FileName", "" ); this->m_Parameters.SetAcceptedFileExtensions( "FileName", @@ -60,11 +63,22 @@ template< class _TPolyLineParametricPath > void cpPluginscpExtensions::PolyLineParametricPathWriter:: _GD0( _TPolyLineParametricPath* skeleton ) { - typedef cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLineParametricPath > _TWriter; + auto o = this->GetInputData( "Image" ); + cpPlugins_Demangle_Image_ScalarPixels_2( o, _GD1, _TPolyLineParametricPath::PathDimension, skeleton ) + this->_GD1< itk::Image< unsigned char, _TPolyLineParametricPath::PathDimension >, _TPolyLineParametricPath >( NULL, skeleton ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TPolyLineParametricPath > +void cpPluginscpExtensions::PolyLineParametricPathWriter:: +_GD1( _TImage* image, _TPolyLineParametricPath* skeleton ) +{ + typedef cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLineParametricPath, _TImage > _TWriter; auto filter = this->_CreateITK< _TWriter >( ); filter->SetInput( skeleton ); filter->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ) ); + filter->SetImage( image ); try { filter->Update( ); diff --git a/plugins/cpExtensions/PolyLineParametricPathWriter.h b/plugins/cpExtensions/PolyLineParametricPathWriter.h index e398b9e..6ef0046 100644 --- a/plugins/cpExtensions/PolyLineParametricPathWriter.h +++ b/plugins/cpExtensions/PolyLineParametricPathWriter.h @@ -23,6 +23,9 @@ namespace cpPluginscpExtensions protected: template< class _TPolyLineParametricPath > inline void _GD0( _TPolyLineParametricPath* skeleton ); + + template< class _TImage, class _TPolyLineParametricPath > + inline void _GD1( _TImage* image, _TPolyLineParametricPath* skeleton ); }; } // ecapseman diff --git a/plugins/cpExtensions/cpExtensions.i b/plugins/cpExtensions/cpExtensions.i index 4d3e1ea..8ab9420 100644 --- a/plugins/cpExtensions/cpExtensions.i +++ b/plugins/cpExtensions/cpExtensions.i @@ -3,8 +3,12 @@ header #define ITK_MANUAL_INSTANTIATION tinclude cpExtensions/Algorithms/SkeletonToImageFilter:h|hxx tinclude cpExtensions/Algorithms/SkeletonReader:h|hxx tinclude cpExtensions/Algorithms/SkeletonWriter:h|hxx +tinclude cpExtensions/Algorithms/PolyLineParametricPathWriter:h|hxx +cinclude cpExtensions/DataStructures/PolyLineParametricPath.h cinclude cpExtensions/DataStructures/Skeleton.h +instances cpExtensions::Algorithms::PolyLineParametricPathWriter< cpExtensions::DataStructures::PolyLineParametricPath< #pdims# >, itk::Image< #scalar_types#, #pdims# > > + instances cpExtensions::Algorithms::SkeletonToImageFilter< cpExtensions::DataStructures::Skeleton< #pdims# >, itk::Image< unsigned char, #pdims# > > instances cpExtensions::Algorithms::SkeletonReader< cpExtensions::DataStructures::Skeleton< #pdims# > >