From bfc16201a35d40fb90f8a354307dca5942fc0fcd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Wed, 5 Oct 2016 18:08:41 -0500 Subject: [PATCH] Line widget added. --- appli/bash/BuildInstances.cxx.in | 2 +- lib/cpPlugins/BaseObjects/Widget.cxx | 14 +++ lib/cpPlugins/BaseObjects/Widget.h | 5 + lib/cpPlugins/Interface/Workspace.cxx | 26 +++++ lib/cpPlugins/Interface/Workspace.h | 9 ++ plugins/Widgets/LineWidget.cxx | 143 ++++++++++++++++++++++++++ plugins/Widgets/LineWidget.h | 39 +++++++ plugins/Widgets/SeedWidget.cxx | 12 +++ plugins/Widgets/SeedWidget.h | 4 + plugins/Widgets/SplineWidget.cxx | 21 +++- plugins/Widgets/SplineWidget.h | 4 + 11 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 plugins/Widgets/LineWidget.cxx create mode 100644 plugins/Widgets/LineWidget.h diff --git a/appli/bash/BuildInstances.cxx.in b/appli/bash/BuildInstances.cxx.in index 79cbcf2..084ee1c 100644 --- a/appli/bash/BuildInstances.cxx.in +++ b/appli/bash/BuildInstances.cxx.in @@ -218,7 +218,7 @@ void Lines( TCommands& commands, const std::deque< std::string >& lines ) for( auto l = lines.begin( ); l != lines.end( ); ++l ) { auto pos = l->find_first_not_of( " " ); - char cmd = std::tolower( ( *l )[ pos ] ); + char cmd = tolower( ( *l )[ pos ] ); commands[ cmd ].push_back( l->substr( l->find_first_not_of( " ", pos + 1 ) ) ); diff --git a/lib/cpPlugins/BaseObjects/Widget.cxx b/lib/cpPlugins/BaseObjects/Widget.cxx index 35bf57a..93bf1b9 100644 --- a/lib/cpPlugins/BaseObjects/Widget.cxx +++ b/lib/cpPlugins/BaseObjects/Widget.cxx @@ -16,6 +16,20 @@ IsInteractive( ) return( true ); } +// ------------------------------------------------------------------------- +void cpPlugins::BaseObjects::Widget:: +EnabledOn( ) +{ + this->SetEnabled( true ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BaseObjects::Widget:: +EnabledOff( ) +{ + this->SetEnabled( false ); +} + // ------------------------------------------------------------------------- cpPlugins::BaseObjects::Widget:: Widget( ) diff --git a/lib/cpPlugins/BaseObjects/Widget.h b/lib/cpPlugins/BaseObjects/Widget.h index daa5de7..1451b7b 100644 --- a/lib/cpPlugins/BaseObjects/Widget.h +++ b/lib/cpPlugins/BaseObjects/Widget.h @@ -28,6 +28,11 @@ namespace cpPlugins virtual bool IsInteractive( ) cpPlugins_OVERRIDE; + virtual void EnabledOn( ); + virtual void EnabledOff( ); + virtual void Clear( ) = 0; + virtual void SetEnabled( bool v ) = 0; + protected: Widget( ); virtual ~Widget( ); diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index d1d2c0d..90c26d5 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -44,6 +44,24 @@ GetFilter( const std::string& name ) const return( NULL ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TWidget* cpPlugins::Interface::Workspace:: +GetWidget( const std::string& name ) +{ + TProcess* process = this->GetFilter( name ); + return( dynamic_cast< TWidget* >( process ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Workspace:: +TWidget* cpPlugins::Interface::Workspace:: +GetWidget( const std::string& name ) const +{ + const TProcess* process = this->GetFilter( name ); + return( dynamic_cast< const TWidget* >( process ) ); +} + // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: HasFilter( const std::string& name ) const @@ -51,6 +69,14 @@ HasFilter( const std::string& name ) const return( this->m_Filters.find( name ) != this->m_Filters.end( ) ); } +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Workspace:: +HasWidget( const std::string& name ) const +{ + const TWidget* wdg = this->GetWidget( name ); + return( wdg != NULL ); +} + // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TProcess* cpPlugins::Interface::Workspace:: diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index 6282f69..428f13a 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -4,6 +4,7 @@ #include #include #include +#include #include class vtkRenderWindowInteractor; @@ -24,6 +25,7 @@ namespace cpPlugins typedef itk::SmartPointer< const Self > ConstPointer; typedef cpPlugins::BaseObjects::ProcessObject TProcess; + typedef cpPlugins::BaseObjects::Widget TWidget; typedef cpPlugins::Interface::Plugins TInterface; typedef std::map< std::string, TProcess::Pointer > TFilters; @@ -51,7 +53,14 @@ namespace cpPlugins const TProcess* GetFilter( const std::string& name ) const; + TWidget* GetWidget( + const std::string& name + ); + const TWidget* GetWidget( + const std::string& name + ) const; bool HasFilter( const std::string& name ) const; + bool HasWidget( const std::string& name ) const; TProcess* CreateFilter( const std::string& category, const std::string& filter, diff --git a/plugins/Widgets/LineWidget.cxx b/plugins/Widgets/LineWidget.cxx new file mode 100644 index 0000000..f73e100 --- /dev/null +++ b/plugins/Widgets/LineWidget.cxx @@ -0,0 +1,143 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::LineWidget:: +Clear( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::LineWidget:: +SetEnabled( bool v ) +{ +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::LineWidget:: +LineWidget( ) + : Superclass( ) +{ + typedef cpPlugins::BaseObjects::DataObject _TData; + typedef cpPlugins::DataObjects::Mesh _TMesh; + + this->_ConfigureInput< _TData >( "Input", false, false ); + this->_ConfigureOutput< _TMesh >( "Output" ); + auto line = vtkSmartPointer< vtkPolyData >::New( ); + line->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); + line->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); + line->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); + line->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); + line->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); + this->GetOutput( "Output" )->SetVTK( line ); +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::LineWidget:: +~LineWidget( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::LineWidget:: +_GenerateData( ) +{ + if( this->m_Interactors.size( ) == 0 ) + this->_Error( "Give at least one valid interactor." ); + + auto image = this->GetInputData< vtkImageData >( "Input" ); + if( image != NULL ) this->_GD_Image( image ); + else this->_Error( "Do not know how to create this widget." ); +} + +// ------------------------------------------------------------------------- +cpPluginsWidgets::LineWidget:: +TValidProps cpPluginsWidgets::LineWidget:: +_GetValidActors( vtkObject* source ) +{ + TValidProps valid_props; + auto iIt = this->m_Interactors.begin( ); + for( ; iIt != this->m_Interactors.end( ); ++iIt ) + { + auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); + if( r != NULL ) + { + auto props = r->GetViewProps( ); + if( props != NULL ) + { + props->InitTraversal( ); + while( vtkProp* prop = props->GetNextProp( ) ) + { + auto image_actor = dynamic_cast< vtkImageSlice* >( prop ); + auto mesh_actor = dynamic_cast< vtkActor* >( prop ); + vtkObject* input = NULL; + if( image_actor != NULL ) + { + auto mapper = image_actor->GetMapper( ); + if( mapper != NULL ) + input = mapper->GetInput( ); + } + else if( mesh_actor != NULL ) + { + auto mapper = mesh_actor->GetMapper( ); + if( mapper != NULL ) + input = mapper->GetInput( ); + + } // fi + if( input != NULL ) + valid_props[ *iIt ].insert( prop ); + + } // elihw + + } // fi + + } // fi + + } // rof + return( valid_props ); +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::LineWidget:: +_GD_Image( vtkImageData* image ) +{ + auto valid_props = this->_GetValidActors( image ); + if( valid_props.size( ) == 0 ) + this->_Error( "Given image does not have a valid associated actor." ); + + vtkSmartPointer< vtkLineWidget2 > wdg = this->GetVTK< vtkLineWidget2 >( ); + if( wdg.GetPointer( ) == NULL ) + { + auto rep = vtkSmartPointer< vtkLineRepresentation >::New( ); + + /* TODO + p[ 0 ] = 0.0; p[ 1 ] = -1.0; p[ 2 ] = 0.0; + rep->SetPoint1WorldPosition( p ); + p[ 0 ] = 0.0; p[ 1 ] = 1.0; p[ 2 ] = 0.0; + rep->SetPoint2WorldPosition( p ); + rep->PlaceWidget( pl3d_block0->GetBounds( ) ); + rep->GetPolyData( seeds ); + rep->DistanceAnnotationVisibilityOn( ); + */ + + wdg = this->_CreateVTK< vtkLineWidget2 >( ); + wdg->SetInteractor( valid_props.begin( )->first ); + wdg->SetRepresentation( rep ); + wdg->EnabledOn( ); + } + else + dynamic_cast< vtkLineRepresentation* >( wdg->GetRepresentation( ) )-> + GetPolyData( this->GetOutputData< vtkPolyData >( "Output" ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/Widgets/LineWidget.h b/plugins/Widgets/LineWidget.h new file mode 100644 index 0000000..281cacd --- /dev/null +++ b/plugins/Widgets/LineWidget.h @@ -0,0 +1,39 @@ +#ifndef __cpPluginsWidgets__LineWidget__h__ +#define __cpPluginsWidgets__LineWidget__h__ + +#include +#include +#include + +// ------------------------------------------------------------------------- +class vtkImageData; +class vtkProp; + +// ------------------------------------------------------------------------- +namespace cpPluginsWidgets +{ + /** + */ + class cpPluginsWidgets_EXPORT LineWidget + : public cpPlugins::BaseObjects::Widget + { + cpPluginsObject( LineWidget, cpPlugins::BaseObjects::Widget, Widgets ); + + public: + virtual void Clear( ) cpPlugins_OVERRIDE; + virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + + protected: + typedef std::set< vtkProp* > TProps; + typedef std::map< vtkRenderWindowInteractor*, TProps > TValidProps; + + protected: + TValidProps _GetValidActors( vtkObject* source ); + void _GD_Image( vtkImageData* image ); + }; + +} // ecapseman + +#endif // __cpPluginsWidgets__LineWidget__h__ + +// eof - $RCSfile$ diff --git a/plugins/Widgets/SeedWidget.cxx b/plugins/Widgets/SeedWidget.cxx index 4400056..dc5b6a5 100644 --- a/plugins/Widgets/SeedWidget.cxx +++ b/plugins/Widgets/SeedWidget.cxx @@ -16,6 +16,18 @@ #include #include +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SeedWidget:: +Clear( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SeedWidget:: +SetEnabled( bool v ) +{ +} + // ------------------------------------------------------------------------- cpPluginsWidgets::SeedWidget:: SeedWidget( ) diff --git a/plugins/Widgets/SeedWidget.h b/plugins/Widgets/SeedWidget.h index b119bb9..7449b94 100644 --- a/plugins/Widgets/SeedWidget.h +++ b/plugins/Widgets/SeedWidget.h @@ -38,6 +38,10 @@ namespace cpPluginsWidgets typedef cpExtensions::Interaction::ImageSlicePointPlacer TPlacer; typedef cpExtensions::Visualization::WindowLevelImageActor TImageActor; + public: + virtual void Clear( ) cpPlugins_OVERRIDE; + virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + protected: /** */ diff --git a/plugins/Widgets/SplineWidget.cxx b/plugins/Widgets/SplineWidget.cxx index 1bba488..057d4e7 100644 --- a/plugins/Widgets/SplineWidget.cxx +++ b/plugins/Widgets/SplineWidget.cxx @@ -7,6 +7,25 @@ #include #include +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SplineWidget:: +Clear( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SplineWidget:: +SetEnabled( bool v ) +{ + auto wdg = this->GetVTK< vtkSplineWidget >( ); + if( wdg != NULL ) + { + wdg->SetEnabled( v ); + wdg->GetInteractor( )->Render( ); + + } // fi +} + // ------------------------------------------------------------------------- cpPluginsWidgets::SplineWidget:: SplineWidget( ) @@ -49,7 +68,6 @@ _GenerateData( ) if( this->m_Configured ) { wdg->GetPolyData( this->m_Contour.GetPointer( ) ); - wdg->Off( ); } else { @@ -111,7 +129,6 @@ _GenerateData( ) ); wdg->SetHandleSize( 0.005 ); wdg->SetNumberOfHandles( 3 ); - wdg->On( ); this->m_Configured = true; } // fi diff --git a/plugins/Widgets/SplineWidget.h b/plugins/Widgets/SplineWidget.h index 83b57b2..7eaeccd 100644 --- a/plugins/Widgets/SplineWidget.h +++ b/plugins/Widgets/SplineWidget.h @@ -29,6 +29,10 @@ namespace cpPluginsWidgets { cpPluginsObject( SplineWidget, cpPlugins::BaseObjects::Widget, Widgets ); + public: + virtual void Clear( ) cpPlugins_OVERRIDE; + virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + protected: bool m_Configured; vtkSmartPointer< vtkPolyData > m_Contour; -- 2.47.1