From ddebf77c2ca8037dc5b4cc8e02468a16a68dc146 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Wed, 6 Apr 2016 18:24:02 -0500 Subject: [PATCH] Suppor for image index list added --- .../DataStructures/ImageIndexesContainer.h | 66 +++++++++++++++++++ ...ta.h => ImageIndexesContainerToPolyData.h} | 20 +++--- ...xx => ImageIndexesContainerToPolyData.hxx} | 40 +++++------ lib/cpPlugins/ImageIndexesContainer.cxx | 39 +++++++++++ lib/cpPlugins/ImageIndexesContainer.h | 53 +++++++++++++++ lib/cpPlugins/ImageIndexesContainer.hxx | 44 +++++++++++++ lib/cpPlugins_Instances/Paths.i | 8 +++ 7 files changed, 240 insertions(+), 30 deletions(-) create mode 100644 lib/cpExtensions/DataStructures/ImageIndexesContainer.h rename lib/cpExtensions/Visualization/{IndexesToPolyData.h => ImageIndexesContainerToPolyData.h} (67%) rename lib/cpExtensions/Visualization/{IndexesToPolyData.hxx => ImageIndexesContainerToPolyData.hxx} (73%) create mode 100644 lib/cpPlugins/ImageIndexesContainer.cxx create mode 100644 lib/cpPlugins/ImageIndexesContainer.h create mode 100644 lib/cpPlugins/ImageIndexesContainer.hxx diff --git a/lib/cpExtensions/DataStructures/ImageIndexesContainer.h b/lib/cpExtensions/DataStructures/ImageIndexesContainer.h new file mode 100644 index 0000000..00dbf64 --- /dev/null +++ b/lib/cpExtensions/DataStructures/ImageIndexesContainer.h @@ -0,0 +1,66 @@ +#ifndef __CPEXTENSIONS__DATASTRUCTURES__IMAGEINDEXESCONTAINER__H__ +#define __CPEXTENSIONS__DATASTRUCTURES__IMAGEINDEXESCONTAINER__H__ + +#include +#include +#include + +namespace cpExtensions +{ + namespace DataStructures + { + /** + */ + template< unsigned int _NDim > + class ImageIndexesContainer + : public itk::SimpleDataObjectDecorator< std::vector< itk::Index< _NDim > > > + { + public: + typedef itk::Index< _NDim > TIndex; + typedef std::vector< TIndex > TContainer; + typedef itk::SimpleDataObjectDecorator< TContainer > Superclass; + + typedef ImageIndexesContainer Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef itk::ImageBase< _NDim > TImageBase; + + public: + itkNewMacro( Self ); + itkTypeMacro( ImageIndexesContainer, itk::SimpleDataObjectDecorator ); + + public: + TImageBase* GetReferenceImage( ) + { return( this->m_ReferenceImage ); } + const TImageBase* GetReferenceImage( ) const + { return( this->m_ReferenceImage ); } + void SetReferenceImage( const TImageBase* image ) + { + this->m_ReferenceImage = TImageBase::New( ); + this->m_ReferenceImage->SetDirection( image->GetDirection( ) ); + this->m_ReferenceImage->SetOrigin( image->GetOrigin( ) ); + this->m_ReferenceImage->SetSpacing( image->GetSpacing( ) ); + this->Modified( ); + } + + protected: + ImageIndexesContainer( ) { } + virtual ~ImageIndexesContainer( ) { } + + private: + // Purposely not implemented + ImageIndexesContainer( const Self& other ); + Self& operator=( const Self& other ); + + protected: + typename TImageBase::Pointer m_ReferenceImage; + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__DATASTRUCTURES__IMAGEINDEXESCONTAINER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/IndexesToPolyData.h b/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.h similarity index 67% rename from lib/cpExtensions/Visualization/IndexesToPolyData.h rename to lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.h index 0dde70c..5613567 100644 --- a/lib/cpExtensions/Visualization/IndexesToPolyData.h +++ b/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.h @@ -1,5 +1,5 @@ -#ifndef __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__H__ -#define __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__H__ +#ifndef __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__H__ +#define __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__H__ #include #include @@ -11,11 +11,11 @@ namespace cpExtensions /** */ template< class _TIndexes > - class IndexesToPolyData + class ImageIndexesContainerToPolyData : public vtkPolyDataAlgorithm { public: - typedef IndexesToPolyData Self; + typedef ImageIndexesContainerToPolyData Self; typedef _TIndexes TIndexes; typedef typename TIndexes::ComponentType TContainer; @@ -23,7 +23,7 @@ namespace cpExtensions typedef itk::ImageBase< TIndex::Dimension > TImage; public: - vtkTypeMacro( IndexesToPolyData, vtkPolyDataAlgorithm ); + vtkTypeMacro( ImageIndexesContainerToPolyData, vtkPolyDataAlgorithm ); public: static Self* New( ); @@ -34,8 +34,8 @@ namespace cpExtensions void SetReferenceImage( const TImage* i ); protected: - IndexesToPolyData( ); - virtual ~IndexesToPolyData( ); + ImageIndexesContainerToPolyData( ); + virtual ~ImageIndexesContainerToPolyData( ); int RequestData( vtkInformation* information, @@ -50,7 +50,7 @@ namespace cpExtensions private: // Purposely not implemented - IndexesToPolyData( const Self& ); + ImageIndexesContainerToPolyData( const Self& ); void operator=( const Self& ); protected: @@ -63,9 +63,9 @@ namespace cpExtensions } // ecapseman #ifndef ITK_MANUAL_INSTANTIATION -#include +#include #endif // ITK_MANUAL_INSTANTIATION -#endif // __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__H__ +#endif // __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__H__ // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/IndexesToPolyData.hxx b/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx similarity index 73% rename from lib/cpExtensions/Visualization/IndexesToPolyData.hxx rename to lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx index 3e6f00d..8d67765 100644 --- a/lib/cpExtensions/Visualization/IndexesToPolyData.hxx +++ b/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx @@ -1,13 +1,13 @@ -#ifndef __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__HXX__ -#define __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__HXX__ +#ifndef __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__ +#define __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__ #include #include // ------------------------------------------------------------------------- template< class _TIndexes > -typename cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -Self* cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +Self* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: New( ) { return( new Self( ) ); @@ -15,8 +15,8 @@ New( ) // ------------------------------------------------------------------------- template< class _TIndexes > -const typename cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -TIndexes* cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +const typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +TIndexes* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: GetInput( ) const { return( this->m_Indexes ); @@ -24,8 +24,8 @@ GetInput( ) const // ------------------------------------------------------------------------- template< class _TIndexes > -const typename cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -TImage* cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +const typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +TImage* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: GetReferenceImage( ) const { return( this->m_ReferenceImage ); @@ -33,12 +33,12 @@ GetReferenceImage( ) const // ------------------------------------------------------------------------- template< class _TIndexes > -void cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -SetInput( const TIndexes* indexes ) +void cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +SetInput( const TIndexes* imageindexescontainer ) { - if( this->m_Indexes != indexes ) + if( this->m_Indexes != imageindexescontainer ) { - this->m_Indexes = indexes; + this->m_Indexes = imageindexescontainer; this->Modified( ); } // fi @@ -46,7 +46,7 @@ SetInput( const TIndexes* indexes ) // ------------------------------------------------------------------------- template< class _TIndexes > -void cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +void cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: SetReferenceImage( const TImage* i ) { if( this->m_ReferenceImage != i ) @@ -59,8 +59,8 @@ SetReferenceImage( const TImage* i ) // ------------------------------------------------------------------------- template< class _TIndexes > -cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -IndexesToPolyData( ) +cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +ImageIndexesContainerToPolyData( ) : vtkPolyDataAlgorithm( ), m_Indexes( NULL ), m_ReferenceImage( NULL ) @@ -70,14 +70,14 @@ IndexesToPolyData( ) // ------------------------------------------------------------------------- template< class _TIndexes > -cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: -~IndexesToPolyData( ) +cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: +~ImageIndexesContainerToPolyData( ) { } // ------------------------------------------------------------------------- template< class _TIndexes > -int cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +int cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: RequestData( vtkInformation* information, vtkInformationVector** input, @@ -149,7 +149,7 @@ RequestData( // ------------------------------------------------------------------------- template< class _TIndexes > int -cpExtensions::Visualization::IndexesToPolyData< _TIndexes >:: +cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >:: RequestInformation( vtkInformation* information, vtkInformationVector** input, @@ -183,6 +183,6 @@ RequestInformation( return( 1 ); } -#endif // __CPEXTENSIONS__VISUALIZATION__INDEXESTOPOLYDATA__HXX__ +#endif // __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/ImageIndexesContainer.cxx b/lib/cpPlugins/ImageIndexesContainer.cxx new file mode 100644 index 0000000..c7d2f8a --- /dev/null +++ b/lib/cpPlugins/ImageIndexesContainer.cxx @@ -0,0 +1,39 @@ +#include + +// ------------------------------------------------------------------------- +void cpPlugins::ImageIndexesContainer:: +SetITK( itk::LightObject* o ) +{ + this->Superclass::SetITK( o ); + bool s = this->_ITK_2_VTK< 2 >( o ); + if( !s ) s = this->_ITK_2_VTK< 3 >( o ); + if( !s ) + { + this->m_VTKObject = NULL; + this->m_ITKvVTK = NULL; + + } // fi + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ImageIndexesContainer:: +SetVTK( vtkObjectBase* o ) +{ + // Do nothing +} + +// ------------------------------------------------------------------------- +cpPlugins::ImageIndexesContainer:: +ImageIndexesContainer( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::ImageIndexesContainer:: +~ImageIndexesContainer( ) +{ +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ImageIndexesContainer.h b/lib/cpPlugins/ImageIndexesContainer.h new file mode 100644 index 0000000..3edfda3 --- /dev/null +++ b/lib/cpPlugins/ImageIndexesContainer.h @@ -0,0 +1,53 @@ +#ifndef __CPPLUGINS__IMAGEINDEXESCONTAINER__H__ +#define __CPPLUGINS__IMAGEINDEXESCONTAINER__H__ + +#include + +#include +#include + +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT ImageIndexesContainer + : public DataObject + { + public: + typedef ImageIndexesContainer Self; + typedef DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( ImageIndexesContainer, DataObject ); + cpPlugins_Id_Macro( ImageIndexesContainer, Object ); + + public: + virtual void SetITK( itk::LightObject* o ) ITK_OVERRIDE; + virtual void SetVTK( vtkObjectBase* o ) ITK_OVERRIDE; + + protected: + ImageIndexesContainer( ); + virtual ~ImageIndexesContainer( ); + + template< unsigned int _NDim > + inline bool _ITK_2_VTK( itk::LightObject* o ); + + private: + // Purposely not implemented + ImageIndexesContainer( const Self& ); + Self& operator=( const Self& ); + + protected: + vtkSmartPointer< vtkPolyDataAlgorithm > m_ITKvVTK; + }; + +} // ecapseman + +#include + +#endif // __CPPLUGINS__IMAGEINDEXESCONTAINER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ImageIndexesContainer.hxx b/lib/cpPlugins/ImageIndexesContainer.hxx new file mode 100644 index 0000000..41bcd25 --- /dev/null +++ b/lib/cpPlugins/ImageIndexesContainer.hxx @@ -0,0 +1,44 @@ +#ifndef __CPPLUGINS__IMAGEINDEXESCONTAINER__HXX__ +#define __CPPLUGINS__IMAGEINDEXESCONTAINER__HXX__ + +#include + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +bool cpPlugins::ImageIndexesContainer:: +_ITK_2_VTK( itk::LightObject* o ) +{ + typedef + cpExtensions::DataStructures::ImageIndexesContainer< _NDim > + _TImageIndexesContainer; + typedef + cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TImageIndexesContainer > + _TFilter; + + auto imageindexescontainer = dynamic_cast< _TImageIndexesContainer* >( o ); + if( imageindexescontainer != NULL ) + { + _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) ); + if( f == NULL ) + { + vtkSmartPointer< _TFilter > nf = _TFilter::New( ); + this->m_ITKvVTK = nf.GetPointer( ); + f = nf.GetPointer( ); + + } // fi + f->SetInput( imageindexescontainer ); + f->SetReferenceImage( imageindexescontainer->GetReferenceImage( ) ); + f->Update( ); + + // Keep object track + this->m_ITKObject = o; + this->m_VTKObject = f->GetOutput( ); + return( true ); + } + else + return( false ); +} + +#endif // __CPPLUGINS__IMAGEINDEXESCONTAINER__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins_Instances/Paths.i b/lib/cpPlugins_Instances/Paths.i index 03d83f9..148ac75 100644 --- a/lib/cpPlugins_Instances/Paths.i +++ b/lib/cpPlugins_Instances/Paths.i @@ -1,14 +1,22 @@ f cpPlugins_Instances/Base.h i cpExtensions/DataStructures/PolyLineParametricPath.h +i cpExtensions/DataStructures/ImageIndexesContainer.h t itkPolyLineParametricPath.h t itkPath.h t itkParametricPath.h t itkVectorContainer.h t cpExtensions/Visualization/PolyLineParametricPathToPolyData.h +t cpExtensions/Visualization/ImageIndexesContainerToPolyData.h +t itkSimpleDataObjectDecorator.h d #dims=2;3 +c itk::SimpleDataObjectDecorator< std::vector< itk::Index< #dims > > > + c itk::PolyLineParametricPath< #dims > +c cpExtensions::DataStructures::ImageIndexesContainer< #dims > + c cpExtensions::Visualization::PolyLineParametricPathToPolyData< cpExtensions::DataStructures::PolyLineParametricPath< #dims > > +c cpExtensions::Visualization::ImageIndexesContainerToPolyData< cpExtensions::DataStructures::ImageIndexesContainer< #dims > > -- 2.47.1