From: Leonardo Florez-Valencia Date: Fri, 16 Oct 2015 22:17:56 +0000 (-0500) Subject: More widgets added X-Git-Tag: v0.1~329 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=fdd4f2cec18107de380ebd350cb1019eed7c294c;p=cpPlugins.git More widgets added --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 58276cb..ca29aaa 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -18,9 +18,6 @@ ImageMPR( QWidget* parent ) { this->m_UI->setupUi( this ); - // Associate callbacks - this->m_UI->MPR->AddCursorCommand( Self::_CursorCommand, this ); - // Connect actions ImageMPR_ConnectAction( OpenImage ); ImageMPR_ConnectAction( OpenSegmentation ); @@ -182,48 +179,46 @@ _execPlugin( ) } // ------------------------------------------------------------------------- -void ImageMPR:: -_CursorCommand( double* pos, int axis, void* data ) -{ - Self* app = reinterpret_cast< Self* >( data ); - if( app == NULL ) - return; - if( !( app->m_Flooding ) ) - return; - - cpPlugins::Interface::ProcessObject::Pointer filter = - app->m_UI->MPR->CreateFilter( - "cpPlugins::BasicFilters::FloodFillImageFilter" - ); - if( filter.IsNull( ) ) - return; - - cpPlugins::Interface::Parameters* params = filter->GetParameters( ); - params->SetPoint( "Seed", 3, pos ); - params->SetReal( "Window", app->m_UI->MPR->GetWindow( ) ); - params->SetReal( "Level", app->m_UI->MPR->GetLevel( ) ); - params->SetUint( "InsideValue", 1 ); - params->SetUint( "OutsideValue", 0 ); - filter->SetInput( "Input", app->m_UI->MPR->GetImage( app->m_ImageLoaded ) ); - app->m_UI->MPR->Block( ); - std::string err = filter->Update( ); - cpPlugins::Interface::BaseMPRWindow::TImage::Pointer image = filter->GetOutput< cpPlugins::Interface::BaseMPRWindow::TImage >( "Output" ); - filter->DisconnectOutputs( ); - app->m_UI->MPR->AddImage( "Segmentation", image ); - app->m_UI->MPR->Unblock( ); - - - - /* TODO - std::cout - << "CursorCommand ==> " - << pos[ 0 ] << " " - << pos[ 1 ] << " " - << pos[ 2 ] << " : " - << axis << " " - << data << std::endl; - */ -} +/* TODO + void ImageMPR:: + _CursorCommand( double* pos, int axis, void* data ) + { + Self* app = reinterpret_cast< Self* >( data ); + if( app == NULL ) + return; + if( !( app->m_Flooding ) ) + return; + + cpPlugins::Interface::ProcessObject::Pointer filter = + app->m_UI->MPR->CreateFilter( + "cpPlugins::BasicFilters::FloodFillImageFilter" + ); + if( filter.IsNull( ) ) + return; + + cpPlugins::Interface::Parameters* params = filter->GetParameters( ); + params->SetPoint( "Seed", 3, pos ); + params->SetReal( "Window", app->m_UI->MPR->GetWindow( ) ); + params->SetReal( "Level", app->m_UI->MPR->GetLevel( ) ); + params->SetUint( "InsideValue", 1 ); + params->SetUint( "OutsideValue", 0 ); + filter->SetInput( "Input", app->m_UI->MPR->GetImage( app->m_ImageLoaded ) ); + app->m_UI->MPR->Block( ); + std::string err = filter->Update( ); + cpPlugins::Interface::BaseMPRWindow::TImage::Pointer image = filter->GetOutput< cpPlugins::Interface::BaseMPRWindow::TImage >( "Output" ); + filter->DisconnectOutputs( ); + app->m_UI->MPR->AddImage( "Segmentation", image ); + app->m_UI->MPR->Unblock( ); + + std::cout + << "CursorCommand ==> " + << pos[ 0 ] << " " + << pos[ 1 ] << " " + << pos[ 2 ] << " : " + << axis << " " + << data << std::endl; + } +*/ /* #include "MementoState.h" diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index a89d0f9..dabf450 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -123,10 +123,6 @@ public: typedef QMainWindow Superclass; typedef cpExtensions::Visualization::MPRObjects TMPRObjects; - typedef TMPRObjects::TCursorCommand TCursorCommand; - typedef TMPRObjects::TMouseCommand TMouseCommand; - typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand; - typedef TMPRObjects::TKeyCommand TKeyCommand; // Plugins types /* @@ -166,10 +162,6 @@ private slots: void _execPlugin( ); -protected: - // Callbacks - static void _CursorCommand( double* pos, int axis, void* data ); - private: Ui::ImageMPR* m_UI; diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 25b7d3c..e12dfa5 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -29,6 +29,8 @@ SET( #example_ReadWriteImage #example_MPR example_View2DImage + example_HandleWidget + example_SeedWidget ##example_MarchingCubes ##example_OtsuFilter ##example_RGBImageToHSVChannels diff --git a/appli/examples/example_BaseInteractorStyle.cxx b/appli/examples/example_BaseInteractorStyle.cxx index a8515d2..75366b7 100644 --- a/appli/examples/example_BaseInteractorStyle.cxx +++ b/appli/examples/example_BaseInteractorStyle.cxx @@ -4,22 +4,22 @@ #include #include #include -#include +#include // ------------------------------------------------------------------------- #define example_BaseInteractorStyle_Macro( x ) \ - virtual void On##x( ) \ + virtual void On##x( ) \ { std::cout << "On" << #x << "( )" << std::endl; } // ------------------------------------------------------------------------- class example_BaseInteractorStyle - : public cpExtensions::Visualization::BaseInteractorStyle + : public cpExtensions::Interaction::BaseInteractorStyle { public: typedef example_BaseInteractorStyle Self; vtkTypeMacro( example_BaseInteractorStyle, - cpExtensions::Visualization::BaseInteractorStyle + cpExtensions::Interaction::BaseInteractorStyle ); public: @@ -59,7 +59,7 @@ protected: virtual ~example_BaseInteractorStyle( ) { } - virtual bool _PickPosition( double pos[ 3 ] ) + virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ) { return( true ); // Just testing... } diff --git a/appli/examples/example_HandleWidget.cxx b/appli/examples/example_HandleWidget.cxx new file mode 100644 index 0000000..193091c --- /dev/null +++ b/appli/examples/example_HandleWidget.cxx @@ -0,0 +1,130 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Interface TInterface; +typedef cpPlugins::Interface::ProcessObject TProcessObject; +typedef cpPlugins::Interface::DataObject TDataObject; +typedef cpPlugins::Interface::Image TImage; +typedef cpPlugins::Interface::Parameters TParameters; +typedef TInterface::TClasses TClasses; + +typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 3 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " plugins_file input_image" + << std::endl; + return( 1 ); + + } // fi + + // Create interface + TInterface plugins; + if( !plugins.Load( argv[ 1 ] ) ) + { + std::cerr << "Failed to load plugins." << std::endl; + return( 1 ); + + } // fi + + // Create objects + TProcessObject::Pointer reader; + reader = plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" ); + if( reader.IsNull( ) ) + { + std::cerr + << "No suitable reader found in plugins." << std::endl + << "Reader: " << reader.GetPointer( ) << std::endl + << std::endl; + return( 1 ); + + } // fi + + // Configure reader + TParameters* reader_params = reader->GetParameters( ); + for( int i = 2; i < argc; ++i ) + reader_params->AddToStringList( "FileNames", argv[ i ] ); + + // Execute pipeline + std::string err = reader->Update( ); + if( err != "" ) + { + std::cerr << "ERROR: " << err << std::endl; + return( 1 ); + + } // fi + TImage* image = reader->GetOutput< TImage >( "Output" ); + + // Configure visualization objects + vtkSmartPointer< vtkRenderer > renderer = + vtkSmartPointer< vtkRenderer >::New( ); + renderer->SetBackground( 0.1, 0.3, 0.5 ); + + vtkSmartPointer< vtkRenderWindow > window = + vtkSmartPointer< vtkRenderWindow >::New( ); + window->AddRenderer( renderer ); + window->SetSize( 600, 600 ); + + // Set up the interaction + vtkSmartPointer< vtkRenderWindowInteractor > interactor = + vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + window->SetInteractor( interactor ); + + // Create slice actors + vtkSmartPointer< TSliceActors > image_actors = + vtkSmartPointer< TSliceActors >::New( ); + image_actors->AddInputData( image->GetVTK< vtkImageData >( ), 2 ); + image_actors->PushActorsInto( window ); + + vtkSmartPointer< vtkImageActorPointPlacer > placer = + vtkSmartPointer< vtkImageActorPointPlacer >::New( ); + placer->SetImageActor( image_actors->GetImageActor( 0 ) ); + + double bnds[ 6 ]; + image_actors->GetImageActor( 0 )->GetDisplayBounds( bnds ); + double pos[] = { bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] }; + + vtkSmartPointer< vtkPointHandleRepresentation3D > rep = + vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + rep->SetDisplayPosition( pos ); + rep->GetProperty( )->SetColor( 1, 0, 0 ); + rep->ActiveRepresentationOff( ); + rep->SetPointPlacer( placer ); + + vtkSmartPointer< vtkHandleWidget > handleWidget = + vtkSmartPointer< vtkHandleWidget >::New( ); + handleWidget->SetInteractor( interactor ); + handleWidget->SetRepresentation( rep ); + + // Begin interaction + interactor->Initialize( ); + renderer->ResetCamera( ); + window->Render( ); + handleWidget->On( ); + interactor->Start( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_SeedWidget.cxx b/appli/examples/example_SeedWidget.cxx new file mode 100644 index 0000000..beac518 --- /dev/null +++ b/appli/examples/example_SeedWidget.cxx @@ -0,0 +1,123 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Interface TInterface; +typedef cpPlugins::Interface::ProcessObject TProcessObject; +typedef cpPlugins::Interface::DataObject TDataObject; +typedef cpPlugins::Interface::Image TImage; +typedef cpPlugins::Interface::Parameters TParameters; +typedef TInterface::TClasses TClasses; + +typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; +typedef cpExtensions::Interaction::SeedWidget TSeedWidget; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 3 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " plugins_file input_image" + << std::endl; + return( 1 ); + + } // fi + + // Create interface + TInterface plugins; + if( !plugins.Load( argv[ 1 ] ) ) + { + std::cerr << "Failed to load plugins." << std::endl; + return( 1 ); + + } // fi + + // Create objects + TProcessObject::Pointer reader; + reader = plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" ); + if( reader.IsNull( ) ) + { + std::cerr + << "No suitable reader found in plugins." << std::endl + << "Reader: " << reader.GetPointer( ) << std::endl + << std::endl; + return( 1 ); + + } // fi + + // Configure reader + TParameters* reader_params = reader->GetParameters( ); + for( int i = 2; i < argc; ++i ) + reader_params->AddToStringList( "FileNames", argv[ i ] ); + + // Execute pipeline + std::string err = reader->Update( ); + if( err != "" ) + { + std::cerr << "ERROR: " << err << std::endl; + return( 1 ); + + } // fi + TImage* image = reader->GetOutput< TImage >( "Output" ); + + // Configure visualization objects + vtkSmartPointer< vtkRenderer > renderer = + vtkSmartPointer< vtkRenderer >::New( ); + renderer->SetBackground( 0.1, 0.3, 0.5 ); + + vtkSmartPointer< vtkRenderWindow > window = + vtkSmartPointer< vtkRenderWindow >::New( ); + window->AddRenderer( renderer ); + window->SetSize( 600, 600 ); + + // Set up the interaction + vtkSmartPointer< vtkRenderWindowInteractor > interactor = + vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + window->SetInteractor( interactor ); + + // Create slice actors + vtkSmartPointer< TSliceActors > image_actors = + vtkSmartPointer< TSliceActors >::New( ); + image_actors->AddInputData( image->GetVTK< vtkImageData >( ), 2 ); + image_actors->PushActorsInto( window ); + + // Create the widget and its representation + vtkSmartPointer< vtkPointHandleRepresentation3D > handle = + vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + handle->GetProperty( )->SetColor( 1, 0, 0 ); + vtkSmartPointer< vtkSeedRepresentation > rep = + vtkSmartPointer< vtkSeedRepresentation >::New( ); + rep->SetHandleRepresentation( handle ); + + vtkSmartPointer< TSeedWidget > widget = + vtkSmartPointer< TSeedWidget >::New( ); + widget->SetInteractor( interactor ); + widget->SetRepresentation( rep ); + + // Begin interaction + renderer->ResetCamera( ); + window->Render( ); + widget->On( ); + interactor->Start( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/CMakeLists.txt b/lib/cpExtensions/CMakeLists.txt index d977c46..fd4cab7 100644 --- a/lib/cpExtensions/CMakeLists.txt +++ b/lib/cpExtensions/CMakeLists.txt @@ -23,6 +23,7 @@ SET( DataStructures Algorithms IO + Interaction Visualization ) FOREACH(dir ${lib_DIRECTORIES}) diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx b/lib/cpExtensions/Interaction/BaseInteractorStyle.cxx similarity index 62% rename from lib/cpExtensions/Visualization/BaseInteractorStyle.cxx rename to lib/cpExtensions/Interaction/BaseInteractorStyle.cxx index b564101..a384eb0 100644 --- a/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/BaseInteractorStyle.cxx @@ -1,4 +1,4 @@ -#include +#include #include @@ -8,101 +8,243 @@ #include // ------------------------------------------------------------------------- -long cpExtensions::Visualization::BaseInteractorStyle::_TMouseButtonEvent:: -MaxDoubleClick = 200; // ms +long cpExtensions::Interaction::BaseInteractorStyle::_TMouseButtonEvent:: +MaxDoubleClick = 350; // ms // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: +SetSetDoubleClickDelay( long delay ) +{ + Self::_TMouseButtonEvent::MaxDoubleClick = delay; +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: AddMouseMoveCommand( TMouseCommand command, void* data ) { - this->m_MouseMoveCommands.push_back( - std::pair< TMouseCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_MouseMoveCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddMouseClickCommand( TMouseCommand command, void* data ) { - this->m_MouseClickCommands.push_back( - std::pair< TMouseCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_MouseClickCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddMouseDoubleClickCommand( TMouseCommand command, void* data ) { - this->m_MouseDoubleClickCommands.push_back( - std::pair< TMouseCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_MouseDoubleClickCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddMouseWheelCommand( TMouseWheelCommand command, void* data ) { - this->m_MouseWheelCommands.push_back( - std::pair< TMouseWheelCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_MouseWheelCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddKeyCommand( TKeyCommand command, void* data ) { - this->m_KeyCommands.push_back( - std::pair< TKeyCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_KeyCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddExposeCommand( TVoidCommand command, void* data ) { - this->m_ExposeCommands.push_back( - std::pair< TVoidCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_ExposeCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddConfigureCommand( TVoidCommand command, void* data ) { - this->m_ConfigureCommands.push_back( - std::pair< TVoidCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_ConfigureCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddEnterCommand( TVoidCommand command, void* data ) { - this->m_EnterCommands.push_back( - std::pair< TVoidCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_EnterCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: AddLeaveCommand( TVoidCommand command, void* data ) { - this->m_LeaveCommands.push_back( - std::pair< TVoidCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_LeaveCommands[ command ] = data; + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveMouseMoveCommand( TMouseCommand command ) +{ + auto i = this->m_MouseMoveCommands.find( command ); + if( i != this->m_MouseMoveCommands.end( ) ) + { + this->m_MouseMoveCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveMouseClickCommand( TMouseCommand command ) +{ + auto i = this->m_MouseClickCommands.find( command ); + if( i != this->m_MouseClickCommands.end( ) ) + { + this->m_MouseClickCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveMouseDoubleClickCommand( TMouseCommand command ) +{ + auto i = this->m_MouseDoubleClickCommands.find( command ); + if( i != this->m_MouseDoubleClickCommands.end( ) ) + { + this->m_MouseDoubleClickCommands.erase( i ); + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveMouseWheelCommand( TMouseWheelCommand command ) +{ + auto i = this->m_MouseWheelCommands.find( command ); + if( i != this->m_MouseWheelCommands.end( ) ) + { + this->m_MouseWheelCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveKeyCommand( TKeyCommand command ) +{ + auto i = this->m_KeyCommands.find( command ); + if( i != this->m_KeyCommands.end( ) ) + { + this->m_KeyCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveExposeCommand( TVoidCommand command ) +{ + auto i = this->m_ExposeCommands.find( command ); + if( i != this->m_ExposeCommands.end( ) ) + { + this->m_ExposeCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveConfigureCommand( TVoidCommand command ) +{ + auto i = this->m_ConfigureCommands.find( command ); + if( i != this->m_ConfigureCommands.end( ) ) + { + this->m_ConfigureCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveEnterCommand( TVoidCommand command ) +{ + auto i = this->m_EnterCommands.find( command ); + if( i != this->m_EnterCommands.end( ) ) + { + this->m_EnterCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: +RemoveLeaveCommand( TVoidCommand command ) +{ + auto i = this->m_LeaveCommands.find( command ); + if( i != this->m_LeaveCommands.end( ) ) + { + this->m_LeaveCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::BaseInteractorStyle:: DelegateTDxEvent( unsigned long event, void* calldata ) { // TODO @@ -111,7 +253,7 @@ DelegateTDxEvent( unsigned long event, void* calldata ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMouseMove( ) { // Get current position on the associated actors @@ -153,19 +295,19 @@ OnMouseMove( ) } // fi // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible specialized events - for( unsigned int i = 0; i < this->m_MouseMoveCommands.size( ); ++i ) - this->m_MouseMoveCommands[ i ].first( - this->m_MouseMoveCommands[ i ].second, button, pos, alt, ctr, sft - ); + auto i = this->m_MouseMoveCommands.begin( ); + for( ; i != this->m_MouseMoveCommands.end( ); ++i ) + i->first( i->second, button, idx, pos, alt, ctr, sft ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMouseWheelForward( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -173,9 +315,10 @@ OnMouseWheelForward( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseWheelCommands.size( ); ++i ) - this->m_MouseWheelCommands[ i ].first( - this->m_MouseWheelCommands[ i ].second, 1, + auto i = this->m_MouseWheelCommands.begin( ); + for( ; i != this->m_MouseWheelCommands.end( ); ++i ) + i->first( + i->second, 1, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -183,7 +326,7 @@ OnMouseWheelForward( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMouseWheelBackward( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -191,9 +334,10 @@ OnMouseWheelBackward( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseWheelCommands.size( ); ++i ) - this->m_MouseWheelCommands[ i ].first( - this->m_MouseWheelCommands[ i ].second, -1, + auto i = this->m_MouseWheelCommands.begin( ); + for( ; i != this->m_MouseWheelCommands.end( ); ++i ) + i->first( + i->second, -1, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -201,21 +345,21 @@ OnMouseWheelBackward( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnLeftButtonDown( ) { this->m_ActiveButton = Self::ButtonID_Left; } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnLeftButtonUp( ) { this->m_ActiveButton = Self::ButtonID_None; } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMiddleButtonDown( ) { this->m_ActiveButton = Self::ButtonID_Middle; @@ -235,7 +379,7 @@ OnMiddleButtonDown( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMiddleButtonUp( ) { this->m_ActiveButton = Self::ButtonID_None; @@ -261,7 +405,7 @@ OnMiddleButtonUp( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnRightButtonDown( ) { this->m_ActiveButton = Self::ButtonID_Right; @@ -281,7 +425,7 @@ OnRightButtonDown( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnRightButtonUp( ) { this->m_ActiveButton = Self::ButtonID_None; @@ -307,7 +451,7 @@ OnRightButtonUp( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnLeftClick( ) { // Get current position on the associated actors @@ -316,16 +460,18 @@ OnLeftClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseClickCommands[ i ].first( - this->m_MouseClickCommands[ i ].second, + auto i = this->m_MouseClickCommands.begin( ); + for( ; i != this->m_MouseClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Left, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -333,7 +479,7 @@ OnLeftClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnLeftDoubleClick( ) { // Get current position on the associated actors @@ -342,16 +488,18 @@ OnLeftDoubleClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseDoubleClickCommands[ i ].first( - this->m_MouseDoubleClickCommands[ i ].second, + auto i = this->m_MouseDoubleClickCommands.begin( ); + for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Left, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -359,7 +507,7 @@ OnLeftDoubleClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMiddleClick( ) { // Get current position on the associated actors @@ -368,16 +516,18 @@ OnMiddleClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseClickCommands[ i ].first( - this->m_MouseClickCommands[ i ].second, + auto i = this->m_MouseClickCommands.begin( ); + for( ; i != this->m_MouseClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Middle, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -385,7 +535,7 @@ OnMiddleClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnMiddleDoubleClick( ) { // Get current position on the associated actors @@ -394,16 +544,18 @@ OnMiddleDoubleClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseDoubleClickCommands[ i ].first( - this->m_MouseDoubleClickCommands[ i ].second, + auto i = this->m_MouseDoubleClickCommands.begin( ); + for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Middle, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -411,7 +563,7 @@ OnMiddleDoubleClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnRightClick( ) { // Get current position on the associated actors @@ -420,16 +572,18 @@ OnRightClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseClickCommands[ i ].first( - this->m_MouseClickCommands[ i ].second, + auto i = this->m_MouseClickCommands.begin( ); + for( ; i != this->m_MouseClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Right, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -437,7 +591,7 @@ OnRightClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnRightDoubleClick( ) { // Get current position on the associated actors @@ -446,16 +600,18 @@ OnRightDoubleClick( ) return; // Get mouse pointer position - double pos[ 3 ]; - if( !( this->_PickPosition( pos ) ) ) + static int idx[ 2 ]; + static double pos[ 3 ]; + if( !( this->_PickPosition( idx, pos ) ) ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i ) - this->m_MouseDoubleClickCommands[ i ].first( - this->m_MouseDoubleClickCommands[ i ].second, + auto i = this->m_MouseDoubleClickCommands.begin( ); + for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i ) + i->first( + i->second, Self::ButtonID_Right, - pos, + idx, pos, rwi->GetAltKey( ) == 1, rwi->GetControlKey( ) == 1, rwi->GetShiftKey( ) == 1 @@ -463,7 +619,7 @@ OnRightDoubleClick( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnChar( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -471,39 +627,37 @@ OnChar( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_KeyCommands.size( ); ++i ) - this->m_KeyCommands[ i ].first( - this->m_KeyCommands[ i ].second, - rwi->GetKeyCode( ) - ); + auto i = this->m_KeyCommands.begin( ); + for( ; i != this->m_KeyCommands.end( ); ++i ) + i->first( i->second, rwi->GetKeyCode( ) ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnKeyDown( ) { } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnKeyUp( ) { } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnKeyPress( ) { } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnKeyRelease( ) { } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnExpose( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -511,12 +665,13 @@ OnExpose( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_ExposeCommands.size( ); ++i ) - this->m_ExposeCommands[ i ].first( this->m_ExposeCommands[ i ].second ); + auto i = this->m_ExposeCommands.begin( ); + for( ; i != this->m_ExposeCommands.end( ); ++i ) + i->first( i->second ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnConfigure( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -524,14 +679,13 @@ OnConfigure( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_ConfigureCommands.size( ); ++i ) - this->m_ConfigureCommands[ i ].first( - this->m_ConfigureCommands[ i ].second - ); + auto i = this->m_ConfigureCommands.begin( ); + for( ; i != this->m_ConfigureCommands.end( ); ++i ) + i->first( i->second ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnEnter( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -539,12 +693,13 @@ OnEnter( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_EnterCommands.size( ); ++i ) - this->m_EnterCommands[ i ].first( this->m_EnterCommands[ i ].second ); + auto i = this->m_EnterCommands.begin( ); + for( ; i != this->m_EnterCommands.end( ); ++i ) + i->first( i->second ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: OnLeave( ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); @@ -552,12 +707,13 @@ OnLeave( ) return; // Invoke possible events - for( unsigned int i = 0; i < this->m_LeaveCommands.size( ); ++i ) - this->m_LeaveCommands[ i ].first( this->m_LeaveCommands[ i ].second ); + auto i = this->m_LeaveCommands.begin( ); + for( ; i != this->m_LeaveCommands.end( ); ++i ) + i->first( i->second ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: Dolly( ) { if( this->CurrentRenderer == NULL ) @@ -571,7 +727,7 @@ Dolly( ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: Pan( ) { if( this->CurrentRenderer == NULL ) @@ -627,7 +783,7 @@ Pan( ) } // ------------------------------------------------------------------------- -cpExtensions::Visualization::BaseInteractorStyle:: +cpExtensions::Interaction::BaseInteractorStyle:: BaseInteractorStyle( ) : Superclass( ), m_MotionFactor( double( 10 ) ) @@ -641,13 +797,13 @@ BaseInteractorStyle( ) } // ------------------------------------------------------------------------- -cpExtensions::Visualization::BaseInteractorStyle:: +cpExtensions::Interaction::BaseInteractorStyle:: ~BaseInteractorStyle( ) { } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: _Dolly( double factor ) { if( this->CurrentRenderer == NULL ) @@ -668,7 +824,7 @@ _Dolly( double factor ) } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::BaseInteractorStyle:: +void cpExtensions::Interaction::BaseInteractorStyle:: _ProcessEvents( vtkObject* object, unsigned long event, diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.h b/lib/cpExtensions/Interaction/BaseInteractorStyle.h similarity index 75% rename from lib/cpExtensions/Visualization/BaseInteractorStyle.h rename to lib/cpExtensions/Interaction/BaseInteractorStyle.h index c02dbc7..1501f00 100644 --- a/lib/cpExtensions/Visualization/BaseInteractorStyle.h +++ b/lib/cpExtensions/Interaction/BaseInteractorStyle.h @@ -1,11 +1,12 @@ -#ifndef __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__ -#define __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__ +#ifndef __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__ +#define __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__ #include #include +#include #include -#include + #include /* ========================================================================= @@ -22,7 +23,7 @@ namespace cpExtensions { - namespace Visualization + namespace Interaction { /** */ @@ -42,12 +43,16 @@ namespace cpExtensions }; // Callbacks types - typedef void ( *TMouseCommand )( void*, const ButtonID&, double*, bool, bool, bool ); + typedef void ( *TMouseCommand )( + void*, const ButtonID&, int*, double*, bool, bool, bool + ); typedef void ( *TMouseWheelCommand )( void*, const int&, bool, bool, bool ); typedef void ( *TKeyCommand )( void*, const char& ); typedef void ( *TVoidCommand )( void* ); public: + static void SetSetDoubleClickDelay( long delay ); + // Associate callbacks for each event void AddMouseMoveCommand( TMouseCommand command, void* data ); void AddMouseClickCommand( TMouseCommand command, void* data ); @@ -59,6 +64,16 @@ namespace cpExtensions void AddEnterCommand( TVoidCommand command, void* data ); void AddLeaveCommand( TVoidCommand command, void* data ); + void RemoveMouseMoveCommand( TMouseCommand command ); + void RemoveMouseClickCommand( TMouseCommand command ); + void RemoveMouseDoubleClickCommand( TMouseCommand command ); + void RemoveMouseWheelCommand( TMouseWheelCommand command ); + void RemoveKeyCommand( TKeyCommand command ); + void RemoveExposeCommand( TVoidCommand command ); + void RemoveConfigureCommand( TVoidCommand command ); + void RemoveEnterCommand( TVoidCommand command ); + void RemoveLeaveCommand( TVoidCommand command ); + void DelegateTDxEvent( unsigned long event, void* calldata ); // Possible mouse motion events @@ -68,7 +83,9 @@ namespace cpExtensions // Possible mouse click-related events inline ButtonID GetButtonID( ) const - { return( this->m_ActiveButton ); } + { + return( this->m_ActiveButton ); + } virtual void OnLeftButtonDown( ); virtual void OnLeftButtonUp( ); @@ -107,7 +124,7 @@ namespace cpExtensions virtual void _Dolly( double factor ); // Extension interface - virtual bool _PickPosition( double pos[ 3 ] ) = 0; + virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ) = 0; // Main event callback static void _ProcessEvents( @@ -126,15 +143,15 @@ namespace cpExtensions double m_MotionFactor; // Callbacks - std::vector< std::pair< TMouseCommand, void* > > m_MouseMoveCommands; - std::vector< std::pair< TMouseCommand, void* > > m_MouseClickCommands; - std::vector< std::pair< TMouseCommand, void* > > m_MouseDoubleClickCommands; - std::vector< std::pair< TMouseWheelCommand, void* > > m_MouseWheelCommands; - std::vector< std::pair< TKeyCommand, void* > > m_KeyCommands; - std::vector< std::pair< TVoidCommand, void* > > m_ExposeCommands; - std::vector< std::pair< TVoidCommand, void* > > m_ConfigureCommands; - std::vector< std::pair< TVoidCommand, void* > > m_EnterCommands; - std::vector< std::pair< TVoidCommand, void* > > m_LeaveCommands; + std::map< TMouseCommand, void* > m_MouseMoveCommands; + std::map< TMouseCommand, void* > m_MouseClickCommands; + std::map< TMouseCommand, void* > m_MouseDoubleClickCommands; + std::map< TMouseWheelCommand, void* > m_MouseWheelCommands; + std::map< TKeyCommand, void* > m_KeyCommands; + std::map< TVoidCommand, void* > m_ExposeCommands; + std::map< TVoidCommand, void* > m_ConfigureCommands; + std::map< TVoidCommand, void* > m_EnterCommands; + std::map< TVoidCommand, void* > m_LeaveCommands; /** * Button events @@ -183,13 +200,13 @@ namespace cpExtensions _TMouseButtonEvent m_LeftButtonEvent; _TMouseButtonEvent m_MiddleButtonEvent; _TMouseButtonEvent m_RightButtonEvent; - ButtonID m_ActiveButton; + ButtonID m_ActiveButton; }; } // ecapseman } // ecapseman -#endif // __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__ +#endif // __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__ // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx similarity index 61% rename from lib/cpExtensions/Visualization/ImageInteractorStyle.cxx rename to lib/cpExtensions/Interaction/ImageInteractorStyle.cxx index 9ed180a..d0a3137 100644 --- a/lib/cpExtensions/Visualization/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx @@ -1,18 +1,18 @@ -#include +#include #include #include // ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageInteractorStyle:: -Self* cpExtensions::Visualization::ImageInteractorStyle:: +cpExtensions::Interaction::ImageInteractorStyle:: +Self* cpExtensions::Interaction::ImageInteractorStyle:: New( ) { return( new Self ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageInteractorStyle:: +void cpExtensions::Interaction::ImageInteractorStyle:: AssociateImageActor( vtkImageActor* actor ) { if( actor != NULL ) @@ -24,7 +24,7 @@ AssociateImageActor( vtkImageActor* actor ) } // ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageInteractorStyle:: +cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) : Superclass( ) { @@ -33,27 +33,29 @@ ImageInteractorStyle( ) } // ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageInteractorStyle:: +cpExtensions::Interaction::ImageInteractorStyle:: ~ImageInteractorStyle( ) { } // ------------------------------------------------------------------------- -bool cpExtensions::Visualization::ImageInteractorStyle:: -_PickPosition( double pos[ 3 ] ) +bool cpExtensions::Interaction::ImageInteractorStyle:: +_PickPosition( int idx[ 2 ], double pos[ 3 ] ) { - static const double _0 = double( 0 ); vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return( false ); // Find the renderer where the event has been raised - double x = double( rwi->GetEventPosition( )[ 0 ] ); - double y = double( rwi->GetEventPosition( )[ 1 ] ); - this->FindPokedRenderer( x, y ); + idx[ 0 ] = rwi->GetEventPosition( )[ 0 ]; + idx[ 1 ] = rwi->GetEventPosition( )[ 1 ]; + this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) ); // Pick a 3D position - int r = this->m_PropPicker->Pick( x, y, _0, this->CurrentRenderer ); + int r = this->m_PropPicker->Pick( + double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ), + this->CurrentRenderer + ); if( r == 0 ) return( false ); this->m_PropPicker->GetPickPosition( pos ); diff --git a/lib/cpExtensions/Visualization/ImageInteractorStyle.h b/lib/cpExtensions/Interaction/ImageInteractorStyle.h similarity index 71% rename from lib/cpExtensions/Visualization/ImageInteractorStyle.h rename to lib/cpExtensions/Interaction/ImageInteractorStyle.h index 9048926..78bf7da 100644 --- a/lib/cpExtensions/Visualization/ImageInteractorStyle.h +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.h @@ -1,7 +1,7 @@ -#ifndef __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__ -#define __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__ +#ifndef __CPEXTENSIONS__INTERACTION__IMAGEINTERACTORSTYLE__H__ +#define __CPEXTENSIONS__INTERACTION__IMAGEINTERACTORSTYLE__H__ -#include +#include #include @@ -13,7 +13,7 @@ class vtkImageActor; namespace cpExtensions { - namespace Visualization + namespace Interaction { /** */ @@ -34,7 +34,7 @@ namespace cpExtensions ImageInteractorStyle( ); virtual ~ImageInteractorStyle( ); - virtual bool _PickPosition( double pos[ 3 ] ); + virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ); private: // Purposely not implemented @@ -49,6 +49,6 @@ namespace cpExtensions } // ecapseman -#endif // __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__ +#endif // __CPEXTENSIONS__INTERACTION__IMAGEINTERACTORSTYLE__H__ // eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/SeedWidget.cxx b/lib/cpExtensions/Interaction/SeedWidget.cxx new file mode 100644 index 0000000..3460532 --- /dev/null +++ b/lib/cpExtensions/Interaction/SeedWidget.cxx @@ -0,0 +1,86 @@ +#include + +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SeedWidget:: +Self* cpExtensions::Interaction::SeedWidget:: +New( ) +{ + return( new Self ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SeedWidget:: +SetInteractor( vtkRenderWindowInteractor* rwi ) +{ + this->Superclass::SetInteractor( rwi ); + TBaseStyle* s = dynamic_cast< TBaseStyle*>( rwi->GetInteractorStyle( ) ); + if( s != NULL ) + { + s->AddMouseClickCommand( Self::_Click, this ); + s->AddMouseDoubleClickCommand( Self::_DoubleClick, this ); + + } // fi +} + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SeedWidget:: +SeedWidget( ) + : Superclass( ) +{ + // Remove default translations + vtkWidgetEventTranslator* t = this->GetEventTranslator( ); + t->RemoveTranslation( vtkCommand::LeftButtonPressEvent ); + t->RemoveTranslation( vtkCommand::MiddleButtonPressEvent ); + t->RemoveTranslation( vtkCommand::RightButtonPressEvent ); +} + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SeedWidget:: +~SeedWidget( ) +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SeedWidget:: +_Click( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ) +{ + SeedWidget* self = reinterpret_cast< SeedWidget* >( data ); + if( self->WidgetState == vtkSeedWidget::MovingSeed ) + return; + + int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] ); + if( st == vtkSeedRepresentation::NearSeed ) + { + self->WidgetState = vtkSeedWidget::MovingSeed; + + // Invoke an event on ourself for the handles + self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL ); + self->Superclass::StartInteraction( ); + self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL ); + self->EventCallbackCommand->SetAbortFlag( 1 ); + self->Render( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SeedWidget:: +_DoubleClick( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ) +{ + Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) ); +} + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/SeedWidget.h b/lib/cpExtensions/Interaction/SeedWidget.h new file mode 100644 index 0000000..526ac7e --- /dev/null +++ b/lib/cpExtensions/Interaction/SeedWidget.h @@ -0,0 +1,54 @@ +#ifndef __CPEXTENSIONS__INTERACTION__SEEDWIDGET__H__ +#define __CPEXTENSIONS__INTERACTION__SEEDWIDGET__H__ + +#include +#include +#include + +namespace cpExtensions +{ + namespace Interaction + { + /** + */ + class cpExtensions_EXPORT SeedWidget + : public vtkSeedWidget + { + public: + typedef SeedWidget Self; + vtkTypeMacro( SeedWidget, vtkSeedWidget ); + + typedef cpExtensions::Interaction::BaseInteractorStyle TBaseStyle; + typedef TBaseStyle::TMouseCommand TMouseCommand; + + public: + static Self* New( ); + + virtual void SetInteractor( vtkRenderWindowInteractor* rwi ); + + protected: + SeedWidget( ); + virtual ~SeedWidget( ); + + static void _Click( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ); + static void _DoubleClick( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ); + + private: + // Purposely not implemented + SeedWidget( const Self& ); + Self& operator=( const Self& ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__INTERACTION__SEEDWIDGET__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 5892fe1..17dc4c4 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -29,22 +29,77 @@ New( ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddSlicesCommand( TCursorCommand command, void* data ) +AddSlicesCommand( TSlicesCommand command, void* data ) { - this->m_SlicesCommands.push_back( - std::pair< TCursorCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_SlicesCommands[ command ] = data; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddSeedCommand( TCursorCommand command, void* data ) +AddWindowLevelCommand( TWindowLevelCommand command, void* data ) { - this->m_SeedCommands.push_back( - std::pair< TCursorCommand, void* >( command, data ) - ); - this->Modified( ); + if( command != NULL ) + { + this->m_WindowLevelCommands[ command ] = data; + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddRenderCommand( TVoidCommand command, void* data ) +{ + if( command != NULL ) + { + this->m_RenderCommands[ command ] = data; + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +RemoveSlicesCommand( TSlicesCommand command ) +{ + auto i = this->m_SlicesCommands.find( command ); + if( i != this->m_SlicesCommands.end( ) ) + { + this->m_SlicesCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +RemoveWindowLevelCommand( TWindowLevelCommand command ) +{ + auto i = this->m_WindowLevelCommands.find( command ); + if( i != this->m_WindowLevelCommands.end( ) ) + { + this->m_WindowLevelCommands.erase( i ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +RemoveRenderCommand( TVoidCommand command ) +{ + auto i = this->m_RenderCommands.find( command ); + if( i != this->m_RenderCommands.end( ) ) + { + this->m_RenderCommands.erase( i ); + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- @@ -126,8 +181,6 @@ Clear( ) this->m_ImageMaps.clear( ); this->m_SliceMappers.clear( ); this->m_ImageActors.clear( ); - this->m_AssociatedSlices.clear( ); - this->m_AssociatedActors.clear( ); // Reconfigure unique objects this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( ); @@ -211,14 +264,6 @@ Clear( ) this->AddItem( this->m_PlaneActor ); } -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AssociateSlice( Self* other ) -{ - this->m_AssociatedSlices.push_back( other ); - this->Modified( ); -} - // ------------------------------------------------------------------------- vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: GetStyle( ) @@ -375,21 +420,6 @@ GetPlaneFunction( ) const return( this->m_PlaneFunction ); } -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AddActor( vtkAlgorithm* algorithm, vtkActor* actor ) -{ - this->m_AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) ); - this->AddItem( actor ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AddActor( vtkActor* actor ) -{ - this->AddActor( NULL, actor ); -} - // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetInterpolate( bool v ) @@ -808,26 +838,38 @@ SetSliceNumber( const int& slice ) if( nImages == 0 ) return; + // Compute plane properties + int axis = this->m_SliceMappers[ 0 ]->GetOrientation( ); + vtkAlgorithm* algo = this->m_SliceMappers[ 0 ]->GetInputAlgorithm( ); + vtkInformation* info = algo->GetOutputInformation( 0 ); + int ext[ 6 ]; + double ori[ 3 ], spac[ 3 ], pos[ 3 ]; + info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext ); + info->Get( vtkDataObject::ORIGIN( ), ori ); + info->Get( vtkDataObject::SPACING( ), spac ); + this->m_SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos ); + + // Update display extent + int d_ext[ 6 ] = + { + ext[ 0 ], ext[ 1 ], + ext[ 2 ], ext[ 3 ], + ext[ 4 ], ext[ 5 ] + }; + d_ext[ axis << 1 ] = slice; + d_ext[ ( axis << 1 ) + 1 ] = slice; + // Change visualization extent for( unsigned int i = 0; i < nImages; ++i ) { this->m_SliceMappers[ i ]->SetSliceNumber( slice ); + this->m_ImageActors[ i ]->SetDisplayExtent( d_ext ); this->m_SliceMappers[ i ]->Modified( ); this->m_ImageActors[ i ]->Modified( ); this->m_SliceMappers[ i ]->Update( ); } // rof - // Compute plane - vtkAlgorithm* algo = this->m_SliceMappers[ 0 ]->GetInputAlgorithm( ); - vtkInformation* info = algo->GetOutputInformation( 0 ); - int ext[ 6 ]; - double ori[ 3 ], spac[ 3 ], pos[ 3 ]; - info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext ); - info->Get( vtkDataObject::ORIGIN( ), ori ); - info->Get( vtkDataObject::SPACING( ), spac ); - this->m_SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos ); - // Prevent obscuring voxels by offsetting the plane geometry double xbnds[ ] = { @@ -871,7 +913,6 @@ SetSliceNumber( const int& slice ) this->m_PlaneFunction->SetOrigin( pos ); // Configure visualization and implicit plane orientation - int axis = this->m_SliceMappers[ 0 ]->GetOrientation( ); this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); this->m_PlaneActor->GetProperty( )->SetLineWidth( 2 ); vtkPoints* plane_points = this->m_Plane->GetPoints( ); @@ -908,37 +949,8 @@ SetSliceNumber( const int& slice ) this->m_PlaneMapper->Modified( ); this->m_PlaneActor->Modified( ); - // Prepare other actors to update - /* TODO - for( unsigned int i = 0; i < this->OtherActors.size( ); ++i ) - { - if( this->OtherActors[ i ].first.GetPointer( ) != NULL ) - { - this->OtherActors[ i ].first->Modified( ); - this->OtherActors[ i ].first->Update( ); - - } // fi - - if( this->OtherActors[ i ].second.GetPointer( ) != NULL ) - { - this->OtherActors[ i ].second->GetMapper( )->Modified( ); - this->OtherActors[ i ].second->Modified( ); - - } // fi - - } // rof - - if( this->m_UpdateCommand != NULL ) - this->m_UpdateCommand( this->m_UpdateData ); - */ - // Update text this->UpdateText( ); - - // Associated slices - for( unsigned int i = 0; i < this->m_AssociatedSlices.size( ); ++i ) - if( this->m_AssociatedSlices[ i ]->GetAxis( ) == this->GetAxis( ) ) - this->m_AssociatedSlices[ i ]->SetSliceNumber( slice ); } // ------------------------------------------------------------------------- @@ -1068,6 +1080,36 @@ UpdateText( const double& w, const double& l ) this->Modified( ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +Render( ) +{ + vtkInteractorStyle* style = this->GetStyle( ); + if( style == NULL ) + return; + vtkRenderWindowInteractor* rwi = style->GetInteractor( ); + if( rwi != NULL ) + rwi->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetCamera( ) +{ + vtkInteractorStyle* style = this->GetStyle( ); + if( style == NULL ) + return; + vtkRenderWindowInteractor* rwi = style->GetInteractor( ); + if( rwi == NULL ) + return; + vtkRenderWindow* rw = rwi->GetRenderWindow( ); + if( rw == NULL ) + return; + vtkRenderer* renderer = rw->GetRenderers( )->GetFirstRenderer( ); + if( renderer != NULL ) + renderer->ResetCamera( ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) @@ -1089,12 +1131,9 @@ void cpExtensions::Visualization::ImageSliceActors:: _ConfigureStyle( ) { // Connect this view with a controller - this->m_Style = vtkSmartPointer< ImageInteractorStyle >::New( ); + this->m_Style = vtkSmartPointer< TStyle >::New( ); this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this ); this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this ); - this->m_Style->AddMouseDoubleClickCommand( - Self::_MouseDoubleClickCommand, this - ); this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this ); this->m_Style->AddKeyCommand( Self::_KeyCommand, this ); } @@ -1174,8 +1213,7 @@ _ConfigureNewInput( int axis ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _MouseMoveCommand( - void* data, - const ImageInteractorStyle::ButtonID& btn, double* pos, + void* data, const TStyle::ButtonID& btn, int* idx, double* pos, bool alt, bool ctr, bool sft ) { @@ -1183,32 +1221,33 @@ _MouseMoveCommand( if( actors == NULL ) return; - if( btn == ImageInteractorStyle::ButtonID_None ) + if( btn == TStyle::ButtonID_None ) { + // Just show the pixel information actors->SetCursor( pos ); actors->UpdateText( pos ); - actors->GetStyle( )->GetInteractor( )->Render( ); - } - else if( btn == ImageInteractorStyle::ButtonID_Left ) - { - unsigned int nC = actors->m_SlicesCommands.size( ); - if( !alt && ctr && !sft && nC > 0 ) - { - for( unsigned int i = 0; i < nC; ++i ) - actors->m_SlicesCommands[ i ].first( - pos, actors->GetAxis( ), actors->m_SlicesCommands[ i ].second - ); - actors->GetStyle( )->GetInteractor( )->Render( ); - - } // fi + actors->Render( ); } - else if( btn == ImageInteractorStyle::ButtonID_Middle ) + else if( btn == TStyle::ButtonID_Left ) { + /* TODO + unsigned int nC = actors->m_SlicesCommands.size( ); + if( !alt && ctr && !sft && nC > 0 ) + { + for( unsigned int i = 0; i < nC; ++i ) + actors->m_SlicesCommands[ i ].first( + pos, actors->GetAxis( ), actors->m_SlicesCommands[ i ].second + ); + actors->Render( ); + + } // fi + */ } - else if( btn == ImageInteractorStyle::ButtonID_Right ) + else if( btn == TStyle::ButtonID_Right ) { if( !alt && !ctr && sft ) { + // Change image window level double bounds[ 6 ]; actors->m_SliceMappers[ 0 ]->GetBounds( bounds ); @@ -1222,12 +1261,16 @@ _MouseMoveCommand( dx *= actors->m_StartWindowLevel[ 0 ]; dy *= actors->m_StartWindowLevel[ 1 ]; - actors->SetWindowLevel( - actors->m_StartWindowLevel[ 0 ] + dx, - actors->m_StartWindowLevel[ 1 ] + dy - ); - actors->GetStyle( )->GetInteractor( )->Render( ); - + dx += actors->m_StartWindowLevel[ 0 ]; + dy += actors->m_StartWindowLevel[ 1 ]; + actors->SetWindowLevel( dx, dy ); + actors->Render( ); + + // Associate objects + auto i = actors->m_WindowLevelCommands.begin( ); + for( ; i != actors->m_WindowLevelCommands.end( ); ++i ) + i->first( dx, dy, i->second ); + } // fi } // fi @@ -1236,8 +1279,7 @@ _MouseMoveCommand( // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _MouseClickCommand( - void* data, - const ImageInteractorStyle::ButtonID& btn, double* pos, + void* data, const TStyle::ButtonID& btn, int* idx, double* pos, bool alt, bool ctr, bool sft ) { @@ -1254,9 +1296,8 @@ _MouseClickCommand( // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_MouseDoubleClickCommand( - void* data, - const ImageInteractorStyle::ButtonID& btn, double* pos, +_MouseWheelCommand( + void* data, const int& dir, bool alt, bool ctr, bool sft ) { @@ -1264,55 +1305,59 @@ _MouseDoubleClickCommand( if( actors == NULL ) return; - if( btn == ImageInteractorStyle::ButtonID_Left ) + if( !alt && !ctr ) { - unsigned int nC = actors->m_SeedCommands.size( ); - if( !alt && ctr && !sft && nC > 0 ) - { - for( unsigned int i = 0; i < nC; ++i ) - actors->m_SeedCommands[ i ].first( - pos, actors->GetAxis( ), actors->m_SeedCommands[ i ].second - ); - actors->GetStyle( )->GetInteractor( )->Render( ); + int slice = actors->GetSliceNumber( ) + ( dir * ( ( sft )? 10: 1 ) ); + if( slice < actors->GetSliceNumberMinValue( ) ) + slice = actors->GetSliceNumberMinValue( ); + if( slice > actors->GetSliceNumberMaxValue( ) ) + slice = actors->GetSliceNumberMaxValue( ); + actors->SetSliceNumber( slice ); + actors->Render( ); + + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); - } // fi - } - else if( btn == ImageInteractorStyle::ButtonID_Middle ) - { - } - else if( btn == ImageInteractorStyle::ButtonID_Right ) - { } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_MouseWheelCommand( - void* data, - const int& dir, bool alt, bool ctr, bool sft - ) +_KeyCommand( void* data, const char& key ) { ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); if( actors == NULL ) return; - if( !alt && !ctr && !sft ) + switch( key ) { - actors->SetSliceNumber( actors->GetSliceNumber( ) + dir ); - actors->GetStyle( )->GetInteractor( )->Render( ); - } - else if( !alt && !ctr && sft ) + case 'r': case 'R': { - actors->SetSliceNumber( actors->GetSliceNumber( ) + ( dir * 10 ) ); - actors->GetStyle( )->GetInteractor( )->Render( ); + actors->ResetCamera( ); + actors->Render( ); - } // fi -} + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); + } + break; + case 'w': case 'W': + { + actors->ResetWindowLevel( ); + actors->Render( ); -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -_KeyCommand( void* data, const char& key ) -{ + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); + } + break; + default: + break; + } // hctiws } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 96d4550..6c7d405 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -3,8 +3,8 @@ #include +#include #include -#include #include #include @@ -17,7 +17,7 @@ #include #include -#include +#include // ------------------------------------------------------------------------- class vtkAlgorithmOutput; @@ -37,11 +37,14 @@ namespace cpExtensions public: typedef ImageSliceActors Self; - typedef void ( *TCursorCommand )( double*, int, void* ); - typedef BaseInteractorStyle::TMouseCommand TMouseCommand; - typedef BaseInteractorStyle::TMouseWheelCommand TMouseWheelCommand; - typedef BaseInteractorStyle::TKeyCommand TKeyCommand; - typedef BaseInteractorStyle::TVoidCommand TVoidCommand; + typedef cpExtensions::Interaction::BaseInteractorStyle TBaseStyle; + typedef cpExtensions::Interaction::ImageInteractorStyle TStyle; + typedef void ( *TSlicesCommand )( double*, int, void* ); + typedef void ( *TWindowLevelCommand )( double, double, void* ); + typedef TBaseStyle::TMouseCommand TMouseCommand; + typedef TBaseStyle::TMouseWheelCommand TMouseWheelCommand; + typedef TBaseStyle::TKeyCommand TKeyCommand; + typedef TBaseStyle::TVoidCommand TVoidCommand; public: vtkTypeMacro( ImageSliceActors, vtkPropCollection ); @@ -50,15 +53,18 @@ namespace cpExtensions // Creation static ImageSliceActors* New( ); - void AddSlicesCommand( TCursorCommand command, void* data ); - void AddSeedCommand( TCursorCommand command, void* data ); + void AddSlicesCommand( TSlicesCommand command, void* data ); + void AddWindowLevelCommand( TWindowLevelCommand command, void* data ); + void AddRenderCommand( TVoidCommand command, void* data ); + + void RemoveSlicesCommand( TSlicesCommand command ); + void RemoveWindowLevelCommand( TWindowLevelCommand command ); + void RemoveRenderCommand( TVoidCommand command ); void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 ); void AddInputData( vtkImageData* data, int axis = 2 ); void Clear( ); - void AssociateSlice( Self* other ); - vtkInteractorStyle* GetStyle( ); const vtkInteractorStyle* GetStyle( ) const; @@ -74,9 +80,6 @@ namespace cpExtensions vtkPlane* GetPlaneFunction( ); const vtkPlane* GetPlaneFunction( ) const; - void AddActor( vtkAlgorithm* algorithm, vtkActor* actor ); - void AddActor( vtkActor* actor ); - void SetInterpolate( bool v ); void InterpolateOn( ); void InterpolateOff( ); @@ -116,6 +119,9 @@ namespace cpExtensions void UpdateText( double pos[ 3 ] ); void UpdateText( const double& w, const double& l ); + void Render( ); + void ResetCamera( ); + protected: ImageSliceActors( ); virtual ~ImageSliceActors( ); @@ -127,17 +133,14 @@ namespace cpExtensions // Events static void _MouseMoveCommand( void* data, - const BaseInteractorStyle::ButtonID& btn, double* pos, + const TBaseStyle::ButtonID& btn, + int* idx, double* pos, bool alt, bool ctr, bool sft ); static void _MouseClickCommand( void* data, - const BaseInteractorStyle::ButtonID& btn, double* pos, - bool alt, bool ctr, bool sft - ); - static void _MouseDoubleClickCommand( - void* data, - const BaseInteractorStyle::ButtonID& btn, double* pos, + const TBaseStyle::ButtonID& btn, + int* idx, double* pos, bool alt, bool ctr, bool sft ); static void _MouseWheelCommand( @@ -155,7 +158,7 @@ namespace cpExtensions Self& operator=( const Self& ); protected: - vtkSmartPointer< ImageInteractorStyle > m_Style; + vtkSmartPointer< TStyle > m_Style; // Multiple actors std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps; @@ -167,17 +170,10 @@ namespace cpExtensions double m_MinWindow, m_MaxWindow; double m_MinLevel, m_MaxLevel; - // Other associated slices - std::vector< vtkSmartPointer< Self > > m_AssociatedSlices; - // Associated commands - std::vector< std::pair< TCursorCommand, void* > > m_SlicesCommands; - std::vector< std::pair< TCursorCommand, void* > > m_SeedCommands; - - // Other associated actors - typedef std::pair< vtkAlgorithm*, vtkActor* > TAssociatedActor; - typedef std::vector< TAssociatedActor > TAssociatedActors; - TAssociatedActors m_AssociatedActors; + std::map< TSlicesCommand, void* > m_SlicesCommands; + std::map< TWindowLevelCommand, void* > m_WindowLevelCommands; + std::map< TVoidCommand, void* > m_RenderCommands; // Unique objects vtkSmartPointer< vtkPolyData > m_Cursor; diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index f755e45..cff7a80 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -321,6 +321,20 @@ SetLookupTableAsColor( unsigned int i, double r, double g, double b ) this->Modified( ); } +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetWindow( ) +{ + return( this->Slices[ 0 ][ 0 ]->GetWindow( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetLevel( ) +{ + return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); +} + // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMinValue( const int& axis ) const @@ -405,9 +419,16 @@ MPRActors( ) for( unsigned int j = 0; j < 3; ++j ) this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( ); - this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); - this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); - this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); + /* + this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); + this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); + this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); + */ + /* + this->Slices[ 0 ][ 0 ]->AddSlicesCommand( TSlicesCommand command, void* data ); + AddWindowLevelCommand( TWindowLevelCommand command, void* data ); + AddRenderCommand + */ /* TODO this->Slices[ 0 ][ 0 ]->SetSlicesCommand( Self::_SetSlices, this ); @@ -501,15 +522,29 @@ _Update( unsigned int i ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -_SetSlices( double* pos, int axis, void* data ) +_SlicesCommand( double* pos, int axis, void* data ) { - MPRActors* actors = reinterpret_cast< MPRActors* >( data ); - if( actors == NULL ) + /* + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) return; - for( unsigned int j = 0; j < 3; ++j ) + for( unsigned int j = 0; j < 3; ++j ) if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis ) - actors->Slices[ 0 ][ j ]->SetSlice( pos ); - actors->Modified( ); + actors->Slices[ 0 ][ j ]->SetSlice( pos ); + actors->Modified( ); + */ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_WindowLevelCommand( double window, double level, void* data ) +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_RenderCommand( void* data ) +{ } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index 2496780..f4283f4 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -1,8 +1,6 @@ #ifndef __CPEXTENSIONS__VISUALIZATION__MPRACTORS__H__ #define __CPEXTENSIONS__VISUALIZATION__MPRACTORS__H__ -#include - #include #include @@ -18,10 +16,14 @@ namespace cpExtensions public: typedef MPRActors Self; - typedef ImageSliceActors::TCursorCommand TCursorCommand; - typedef ImageSliceActors::TMouseCommand TMouseCommand; - typedef ImageSliceActors::TMouseWheelCommand TMouseWheelCommand; - typedef ImageSliceActors::TKeyCommand TKeyCommand; + typedef ImageSliceActors::TBaseStyle TBaseStyle; + typedef ImageSliceActors::TStyle TStyle; + typedef ImageSliceActors::TSlicesCommand TSlicesCommand; + typedef ImageSliceActors::TWindowLevelCommand TWindowLevelCommand; + typedef ImageSliceActors::TMouseCommand TMouseCommand; + typedef ImageSliceActors::TMouseWheelCommand TMouseWheelCommand; + typedef ImageSliceActors::TKeyCommand TKeyCommand; + typedef ImageSliceActors::TVoidCommand TVoidCommand; public: vtkTypeMacro( MPRActors, vtkPropCollection ); @@ -30,13 +32,6 @@ namespace cpExtensions // Creation static MPRActors* New( ); - void AddCursorCommand( TCursorCommand command, void* data ) - { - this->Slices[ 0 ][ 0 ]->AddSlicesCommand( command, data ); - this->Slices[ 0 ][ 1 ]->AddSlicesCommand( command, data ); - this->Slices[ 0 ][ 2 ]->AddSlicesCommand( command, data ); - } - ImageSliceActors* GetSliceActors( const int& i ) const; int AddInputConnection( vtkAlgorithmOutput* aout ); @@ -61,14 +56,8 @@ namespace cpExtensions unsigned int i, double r, double g, double b ); - double GetWindow( ) - { - return( this->Slices[ 0 ][ 0 ]->GetWindow( ) ); - } - double GetLevel( ) - { - return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); - } + double GetWindow( ); + double GetLevel( ); // Slice access int GetSliceNumberMinValue( const int& axis ) const; @@ -85,7 +74,9 @@ namespace cpExtensions vtkImageData* _Image( unsigned int i ) const; void _Update( unsigned int i ); - static void _SetSlices( double* pos, int axis, void* data ); + static void _SlicesCommand( double* pos, int axis, void* data ); + static void _WindowLevelCommand( double window, double level, void* data ); + static void _RenderCommand( void* data ); private: // Purposely not implemented @@ -95,13 +86,6 @@ namespace cpExtensions protected: vtkSmartPointer< vtkActor > ImageOutlineActor; vtkSmartPointer< ImageSliceActors > Slices[ 2 ][ 3 ]; - - std::vector< TCursorCommand > CursorCommands; - std::vector< TMouseCommand > MouseCommands; - std::vector< TMouseCommand > MouseClickCommands; - std::vector< TMouseCommand > MouseDoubleClickCommands; - std::vector< TMouseWheelCommand > MouseWheelCommands; - std::vector< TKeyCommand > KeyCommands; }; } // ecapseman diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index cfee04e..2a50c62 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -175,28 +175,42 @@ Get3DRenderer( ) const } // ------------------------------------------------------------------------- -cpExtensions::Visualization::MPRObjects:: -TMPRActors* cpExtensions::Visualization::MPRObjects:: +cpExtensions::Visualization:: +MPRActors* cpExtensions::Visualization::MPRObjects:: GetMPRActors( ) { return( this->m_MPRActors ); } // ------------------------------------------------------------------------- -const cpExtensions::Visualization::MPRObjects:: -TMPRActors* cpExtensions::Visualization::MPRObjects:: +const cpExtensions::Visualization:: +MPRActors* cpExtensions::Visualization::MPRObjects:: GetMPRActors( ) const { return( this->m_MPRActors ); } +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRObjects:: +GetWindow( ) const +{ + return( this->m_MPRActors->GetWindow( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRObjects:: +GetLevel( ) const +{ + return( this->m_MPRActors->GetLevel( ) ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRObjects:: MPRObjects( ) : vtkObject( ) { // Prepare actors - this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( ); + this->m_MPRActors = vtkSmartPointer< MPRActors >::New( ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index 1920bb7..71741ef 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -19,12 +19,15 @@ namespace cpExtensions { public: typedef MPRObjects Self; - typedef cpExtensions::Visualization::MPRActors TMPRActors; - typedef TMPRActors::TCursorCommand TCursorCommand; - typedef TMPRActors::TMouseCommand TMouseCommand; - typedef TMPRActors::TMouseWheelCommand TMouseWheelCommand; - typedef TMPRActors::TKeyCommand TKeyCommand; + typedef MPRActors::TBaseStyle TBaseStyle; + typedef MPRActors::TStyle TStyle; + typedef MPRActors::TSlicesCommand TSlicesCommand; + typedef MPRActors::TWindowLevelCommand TWindowLevelCommand; + typedef MPRActors::TMouseCommand TMouseCommand; + typedef MPRActors::TMouseWheelCommand TMouseWheelCommand; + typedef MPRActors::TKeyCommand TKeyCommand; + typedef MPRActors::TVoidCommand TVoidCommand; public: vtkTypeMacro( MPRObjects, vtkObject ); @@ -33,11 +36,6 @@ namespace cpExtensions // Creation static MPRObjects* New( ); - void AddCursorCommand( TCursorCommand command, void* data ) - { - this->m_MPRActors->AddCursorCommand( command, data ); - } - void SetRenderWindows( vtkRenderWindow* wx, vtkRenderWindow* wy, vtkRenderWindow* wz, vtkRenderWindow* w3D @@ -58,17 +56,11 @@ namespace cpExtensions const vtkRenderer* GetZRenderer( ) const; const vtkRenderer* Get3DRenderer( ) const; - TMPRActors* GetMPRActors( ); - const TMPRActors* GetMPRActors( ) const; + MPRActors* GetMPRActors( ); + const MPRActors* GetMPRActors( ) const; - double GetWindow( ) const - { - return( this->m_MPRActors->GetWindow( ) ); - } - double GetLevel( ) const - { - return( this->m_MPRActors->GetLevel( ) ); - } + double GetWindow( ) const; + double GetLevel( ) const; protected: MPRObjects( ); @@ -84,15 +76,8 @@ namespace cpExtensions vtkSmartPointer< vtkRenderWindow > m_Windows[ 4 ]; // Internal pipelines - vtkSmartPointer< TMPRActors > m_MPRActors; + vtkSmartPointer< MPRActors > m_MPRActors; vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; - - std::vector< TCursorCommand > CursorCommands; - std::vector< TMouseCommand > MouseCommands; - std::vector< TMouseCommand > MouseClickCommands; - std::vector< TMouseCommand > MouseDoubleClickCommands; - std::vector< TMouseWheelCommand > MouseWheelCommands; - std::vector< TKeyCommand > KeyCommands; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.h b/lib/cpPlugins/Interface/BaseMPRWindow.h index 9507d6f..6799abe 100644 --- a/lib/cpPlugins/Interface/BaseMPRWindow.h +++ b/lib/cpPlugins/Interface/BaseMPRWindow.h @@ -42,10 +42,15 @@ namespace cpPlugins typedef cpPlugins::Interface::Mesh TMesh; typedef cpExtensions::Visualization::MPRObjects TMPRObjects; - typedef TMPRObjects::TCursorCommand TCursorCommand; - typedef TMPRObjects::TMouseCommand TMouseCommand; - typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand; - typedef TMPRObjects::TKeyCommand TKeyCommand; + + typedef TMPRObjects::TBaseStyle TBaseStyle; + typedef TMPRObjects::TStyle TStyle; + typedef TMPRObjects::TSlicesCommand TSlicesCommand; + typedef TMPRObjects::TWindowLevelCommand TWindowLevelCommand; + typedef TMPRObjects::TMouseCommand TMouseCommand; + typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand; + typedef TMPRObjects::TKeyCommand TKeyCommand; + typedef TMPRObjects::TVoidCommand TVoidCommand; typedef std::map< std::string, TImage::Pointer > TImages; typedef std::map< std::string, TMesh::Pointer > TMeshes; @@ -56,11 +61,6 @@ namespace cpPlugins explicit BaseMPRWindow( QWidget* parent = 0 ); virtual ~BaseMPRWindow( ); - void AddCursorCommand( TCursorCommand command, void* data ) - { - this->m_MPRObjects->AddCursorCommand( command, data ); - } - void DialogLoadPlugins( ); void AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot