From d8c6c19cd58d865ddfde7a5724bd99bbad19878c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Fri, 11 Nov 2016 10:53:14 -0500 Subject: [PATCH] ... --- lib/cpPlugins/DataObjects/BoundingBox.cxx | 93 +++++++++++++++ lib/cpPlugins/DataObjects/BoundingBox.h | 107 ++++++++++++++++++ plugins/CMakeLists.txt | 26 ++--- plugins/Extensions/Simple3DCurve.cxx | 63 +++++++++++ plugins/Extensions/Simple3DCurve.d | 4 + plugins/Extensions/Simple3DCurve.h | 58 ++++++++++ .../PolyLineParametricPathToSimple3DCurve.cxx | 8 +- plugins/ImageSliceFilters/CPRImageFilter.cxx | 9 +- 8 files changed, 345 insertions(+), 23 deletions(-) create mode 100644 lib/cpPlugins/DataObjects/BoundingBox.cxx create mode 100644 lib/cpPlugins/DataObjects/BoundingBox.h create mode 100644 plugins/Extensions/Simple3DCurve.cxx create mode 100644 plugins/Extensions/Simple3DCurve.d create mode 100644 plugins/Extensions/Simple3DCurve.h diff --git a/lib/cpPlugins/DataObjects/BoundingBox.cxx b/lib/cpPlugins/DataObjects/BoundingBox.cxx new file mode 100644 index 0000000..4a81b0b --- /dev/null +++ b/lib/cpPlugins/DataObjects/BoundingBox.cxx @@ -0,0 +1,93 @@ +#include +#include +#include + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjects::BoundingBox:: +SetDataObject( DataObject* o ) +{ + auto i = o->GetITK< itk::LightObject >( ); + auto v = o->GetVTK< vtkObjectBase >( ); + if( v != NULL ) this->SetVTK( v ); + else if( i != NULL ) this->SetITK( i ); + this->_UpdateVTK( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjects::BoundingBox:: +Copy( Self* other ) +{ + this->m_Points[ 0 ] = other->m_Points[ 0 ]; + this->m_Points[ 1 ] = other->m_Points[ 1 ]; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjects::BoundingBox:: +Blend( Self* other ) +{ + if( this->m_Points[ 0 ].size( ) < other->m_Points[ 0 ].size( ) ) + this->m_Points[ 0 ].resize( + other->m_Points[ 0 ].size( ), + std::numeric_limits< double >::max( ) + ); + if( this->m_Points[ 1 ].size( ) < other->m_Points[ 1 ].size( ) ) + this->m_Points[ 1 ].resize( + other->m_Points[ 1 ].size( ), + -std::numeric_limits< double >::max( ) + ); + for( unsigned int d = 0; d < this->m_Points[ 0 ].size( ); ++d ) + if( other->m_Points[ 0 ][ d ] < this->m_Points[ 0 ][ d ] ) + this->m_Points[ 0 ][ d ] = other->m_Points[ 0 ][ d ]; + for( unsigned int d = 0; d < this->m_Points[ 1 ].size( ); ++d ) + if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] ) + this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ]; + this->Modified( ); + this->_UpdateVTK( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObjects::BoundingBox:: +BoundingBox( ) + : Superclass( ) +{ + this->m_Points[ 0 ].push_back( double( 0 ) ); + this->m_Points[ 1 ].push_back( double( 0 ) ); + this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( ); + this->_UpdateVTK( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObjects::BoundingBox:: +~BoundingBox( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjects::BoundingBox:: +_UpdateVTK( ) +{ + auto dobj = this->GetVTK< vtkDataSet >( ); + if( dobj == NULL ) + return; + + // Get bounds + double bounds[ 6 ]; + dobj->GetBounds( bounds ); + + this->m_Points[ 0 ].clear( ); + this->m_Points[ 1 ].clear( ); + this->m_Points[ 0 ].push_back( bounds[ 0 ] ); + this->m_Points[ 0 ].push_back( bounds[ 2 ] ); + this->m_Points[ 0 ].push_back( bounds[ 4 ] ); + this->m_Points[ 1 ].push_back( bounds[ 1 ] ); + this->m_Points[ 1 ].push_back( bounds[ 3 ] ); + this->m_Points[ 1 ].push_back( bounds[ 5 ] ); + + // Update vtk objects + this->m_Outline->SetBounds( bounds ); + this->m_Outline->Update( ); + this->m_VTK = this->m_Outline->GetOutput( ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/DataObjects/BoundingBox.h b/lib/cpPlugins/DataObjects/BoundingBox.h new file mode 100644 index 0000000..9ee33cc --- /dev/null +++ b/lib/cpPlugins/DataObjects/BoundingBox.h @@ -0,0 +1,107 @@ +#ifndef __cpPlugins__DataObjects__BoundingBox__h__ +#define __cpPlugins__DataObjects__BoundingBox__h__ + +#include +#include +#include +#include + +namespace cpPlugins +{ + namespace DataObjects + { + /** + */ + class cpPlugins_EXPORT BoundingBox + : public cpPlugins::BaseObjects::DataObject + { + public: + typedef BoundingBox Self; + typedef cpPlugins::BaseObjects::DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( BoundingBox, DataObject ); + cpPlugins_Id_Macro( BoundingBox, Object ); + cpPlugins_Compatibility_Macro; + + public: + void SetDataObject( DataObject* o ); + + void Copy( Self* other ); + void Blend( Self* other ); + + template< class _TPoint > + inline void SetMinimum( const _TPoint& p ) + { + this->_SetPoint( 0, p ); + } + + template< class _TPoint > + inline void SetMaximum( const _TPoint& p ) + { + this->_SetPoint( 1, p ); + } + + template< class _TPoint > + inline _TPoint GetMinimum( ) const + { + return( this->_GetPoint< _TPoint >( 0 ) ); + } + + template< class _TPoint > + inline _TPoint GetMaximum( ) const + { + return( this->_GetPoint< _TPoint >( 1 ) ); + } + + protected: + BoundingBox( ); + virtual ~BoundingBox( ); + + void _UpdateVTK( ); + + template< class _TPoint > + inline void _SetPoint( unsigned int m, const _TPoint& p ) + { + this->m_Points[ m ].clear( ); + for( unsigned int d = 0; d < _TPoint::PointDimension; ++d ) + this->m_Points[ m ].push_back( double( p[ d ] ) ); + this->_UpdateVTK( ); + this->Modified( ); + } + + template< class _TPoint > + inline _TPoint _GetPoint( unsigned int m ) const + { + unsigned int dim = this->m_Points[ m ].size( ); + dim = + ( _TPoint::PointDimension < dim )? _TPoint::PointDimension: dim; + _TPoint p; + p.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + p[ d ] = this->m_Points[ m ][ d ]; + return( p ); + } + + private: + // Purposely not implemented + BoundingBox( const Self& ); + Self& operator=( const Self& ); + + protected: + std::vector< double > m_Points[ 2 ]; + vtkSmartPointer< vtkOutlineSource > m_Outline; + }; + + } // ecapseman + +} // ecapseman + +// #include + +#endif // __cpPlugins__DataObjects__BoundingBox__h__ + +// eof - $RCSfile$ diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c83c434..99f07e0 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -5,20 +5,20 @@ SET( _dirlist Extensions - # AnisotropicDiffusion - # GenericFilters - # ImageArithmeticFilters - # ImageBooleanFilters - # ImageDistanceMaps - # ImageGenericFilters - # ImageGradientFilters - # ImageMeshFilters - # ImageSliceFilters - # ImageSources - # ImageThresholdFilters + AnisotropicDiffusion + GenericFilters + ImageArithmeticFilters + ImageBooleanFilters + ImageDistanceMaps + ImageGenericFilters + ImageGradientFilters + ImageMeshFilters + ImageSliceFilters + ImageSources + ImageThresholdFilters IO - # MeshFilters - # MeshSources + MeshFilters + MeshSources Widgets ) diff --git a/plugins/Extensions/Simple3DCurve.cxx b/plugins/Extensions/Simple3DCurve.cxx new file mode 100644 index 0000000..25aa5a1 --- /dev/null +++ b/plugins/Extensions/Simple3DCurve.cxx @@ -0,0 +1,63 @@ +#include +#include +#include + +// ------------------------------------------------------------------------- +void cpPluginsExtensions::Simple3DCurve:: +SetITK( itk::LightObject* o ) +{ + cpPlugins_Demangle_Simple3DCurve_All_1( o, _ITK_2_VTK ) + { + this->m_VTK = NULL; + this->m_ITKvVTK = NULL; + } +} + +// ------------------------------------------------------------------------- +void cpPluginsExtensions::Simple3DCurve:: +SetVTK( vtkObjectBase* o ) +{ + // Do nothing + this->m_ITK = NULL; + this->m_VTK = NULL; + this->m_ITKvVTK = NULL; +} + +// ------------------------------------------------------------------------- +cpPluginsExtensions::Simple3DCurve:: +Simple3DCurve( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPluginsExtensions::Simple3DCurve:: +~Simple3DCurve( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSimple3DCurve > +void cpPluginsExtensions::Simple3DCurve:: +_ITK_2_VTK( _TSimple3DCurve* curve ) +{ + typedef + cpExtensions::Visualization::Simple3DCurveToPolyData< _TSimple3DCurve > + _TFilter; + _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) ); + if( f == NULL ) + { + _TFilter* nf = _TFilter::New( ); + this->m_ITKvVTK = nf; + f = nf; + + } // fi + f->SetInput( curve ); + f->Update( ); + + // Keep object track + this->m_ITK = curve; + this->m_VTK = f->GetOutput( ); +} + +// eof - $RCSfile$ diff --git a/plugins/Extensions/Simple3DCurve.d b/plugins/Extensions/Simple3DCurve.d new file mode 100644 index 0000000..998b791 --- /dev/null +++ b/plugins/Extensions/Simple3DCurve.d @@ -0,0 +1,4 @@ + +All cpExtensions::DataStructures::Simple3DCurve< #real_types# > + +** eof - $RCSfile$ diff --git a/plugins/Extensions/Simple3DCurve.h b/plugins/Extensions/Simple3DCurve.h new file mode 100644 index 0000000..cb68176 --- /dev/null +++ b/plugins/Extensions/Simple3DCurve.h @@ -0,0 +1,58 @@ +#ifndef __cpPluginsExtensions__Simple3DCurve__h__ +#define __cpPluginsExtensions__Simple3DCurve__h__ + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +class vtkPolyDataAlgorithm; + +// ------------------------------------------------------------------------- +namespace cpPluginsExtensions +{ + /** + */ + class cpPluginsExtensions_EXPORT Simple3DCurve + : public cpPlugins::BaseObjects::DataObject + { + public: + typedef Simple3DCurve Self; + typedef cpPlugins::BaseObjects::DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( + Simple3DCurve, cpPlugins::BaseObjects::DataObject + ); + cpPlugins_Id_Macro( Simple3DCurve, Object ); + cpPlugins_Compatibility_Macro; + + public: + virtual void SetITK( itk::LightObject* o ) cpPlugins_OVERRIDE; + virtual void SetVTK( vtkObjectBase* o ) cpPlugins_OVERRIDE; + + protected: + Simple3DCurve( ); + virtual ~Simple3DCurve( ); + + template< class _TSimple3DCurve > + inline void _ITK_2_VTK( _TSimple3DCurve* curve ); + + private: + // Purposely not implemented + Simple3DCurve( const Self& ); + Self& operator=( const Self& ); + + protected: + vtkSmartPointer< vtkPolyDataAlgorithm > m_ITKvVTK; + }; + +} // ecapseman + +#endif // __cpPluginsExtensions__Simple3DCurve__h__ + +// eof - $RCSfile$ diff --git a/plugins/GenericFilters/PolyLineParametricPathToSimple3DCurve.cxx b/plugins/GenericFilters/PolyLineParametricPathToSimple3DCurve.cxx index 5271174..af6facf 100644 --- a/plugins/GenericFilters/PolyLineParametricPathToSimple3DCurve.cxx +++ b/plugins/GenericFilters/PolyLineParametricPathToSimple3DCurve.cxx @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include #include @@ -11,8 +11,8 @@ cpPluginsGenericFilters::PolyLineParametricPathToSimple3DCurve:: PolyLineParametricPathToSimple3DCurve( ) : Superclass( ) { - typedef cpPlugins::DataObjects::PolyLineParametricPath _TPath; - typedef cpPlugins::DataObjects::Simple3DCurve _TCurve; + typedef cpPluginsExtensions::PolyLineParametricPath _TPath; + typedef cpPluginsExtensions::Simple3DCurve _TCurve; this->_ConfigureInput< _TPath >( "Input", true, false ); this->_ConfigureOutput< _TCurve >( "Output" ); diff --git a/plugins/ImageSliceFilters/CPRImageFilter.cxx b/plugins/ImageSliceFilters/CPRImageFilter.cxx index 4e80ed2..77c7f81 100644 --- a/plugins/ImageSliceFilters/CPRImageFilter.cxx +++ b/plugins/ImageSliceFilters/CPRImageFilter.cxx @@ -1,9 +1,6 @@ #include #include -#include - -#include -#include +#include #include #include @@ -14,8 +11,8 @@ cpPluginsImageSliceFilters::CPRImageFilter:: CPRImageFilter( ) : Superclass( ) { - typedef cpPlugins::DataObjects::Image _TImage; - typedef cpPlugins::DataObjects::Simple3DCurve _TCurve; + typedef cpPlugins::DataObjects::Image _TImage; + typedef cpPluginsExtensions::Simple3DCurve _TCurve; this->_ConfigureInput< _TImage >( "Image", true, false ); this->_ConfigureInput< _TCurve >( "Curve", true, false ); this->_ConfigureOutput< _TImage >( "Output" ); -- 2.47.1