From b6c7e73ebcce23619daced67f85d9e1364b33f30 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Wed, 17 Feb 2016 23:23:19 -0500 Subject: [PATCH] ... --- .../cpPipelineEditor/App_cpPipelineEditor.cxx | 2 +- .../DataStructures/VectorValuesContainer.h | 66 +++++++++ lib/cpPlugins/Interface/PointList.cxx | 27 +--- lib/cpPlugins/Interface/PointList.h | 20 --- lib/cpPlugins/Interface/PointList.hxx | 47 +------ lib/cpPlugins/Interface/Workspace.cxx | 36 +++++ lib/cpPlugins/Interface/Workspace.h | 6 +- .../BasicFilters/AppendMeshesFilter.cxx | 6 +- .../BasicFilters/BinaryErodeImageFilter.cxx | 4 +- .../BinaryThresholdImageFilter.cxx | 4 +- lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx | 9 +- .../BasicFilters/ExtractSliceImageFilter.cxx | 4 +- .../BasicFilters/ImageInterpolatorSource.cxx | 6 +- .../Plugins/BasicFilters/MacheteFilter.cxx | 20 +-- .../Plugins/BasicFilters/MacheteFilter.h | 4 +- .../BasicFilters/MacheteImageFilter.cxx | 4 +- .../Plugins/BasicFilters/MarchingCubes.cxx | 4 +- .../BasicFilters/MedianImageFilter.cxx | 4 +- .../BasicFilters/MultiplyImageFilter.cxx | 4 +- .../BasicFilters/OtsuThresholdImageFilter.cxx | 4 +- .../RGBImageToOtherChannelsFilter.cxx | 4 +- .../SignedMaurerDistanceMapImageFilter.cxx | 4 +- .../Plugins/BasicFilters/SphereMeshSource.cxx | 2 +- .../TriangleMeshToBinaryImageFilter.cxx | 4 +- lib/cpPlugins/Plugins/IO/ImageReader.cxx | 2 +- lib/cpPlugins/Plugins/IO/ImageWriter.cxx | 4 +- lib/cpPlugins/Plugins/IO/MeshReader.cxx | 4 +- lib/cpPlugins/Plugins/IO/MeshWriter.cxx | 2 +- lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx | 125 ++++++++++++++---- lib/cpPlugins/Plugins/Widgets/SeedWidget.h | 6 + 30 files changed, 262 insertions(+), 176 deletions(-) create mode 100644 lib/cpExtensions/DataStructures/VectorValuesContainer.h diff --git a/appli/cpPipelineEditor/App_cpPipelineEditor.cxx b/appli/cpPipelineEditor/App_cpPipelineEditor.cxx index df947d5..af73df5 100644 --- a/appli/cpPipelineEditor/App_cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/App_cpPipelineEditor.cxx @@ -309,7 +309,7 @@ _ShowFilterOutput( auto filter = this->m_Workspace->GetFilter( filter_name ); if( filter != NULL ) { - auto output = filter->GetOutputData< _TDataObject >( output_name ); + auto output = filter->GetOutputData( output_name ); if( output != NULL ) { std::string data_name = output_name + "@" + filter_name; diff --git a/lib/cpExtensions/DataStructures/VectorValuesContainer.h b/lib/cpExtensions/DataStructures/VectorValuesContainer.h new file mode 100644 index 0000000..eea4e40 --- /dev/null +++ b/lib/cpExtensions/DataStructures/VectorValuesContainer.h @@ -0,0 +1,66 @@ +#ifndef __CPEXTENSIONS__DATASTRUCTURES__VECTORVALUESCONTAINER__H__ +#define __CPEXTENSIONS__DATASTRUCTURES__VECTORVALUESCONTAINER__H__ + +#include +#include +#include + +namespace cpExtensions +{ + namespace DataStructures + { + /** + */ + template< class T > + class VectorValuesContainer + : public itk::SimpleDataObjectDecorator< std::vector< T > > + { + public: + typedef std::vector< T > TDecorated; + typedef VectorValuesContainer Self; + typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef T TValue; + typedef typename TDecorated::iterator Iterator; + typedef typename TDecorated::const_iterator ConstIterator; + + public: + itkNewMacro( Self ); + itkTypeMacro( VectorValuesContainer, itkSimpleDataObjectDecorator ); + + public: + void PushBack( const T& v ) + { this->Get( ).push_back( v ); this->Modified( ); } + void PopBack( const T& v ) + { this->Get( ).pop_back( ); this->Modified( ); } + Iterator Begin( ) + { return( this->Get( ).begin( ) ); } + Iterator End( ) + { return( this->Get( ).end( ) ); } + ConstIterator Begin( ) const + { return( this->Get( ).begin( ) ); } + ConstIterator End( ) const + { return( this->Get( ).end( ) ); } + + protected: + VectorValuesContainer( ) + : Superclass( ) + { } + virtual ~VectorValuesContainer( ) + { } + + private: + // Purposely not implemented + VectorValuesContainer( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__DATASTRUCTURES__VECTORVALUESCONTAINER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/PointList.cxx b/lib/cpPlugins/Interface/PointList.cxx index 8c3f232..69acc92 100644 --- a/lib/cpPlugins/Interface/PointList.cxx +++ b/lib/cpPlugins/Interface/PointList.cxx @@ -1,35 +1,10 @@ #include -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::PointList:: -HaveEuclideanPoints( ) const -{ - return( this->m_HaveEuclideanPoints ); -} - -// ------------------------------------------------------------------------- -unsigned long cpPlugins::Interface::PointList:: -GetNumberOfPoints( ) const -{ - return( this->m_NumberOfPoints ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::PointList:: -Clear( ) -{ - this->m_ITKObject = NULL; - this->m_VTKObject = NULL; - this->m_NumberOfPoints = 0; -} - // ------------------------------------------------------------------------- cpPlugins::Interface::PointList:: PointList( ) - : Superclass( ), - m_HaveEuclideanPoints( true ) + : Superclass( ) { - this->Clear( ); } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/PointList.h b/lib/cpPlugins/Interface/PointList.h index 6f43b32..286825c 100644 --- a/lib/cpPlugins/Interface/PointList.h +++ b/lib/cpPlugins/Interface/PointList.h @@ -23,22 +23,6 @@ namespace cpPlugins itkTypeMacro( PointList, DataObject ); cpPlugins_Id_Macro( PointList, DataObject ); - itkBooleanMacro( HaveEuclideanPoints ); - itkGetConstMacro( HaveEuclideanPoints, bool ); - itkSetMacro( HaveEuclideanPoints, bool ); - - public: - bool HaveEuclideanPoints( ) const; - unsigned long GetNumberOfPoints( ) const; - - void Clear( ); - - template< class P > - inline void AddPoint( const P& p ); - - template< class P > - inline P GetPoint( const unsigned long& i ) const; - protected: PointList( ); virtual ~PointList( ); @@ -47,10 +31,6 @@ namespace cpPlugins // Purposely not implemented PointList( const Self& ); Self& operator=( const Self& ); - - protected: - unsigned long m_NumberOfPoints; - bool m_HaveEuclideanPoints; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/PointList.hxx b/lib/cpPlugins/Interface/PointList.hxx index 95e9e1f..651e4cd 100644 --- a/lib/cpPlugins/Interface/PointList.hxx +++ b/lib/cpPlugins/Interface/PointList.hxx @@ -1,52 +1,7 @@ #ifndef __CPPLUGINS__INTERFACE__POINTLIST__HXX__ #define __CPPLUGINS__INTERFACE__POINTLIST__HXX__ -#include -#include -#include - -// ------------------------------------------------------------------------- -template< class P > -void cpPlugins::Interface::PointList:: -AddPoint( const P& p ) -{ - typedef itk::SimpleDataObjectDecorator< std::vector< P > > _T; - - _T* container = NULL; - if( this->m_NumberOfPoints == 0 ) - { - typename _T::Pointer obj = _T::New( ); - container = obj.GetPointer( ); - this->m_ITKObject = container; - } - else - container = dynamic_cast< _T* >( this->m_ITKObject.GetPointer( ) ); - - if( container != NULL ) - { - container->Get( ).push_back( p ); - this->m_NumberOfPoints += 1; - - } // fi -} - -// ------------------------------------------------------------------------- -template< class P > -P cpPlugins::Interface::PointList:: -GetPoint( const unsigned long& i ) const -{ - typedef itk::SimpleDataObjectDecorator< std::vector< P > > _T; - - P ret; - if( i < this->m_NumberOfPoints ) - { - _T* container = dynamic_cast< _T* >( this->m_ITKObject.GetPointer( ) ); - if( container != NULL ) - ret = container->Get( )[ i ]; - - } // fi - return( ret ); -} +// TODO: erase this file #endif // __CPPLUGINS__INTERFACE__POINTLIST__HXX__ diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 437b037..a65aec6 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -339,6 +339,42 @@ GetExposedOutputPorts( ) const return( this->m_ExposedOutputPorts ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::Workspace:: +GetExposedOutput( const std::string& name ) +{ + static OutputProcessObjectPort null_port; + + auto i = this->m_ExposedOutputPorts.find( name ); + if( i != this->m_ExposedOutputPorts.end( ) ) + { + TFilter* filter = this->GetFilter( i->second.first ); + if( filter != NULL ) + return( filter->GetOutput( i->second.second ) ); + + } // fi + return( null_port ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::Workspace:: +GetExposedOutput( const std::string& name ) const +{ + static const OutputProcessObjectPort null_port; + + auto i = this->m_ExposedOutputPorts.find( name ); + if( i != this->m_ExposedOutputPorts.end( ) ) + { + const TFilter* filter = this->GetFilter( i->second.first ); + if( filter != NULL ) + return( filter->GetOutput( i->second.second ) ); + + } // fi + return( null_port ); +} + // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: Execute( ) diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index dedb8b4..75ef769 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -126,10 +126,8 @@ namespace cpPlugins const TExposedPorts& GetExposedInputPorts( ) const; const TExposedPorts& GetExposedOutputPorts( ) const; - TData* GetExposedInput( const std::string& name ); - const TData* GetExposedInput( const std::string& name ) const; - TData* GetExposedOutput( const std::string& name ); - const TData* GetExposedOutput( const std::string& name ) const; + OutputProcessObjectPort& GetExposedOutput( const std::string& name ); + const OutputProcessObjectPort& GetExposedOutput( const std::string& name ) const; // Pipeline execution std::string Execute( ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx index 9cfc8be..9d6a9f4 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx @@ -23,15 +23,15 @@ cpPlugins::BasicFilters::AppendMeshesFilter:: std::string cpPlugins::BasicFilters::AppendMeshesFilter:: _GenerateData( ) { - auto m0 = this->GetInputData< cpPlugins::Interface::Mesh >( "Input0" ); - auto m1 = this->GetInputData< cpPlugins::Interface::Mesh >( "Input1" ); + auto m0 = this->GetInputData( "Input0" ); + auto m1 = this->GetInputData( "Input1" ); auto filter = this->_CreateVTK< vtkAppendPolyData >( ); filter->AddInputData( m0->GetVTK< vtkPolyData >( ) ); filter->AddInputData( m1->GetVTK< vtkPolyData >( ) ); filter->Update( ); - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx index f4dd37b..4391732 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx @@ -27,7 +27,7 @@ cpPlugins::BasicFilters::BinaryErodeImageFilter:: std::string cpPlugins::BasicFilters::BinaryErodeImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -75,7 +75,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx index af2c26a..ab26ffa 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx @@ -32,7 +32,7 @@ cpPlugins::BasicFilters::BinaryThresholdImageFilter:: std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -81,7 +81,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx index a6a916c..2afadd5 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx @@ -29,11 +29,8 @@ std::string cpPlugins::BasicFilters::Cutter:: _GenerateData( ) { // Get inputs - auto mesh = this->GetInputData< cpPlugins::Interface::Mesh >( "InputMesh" ); - auto function = - this->GetInputData< cpPlugins::Interface::ImplicitFunction >( - "InputFunction" - ); + auto mesh = this->GetInputData( "InputMesh" ); + auto function = this->GetInputData( "InputFunction" ); vtkCutter* cutter = this->_CreateVTK< vtkCutter >( ); cutter->DebugOn( ); cutter->SetInputData( mesh->GetVTK< vtkPolyData >( ) ); @@ -43,7 +40,7 @@ _GenerateData( ) cutter->Update( ); // Execute filter - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( cutter->GetOutput( ) ); return( "" ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx index 12cb540..a700a01 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.cxx @@ -28,7 +28,7 @@ cpPlugins::BasicFilters::ExtractSliceImageFilter:: std::string cpPlugins::BasicFilters::ExtractSliceImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; /* @@ -76,7 +76,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx b/lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx index 0a1aa5c..bffab16 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx @@ -35,8 +35,7 @@ cpPlugins::BasicFilters::ImageInterpolatorSource:: std::string cpPlugins::BasicFilters::ImageInterpolatorSource:: _GenerateData( ) { - auto image = - this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" ); + auto image = this->GetInputData( "ReferenceImage" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -91,8 +90,7 @@ template< class T > std::string cpPlugins::BasicFilters::ImageInterpolatorSource:: _GD1( ) { - auto out = - this->GetOutputData< cpPlugins::Interface::DataObject >( "Output" ); + auto out = this->GetOutputData( "Output" ); if( out->GetITK< T >( ) == NULL ) { typename T::Pointer res = T::New( ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx index e8e9b10..6a077f5 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx @@ -130,7 +130,7 @@ ExecConfigurationDialog( QWidget* parent ) // Get bounding box double bbox[ 6 ]; - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); bool input_found = false; if( image != NULL ) { @@ -138,7 +138,7 @@ ExecConfigurationDialog( QWidget* parent ) input_found = true; } // fi - auto mesh = this->GetInputData< cpPlugins::Interface::Mesh >( "Input" ); + auto mesh = this->GetInputData( "Input" ); if( mesh != NULL ) { mesh->GetVTK< vtkPolyData >( )->GetBounds( bbox ); @@ -216,10 +216,10 @@ cpPlugins::BasicFilters::MacheteFilter:: std::string cpPlugins::BasicFilters::MacheteFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); if( image != NULL ) return( this->_FromImage( image ) ); - auto mesh = this->GetInputData< cpPlugins::Interface::Mesh >( "Input" ); + auto mesh = this->GetInputData( "Input" ); if( mesh == NULL ) return( this->_FromMesh( mesh ) ); return( "MacheteFilter: No valid input." ); @@ -227,7 +227,7 @@ _GenerateData( ) // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::MacheteFilter:: -_FromImage( cpPlugins::Interface::Image* image ) +_FromImage( cpPlugins::Interface::DataObject* image ) { itk::DataObject* itk_image = NULL; std::string r = ""; @@ -239,7 +239,7 @@ _FromImage( cpPlugins::Interface::Image* image ) // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::MacheteFilter:: -_FromMesh( cpPlugins::Interface::Mesh* mesh ) +_FromMesh( cpPlugins::Interface::DataObject* mesh ) { return( "" ); } @@ -286,18 +286,18 @@ _RealImage( itk::DataObject* dobj ) filter->Update( ); // Connect outputs (and correct their types and names) - _TImage* pos_out = this->GetOutputData< _TImage >( "PositiveOutput" ); + _TObj* pos_out = this->GetOutputData( "PositiveOutput" ); if( pos_out == NULL ) { this->_AddOutput< _TImage >( "PositiveOutput" ); - pos_out = this->GetOutputData< _TImage >( "PositiveOutput" ); + pos_out = this->GetOutputData( "PositiveOutput" ); } // fi - _TImage* neg_out = this->GetOutputData< _TImage >( "NegativeOutput" ); + _TObj* neg_out = this->GetOutputData( "NegativeOutput" ); if( neg_out == NULL ) { this->_AddOutput< _TImage >( "NegativeOutput" ); - neg_out = this->GetOutputData< _TImage >( "NegativeOutput" ); + neg_out = this->GetOutputData( "NegativeOutput" ); } // fi diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h index 75e52cd..05068a4 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h @@ -88,8 +88,8 @@ namespace cpPlugins virtual std::string _GenerateData( ); - std::string _FromImage( cpPlugins::Interface::Image* image ); - std::string _FromMesh( cpPlugins::Interface::Mesh* mesh ); + std::string _FromImage( cpPlugins::Interface::DataObject* image ); + std::string _FromMesh( cpPlugins::Interface::DataObject* mesh ); template< class I > inline std::string _RealImage( itk::DataObject* dobj ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx index 7f9d251..ea7bc98 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx @@ -38,7 +38,7 @@ cpPlugins::BasicFilters::MacheteImageFilter:: std::string cpPlugins::BasicFilters::MacheteImageFilter:: _GenerateData() { - auto image = this->GetInputData< cpPlugins::Interface::Image >("Input"); + auto image = this->GetInputData("Input"); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes(2, image, itk_image, r, _GD0); @@ -86,7 +86,7 @@ _RealGD(itk::DataObject* image) filter->Update(); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >("Output"); + auto out = this->GetOutputData("Output"); out->SetITK( filter->GetOutput( ) ); return(""); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx index 388b75e..f05296e 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx @@ -28,7 +28,7 @@ std::string cpPlugins::BasicFilters::MarchingCubes:: _GenerateData( ) { // Get input - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); vtkImageData* vtk_image = image->GetVTK< vtkImageData >( ); if( vtk_image == NULL ) return( "MarchingCubes: Input does not have a valid VTK conversion." ); @@ -59,7 +59,7 @@ _GenerateData( ) return( "MarchingCubes: Input data does not have a valid dimension." ); // Execute filter - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( pd ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx index 0046f07..a7fdb3b 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx @@ -25,7 +25,7 @@ cpPlugins::BasicFilters::MedianImageFilter:: std::string cpPlugins::BasicFilters::MedianImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -66,7 +66,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/MultiplyImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MultiplyImageFilter.cxx index 48d1a9e..c1822ed 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MultiplyImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MultiplyImageFilter.cxx @@ -26,7 +26,7 @@ cpPlugins::BasicFilters::MultiplyImageFilter:: std::string cpPlugins::BasicFilters::MultiplyImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input0" ); + auto image = this->GetInputData( "Input0" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -62,7 +62,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx index 5c419ae..6ce525a 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx @@ -30,7 +30,7 @@ cpPlugins::BasicFilters::OtsuThresholdImageFilter:: std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -74,7 +74,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx index f7fdfff..92b8ac5 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx @@ -30,7 +30,7 @@ cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter:: std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllRGBTypes( 2, image, itk_image, r, _GD0 ); @@ -80,7 +80,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx index 90fa019..f2f2ce6 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/SignedMaurerDistanceMapImageFilter.cxx @@ -38,7 +38,7 @@ cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter:: _GenerateData( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); @@ -94,7 +94,7 @@ _RealGD( itk::DataObject* image ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx index df01a69..1497134 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.cxx @@ -50,7 +50,7 @@ _GenerateData( ) src->Update( ); // Execute filter - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( src->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/BasicFilters/TriangleMeshToBinaryImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/TriangleMeshToBinaryImageFilter.cxx index 5dc3f68..cc2e388 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/TriangleMeshToBinaryImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/TriangleMeshToBinaryImageFilter.cxx @@ -35,7 +35,7 @@ _GenerateData( ) typedef itk::Mesh< float, 3 > _3F; typedef itk::Mesh< double, 3 > _3D; - auto input = this->GetInputData< cpPlugins::Interface::Mesh >( "Input" ); + auto input = this->GetInputData( "Input" ); auto in_3f = input->GetITK< _3F >( ); auto in_3d = input->GetITK< _3D >( ); if ( in_3f != NULL ) return( this->_GD0( in_3f ) ); @@ -116,7 +116,7 @@ _RealGD( M* mesh ) filter->Update( ); // Connect output - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetITK( filter->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index 900940b..de091b1 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -317,7 +317,7 @@ template< class I > std::string cpPlugins::IO::ImageReader:: _RealGD( const TStringList& names ) { - auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); + auto out = this->GetOutputData( "Output" ); std::string r = ""; if( names.size( ) == 1 ) { diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx index 234c916..f2afa0f 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx @@ -41,7 +41,7 @@ template< unsigned int D > std::string cpPlugins::IO::ImageWriter:: _GD0_Image( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD ); @@ -54,7 +54,7 @@ template< unsigned int D > std::string cpPlugins::IO::ImageWriter:: _GD0_VectorImage( ) { - auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" ); + auto image = this->GetInputData( "Input" ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD ); diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 040f8ae..3042d67 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -84,7 +84,7 @@ _GD1( ) stlr->SetFileName( fname.c_str( ) ); stlr->Update( ); - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( stlr->GetOutput( ) ); return( "" ); } @@ -98,7 +98,7 @@ _GD1( ) pdr->SetFileName( fname.c_str( ) ); pdr->Update( ); - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + auto out = this->GetOutputData( "Output" ); out->SetVTK( pdr->GetOutput( ) ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx index ac20473..c9ba1c9 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx @@ -28,7 +28,7 @@ cpPlugins::IO::MeshWriter:: std::string cpPlugins::IO::MeshWriter:: _GenerateData( ) { - auto mesh = this->GetInputData< cpPlugins::Interface::Mesh >( "Input" ); + auto mesh = this->GetInputData( "Input" ); vtkPolyData* i = mesh->GetVTK< vtkPolyData >( ); if( i == NULL ) return( "MeshWriter: No suitable input." ); diff --git a/lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx b/lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx index 58cbed5..fbd30d2 100644 --- a/lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx +++ b/lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -41,8 +42,7 @@ _GenerateData( ) typedef itk::ImageBase< 2 > _2DImage; typedef itk::ImageBase< 3 > _3DImage; - auto image = - this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" ); + auto image = this->GetInputData( "ReferenceImage" ); itk::DataObject* itk_image = image->GetITK< _2DImage >( ); if( itk_image != NULL ) return( this->_GD0< _2DImage >( itk_image ) ); @@ -60,19 +60,28 @@ _GenerateData( ) template< class I > std::string cpPlugins::Widgets::SeedWidget:: _GD0( itk::DataObject* image ) +{ + if( this->m_Parameters->GetBool( "SeedsAreInRealSpace" ) ) + return( this->_GD1_Points< I >( dynamic_cast< I* >( image ) ) ); + else + return( this->_GD1_Vertices< I >( dynamic_cast< I* >( image ) ) ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::Widgets::SeedWidget:: +_GD1_Points( I* image ) { typedef cpExtensions::Interaction::ImageInteractorStyle _S; + typedef itk::Point< double, I::ImageDimension > _P; + typedef cpExtensions::DataStructures::VectorValuesContainer< _P > _Container; + + auto container = this->_CreateITK< _Container >( ); - I* base_image = dynamic_cast< I* >( image ); - auto out = - this->GetOutputData< cpPlugins::Interface::PointList >( "Output" ); double aux_pnt[ 3 ]; unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3; - bool real_space = this->m_Parameters->GetBool( "SeedsAreInRealSpace" ); - // Prepare output - out->Clear( ); - out->SetHaveEuclideanPoints( real_space ); + container->Get( ).clear( ); // MPR if( this->m_MPRViewer != NULL ) @@ -90,18 +99,10 @@ _GD0( itk::DataObject* image ) for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) { s->GetSeedAsPoint( i, aux_pnt ); - typename I::PointType seed; + _P seed; for( unsigned int d = 0; d < dim; ++d ) seed[ d ] = aux_pnt[ d ]; - - if( !real_space ) - { - typename I::IndexType index; - if( base_image->TransformPhysicalPointToIndex( seed, index ) ) - out->AddPoint( index ); - } - else - out->AddPoint( seed ); + container->PushBack( seed ); } // rof } @@ -123,17 +124,88 @@ _GD0( itk::DataObject* image ) for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) { s->GetSeedAsPoint( i, aux_pnt ); - typename I::PointType seed; + _P seed; for( unsigned int d = 0; d < dim; ++d ) seed[ d ] = aux_pnt[ d ]; - if( !real_space ) + container->PushBack( seed ); + + } // rof + } + else + s->SeedWidgetOn( ); + + } // fi + this->m_Configured = true; + + auto out = this->GetOutputData( "Output" ); + out->SetITK( container ); + return( "" ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::Widgets::SeedWidget:: +_GD1_Vertices( I* image ) +{ + typedef cpExtensions::Interaction::ImageInteractorStyle _S; + typedef cpExtensions::DataStructures::VectorValuesContainer< typename I::IndexType > _Container; + + auto container = this->_CreateITK< _Container >( ); + + double aux_pnt[ 3 ]; + unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3; + + container->Get( ).clear( ); + + // MPR + if( this->m_MPRViewer != NULL ) + { + for( unsigned int i = 0; i < 4; ++i ) + { + _S* s = + dynamic_cast< _S* >( + this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( ) + ); + if( s != NULL ) + { + if( this->m_Configured ) { - typename I::IndexType index; - if( base_image->TransformPhysicalPointToIndex( seed, index ) ) - out->AddPoint( index ); + for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) + { + s->GetSeedAsPoint( i, aux_pnt ); + typename I::PointType seed; + for( unsigned int d = 0; d < dim; ++d ) + seed[ d ] = aux_pnt[ d ]; + typename I::IndexType idx; + if( image->TransformPhysicalPointToIndex( seed, idx ) ) + container->PushBack( idx ); + + } // rof } else - out->AddPoint( seed ); + s->SeedWidgetOn( ); + + } // fi + + } // rof + + } // fi + + // Single interactor + _S* s = dynamic_cast< _S* >( this->m_SingleInteractor ); + if( s != NULL ) + { + if( this->m_Configured ) + { + for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) + { + s->GetSeedAsPoint( i, aux_pnt ); + typename I::PointType seed; + for( unsigned int d = 0; d < dim; ++d ) + seed[ d ] = aux_pnt[ d ]; + typename I::IndexType idx; + if( image->TransformPhysicalPointToIndex( seed, idx ) ) + container->PushBack( idx ); } // rof } @@ -142,6 +214,9 @@ _GD0( itk::DataObject* image ) } // fi this->m_Configured = true; + + auto out = this->GetOutputData( "Output" ); + out->SetITK( container ); return( "" ); } diff --git a/lib/cpPlugins/Plugins/Widgets/SeedWidget.h b/lib/cpPlugins/Plugins/Widgets/SeedWidget.h index ee6aa16..5d11e1d 100644 --- a/lib/cpPlugins/Plugins/Widgets/SeedWidget.h +++ b/lib/cpPlugins/Plugins/Widgets/SeedWidget.h @@ -36,6 +36,12 @@ namespace cpPlugins template< class I > inline std::string _GD0( itk::DataObject* image ); + template< class I > + inline std::string _GD1_Points( I* image ); + + template< class I > + inline std::string _GD1_Vertices( I* image ); + private: // Purposely not implemented SeedWidget( const Self& ); -- 2.47.1