From: Leonardo Florez-Valencia Date: Wed, 20 Apr 2016 23:58:52 +0000 (-0500) Subject: MPR objects updated X-Git-Tag: v0.1~182 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e6bef8234ffd9030c68a6786466a08cf144b7871;p=cpPlugins.git MPR objects updated --- diff --git a/appli/PipelineEditor/PipelineEditor.cxx b/appli/PipelineEditor/PipelineEditor.cxx index eeaee07..7c06aac 100644 --- a/appli/PipelineEditor/PipelineEditor.cxx +++ b/appli/PipelineEditor/PipelineEditor.cxx @@ -2,7 +2,9 @@ #include "ui_PipelineEditor.h" #include +#include #include +#include // ------------------------------------------------------------------------- PipelineEditor:: @@ -47,6 +49,18 @@ PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent ) this, SLOT( _ShowFilterOutput( const std::string&, const std::string& ) ) ); + this->connect( + this->m_UI->Canvas->editor( ), + SIGNAL( hideFilterOutput( const std::string&, const std::string& ) ), + this, + SLOT( _HideFilterOutput( const std::string&, const std::string& ) ) + ); + this->connect( + this->m_UI->Canvas->editor( ), + SIGNAL( visualPropertiesFilterOutput( const std::string&, const std::string& ) ), + this, + SLOT( _PropertiesFilterOutput( const std::string&, const std::string& ) ) + ); } // ------------------------------------------------------------------------- @@ -114,4 +128,57 @@ _ShowFilterOutput( } // fi } +// ------------------------------------------------------------------------- +void PipelineEditor:: +_HideFilterOutput( + const std::string& filter_name, const std::string& output_name + ) +{ + // Get output + auto filter = this->m_Workspace.GetFilter( filter_name ); + if( filter != NULL ) + { + auto output = filter->GetOutputData( output_name ); + if( output != NULL ) + { + std::string data_name = output_name + "@" + filter_name; + this->m_UI->Viewer->HideData( data_name ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void PipelineEditor:: +_PropertiesFilterOutput( + const std::string& filter_name, const std::string& output_name + ) +{ + // Get output + auto filter = this->m_Workspace.GetFilter( filter_name ); + if( filter != NULL ) + { + auto output = filter->GetOutputData( output_name ); + if( output != NULL ) + { + std::string data_name = output_name + "@" + filter_name; + auto prop = this->m_UI->Viewer->GetProp( data_name ); + + cpExtensions::QT::PropertyWidget* wdg = + new cpExtensions::QT::PropertyWidget( NULL ); + wdg->SetProp( prop ); + wdg->SetRenderWindow( this->m_UI->Viewer->GetInteractor( 3 )->GetRenderWindow( ) ); + wdg->show( ); + } + else + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing data" ), + QMessageBox::tr( "No known VTK conversion!" ) + ); + + } // fi +} + // eof - $RCSfile$ diff --git a/appli/PipelineEditor/PipelineEditor.h b/appli/PipelineEditor/PipelineEditor.h index 3a753d1..123f5e1 100644 --- a/appli/PipelineEditor/PipelineEditor.h +++ b/appli/PipelineEditor/PipelineEditor.h @@ -32,6 +32,12 @@ protected slots: void _ShowFilterOutput( const std::string& filter_name, const std::string& output_name ); + void _HideFilterOutput( + const std::string& filter_name, const std::string& output_name + ); + void _PropertiesFilterOutput( + const std::string& filter_name, const std::string& output_name + ); private: Ui::PipelineEditor* m_UI; diff --git a/appli/examples/extensions/CMakeLists.txt b/appli/examples/extensions/CMakeLists.txt index 2815120..b39f42c 100644 --- a/appli/examples/extensions/CMakeLists.txt +++ b/appli/examples/extensions/CMakeLists.txt @@ -1,6 +1,7 @@ SET( examples_SOURCES example_KalmanVelocity + example_ImageSlice ) FOREACH(example ${examples_SOURCES}) diff --git a/appli/examples/extensions/example_ImageSlice.cxx b/appli/examples/extensions/example_ImageSlice.cxx new file mode 100644 index 0000000..86dc891 --- /dev/null +++ b/appli/examples/extensions/example_ImageSlice.cxx @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +#include + +int main( int argc, char* argv[] ) +{ + if( argc < 2 ) + { + std::cerr << "Usage: " << argv[ 0 ] << " input_image.png" << std::endl; + return( 1 ); + + } // fi + + // Read a test image + vtkSmartPointer< vtkPNGReader > reader = + vtkSmartPointer< vtkPNGReader >::New( ); + reader->SetFileName( argv[ 1 ] ); + reader->Update( ); + + // Prepate slice objects + vtkSmartPointer< cpExtensions::Visualization::ImageSliceActors > actors = + vtkSmartPointer< cpExtensions::Visualization::ImageSliceActors >::New( ); + actors->SetInputConnection( reader->GetOutputPort( ) ); + + // Prepare scene + vtkSmartPointer< vtkRenderer > ren = + vtkSmartPointer< vtkRenderer >::New( ); + ren->SetBackground( 0, 0, 0 ); + actors->PushInto( ren ); + + vtkSmartPointer< vtkRenderWindow > win = + vtkSmartPointer< vtkRenderWindow >::New( ); + win->AddRenderer( ren ); + win->SetSize( 300, 300 ); + + vtkSmartPointer< vtkRenderWindowInteractor > iren = + vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + iren->SetRenderWindow( win ); + iren->SetInteractorStyle( actors->GetStyle( ) ); + + iren->Initialize( ); + ren->ResetCamera( ); + iren->Start( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/CMakeLists.txt b/appli/examples/plugins/CMakeLists.txt index fa578a8..0408f3c 100644 --- a/appli/examples/plugins/CMakeLists.txt +++ b/appli/examples/plugins/CMakeLists.txt @@ -5,11 +5,18 @@ SET( example_LoadPluginsDirectory example_ReadWriteImage example_ReadWriteImageWithWorkspace + example_ShowImage ) FOREACH(example ${examples_SOURCES}) ADD_EXECUTABLE(${example} ${example}.cxx) - TARGET_LINK_LIBRARIES(${example} cpPlugins) + TARGET_LINK_LIBRARIES(${example} cpExtensions cpPlugins) ENDFOREACH(example) +IF(USE_QT4) + SUBDIRS( + QT + ) +ENDIF(USE_QT4) + ## eof - $RCSfile$ diff --git a/appli/examples/plugins/QT/CMakeLists.txt b/appli/examples/plugins/QT/CMakeLists.txt new file mode 100644 index 0000000..b87ebe8 --- /dev/null +++ b/appli/examples/plugins/QT/CMakeLists.txt @@ -0,0 +1,4 @@ +SUBDIRS( + example_MPRViewer + ) +## eof - $RCSfile$ diff --git a/appli/examples/plugins/QT/example_MPRViewer/CMakeLists.txt b/appli/examples/plugins/QT/example_MPRViewer/CMakeLists.txt new file mode 100644 index 0000000..fb7f22e --- /dev/null +++ b/appli/examples/plugins/QT/example_MPRViewer/CMakeLists.txt @@ -0,0 +1,57 @@ +SET(app_NAME "example_MPRViewer") + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ) + +## ==================================================== +## = Source code, user interafaces and resources here = +## ==================================================== + +SET( + app_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/example_MPRViewer.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/main.cxx + ) + +SET( + app_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/example_MPRViewer.h + ) + +SET( + app_UI + ${CMAKE_CURRENT_SOURCE_DIR}/example_MPRViewer.ui + ) + +## ===================== +## = Compilation rules = +## ===================== + +QT4_WRAP_UI(app_UI_HEADERS ${app_UI}) +QT4_WRAP_CPP(app_MOC_SOURCES ${app_HEADERS}) + +SET(GUI_TYPE "") +IF(WIN32) + SET(GUI_TYPE WIN32) +ENDIF(WIN32) +IF(APPLE) + SET(GUI_TYPE MACOSX_BUNDLE) +ENDIF(APPLE) + +ADD_EXECUTABLE( + ${app_NAME} + ${GUI_TYPE} + ${app_HEADERS} + ${app_UI_HEADERS} + ${app_SOURCES} + ${app_MOC_SOURCES} + ) +TARGET_LINK_LIBRARIES( + ${app_NAME} + cpExtensions + cpPlugins + ) + +## eof - $RCSfile$ diff --git a/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx new file mode 100644 index 0000000..698b082 --- /dev/null +++ b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx @@ -0,0 +1,79 @@ +#include "example_MPRViewer.h" +#include "ui_example_MPRViewer.h" + +#include +#include + +// ------------------------------------------------------------------------- +example_MPRViewer:: +example_MPRViewer( int argc, char* argv[], QWidget* parent ) + : Superclass( parent ), + m_UI( new Ui::example_MPRViewer ) +{ + this->m_UI->setupUi( this ); + + if( argc < 2 ) + { + QMessageBox::critical( + this, + QMessageBox::tr( "Error" ), + QMessageBox::tr( "Give some input image(s)." ) + ); + std::exit( 1 ); + + } // fi + + // Create reader + this->m_Interface.GuessAccesiblePlugins( ); + try + { + this->m_Reader = this->m_Interface.Create( "IO", "ImageReader" ); + if( this->m_Reader.IsNull( ) ) + { + QMessageBox::critical( + this, + QMessageBox::tr( "Error" ), + QMessageBox::tr( "\"IO::ImageReader\" creation failed." ) + ); + std::exit( 1 ); + + } // fi + + // Configure filters + auto reader_params = this->m_Reader->GetParameters( ); + for( int i = 1; i < argc; ++i ) + reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] ); + this->m_Reader->Update( ); + } + catch( itk::ExceptionObject& err1 ) + { + QMessageBox::critical( + this, + QMessageBox::tr( "Error" ), + QMessageBox::tr( err1.GetDescription( ) ) + ); + std::exit( 1 ); + } + catch( std::exception& err2 ) + { + QMessageBox::critical( + this, + QMessageBox::tr( "Error" ), + QMessageBox::tr( err2.what( ) ) + ); + std::exit( 1 ); + + } // yrt + + this->m_UI->Viewer->SetMainImage( + this->m_Reader->GetOutputData( "Output" )->GetVTK< vtkImageData >( ) + ); +} + +// ------------------------------------------------------------------------- +example_MPRViewer:: +~example_MPRViewer( ) +{ +} + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.h b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.h new file mode 100644 index 0000000..dc26a5e --- /dev/null +++ b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.h @@ -0,0 +1,40 @@ +#ifndef __EXAMPLE_MPRVIEWER__H__ +#define __EXAMPLE_MPRVIEWER__H__ + +#include +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class example_MPRViewer; +} + +// ------------------------------------------------------------------------- +/** + */ +class example_MPRViewer + : public QMainWindow +{ + Q_OBJECT; + +public: + typedef example_MPRViewer Self; + typedef QMainWindow Superclass; + +public: + explicit example_MPRViewer( + int argc, char* argv[], + QWidget* parent = NULL + ); + virtual ~example_MPRViewer( ); + +private: + Ui::example_MPRViewer* m_UI; + cpPlugins::Interface m_Interface; + cpPlugins::ProcessObject::Pointer m_Reader; +}; + +#endif // __CPEXAMPLE_MPRVIEWER__H__ + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.ui b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.ui new file mode 100644 index 0000000..7f4ef2f --- /dev/null +++ b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.ui @@ -0,0 +1,47 @@ + + + example_MPRViewer + + + + 0 + 0 + 800 + 600 + + + + + 800 + 600 + + + + MainWindow + + + + + + + + 0 + 200 + + + + + + + + + + cpExtensions::QT::SimpleMPRWidget + QWidget +
cpExtensions/QT/SimpleMPRWidget.h
+ 1 +
+
+ + +
diff --git a/appli/examples/plugins/QT/example_MPRViewer/main.cxx b/appli/examples/plugins/QT/example_MPRViewer/main.cxx new file mode 100644 index 0000000..90e64c2 --- /dev/null +++ b/appli/examples/plugins/QT/example_MPRViewer/main.cxx @@ -0,0 +1,80 @@ +#include "example_MPRViewer.h" +#include +#include + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + QApplication a( argc, argv ); + example_MPRViewer w( argc, argv ); + w.show( ); + return( a.exec( ) ); +} + +// ------------------------------------------------------------------------- +#ifdef _WIN32 + +#include +#include +#include +#include + +/** + */ +class Win32CommandLineConverter +{ +private: + std::unique_ptr< char*[ ] > argv_; + std::vector< std::unique_ptr< char[ ] > > storage_; + +public: + Win32CommandLineConverter( ) + { + LPWSTR cmd_line = GetCommandLineW( ); + int argc; + LPWSTR* w_argv = CommandLineToArgvW( cmd_line, &argc ); + argv_ = std::unique_ptr< char*[ ] >( new char*[ argc ] ); + storage_.reserve( argc ); + for( int i = 0; i < argc; ++i ) + { + storage_.push_back( ConvertWArg( w_argv[ i ] ) ); + argv_[ i ] = storage_.back( ).get( ); + + } // rof + LocalFree( w_argv ); + } + int argc( ) const + { + return( static_cast< int >(storage_.size( ) ) ); + } + char** argv( ) const + { + return( argv_.get( ) ); + } + static std::unique_ptr< char[ ] > ConvertWArg( LPWSTR w_arg ) + { + int size = WideCharToMultiByte( + CP_UTF8, 0, w_arg, -1, nullptr, 0, nullptr, nullptr + ); + std::unique_ptr< char[ ] > ret( new char[ size ] ); + WideCharToMultiByte( + CP_UTF8, 0, w_arg, -1, ret.get( ), size, nullptr, nullptr + ); + return( ret ); + } +}; + +int CALLBACK WinMain( + HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow + ) +{ + Win32CommandLineConverter cmd_line; + return( main( cmd_line.argc( ), cmd_line.argv( ) ) ); +} + +#endif + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/example_ShowImage.cxx b/appli/examples/plugins/example_ShowImage.cxx new file mode 100644 index 0000000..d08cc14 --- /dev/null +++ b/appli/examples/plugins/example_ShowImage.cxx @@ -0,0 +1,91 @@ +#include + +#include +#include + +#include +#include +#include +#include +#include + +int main( int argc, char* argv[] ) +{ + if( argc < 2 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image(s)" << std::endl; + return( 1 ); + + } // fi + + // Load interface + cpPlugins::Interface interface; + interface.GuessAccesiblePlugins( ); + + // Create filters + cpPlugins::ProcessObject::Pointer reader; + try + { + reader = interface.Create( "IO", "ImageReader" ); + if( reader.IsNull( ) ) + { + std::cerr + << "\"IO::ImageReader\" creation failed." + << std::endl; + return( 1 ); + + } // fi + + // Configure filters + auto reader_params = reader->GetParameters( ); + for( int i = 1; i < argc; ++i ) + reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] ); + reader->Update( ); + } + catch( itk::ExceptionObject& err1 ) + { + std::cerr << "Error: " << err1.GetDescription( ) << std::endl; + return( 1 ); + } + catch( std::exception& err2 ) + { + std::cerr << "Error: " << err2.what( ) << std::endl; + return( 1 ); + + } // yrt + + // Prepate slice objects + vtkSmartPointer< cpExtensions::Visualization::ImageSliceActors > actors = + vtkSmartPointer< cpExtensions::Visualization::ImageSliceActors >::New( ); + actors->SetInputData( + reader->GetOutputData( "Output" )->GetVTK< vtkImageData >( ), 1 + ); + + // Prepare scene + vtkSmartPointer< vtkRenderer > ren = + vtkSmartPointer< vtkRenderer >::New( ); + ren->SetBackground( 0, 0, 0 ); + actors->PushInto( ren ); + + vtkSmartPointer< vtkRenderWindow > win = + vtkSmartPointer< vtkRenderWindow >::New( ); + win->AddRenderer( ren ); + win->SetSize( 500, 500 ); + + vtkSmartPointer< vtkRenderWindowInteractor > iren = + vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + iren->SetRenderWindow( win ); + iren->SetInteractorStyle( actors->GetStyle( ) ); + + iren->Initialize( ); + ren->Render( ); + ren->ResetCamera( ); + iren->Start( ); + + // Ok finish + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/CMakeLists.txt b/lib/cpExtensions/CMakeLists.txt index c2abf2c..6e3c940 100644 --- a/lib/cpExtensions/CMakeLists.txt +++ b/lib/cpExtensions/CMakeLists.txt @@ -83,7 +83,6 @@ IF(USE_QT4) ) ENDIF(USE_QT4) - ## ===================== ## = Compilation rules = ## ===================== diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx index c037193..f2781dc 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx @@ -1,41 +1,47 @@ #include +#include #include #include +#include +#include #include #include #include +#include // ------------------------------------------------------------------------- -cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: -TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) -{ - this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); - this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( ); - this->Widget = vtkSmartPointer< SeedWidget >::New( ); - - this->Placer->SetImageActor( actor ); - this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); - this->Handle->SetPointPlacer( this->Placer ); - this->Representation->SetHandleRepresentation( this->Handle ); - this->Widget->SetRepresentation( this->Representation ); - this->Widget->SetInteractor( interactor ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: -On( ) -{ - this->Widget->On( ); -} +/* TODO + cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: + TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) + { + this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); + this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( ); + this->Widget = vtkSmartPointer< SeedWidget >::New( ); -// ------------------------------------------------------------------------- -void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: -Off( ) -{ - this->Widget->Off( ); -} + this->Placer->SetImageActor( actor ); + this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); + this->Handle->SetPointPlacer( this->Placer ); + this->Representation->SetHandleRepresentation( this->Handle ); + this->Widget->SetRepresentation( this->Representation ); + this->Widget->SetInteractor( interactor ); + } + + // ------------------------------------------------------------------------- + void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: + On( ) + { + this->Widget->On( ); + } + + // ------------------------------------------------------------------------- + void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: + Off( ) + { + this->Widget->Off( ); + } +*/ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: @@ -45,19 +51,52 @@ New( ) return( new Self ); } +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +SetCurrentRenderer( vtkRenderer* r ) +{ + this->Superclass::SetCurrentRenderer( r ); + + if( !( this->m_Configured ) ) + { + auto lst = this->m_PropPicker->GetPickList( ); + if( lst == NULL ) + return; + if( lst->GetNumberOfItems( ) == 1 ) + { + auto actor = dynamic_cast< vtkImageActor* >( lst->GetItemAsObject( 0 ) ); + if( actor != NULL ) + { + this->_ConfigureCamera( actor ); + this->Modified( ); + + } // fi + + } // fi + + } // fi +} + // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: AssociateImageActor( vtkImageActor* actor ) { if( actor != NULL ) { + // Update picker + this->m_PropPicker->GetPickList( )->RemoveAllItems( ); this->m_PropPicker->AddPickList( actor ); + this->m_Configured = false; + this->_ConfigureCamera( actor ); + + // Ok, done this->Modified( ); } // fi } // ------------------------------------------------------------------------- +/* void cpExtensions::Interaction::ImageInteractorStyle:: SeedWidgetOn( ) { @@ -85,8 +124,10 @@ SeedWidgetOff( ) } // fi } +*/ // ------------------------------------------------------------------------- +/* void cpExtensions::Interaction::ImageInteractorStyle:: SetSeedWidgetCommand( vtkCommand* cmd ) { @@ -118,17 +159,20 @@ GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const void cpExtensions::Interaction::ImageInteractorStyle:: GetSeedAsIndex( unsigned int id, int idx[ 3 ] ) const { - /* TODO if( this->m_SeedWidget != NULL ) this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos ); - */ } +*/ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) : Superclass( ), - m_SeedWidget( NULL ) + m_Configured( false ) + /* + , + m_SeedWidget( NULL ) + */ { this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); @@ -138,7 +182,54 @@ ImageInteractorStyle( ) cpExtensions::Interaction::ImageInteractorStyle:: ~ImageInteractorStyle( ) { - if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; + // if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +_ConfigureCamera( vtkImageActor* actor ) +{ + if( this->CurrentRenderer != NULL ) + { + // Update camera + auto camera = this->CurrentRenderer->GetActiveCamera( ); + auto mapper = dynamic_cast< vtkImageSliceMapper* >( actor->GetMapper( ) ); + if( mapper != NULL && camera != NULL ) + { + double bounds[ 6 ]; + actor->GetBounds( bounds ); + camera->ParallelProjectionOn( ); + camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); + int orientation = mapper->GetOrientation( ); + switch( orientation ) + { + case 0: + { + camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); + camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); + } + break; + case 1: + { + camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) ); + camera->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) ); + } + break; + case 2: + { + camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) ); + camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); + } + break; + default: + break; + } // hctiws + this->CurrentRenderer->ResetCamera( ); + this->m_Configured = true; + + } // fi + + } // fi } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.h b/lib/cpExtensions/Interaction/ImageInteractorStyle.h index ec54f5e..c02f65d 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.h +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.h @@ -5,12 +5,14 @@ #include -#include -#include #include -#include -#include -#include +#include +/* TODO + #include + #include + #include + #include +*/ // Forward definitions class vtkCommand; @@ -43,38 +45,45 @@ namespace cpExtensions typedef Superclass::TLeaveCommand TLeaveCommand; // Widgets - struct TSeedWidget - { - vtkSmartPointer< vtkImageActorPointPlacer > Placer; - vtkSmartPointer< vtkPointHandleRepresentation3D > Handle; - vtkSmartPointer< vtkSeedRepresentation > Representation; - vtkSmartPointer< SeedWidget > Widget; - - TSeedWidget( - vtkRenderWindowInteractor* interactor, vtkImageActor* actor - ); - void On( ); - void Off( ); - }; + /* TODO + struct TSeedWidget + { + vtkSmartPointer< vtkImageActorPointPlacer > Placer; + vtkSmartPointer< vtkPointHandleRepresentation3D > Handle; + vtkSmartPointer< vtkSeedRepresentation > Representation; + vtkSmartPointer< SeedWidget > Widget; + + TSeedWidget( + vtkRenderWindowInteractor* interactor, vtkImageActor* actor + ); + void On( ); + void Off( ); + }; + */ public: static Self* New( ); + virtual void SetCurrentRenderer( vtkRenderer* r ) VTK_OVERRIDE; + // Data for local picker virtual void AssociateImageActor( vtkImageActor* actor ); // Widgets - void SeedWidgetOn( ); - void SeedWidgetOff( ); - void SetSeedWidgetCommand( vtkCommand* cmd ); - unsigned int GetNumberOfSeeds( ) const; - void GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const; - void GetSeedAsIndex( unsigned int id, int pos[ 3 ] ) const; + /* TODO + void SeedWidgetOn( ); + void SeedWidgetOff( ); + void SetSeedWidgetCommand( vtkCommand* cmd ); + unsigned int GetNumberOfSeeds( ) const; + void GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const; + void GetSeedAsIndex( unsigned int id, int pos[ 3 ] ) const; + */ protected: ImageInteractorStyle( ); virtual ~ImageInteractorStyle( ); + void _ConfigureCamera( vtkImageActor* actor ); virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ); private: @@ -83,9 +92,11 @@ namespace cpExtensions Self& operator=( const Self& ); protected: + bool m_Configured; vtkSmartPointer< vtkPropPicker > m_PropPicker; - - TSeedWidget* m_SeedWidget; + /* TODO + TSeedWidget* m_SeedWidget; + */ }; } // ecapseman diff --git a/lib/cpExtensions/QT/PropertyWidget.cxx b/lib/cpExtensions/QT/PropertyWidget.cxx new file mode 100644 index 0000000..3b719ff --- /dev/null +++ b/lib/cpExtensions/QT/PropertyWidget.cxx @@ -0,0 +1,176 @@ +#include + +#ifdef cpExtensions_QT4 + +#include +#include +#include +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpExtensions::QT::PropertyWidget:: +PropertyWidget( QWidget* parent ) + : QWidget( parent ), + m_UI( new Ui::PropertyWidget ), + m_Prop( NULL ), + m_Window( NULL ) +{ + this->m_UI->setupUi( this ); + this->connect( + this->m_UI->m_Color, SIGNAL( clicked( ) ), + this, SLOT( _Color( ) ) + ); + this->connect( + this->m_UI->m_Opacity, SIGNAL( valueChanged( int ) ), + this, SLOT( _Opacity( int ) ) + ); + this->connect( + this->m_UI->m_LineWidth, SIGNAL( valueChanged( double ) ), + this, SLOT( _LineWidth( double ) ) + ); + this->connect( + this->m_UI->m_PointSize, SIGNAL( valueChanged( double ) ), + this, SLOT( _PointSize( double ) ) + ); +} + +// ------------------------------------------------------------------------- +cpExtensions::QT::PropertyWidget:: +~PropertyWidget( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +vtkProp* cpExtensions::QT::PropertyWidget:: +GetProp( ) +{ + return( this->m_Prop ); +} + +// ------------------------------------------------------------------------- +vtkRenderWindow* cpExtensions::QT::PropertyWidget:: +GetRenderWindow( ) +{ + return( this->m_Window ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +SetProp( vtkProp* p ) +{ + this->m_Prop = p; + if( this->m_Prop == NULL ) + return; + + auto actor = dynamic_cast< vtkActor* >( this->m_Prop ); + if( actor == NULL ) + return; + + double opacity = actor->GetProperty( )->GetOpacity( ); + double lw = actor->GetProperty( )->GetLineWidth( ); + double ps = actor->GetProperty( )->GetPointSize( ); + opacity *= this->m_UI->m_Opacity->maximum( ); + + this->m_UI->m_Opacity->setValue( opacity ); + this->m_UI->m_LineWidth->setValue( lw ); + this->m_UI->m_PointSize->setValue( ps ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +SetRenderWindow( vtkRenderWindow* w ) +{ + this->m_Window = w; +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +_Color( ) +{ + if( this->m_Prop == NULL ) + return; + + auto actor = dynamic_cast< vtkActor* >( this->m_Prop ); + if( actor == NULL ) + return; + + double rgb[ 3 ]; + actor->GetProperty( )->GetColor( rgb ); + QColor color = + QColorDialog::getColor( + QColor( rgb[ 0 ] * 255, rgb[ 1 ] * 255, rgb[ 2 ] * 255 ), + this, + "Select Color", + QColorDialog::DontUseNativeDialog + ); + if( color.isValid( ) ) + { + rgb[ 0 ] = double( color.red( ) ) / double( 255 ); + rgb[ 1 ] = double( color.green( ) ) / double( 255 ); + rgb[ 2 ] = double( color.blue( ) ) / double( 255 ); + actor->GetMapper( )->ScalarVisibilityOff( ); + actor->GetProperty( )->SetColor( rgb ); + actor->Modified( ); + if( this->m_Window != NULL ) + this->m_Window->Render( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +_Opacity( int o ) +{ + if( this->m_Prop == NULL ) + return; + + auto actor = dynamic_cast< vtkActor* >( this->m_Prop ); + if( actor == NULL ) + return; + double v = double( o ) / double( this->m_UI->m_Opacity->maximum( ) ); + actor->GetProperty( )->SetOpacity( v ); + actor->Modified( ); + if( this->m_Window != NULL ) + this->m_Window->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +_LineWidth( double lw ) +{ + if( this->m_Prop == NULL ) + return; + + auto actor = dynamic_cast< vtkActor* >( this->m_Prop ); + if( actor == NULL ) + return; + actor->GetProperty( )->SetLineWidth( lw ); + actor->Modified( ); + if( this->m_Window != NULL ) + this->m_Window->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::PropertyWidget:: +_PointSize( double ps ) +{ + if( this->m_Prop == NULL ) + return; + + auto actor = dynamic_cast< vtkActor* >( this->m_Prop ); + if( actor == NULL ) + return; + actor->GetProperty( )->SetPointSize( ps ); + actor->Modified( ); + if( this->m_Window != NULL ) + this->m_Window->Render( ); +} + +#endif // cpExtensions_QT4 + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/QT/PropertyWidget.h b/lib/cpExtensions/QT/PropertyWidget.h new file mode 100644 index 0000000..598ad08 --- /dev/null +++ b/lib/cpExtensions/QT/PropertyWidget.h @@ -0,0 +1,63 @@ +#ifndef __CPEXTENSIONS__QT__PROPERTYWIDGET__H__ +#define __CPEXTENSIONS__QT__PROPERTYWIDGET__H__ + +#include + +#ifdef cpExtensions_QT4 + +#include + +// ------------------------------------------------------------------------- +class vtkProp; +class vtkRenderWindow; + +namespace Ui +{ + class PropertyWidget; +} + +// ------------------------------------------------------------------------- +namespace cpExtensions +{ + namespace QT + { + /** + */ + class cpExtensions_EXPORT PropertyWidget + : public QWidget + { + Q_OBJECT; + + public: + typedef PropertyWidget Self; + + public: + explicit PropertyWidget( QWidget* parent = 0 ); + virtual ~PropertyWidget( ); + + vtkProp* GetProp( ); + vtkRenderWindow* GetRenderWindow( ); + void SetProp( vtkProp* p ); + void SetRenderWindow( vtkRenderWindow* w ); + + protected slots: + void _Color( ); + void _Opacity( int o ); + void _LineWidth( double lw ); + void _PointSize( double ps ); + + protected: + Ui::PropertyWidget* m_UI; + vtkProp* m_Prop; + vtkRenderWindow* m_Window; + }; + + } // ecapseman + +} // ecapseman + +#endif // cpExtensions_QT4 + +#endif // __CPEXTENSIONS__QT__PROPERTYWIDGET__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/QT/PropertyWidget.ui b/lib/cpExtensions/QT/PropertyWidget.ui new file mode 100644 index 0000000..3784ecd --- /dev/null +++ b/lib/cpExtensions/QT/PropertyWidget.ui @@ -0,0 +1,160 @@ + + + PropertyWidget + + + + 0 + 0 + 595 + 125 + + + + + 595 + 125 + + + + + 595 + 125 + + + + Form + + + + + + + + Color + + + + + + + + + + + + 54 + 21 + + + + + 54 + 21 + + + + Opacity: + + + + + + + 100 + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + + 71 + 21 + + + + + 71 + 21 + + + + Line width: + + + + + + + 100.000000000000000 + + + 1.000000000000000 + + + 1.000000000000000 + + + + + + + + + + + + 67 + 21 + + + + + 67 + 21 + + + + Point size: + + + + + + + 100.000000000000000 + + + 1.000000000000000 + + + 1.000000000000000 + + + + + + + + + + + + + + + + diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index ee2196e..f3f1eb3 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,29 +3,34 @@ #ifdef cpExtensions_QT4 #include +#include -#include -#include - -double cpExtensions::QT::SimpleMPRWidget:: -cm_Colors[ 8 ][ 3 ] = -{ - { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, - { 0.0, 1.0, 1.0 }, - { 1.0, 0.0, 1.0 }, - { 1.0, 1.0, 0.0 }, - { 1.0, 0.5, 0.0 }, - { 1.0, 0.0, 0.5 } -}; +/* TODO + #include + #include + double cpExtensions::QT::SimpleMPRWidget:: + cm_Colors[ 8 ][ 3 ] = + { + { 1.0, 0.0, 0.0 }, + { 0.0, 1.0, 0.0 }, + { 0.0, 0.0, 1.0 }, + { 0.0, 1.0, 1.0 }, + { 1.0, 0.0, 1.0 }, + { 1.0, 1.0, 0.0 }, + { 1.0, 0.5, 0.0 }, + { 1.0, 0.0, 0.5 } + }; +*/ // ------------------------------------------------------------------------- cpExtensions::QT::SimpleMPRWidget:: SimpleMPRWidget( QWidget* parent ) : QWidget( parent ), - m_UI( new Ui::SimpleMPRWidget ), - m_MainImage( "" ) + m_UI( new Ui::SimpleMPRWidget ) + /* + , + m_MainImage( "" ) + */ { this->m_UI->setupUi( this ); @@ -35,13 +40,22 @@ SimpleMPRWidget( QWidget* parent ) this->m_VTK[ 2 ] = this->m_UI->VTK10; this->m_VTK[ 3 ] = this->m_UI->VTK11; - this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); - this->m_MPRObjects->SetRenderWindows( + for( unsigned int i = 0; i < 4; ++i ) + { + this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); + this->m_VTK[ i ]->GetRenderWindow( )->AddRenderer( this->m_Renderers[ i ] ); + + } // rof + + /* + this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); + this->m_MPRObjects->SetRenderWindows( this->m_VTK[ 0 ]->GetRenderWindow( ), this->m_VTK[ 1 ]->GetRenderWindow( ), this->m_VTK[ 2 ]->GetRenderWindow( ), this->m_VTK[ 3 ]->GetRenderWindow( ) ); + */ // Connect slots QObject::connect( @@ -61,446 +75,52 @@ cpExtensions::QT::SimpleMPRWidget:: delete this->m_UI; } -// ------------------------------------------------------------------------- -unsigned int cpExtensions::QT::SimpleMPRWidget:: -GetNumberOfData( ) const -{ - return( this->m_Data.size( ) ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -AddData( - vtkImageData* data, const std::string& name, - const std::string& parent - ) -{ - if( name == "" ) - return( false ); - - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - { - if( parent != "" ) - { - auto pIt = this->m_Data.find( parent ); - if( pIt == this->m_Data.end( ) ) - return( false ); - - } // fi - - // Add new data - this->m_Data[ name ].SetImageData( data ); - - // Set color - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - vtkActor* actor = - dynamic_cast< vtkActor* >( iIt->second.GetMeshActor( ) ); - if( actor != NULL ) - { - unsigned int idx = this->m_Data.size( ) % 8; - actor->GetProperty( )->SetColor( - Self::cm_Colors[ idx ][ 0 ], - Self::cm_Colors[ idx ][ 1 ], - Self::cm_Colors[ idx ][ 2 ] - ); - - } // fi - - } // fi - - // Add to tree view - // TODO: this->_UpdateTreeItem( name, parent ); - return( true ); - } - else - return( false ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -AddData( vtkPolyData* data, const std::string& name ) -{ - if( name == "" ) - return( false ); - - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - { - // Add new data - this->m_Data[ name ].SetPolyData( data ); - - // Set color - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - vtkActor* actor = - dynamic_cast< vtkActor* >( iIt->second.GetMeshActor( ) ); - if( actor != NULL ) - { - unsigned int idx = this->m_Data.size( ) % 8; - actor->GetProperty( )->SetColor( - Self::cm_Colors[ idx ][ 0 ], - Self::cm_Colors[ idx ][ 1 ], - Self::cm_Colors[ idx ][ 2 ] - ); - - } // fi - - } // fi - - // Add to tree view - // TODO: this->_UpdateTreeItem( name, parent ); - return( true ); - } - else - return( false ); -} - -// ------------------------------------------------------------------------- -const std::string& cpExtensions::QT::SimpleMPRWidget:: -GetMainImage( ) const -{ - return( this->m_MainImage ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -SetMainImage( const std::string& name ) -{ - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - if( iIt->second.Tag == Data::IMAGE ) - { - this->m_MainImage = name; - return( true ); - } - else - return( false ); - } - else - return( false ); -} - // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -DeleteData( const std::string& name ) +SetMainImage( vtkImageData* image ) { - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) + for( unsigned int i = 0; i < 3; ++i ) { - this->m_Data.erase( iIt ); - - // Get children - std::vector< std::string > to_erase; - auto tIt = this->m_Tree.begin( ); - for( ; tIt != this->m_Tree.end( ); ++tIt ) - if( tIt->second == name ) - to_erase.push_back( tIt->first ); - - // Delete from tree - tIt = this->m_Tree.find( name ); - if( tIt != this->m_Tree.end( ) ) - this->m_Tree.erase( tIt ); - - // Recursive erase - auto dIt = to_erase.begin( ); - for( ; dIt != to_erase.end( ); ++dIt ) - this->DeleteData( *dIt ); - - // Delete from tree widget - /* TODO - QTreeWidgetItem* item = this->_FindItemInTree( name ); - if( item != NULL ) - this->m_UI->LoadedData->removeItemWidget( item, 0 ); - */ - - // Reset main image, just in case - if( this->m_Data.size( ) == 0 ) - this->m_MainImage = ""; - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -DeleteAllData( ) -{ - this->m_MPRObjects->Clear( ); - this->m_Data.clear( ); - this->m_Tree.clear( ); - // TODO: this->m_UI->LoadedData->clear( ); - this->m_MainImage = ""; -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -SetDataColor( - const std::string& name, const double& r, const double& g, const double& b - ) -{ - /* - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - return; - - if( iIt->second.Tag == Data::IMAGE ) - { - } - else if( iIt->second.Tag == Data::MESH ) - { - } // fi - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -ShowData( const std::string& name ) -{ - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - return; - - if( iIt->second.Tag == Data::IMAGE ) - { - if( name == this->m_MainImage ) - this->m_MPRObjects->SetInputImage( iIt->second.Image ); - else - { - unsigned int i = ( this->m_MPRObjects->GetNumberOfImages( ) - 1 ) % 8; - this->m_MPRObjects->AddBinaryImage( - iIt->second.Image, - Self::cm_Colors[ i ][ 0 ], - Self::cm_Colors[ i ][ 1 ], - Self::cm_Colors[ i ][ 2 ] - ); - } - this->m_MPRObjects->Show( ); - } - else if( iIt->second.Tag == Data::MESH ) - { - vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - ren->AddActor( iIt->second.GetMeshActor( ) ); - this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -HideData( const std::string& name ) -{ -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -SetWindowLevel( const double& w, const double& l ) -{ - this->m_MPRObjects->SetWindowLevel( w, l ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::QT::SimpleMPRWidget:: -GetWindow( ) const -{ - return( this->m_MPRObjects->GetWindow( ) ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::QT::SimpleMPRWidget:: -GetLevel( ) const -{ - return( this->m_MPRObjects->GetLevel( ) ); -} - -// ------------------------------------------------------------------------- -vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget:: -GetInteractor( unsigned int i ) -{ - if( i < 4 ) - { - if( this->m_VTK[ i ] != NULL ) - return( this->m_VTK[ i ]->GetInteractor( ) ); - else - return( NULL ); - } - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -/* - bool cpExtensions::QT::SimpleMPRWidget:: - ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent - ) - { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - this->m_Images[ name ] = image; - this->m_Tree[ name ] = parent; - - // Show image and return - this->m_MPRObjects->AddImage( image ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ) - { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - this->m_Images[ name ] = image; - this->m_Tree[ name ] = parent; - - // Show image and return - this->m_MPRObjects->AddImage( image ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent - ) - { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - PolyDataActor* actor = new PolyDataActor( mesh ); - this->m_Meshes[ name ] = actor; - this->m_Tree[ name ] = parent; - - // Show mesh - this->_Add3DActor( actor->Actor ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ) - { - return false; - } - - // ------------------------------------------------------------------------- - void cpExtensions::QT::SimpleMPRWidget:: - ClearAll( ) - { - this->m_MPRObjects->ClearAll( ); - this->m_Images.clear( ); - this->m_Meshes.clear( ); - } -*/ - -// ------------------------------------------------------------------------- -std::string cpExtensions::QT::SimpleMPRWidget:: -GetSelectedData( ) const -{ - /* TODO - QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( ); - if( item != NULL ) - return( item->text( 0 ).toStdString( ) ); - else - */ - return( "" ); -} - -// ------------------------------------------------------------------------- -/* TODO -QTreeWidgetItem* cpExtensions::QT::SimpleMPRWidget:: -_FindItemInTree( const std::string& name ) const -{ - QList< QTreeWidgetItem* > items = - this->m_UI->LoadedData->findItems( - name.c_str( ), Qt::MatchExactly | Qt::MatchRecursive + this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( ); + this->m_2DSlices[ i ]->SetInputData( image, i ); + this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] ); + this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )-> + SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) ); + + this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( ); + this->m_3DSlices[ i ]->SetInputData( image, i ); + this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] ); + this->m_3DSlices[ i ]->SetStyle( + dynamic_cast< vtkInteractorStyle* >( + this->m_Renderers[ 3 ]->GetRenderWindow( )-> + GetInteractor( )->GetInteractorStyle( ) + ) ); - if( items.size( ) > 0 ) - return( items[ 0 ] ); - else - return( NULL ); -} -// ------------------------------------------------------------------------- -QTreeWidgetItem* cpExtensions::QT::SimpleMPRWidget:: -_UpdateTreeItem( const std::string& name, const std::string& parent ) -{ - // Update tree view - QTreeWidgetItem* new_item = NULL; - if( parent != "" ) + } // rof + + for( unsigned int i = 0; i < 3; ++i ) { - QTreeWidgetItem* parent_item = this->_FindItemInTree( parent ); - if( parent_item != NULL ) + for( unsigned int j = 0; j < 3; ++j ) { - QTreeWidgetItem* old_item = this->_FindItemInTree( name ); - if( old_item == NULL ) - { - new_item = - new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) ); - parent_item->setExpanded( true ); + if( i != j ) + this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] ); + this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] ); - } // fi + } // rof - } // fi - } - else + } // rof + for( unsigned int i = 0; i < 3; ++i ) { - new_item = new QTreeWidgetItem( - ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) ) - ); - this->m_UI->LoadedData->addTopLevelItem( new_item ); - - } // fi - return( new_item ); -} -*/ + this->m_2DSlices[ i ]->GetStyle( )-> + SetCurrentRenderer( this->m_Renderers[ i ] ); + this->m_Renderers[ i ]->ResetCamera( ); + this->m_VTK[ i ]->GetRenderWindow( )->Render( ); -// ------------------------------------------------------------------------- -/* - void cpExtensions::QT::SimpleMPRWidget:: - _Add3DActor( vtkProp3D* prop ) - { - vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - ren->AddActor( prop ); + } // rof + this->m_Renderers[ 3 ]->ResetCamera( ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); - } -*/ +} // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: @@ -516,129 +136,6 @@ _SyncTop( int a, int b ) this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) ); } -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -PolyDataActor( ) - : Mesh( NULL ), - Normals( NULL ), - Stripper( NULL ), - Mapper( NULL ), - Actor( NULL ) -{ -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -~PolyDataActor( ) -{ - if( this->Actor != NULL ) this->Actor->Delete( ); - if( this->Mapper != NULL ) this->Mapper->Delete( ); - if( this->Stripper != NULL ) this->Stripper->Delete( ); - if( this->Normals != NULL ) this->Normals->Delete( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -Configure( vtkPolyData* pd ) -{ - if( pd == NULL ) - return; - - double range[ 2 ]; - pd->GetScalarRange( range ); - - this->Normals = vtkPolyDataNormals::New( ); - this->Stripper = vtkStripper::New( ); - this->Mapper = vtkPolyDataMapper::New( ); - this->Actor = vtkQuadricLODActor::New( ); - - this->Mesh = pd; - this->Normals->SetInputData( pd ); - this->Normals->SetFeatureAngle( 60.0 ); - this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) ); - this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) ); - this->Mapper->UseLookupTableScalarRangeOff( ); - this->Mapper->SetScalarRange( - range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ] - ); - this->Actor->SetMapper( this->Mapper ); - this->Actor->GetProperty( )->SetPointSize( 10 ); - this->Actor->DeferLODConstructionOff( ); -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::Data:: -Data( ) -{ - this->Tag = Data::IMAGE; - this->Image = NULL; -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::Data:: -~Data( ) -{ -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget:: -Data& cpExtensions::QT::SimpleMPRWidget::Data:: -operator=( const Data& data ) -{ - this->Tag = data.Tag; - if( this->Tag == Data::IMAGE ) - this->Image = data.Image; - else if( this->Tag == Data::MESH ) - this->Mesh = data.Mesh; - return( *this ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::Data:: -SetImageData( vtkImageData* data ) -{ - this->Tag = Data::IMAGE; - this->Image = data; -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::Data:: -SetPolyData( vtkPolyData* data ) -{ - this->Tag = Data::MESH; - this->Mesh.Configure( data ); -} - -// ------------------------------------------------------------------------- -vtkImageData* cpExtensions::QT::SimpleMPRWidget::Data:: -GetImage( ) -{ - if( this->Tag == Data::IMAGE ) - return( this->Image ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -vtkPolyData* cpExtensions::QT::SimpleMPRWidget::Data:: -GetMesh( ) -{ - if( this->Tag == Data::MESH ) - return( this->Mesh.Mesh ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -vtkProp* cpExtensions::QT::SimpleMPRWidget::Data:: -GetMeshActor( ) -{ - if( this->Tag == Data::MESH ) - return( this->Mesh.Actor ); - else - return( NULL ); -} - #endif // cpExtensions_QT4 // eof - $RCSfile$ diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.h b/lib/cpExtensions/QT/SimpleMPRWidget.h index ba2b79b..3dd2309 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.h +++ b/lib/cpExtensions/QT/SimpleMPRWidget.h @@ -5,22 +5,26 @@ #ifdef cpExtensions_QT4 -#include -#include - #include +#include +#include #include -#include -#include -#include -#include -#include -#include +/* + #include + #include + #include + #include + #include + #include + #include + #include + #include +*/ // ------------------------------------------------------------------------- -class QTreeWidgetItem; +// TODO: class QTreeWidgetItem; class QVTKWidget; namespace Ui @@ -43,100 +47,108 @@ namespace cpExtensions public: typedef SimpleMPRWidget Self; - typedef cpExtensions::Visualization::MPRObjects TMPRObjects; - typedef TMPRObjects::TStyle TStyle; - typedef TMPRObjects::TMouseCommand TMouseCommand; - typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand; - typedef TMPRObjects::TKeyCommand TKeyCommand; - typedef TMPRObjects::TVoidCommand TVoidCommand; - typedef TMPRObjects::TMouseMoveCommand TMouseMoveCommand; - typedef TMPRObjects::TMouseClickCommand TMouseClickCommand; - typedef TMPRObjects::TMouseDoubleClickCommand TMouseDoubleClickCommand; - typedef TMPRObjects::TExposeCommand TExposeCommand; - typedef TMPRObjects::TConfigureCommand TConfigureCommand; - typedef TMPRObjects::TEnterCommand TEnterCommand; - typedef TMPRObjects::TLeaveCommand TLeaveCommand; + typedef cpExtensions::Visualization::ImageSliceActors TActors; + /* TODO + typedef cpExtensions::Visualization::MPRObjects TMPRObjects; + typedef TMPRObjects::TStyle TStyle; + typedef TMPRObjects::TMouseCommand TMouseCommand; + typedef TMPRObjects::TMouseWheelCommand TMouseWheelCommand; + typedef TMPRObjects::TKeyCommand TKeyCommand; + typedef TMPRObjects::TVoidCommand TVoidCommand; + typedef TMPRObjects::TMouseMoveCommand TMouseMoveCommand; + typedef TMPRObjects::TMouseClickCommand TMouseClickCommand; + typedef TMPRObjects::TMouseDoubleClickCommand TMouseDoubleClickCommand; + typedef TMPRObjects::TExposeCommand TExposeCommand; + typedef TMPRObjects::TConfigureCommand TConfigureCommand; + typedef TMPRObjects::TEnterCommand TEnterCommand; + typedef TMPRObjects::TLeaveCommand TLeaveCommand; + */ public: explicit SimpleMPRWidget( QWidget* parent = 0 ); virtual ~SimpleMPRWidget( ); // Data management - unsigned int GetNumberOfData( ) const; - bool AddData( - vtkImageData* data, const std::string& name, - const std::string& parent - ); - bool AddData( - vtkPolyData* data, const std::string& name - ); - const std::string& GetMainImage( ) const; - bool SetMainImage( const std::string& name ); - void DeleteData( const std::string& name ); - void DeleteAllData( ); - - // Some qt accessors - void SetDataColor( - const std::string& name, - const double& r, const double& g, const double& b - ); - void ShowData( const std::string& name ); - void HideData( const std::string& name ); - void SetWindowLevel( const double& w, const double& l ); - double GetWindow( ) const; - double GetLevel( ) const; - - vtkRenderWindowInteractor* GetInteractor( unsigned int i ); - - // Visual objects accessors - std::string GetSelectedData( ) const; - + void SetMainImage( vtkImageData* image ); + + /* TODO + unsigned int GetNumberOfData( ) const; + bool AddData( + vtkImageData* data, const std::string& name, + const std::string& parent + ); + bool AddData( + vtkPolyData* data, const std::string& name + ); + const std::string& GetMainImage( ) const; + bool SetMainImage( const std::string& name ); + void DeleteData( const std::string& name ); + void DeleteAllData( ); + + // Some qt accessors + void SetDataColor( + const std::string& name, + const double& r, const double& g, const double& b + ); + void ShowData( const std::string& name ); + void HideData( const std::string& name ); + void SetWindowLevel( const double& w, const double& l ); + double GetWindow( ) const; + double GetLevel( ) const; + + vtkRenderWindowInteractor* GetInteractor( unsigned int i ); + + // Visual objects accessors + std::string GetSelectedData( ) const; + vtkProp* GetProp( const std::string& name ); + */ + private slots: void _SyncBottom( int a, int b ); void _SyncTop( int a, int b ); protected: - static double cm_Colors[ 8 ][ 3 ]; - - Ui::SimpleMPRWidget* m_UI; - vtkSmartPointer< TMPRObjects > m_MPRObjects; - QVTKWidget* m_VTK[ 4 ]; - - struct PolyDataActor - { - vtkPolyData* Mesh; - vtkPolyDataNormals* Normals; - vtkStripper* Stripper; - vtkPolyDataMapper* Mapper; - vtkQuadricLODActor* Actor; - - PolyDataActor( ); - virtual ~PolyDataActor( ); - void Configure( vtkPolyData* pd ); - }; - - struct Data - { - enum { IMAGE, MESH } Tag; - vtkImageData* Image; - PolyDataActor Mesh; - - Data( ); - virtual ~Data( ); - - Data& operator=( const Data& data ); - - void SetImageData( vtkImageData* data ); - void SetPolyData( vtkPolyData* data ); - - vtkImageData* GetImage( ); - vtkPolyData* GetMesh( ); - vtkProp* GetMeshActor( ); - }; - - std::string m_MainImage; - std::map< std::string, Data > m_Data; - std::map< std::string, std::string > m_Tree; + Ui::SimpleMPRWidget* m_UI; + QVTKWidget* m_VTK[ 4 ]; + + vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; + vtkSmartPointer< TActors > m_2DSlices[ 3 ]; + vtkSmartPointer< TActors > m_3DSlices[ 3 ]; + + /* TODO + static double cm_Colors[ 8 ][ 3 ]; + vtkSmartPointer< TMPRObjects > m_MPRObjects; + struct PolyDataActor + { + vtkPolyData* Mesh; + vtkPolyDataNormals* Normals; + vtkStripper* Stripper; + vtkPolyDataMapper* Mapper; + vtkQuadricLODActor* Actor; + + PolyDataActor( ); + virtual ~PolyDataActor( ); + void Configure( vtkPolyData* pd ); + }; + + struct Data + { + enum { IMAGE, MESH } Tag; + vtkImageData* Image; + PolyDataActor Mesh; + Data( ); + virtual ~Data( ); + Data& operator=( const Data& data ); + void SetImageData( vtkImageData* data ); + void SetPolyData( vtkPolyData* data ); + vtkImageData* GetImage( ); + vtkPolyData* GetMesh( ); + vtkProp* GetMeshActor( ); + }; + std::string m_MainImage; + std::map< std::string, Data > m_Data; + std::map< std::string, std::string > m_Tree; + */ }; } // ecapseman diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.ui b/lib/cpExtensions/QT/SimpleMPRWidget.ui index e468e92..c8246e1 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.ui +++ b/lib/cpExtensions/QT/SimpleMPRWidget.ui @@ -93,4 +93,4 @@ - \ No newline at end of file + diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 024fbe0..be7efe3 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -1,226 +1,40 @@ #include -#include #include - -#include #include -#include #include #include -#include #include #include -#include #include -#include #include // ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -m_PlaneColors[ 3 ][ 3 ] = -{ - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } -}; - -// ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageSliceActors* cpExtensions::Visualization::ImageSliceActors:: +Self* cpExtensions::Visualization::ImageSliceActors:: New( ) { return( new Self( ) ); } -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetAxis( int axis ) -{ - this->m_ImageMapper->SetOrientation( axis ); - this->m_BlenderMapper->SetOrientation( axis ); - this->m_ImageMapper->Update( ); - this->m_BlenderMapper->Update( ); - this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); - this->m_ImageActor->Modified( ); - this->m_BlenderActor->Modified( ); - this->Modified( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetInputConnection( vtkAlgorithmOutput* aout ) -{ - // Get input vtkImageData - if( aout == NULL ) - return; - - // Create mapper and actors - this->m_ImageMapper->SetInputConnection( aout ); - this->_ConfigureInputImage( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetInputImage( vtkImageData* data ) -{ - // Get input vtkImageData - if( data == NULL ) - return; - - // Create mapper and actors - this->m_ImageMapper->SetInputData( data ); - this->_ConfigureInputImage( ); -} - -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: -AddBinaryConnection( - vtkAlgorithmOutput* aout, - const double& r, const double& g, const double& b - ) -{ - if( aout == NULL ) - return( -1 ); - this->m_Blender->AddInputConnection( aout ); - this->_ConfigureBinaryImage( r, g, b ); - return( this->m_Blender->GetNumberOfInputs( ) - 1 ); -} - -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: -AddBinaryImage( - vtkImageData* data, - const double& r, const double& g, const double& b - ) -{ - if( data == NULL ) - return( -1 ); - this->m_Blender->AddInputData( data ); - this->_ConfigureBinaryImage( r, g, b ); - return( this->m_Blender->GetNumberOfInputs( ) - 1 ); -} - // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: Clear( ) { - // Unbind from container this->RemoveAllItems( ); - // Filters and mappers - this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( ); - this->m_Blender = vtkSmartPointer< TBlender >::New( ); - this->m_BlenderMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->m_BlenderLUT = vtkSmartPointer< vtkLookupTable >::New( ); - this->m_BlenderActor = vtkSmartPointer< vtkImageActor >::New( ); - - this->m_ImageActor->SetMapper( this->m_ImageMapper ); - this->m_BlenderMapper-> - SetInputConnection( this->m_Blender->GetOutputPort( ) ); - - this->m_BlenderLUT->SetNumberOfTableValues( 1 ); - this->m_BlenderLUT->SetTableRange( 0, 1 ); - this->m_BlenderLUT->SetTableValue( 0, 0, 0, 0, 0 ); - this->m_BlenderLUT->Build( ); - - this->m_BlenderActor->SetMapper( this->m_BlenderMapper ); - this->m_BlenderActor->GetProperty( )->SetLookupTable( this->m_BlenderLUT ); - this->m_BlenderActor->GetProperty( )->UseLookupTableScalarRangeOn( ); - - // White cursor - vtkSmartPointer< vtkPoints > cursor_points = - vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkCellArray > cursor_lines = - vtkSmartPointer< vtkCellArray >::New( ); - cursor_points->InsertNextPoint( 0, 0, 0 ); - cursor_points->InsertNextPoint( 0, 0, 0 ); - cursor_points->InsertNextPoint( 0, 0, 0 ); - cursor_points->InsertNextPoint( 0, 0, 0 ); - cursor_lines->InsertNextCell( 2 ); - cursor_lines->InsertCellPoint( 0 ); - cursor_lines->InsertCellPoint( 1 ); - cursor_lines->InsertNextCell( 2 ); - cursor_lines->InsertCellPoint( 2 ); - cursor_lines->InsertCellPoint( 3 ); - - this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( ); - this->m_CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_CursorActor = vtkSmartPointer< vtkActor >::New( ); - - this->m_Cursor->SetPoints( cursor_points ); - this->m_Cursor->SetLines( cursor_lines ); - this->m_CursorMapper->SetInputData( this->m_Cursor ); - this->m_CursorActor->SetMapper( this->m_CursorMapper ); - this->m_CursorActor->GetProperty( )->SetColor( 1, 1, 0 ); - this->m_CursorActor->GetProperty( )->SetLineWidth( 2 ); - - // Plane intersections - this->m_Axis1 = vtkSmartPointer< vtkPolyData >::New( ); - this->m_Axis1Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_Axis1Actor = vtkSmartPointer< vtkActor >::New( ); - - vtkSmartPointer< vtkPoints > h_points = - vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkCellArray > h_lines = - vtkSmartPointer< vtkCellArray >::New( ); - h_points->InsertNextPoint( 0, 0, 0 ); - h_points->InsertNextPoint( 0, 0, 0 ); - h_lines->InsertNextCell( 2 ); - h_lines->InsertCellPoint( 0 ); - h_lines->InsertCellPoint( 1 ); - this->m_Axis1->SetPoints( h_points ); - this->m_Axis1->SetLines( h_lines ); - this->m_Axis1Mapper->SetInputData( this->m_Axis1 ); - this->m_Axis1Actor->SetMapper( this->m_Axis1Mapper ); - - this->m_Axis2 = vtkSmartPointer< vtkPolyData >::New( ); - this->m_Axis2Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_Axis2Actor = vtkSmartPointer< vtkActor >::New( ); - - vtkSmartPointer< vtkPoints > v_points = - vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkCellArray > v_lines = - vtkSmartPointer< vtkCellArray >::New( ); - v_points->InsertNextPoint( 0, 0, 0 ); - v_points->InsertNextPoint( 0, 0, 0 ); - v_lines->InsertNextCell( 2 ); - v_lines->InsertCellPoint( 0 ); - v_lines->InsertCellPoint( 1 ); - this->m_Axis2->SetPoints( v_points ); - this->m_Axis2->SetLines( v_lines ); - this->m_Axis2Mapper->SetInputData( this->m_Axis2 ); - this->m_Axis2Actor->SetMapper( this->m_Axis2Mapper ); - - // Plane - this->m_Plane = vtkSmartPointer< vtkPolyData >::New( ); - this->m_PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_PlaneActor = vtkSmartPointer< vtkActor >::New( ); - - vtkSmartPointer< vtkPoints > plane_points = - vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkCellArray > plane_lines = - vtkSmartPointer< vtkCellArray >::New( ); - plane_points->InsertNextPoint( 0, 0, 0 ); - plane_points->InsertNextPoint( 0, 1, 0 ); - plane_points->InsertNextPoint( 1, 1, 0 ); - plane_points->InsertNextPoint( 1, 0, 0 ); - plane_lines->InsertNextCell( 5 ); - plane_lines->InsertCellPoint( 0 ); - plane_lines->InsertCellPoint( 1 ); - plane_lines->InsertCellPoint( 2 ); - plane_lines->InsertCellPoint( 3 ); - plane_lines->InsertCellPoint( 0 ); - this->m_Plane->SetPoints( plane_points ); - this->m_Plane->SetLines( plane_lines ); - - this->m_PlaneMapper->SetInputData( this->m_Plane ); - this->m_PlaneActor->SetMapper( this->m_PlaneMapper ); - - // Text actor - this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( ); + // Main image + this->m_Mapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + this->m_Actor = vtkSmartPointer< vtkImageActor >::New( ); + this->m_Actor->SetMapper( this->m_Mapper ); + + // Cursor + this->m_Cursor.Create( ); + this->m_Cursor.Actor->GetProperty( )->SetColor( 1, 1, 0 ); + + // Text this->m_TextBuffer[ 0 ] = '\0'; + this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( ); this->m_TextActor->SetTextScaleModeToNone( ); vtkTextProperty* textprop = this->m_TextActor->GetTextProperty( ); textprop->SetColor( 1, 1, 0 ); @@ -233,708 +47,146 @@ Clear( ) textprop->SetVerticalJustificationToBottom( ); vtkCoordinate* coord = this->m_TextActor->GetPositionCoordinate( ); coord->SetCoordinateSystemToNormalizedViewport( ); - coord->SetValue( 0.01, 0.01 ); -} + coord->SetValue( 0.01, 0.05 ); -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AssociateSlice( Self* slice ) -{ - this->m_AssociatedSlices.push_back( slice ); - this->Modified( ); -} - -// ------------------------------------------------------------------------- -vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: -GetStyle( ) -{ - return( this->m_Style.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: -GetStyle( ) const -{ - return( this->m_Style.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -vtkImageData* cpExtensions::Visualization::ImageSliceActors:: -GetInputImage( ) -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetInput( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -const vtkImageData* cpExtensions::Visualization::ImageSliceActors:: -GetInputImage( ) const -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetInput( ) ); - else - return( NULL ); + // Configure style + vtkSmartPointer< TStyle > st = vtkSmartPointer< TStyle >::New( ); + st->SetAssociatedObject( this ); + st->AddMouseMoveCommand( Self::_MouseMoveCommand, this ); + st->AddMouseClickCommand( Self::_MouseClickCommand, this ); + st->AddMouseWheelCommand( Self::_MouseWheelCommand, this ); + st->AddKeyCommand( Self::_KeyCommand, this ); + st->AddEnterCommand( Self::_EnterCommand, this ); + st->AddLeaveCommand( Self::_LeaveCommand, this ); + this->m_Style = st; } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -PushActorsInto( vtkRenderWindow* window, bool force_style ) +SetInputConnection( vtkAlgorithmOutput* aout, int orientation ) { - this->m_Window = window; - if( window == NULL ) - return; - vtkRenderWindowInteractor* rwi = window->GetInteractor( ); - vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); - if( rwi == NULL || renderer == NULL ) + if( aout == NULL ) return; - - // Update style - if( this->m_Style.GetPointer( ) != NULL && force_style ) - rwi->SetInteractorStyle( this->m_Style ); - - // Update actors - renderer->AddViewProp( this->m_ImageActor ); - renderer->AddViewProp( this->m_BlenderActor ); - if( force_style ) - { - renderer->AddViewProp( this->m_CursorActor ); - renderer->AddViewProp( this->m_PlaneActor ); - renderer->AddViewProp( this->m_TextActor ); - renderer->AddViewProp( this->m_Axis1Actor ); - renderer->AddViewProp( this->m_Axis2Actor ); - - } // fi - - // Configure camera - vtkCamera* camera = renderer->GetActiveCamera( ); - if( camera != NULL && force_style ) - { - // Parallel projections are better when displaying 2D images - int axis = this->GetAxis( ); - camera->ParallelProjectionOn( ); - camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); - if( axis == 0 ) - { - camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); - camera->SetViewUp ( double( 0 ), double( 0 ), double( 1 ) ); - } - else if( axis == 1 ) - { - camera->SetPosition( double( 0 ), double( -1 ), double( 0 ) ); - camera->SetViewUp ( double( 0 ), double( 0 ), double( 1 ) ); - } - else // if( axis == 2 ) - { - camera->SetPosition( double( 0 ), double( 0 ), double( -1 ) ); - camera->SetViewUp ( double( 0 ), double( -1 ), double( 0 ) ); - - } // fi - - } // fi - renderer->ResetCamera( ); + this->m_Mapper->SetInputConnection( aout ); + this->_ConfigureInput( orientation ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -PopActorsFrom( vtkRenderWindow* window ) -{ - vtkRenderWindowInteractor* rwi = window->GetInteractor( ); - vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); - if( renderer != NULL ) - { - renderer->RemoveViewProp( this->m_ImageActor ); - renderer->RemoveViewProp( this->m_BlenderActor ); - renderer->RemoveViewProp( this->m_CursorActor ); - renderer->RemoveViewProp( this->m_PlaneActor ); - renderer->RemoveViewProp( this->m_TextActor ); - renderer->RemoveViewProp( this->m_Axis1Actor ); - renderer->RemoveViewProp( this->m_Axis2Actor ); - - } // fi -} - -// ------------------------------------------------------------------------- -unsigned int cpExtensions::Visualization::ImageSliceActors:: -GetNumberOfImages( ) const +SetInputData( vtkImageData* data, int orientation ) { - return( this->m_Blender->GetNumberOfInputs( ) ); -} - -// ------------------------------------------------------------------------- -vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( ) -{ - return( this->m_ImageActor ); -} - -// ------------------------------------------------------------------------- -const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( ) const -{ - return( this->m_ImageActor ); -} - -// ------------------------------------------------------------------------- -vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetBinaryActor( ) -{ - return( this->m_BlenderActor ); -} - -// ------------------------------------------------------------------------- -const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetBinaryActor( ) const -{ - return( this->m_BlenderActor ); -} - -// ------------------------------------------------------------------------- -vtkTextActor* cpExtensions::Visualization::ImageSliceActors:: -GetTextActor( ) -{ - return( this->m_TextActor ); -} - -// ------------------------------------------------------------------------- -const vtkTextActor* cpExtensions::Visualization::ImageSliceActors:: -GetTextActor( ) const -{ - return( this->m_TextActor ); -} - -// ------------------------------------------------------------------------- -vtkActor* cpExtensions::Visualization::ImageSliceActors:: -GetPlaneActor( ) -{ - return( this->m_PlaneActor ); -} - -// ------------------------------------------------------------------------- -const vtkActor* cpExtensions::Visualization::ImageSliceActors:: -GetPlaneActor( ) const -{ - return( this->m_PlaneActor ); -} - -// ------------------------------------------------------------------------- -vtkPlane* cpExtensions::Visualization::ImageSliceActors:: -GetPlaneFunction( ) -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetSlicePlane( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: -GetPlaneFunction( ) const -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetSlicePlane( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetInterpolate( bool v ) -{ - if( this->m_Interpolate != v ) - { - this->m_ImageActor->SetInterpolate( v ); - this->m_BlenderActor->SetInterpolate( v ); - this->m_Interpolate = v; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -InterpolateOn( ) -{ - this->SetInterpolate( true ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -InterpolateOff( ) -{ - this->SetInterpolate( false ); -} - -// ------------------------------------------------------------------------- -double* cpExtensions::Visualization::ImageSliceActors:: -GetDisplayBounds( ) const -{ - if( this->m_ImageActor.GetPointer( ) != NULL ) - return( this->m_ImageActor->GetDisplayBounds( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -GetDisplayBounds( double bounds[ 6 ] ) const -{ - if( this->m_ImageActor.GetPointer( ) == NULL ) - { - bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( 0 ); - bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 ); - } - else - this->m_ImageActor->GetDisplayBounds( bounds ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -ResetCursor( ) -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - { - double pos[] = - { - this->m_VisibleBounds[ 0 ], - this->m_VisibleBounds[ 2 ], - this->m_VisibleBounds[ 4 ] - }; - this->SetCursor( pos ); - } - else - { - vtkPoints* points = this->m_Cursor->GetPoints( ); - points->SetPoint( 0, 0, 0, 0 ); - points->SetPoint( 1, 0, 0, 0 ); - points->SetPoint( 2, 0, 0, 0 ); - points->SetPoint( 3, 0, 0, 0 ); - this->m_Cursor->Modified( ); - this->m_CursorMapper->Modified( ); - this->m_CursorActor->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetCursor( double pos[ 3 ] ) -{ - if( this->m_ImageMapper.GetPointer( ) == NULL ) + if( data == NULL ) return; - - // Get ordered axes - int a0 = this->GetAxis( ); - int a1 = ( a0 + 1 ) % 3; - int a2 = ( a0 + 2 ) % 3; - int ma0 = a0 << 1; - int ma1 = a1 << 1; - int ma2 = a2 << 1; - - // Update cross - double* bounds = this->m_VisibleBounds; - double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ]; - - p0[ a2 ] = p1[ a2 ] = pos[ a2 ]; - p2[ a1 ] = p3[ a1 ] = pos[ a1 ]; - p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ]; - p0[ a1 ] = bounds[ ma1 ]; - p1[ a1 ] = bounds[ ma1 + 1 ]; - p2[ a2 ] = bounds[ ma2 ]; - p3[ a2 ] = bounds[ ma2 + 1 ]; - - vtkPoints* points = this->m_Cursor->GetPoints( ); - points->SetPoint( 0, p0 ); - points->SetPoint( 1, p1 ); - points->SetPoint( 2, p2 ); - points->SetPoint( 3, p3 ); - this->m_Cursor->Modified( ); - this->m_CursorMapper->Modified( ); - this->m_CursorActor->Modified( ); + this->m_Mapper->SetInputData( data ); + this->_ConfigureInput( orientation ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -ResetAxesCursor( ) +AssociateSlice( Self* slice ) { - if( this->m_ImageMapper.GetPointer( ) != NULL ) - { - double pos[] = - { - this->m_VisibleBounds[ 0 ], - this->m_VisibleBounds[ 2 ], - this->m_VisibleBounds[ 4 ] - }; - this->SetAxesCursor( pos ); - } - else - { - vtkPoints* points = this->m_Axis1->GetPoints( ); - points->SetPoint( 0, 0, 0, 0 ); - points->SetPoint( 1, 0, 0, 0 ); - this->m_Axis1->Modified( ); - this->m_Axis1Mapper->Modified( ); - this->m_Axis1Actor->Modified( ); - - points = this->m_Axis2->GetPoints( ); - points->SetPoint( 0, 0, 0, 0 ); - points->SetPoint( 1, 0, 0, 0 ); - this->m_Axis2->Modified( ); - this->m_Axis2Mapper->Modified( ); - this->m_Axis2Actor->Modified( ); - - } // fi + this->m_AssociatedSlices.push_back( slice ); + this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetAxesCursor( double pos[ 3 ] ) -{ - if( this->m_ImageMapper.GetPointer( ) == NULL ) - return; - - // Get ordered axes - int a0 = this->GetAxis( ); - int a1 = ( a0 + 1 ) % 3; - int a2 = ( a0 + 2 ) % 3; - int ma0 = a0 << 1; - int ma1 = a1 << 1; - int ma2 = a2 << 1; - - // Update cross - double* bounds = this->m_VisibleBounds; - double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ]; - - p0[ a2 ] = p1[ a2 ] = pos[ a2 ]; - p2[ a1 ] = p3[ a1 ] = pos[ a1 ]; - p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ]; - p0[ a1 ] = bounds[ ma1 ]; - p1[ a1 ] = bounds[ ma1 + 1 ]; - p2[ a2 ] = bounds[ ma2 ]; - p3[ a2 ] = bounds[ ma2 + 1 ]; - - vtkPoints* points1 = this->m_Axis1->GetPoints( ); - points1->SetPoint( 0, p2 ); - points1->SetPoint( 1, p3 ); - - vtkPoints* points2 = this->m_Axis2->GetPoints( ); - points2->SetPoint( 0, p0 ); - points2->SetPoint( 1, p1 ); - - this->m_Axis1->Modified( ); - this->m_Axis1Mapper->Modified( ); - this->m_Axis1Actor->Modified( ); - - this->m_Axis2->Modified( ); - this->m_Axis2Mapper->Modified( ); - this->m_Axis2Actor->Modified( ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetMinWindow( ) const -{ - return( this->m_WLRange[ 0 ] ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetMaxWindow( ) const +CleanAssociatedSlices( ) { - return( this->m_WLRange[ 1 ] ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetMinLevel( ) const -{ - return( this->m_WLRange[ 2 ] ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetMaxLevel( ) const -{ - return( this->m_WLRange[ 3 ] ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetWindow( ) const -{ - if( this->m_ImageActor.GetPointer( ) != NULL ) - return( this->m_ImageActor->GetProperty( )->GetColorWindow( ) ); - else - return( double( 0 ) ); -} - -// ------------------------------------------------------------------------- -double cpExtensions::Visualization::ImageSliceActors:: -GetLevel( ) const -{ - if( this->m_ImageActor.GetPointer( ) != NULL ) - return( this->m_ImageActor->GetProperty( )->GetColorLevel( ) ); - else - return( double( 0 ) ); + this->m_AssociatedSlices.clear( ); + this->Modified( ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetWindow( double w ) +cpExtensions::Interaction::ImageInteractorStyle* +cpExtensions::Visualization::ImageSliceActors:: +GetStyle( ) { - if( this->m_ImageActor.GetPointer( ) == NULL ) - return; - double v = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w; - v = ( v > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: v; - this->m_ImageActor->GetProperty( )->SetColorWindow( v ); + return( dynamic_cast< TStyle* >( this->m_Style.GetPointer( ) ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetLevel( double l ) +SetStyle( vtkInteractorStyle* st ) { - if( this->m_ImageActor.GetPointer( ) == NULL ) - return; - double v = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l; - v = ( v > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: v; - this->m_ImageActor->GetProperty( )->SetColorLevel( v ); + this->m_Style = st; + this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetWindowLevel( double w, double l ) +PushInto( vtkRenderer* ren ) { - if( this->m_ImageActor.GetPointer( ) == NULL ) - return; - double a = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w; - a = ( a > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: a; - double b = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l; - b = ( b > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: b; - this->m_ImageActor->GetProperty( )->SetColorWindow( a ); - this->m_ImageActor->GetProperty( )->SetColorLevel( b ); - this->UpdateText( a, b ); + this->InitTraversal( ); + vtkProp* prop; + while( ( prop = this->GetNextProp( ) ) != NULL ) + ren->AddViewProp( prop ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -ResetWindowLevel( ) +PopFrom( vtkRenderer* ren ) { - this->SetWindowLevel( - this->m_WLRange[ 1 ] * double( 0.5 ), - ( this->m_WLRange[ 3 ] + this->m_WLRange[ 2 ] ) * double( 0.5 ) - ); -} - -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: -GetAxis( ) const -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetOrientation( ) ); - else - return( -1 ); + this->InitTraversal( ); + vtkProp* prop; + while( ( prop = this->GetNextProp( ) ) != NULL ) + ren->RemoveViewProp( prop ); } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: +long cpExtensions::Visualization::ImageSliceActors:: GetSliceNumber( ) const { - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetSliceNumber( ) ); - else - return( -1 ); -} - -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: -GetSliceNumberMinValue( ) const -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetSliceNumberMinValue( ) ); - else - return( -1 ); -} - -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::ImageSliceActors:: -GetSliceNumberMaxValue( ) const -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - return( this->m_ImageMapper->GetSliceNumberMaxValue( ) ); + if( this->m_Mapper.GetPointer( ) != NULL ) + return( this->m_Mapper->GetSliceNumber( ) ); else return( -1 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -SetSliceNumber( const int& slice ) +SetSliceNumber( long slice ) { - if( this->m_ImageMapper.GetPointer( ) == NULL ) + if( this->m_Mapper.GetPointer( ) == NULL ) return; - int axis = this->GetAxis( ); - double prev_pos = this->m_VisibleBounds[ axis << 1 ]; + // Get orientation + int a = this->m_Mapper->GetOrientation( ); - // Update mappers and display bounds - this->m_ImageMapper->SetSliceNumber( slice ); - this->m_BlenderMapper->SetSliceNumber( slice ); - this->m_ImageMapper->Modified( ); - this->m_BlenderMapper->Modified( ); - this->m_ImageActor->Modified( ); - this->m_BlenderActor->Modified( ); + // Check extent + int ext[ 6 ]; + this->m_Mapper->GetInput( )->GetExtent( ext ); + long rs = slice; + rs = ( rs > ext[ a << 1 ] )? rs: ext[ a << 1 ]; + rs = ( rs < ext[ ( a << 1 ) + 1 ] )? rs: ext[ ( a << 1 ) + 1 ]; - // Update display extent (this isn't done automatically) - this->m_ImageMapper->GetInput( )->GetExtent( this->m_VisibleExtent ); - this->m_VisibleExtent[ axis << 1 ] = slice; - this->m_VisibleExtent[ ( axis << 1 ) + 1 ] = slice; - this->m_ImageActor->SetDisplayExtent( this->m_VisibleExtent ); - - // Prepare plane data - this->m_ImageMapper->GetBounds( this->m_VisibleBounds ); - double x0[][ 3 ] = - { - { - this->m_VisibleBounds[ 0 ], - this->m_VisibleBounds[ 2 ], - this->m_VisibleBounds[ 4 ] - }, - { - this->m_VisibleBounds[ 1 ], - this->m_VisibleBounds[ 3 ], - this->m_VisibleBounds[ 5 ] - } - }; - double p0[ 2 ][ 3 ]; - - vtkPlane* plane = this->m_ImageMapper->GetSlicePlane( ); - plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] ); - plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] ); - - this->m_VisibleBounds[ 0 ] = p0[ 0 ][ 0 ]; - this->m_VisibleBounds[ 1 ] = p0[ 1 ][ 0 ]; - this->m_VisibleBounds[ 2 ] = p0[ 0 ][ 1 ]; - this->m_VisibleBounds[ 3 ] = p0[ 1 ][ 1 ]; - this->m_VisibleBounds[ 4 ] = p0[ 0 ][ 2 ]; - this->m_VisibleBounds[ 5 ] = p0[ 1 ][ 2 ]; - double* bnds = this->m_VisibleBounds; - - // Configure visualization and implicit plane orientation - this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); - this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 ); - vtkPoints* plane_points = this->m_Plane->GetPoints( ); - plane_points->SetPoint( 0, bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] ); - plane_points->SetPoint( 2, bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] ); - if( axis == 0 || axis == 2 ) // YZ, x-normal - { - plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] ); - plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] ); - } - else if( axis == 1 ) // ZX, y-normal - { - plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] ); - plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] ); - - } // fi - - // Set plane colors - this->m_PlaneActor->GetProperty( )-> - SetColor( this->m_PlaneColors[ axis ] ); - this->m_Axis1Actor->GetProperty( )-> - SetColor( this->m_PlaneColors[ ( axis + 1 ) % 3 ] ); - this->m_Axis2Actor->GetProperty( )-> - SetColor( this->m_PlaneColors[ ( axis + 2 ) % 3 ] ); - - this->m_Plane->Modified( ); - this->m_PlaneMapper->Modified( ); - this->m_PlaneActor->Modified( ); - - this->m_Axis1->Modified( ); - this->m_Axis1Mapper->Modified( ); - this->m_Axis1Actor->Modified( ); - - this->m_Axis2->Modified( ); - this->m_Axis2Mapper->Modified( ); - this->m_Axis2Actor->Modified( ); - - // Update text - this->UpdateText( ); - - // Update camera position - if( this->m_Window == NULL ) - return; - vtkRenderer* renderer = - this->m_Window->GetRenderers( )->GetFirstRenderer( ); - if( renderer == NULL ) - return; - vtkCamera* camera = renderer->GetActiveCamera( ); - if( camera == NULL ) - return; - double cam_pos[ 3 ]; - camera->GetPosition( cam_pos ); - cam_pos[ axis ] += this->m_VisibleBounds[ axis << 1 ] - prev_pos; - camera->SetPosition( cam_pos ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetSlice( double* pos ) -{ - vtkImageData* image = this->GetInputImage( ); - if( image == NULL ) - return; + // Update pipeline + this->m_Mapper->SetSliceNumber( rs ); - int ijk[ 3 ]; - double pcoords[ 3 ]; - image->ComputeStructuredCoordinates( pos, ijk, pcoords ); - this->SetSliceNumber( ijk[ this->GetAxis( ) ] ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -UpdateText( ) -{ - if( this->m_ImageMapper.GetPointer( ) != NULL ) - { - char axis; - int axId = this->m_ImageMapper->GetOrientation( ); - if ( axId == 0 ) axis = 'X'; - else if( axId == 1 ) axis = 'Y'; - else if( axId == 2 ) axis = 'Z'; + // Update display extent (this isn't done automatically) + ext[ a << 1 ] = ext[ ( a << 1 ) + 1 ] = rs; + this->m_Actor->SetDisplayExtent( ext ); -#if defined(WIN32) - sprintf_s( - this->m_TextBuffer, 1024, "Axis: %c (%d)", - axis, this->m_ImageMapper->GetSliceNumber( ) - ); -#else // defined(WIN32) - std::sprintf( - this->m_TextBuffer, "Axis: %c (%d)", - axis, this->m_ImageMapper->GetSliceNumber( ) - ); -#endif // defined(WIN32) - } - else - this->m_TextBuffer[ 0 ] = '\0'; - this->m_TextActor->SetInput( this->m_TextBuffer ); - this->m_TextActor->Modified( ); + this->m_Mapper->Modified( ); + this->m_Actor->Modified( ); + this->_ConfigureCursor( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -UpdateText( double pos[ 3 ] ) +ShowPixelText( double* pos ) { - if( this->m_ImageMapper.GetPointer( ) != NULL ) + if( this->m_Mapper.GetPointer( ) != NULL ) { char axis; - int axId = this->m_ImageMapper->GetOrientation( ); + int axId = this->m_Mapper->GetOrientation( ); if ( axId == 0 ) axis = 'X'; else if( axId == 1 ) axis = 'Y'; else if( axId == 2 ) axis = 'Z'; - int slice = this->GetSliceNumber( ); + long slice = this->GetSliceNumber( ); - vtkImageData* image = this->GetInputImage( ); + vtkImageData* image = this->m_Actor->GetInput( ); int ijk[ 3 ]; double pcoords[ 3 ]; image->ComputeStructuredCoordinates( pos, ijk, pcoords ); @@ -966,7 +218,7 @@ UpdateText( double pos[ 3 ] ) #if defined(WIN32) sprintf_s( - this->m_TextBuffer, 1024, "Axis: %c (%d)\nPixel %s", + this->m_TextBuffer, MAX_TEXT_BUFFER, "Axis: %c (%d)\nPixel %s", axis, slice, str.str( ).c_str( ) ); #else // defined(WIN32) @@ -986,71 +238,101 @@ UpdateText( double pos[ 3 ] ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -UpdateText( const double& w, const double& l ) +GetScalarRange( double r[ 2 ] ) const { - if( this->m_ImageMapper.GetPointer( ) != NULL ) + r[ 0 ] = this->m_ScalarRange[ 0 ]; + r[ 1 ] = this->m_ScalarRange[ 1 ]; +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetScalarRange( const double& a, const double& b ) +{ + this->m_ManualScalarRange = true; + this->m_ScalarRange[ 0 ] = a; + this->m_ScalarRange[ 1 ] = b; + this->SetWindowLevel( 1, 0.5 ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +UnsetScalarRange( ) +{ + auto image = this->m_Actor->GetInput( ); + if( image != NULL ) { - char axis; - int axId = this->m_ImageMapper->GetOrientation( ); - if ( axId == 0 ) axis = 'X'; - else if( axId == 1 ) axis = 'Y'; - else if( axId == 2 ) axis = 'Z'; + double r[ 2 ]; + image->GetScalarRange( r ); + this->SetScalarRange( r[ 0 ], r[ 1 ] ); -#if defined(WIN32) - sprintf_s( - this->m_TextBuffer, 1024, "Axis: %c (%d)\nW/L (%.2f/%.2f)", - axis, this->m_ImageMapper->GetSliceNumber( ), w, l - ); -#else // defined(WIN32) - std::sprintf( - this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)", - axis, this->m_ImageMapper->GetSliceNumber( ), w, l - ); -#endif // defined(WIN32) - } - else - this->m_TextBuffer[ 0 ] = '\0'; - this->m_TextActor->SetInput( this->m_TextBuffer ); - this->m_TextActor->Modified( ); - this->Modified( ); + } // fi + this->m_ManualScalarRange = false; } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -Render( ) +SetWindowLevel( const double& w, const double& l ) { - if( this->m_Window == NULL ) - return; - vtkRenderer* renderer = - this->m_Window->GetRenderers( )->GetFirstRenderer( ); - if( renderer == NULL ) - return; - renderer->SetAllocatedRenderTime( 1e-3 ); - this->m_Window->Render( ); + static const double _0 = double( 0 ); + static const double _1 = double( 1 ); + + double rw = ( w < _0 )? _0: ( ( w > _1 )? _1: w ); + double rl = ( l < _0 )? _0: ( ( l > _1 )? _1: l ); + + double d = this->m_ScalarRange[ 1 ] - this->m_ScalarRange[ 0 ]; + rw *= d; + rl *= d; + rl += this->m_ScalarRange[ 0 ]; + + if( this->m_Actor.GetPointer( ) != NULL ) + { + this->m_Actor->GetProperty( )->SetColorWindow( rw ); + this->m_Actor->GetProperty( )->SetColorLevel( rl ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetWindow( ) const +{ + if( this->m_Actor.GetPointer( ) != NULL ) + return( this->m_Actor->GetProperty( )->GetColorWindow( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetLevel( ) const +{ + if( this->m_Actor.GetPointer( ) != NULL ) + return( this->m_Actor->GetProperty( )->GetColorLevel( ) ); + else + return( double( 0 ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -ResetCamera( ) +Render( ) { - if( this->m_Window == NULL ) + auto ren = this->m_Style->GetCurrentRenderer( ); + if( ren == NULL ) return; - vtkRenderer* renderer = - this->m_Window->GetRenderers( )->GetFirstRenderer( ); - if( renderer == NULL ) + auto win = ren->GetRenderWindow( ); + if( win == NULL ) return; - renderer->ResetCamera( ); + win->Render( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) : Superclass( ), - m_Window( NULL ), - m_Interpolate( false ) + m_ManualScalarRange( false ) { this->Clear( ); - this->_ConfigureStyle( ); } // ------------------------------------------------------------------------- @@ -1061,46 +343,51 @@ cpExtensions::Visualization::ImageSliceActors:: // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_ConfigureStyle( ) +_ConfigureInput( int orientation ) { - // Connect this view with a controller - this->m_Style = vtkSmartPointer< TStyle >::New( ); - this->m_Style->SetAssociatedObject( this ); - this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this ); - this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this ); - this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this ); - this->m_Style->AddKeyCommand( Self::_KeyCommand, this ); - this->m_Style->AddEnterCommand( Self::_EnterCommand, this ); - this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this ); -} + // Prepare main image + this->m_Mapper->SetOrientation( orientation ); + this->m_Mapper->Update( ); + this->m_Actor->GetProperty( )->SetOpacity( 0.8 ); + this->m_Actor->Modified( ); + auto st = this->GetStyle( ); + if( st != NULL ) + st->AssociateImageActor( this->m_Actor ); + this->AddItem( this->m_Actor ); -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -_ConfigureInputImage( ) -{ - this->m_ImageMapper->SetOrientation( 0 ); - this->m_ImageMapper->Update( ); + // Prepare main cursor + this->_ConfigureCursor( ); + this->AddItem( this->m_Cursor.Actor ); - // Create actor - this->m_ImageActor->SetInterpolate( this->m_Interpolate ); - this->m_ImageActor->Modified( ); + // Prepare window/level + if( !( this->m_ManualScalarRange ) ) + this->UnsetScalarRange( ); - if( this->m_Style.GetPointer( ) != NULL ) - this->m_Style->AssociateImageActor( this->m_ImageActor ); - this->AddItem( this->m_ImageActor ); + // Add all other actors + this->AddItem( this->m_TextActor ); - this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); - this->ResetCursor( ); - this->Modified( ); + // Put it in the first slice + auto image = this->m_Mapper->GetInput( ); + int ext[ 6 ]; + image->GetExtent( ext ); + this->SetSliceNumber( ext[ orientation << 1 ] ); - // Reset cursors - this->ResetCursor( ); - this->ResetAxesCursor( ); + /* + if( this->m_Style.GetPointer( ) != NULL ) + this->AddItem( this->m_Actor ); - // Update window/level ranges - vtkImageData* data = this->GetInputImage( ); - if( data != NULL ) - { + this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); + this->ResetCursor( ); + this->Modified( ); + + // Reset cursors + this->ResetCursor( ); + this->ResetAxesCursor( ); + + // Update window/level ranges + vtkImageData* data = this->GetInputImage( ); + if( data != NULL ) + { double r[ 2 ]; data->GetScalarRange( r ); this->m_WLRange[ 0 ] = double( 0 ); @@ -1114,92 +401,81 @@ _ConfigureInputImage( ) this->m_BlenderBase->ShallowCopy( data ); this->m_BlenderBase->AllocateScalars( VTK_UNSIGNED_CHAR, 1 ); std::memset( - this->m_BlenderBase->GetScalarPointer( ), 0, - this->m_BlenderBase->GetActualMemorySize( ) - ); + this->m_BlenderBase->GetScalarPointer( ), 0, + this->m_BlenderBase->GetActualMemorySize( ) + ); this->m_Blender->AddInputData( this->m_BlenderBase ); - } // fi + } // fi + */ } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_ConfigureBinaryImage( const double& r, const double& g, const double& b ) +_ConfigureCursor( ) { - unsigned int nValues = this->m_BlenderLUT->GetNumberOfTableValues( ); - this->m_BlenderLUT->SetNumberOfTableValues( nValues + 1 ); - this->m_BlenderLUT->SetTableRange( 0, nValues ); - this->m_BlenderLUT->SetTableValue( nValues, r, g, b, 0.5 ); - this->m_BlenderLUT->Build( ); - - this->m_BlenderLUT->Modified( ); - this->m_Blender->Modified( ); - this->m_Blender->Update( ); - - this->m_BlenderMapper->Modified( ); - this->m_BlenderActor->Modified( ); + int a = this->m_Mapper->GetOrientation( ); + double bounds[ 6 ]; + this->m_Actor->GetBounds( bounds ); + bounds[ a << 1 ] += 1e-5; + bounds[ ( a << 1 ) + 1 ] += 1e-5; + + this->m_Cursor.Source->SetModelBounds( bounds ); + this->m_Cursor.Source->AllOn( ); + this->m_Cursor.Actor->GetProperty( )->SetOpacity( 1 ); + this->m_Cursor.Actor->GetProperty( )->SetLineWidth( 3 ); + this->m_Cursor.Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _MouseMoveCommand( - void* data, const TStyle::ButtonID& btn, int* idx, double* pos, + void* data, + const TStyle::ButtonID& btn, + int* idx, double* pos, bool alt, bool ctr, bool sft ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) + ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data ); + if( self == NULL ) return; if( btn == TStyle::ButtonID_None ) { - // Just show the pixel information - actors->SetCursor( pos ); - actors->UpdateText( pos ); - actors->Render( ); - } - else if( btn == TStyle::ButtonID_Left ) - { - if( !alt && ctr && !sft ) - { - // Show axes in current renderer - actors->SetAxesCursor( pos ); - actors->Render( ); - - // Interactively move slices - auto i = actors->m_SlicesCommands.begin( ); - for( ; i != actors->m_SlicesCommands.end( ); ++i ) - i->first( pos, actors->GetAxis( ), i->second ); - - } // fi + self->ShowPixelText( pos ); + self->m_Cursor.Source->SetFocalPoint( pos ); + self->m_Cursor.Source->Modified( ); + self->m_Cursor.Modified( ); + self->Render( ); } else if( btn == TStyle::ButtonID_Right ) { if( !alt && !ctr && sft ) { - // Change image window level - double bounds[ 6 ]; - actors->m_ImageMapper->GetBounds( bounds ); - - int a0 = actors->GetAxis( ); + int a0 = self->m_Mapper->GetOrientation( ); int a1 = ( a0 + 1 ) % 3; int a2 = ( a0 + 2 ) % 3; - double dx = pos[ a1 ] - actors->m_StartWindowLevelPos[ a1 ]; - double dy = pos[ a2 ] - actors->m_StartWindowLevelPos[ a2 ]; + double dx = pos[ a1 ] - self->m_StartMouseEvent[ a1 ]; + double dy = pos[ a2 ] - self->m_StartMouseEvent[ a2 ]; + double bounds[ 6 ]; + self->m_Actor->GetBounds( bounds ); dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ]; dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ]; + double w = self->m_StartWindow + dx; + double l = self->m_StartLevel + dy; + + self->SetWindowLevel( w, l ); + self->Render( ); + for( + auto aIt = self->m_AssociatedSlices.begin( ); + aIt != self->m_AssociatedSlices.end( ); + ++aIt + ) + { + ( *aIt )->SetWindowLevel( w, l ); + ( *aIt )->Render( ); - dx *= actors->m_StartWindowLevel[ 0 ]; - dy *= actors->m_StartWindowLevel[ 1 ]; - 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 ); + } // rof } // fi @@ -1209,115 +485,112 @@ _MouseMoveCommand( // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _MouseClickCommand( - void* data, const TStyle::ButtonID& btn, int* idx, double* pos, + void* data, + const TStyle::ButtonID& btn, + int* idx, double* pos, bool alt, bool ctr, bool sft ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) + ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data ); + if( self == NULL ) return; - actors->m_StartWindowLevelPos[ 0 ] = pos[ 0 ]; - actors->m_StartWindowLevelPos[ 1 ] = pos[ 1 ]; - actors->m_StartWindowLevelPos[ 2 ] = pos[ 2 ]; - actors->m_StartWindowLevel[ 0 ] = actors->GetWindow( ); - actors->m_StartWindowLevel[ 1 ] = actors->GetLevel( ); + self->m_StartMouseEvent[ 0 ] = pos[ 0 ]; + self->m_StartMouseEvent[ 1 ] = pos[ 1 ]; + self->m_StartMouseEvent[ 2 ] = pos[ 2 ]; + + if( btn == TStyle::ButtonID_Right ) + { + if( !alt && !ctr && sft ) + { + double r[ 2 ]; + self->GetScalarRange( r ); + double d = r[ 1 ] - r[ 0 ]; + self->m_StartWindow = self->GetWindow( ) / d; + self->m_StartLevel = ( self->GetLevel( ) - r[ 0 ] ) / d; + + } // fi + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _MouseWheelCommand( - void* data, const int& dir, - bool alt, bool ctr, bool sft + void* data, + const int& dir, bool alt, bool ctr, bool sft ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) + ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data ); + if( self == NULL ) + return; + auto ren = self->m_Style->GetCurrentRenderer( ); + if( ren == NULL ) + return; + auto cam = ren->GetActiveCamera( ); + if( cam == NULL ) + return; + auto win = ren->GetRenderWindow( ); + if( win == NULL ) return; - if( !alt && !ctr ) + // Get previous values + int a = self->m_Mapper->GetOrientation( ); + double bounds[ 6 ]; + self->m_Actor->GetBounds( bounds ); + double prev_pos = bounds[ a << 1 ]; + + // Move slice + long slice = self->GetSliceNumber( ) + dir * ( ( sft )? 10: 1 ); + self->SetSliceNumber( slice ); + self->m_Actor->GetBounds( bounds ); + + // Reset camera + double cam_pos[ 3 ]; + cam->GetPosition( cam_pos ); + cam_pos[ a ] += bounds[ a << 1 ] - prev_pos; + cam->SetPosition( cam_pos ); + + // Update text + self->ShowPixelText( self->m_Cursor.Source->GetFocalPoint( ) ); + + // Update all + win->Render( ); + for( + auto aIt = self->m_AssociatedSlices.begin( ); + aIt != self->m_AssociatedSlices.end( ); + ++aIt + ) { - 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( ); - - auto a = actors->m_AssociatedSlices.begin( ); - for( ; a != actors->m_AssociatedSlices.end( ); ++a ) - ( *a )->SetSliceNumber( slice ); - - // Associate objects - auto i = actors->m_RenderCommands.begin( ); - for( ; i != actors->m_RenderCommands.end( ); ++i ) - i->first( i->second ); + if( ( *aIt )->m_Mapper->GetOrientation( ) == a ) + { + ( *aIt )->SetSliceNumber( slice ); + ( *aIt )->Render( ); + + } // fi } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_KeyCommand( void* data, const char& key ) +_KeyCommand( + void* data, + const char& key + ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) - return; - - switch( key ) - { - case 'r': case 'R': - { - actors->ResetCamera( ); - actors->Render( ); - - // 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( ); - - // Associate objects - auto i = actors->m_RenderCommands.begin( ); - for( ; i != actors->m_RenderCommands.end( ); ++i ) - i->first( i->second ); - } - break; - default: - break; - } // hctiws } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _EnterCommand( void* data ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) - return; - - actors->ResetCursor( ); - actors->m_CursorActor->VisibilityOn( ); - actors->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _LeaveCommand( void* data ) { - ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); - if( actors == NULL ) - return; - - actors->ResetCursor( ); - actors->m_CursorActor->VisibilityOff( ); - actors->Render( ); } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index b4cec90..4e29dc5 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -3,27 +3,22 @@ #include -#include +#include #include +#include #include #include -#include -#include -#include #include #include #include +#include -#include -#include +#define MAX_TEXT_BUFFER 1024 -// ------------------------------------------------------------------------- class vtkAlgorithmOutput; class vtkImageData; -class vtkLookupTable; class vtkRenderer; -// ------------------------------------------------------------------------- namespace cpExtensions { namespace Visualization @@ -35,7 +30,6 @@ namespace cpExtensions { public: typedef ImageSliceActors Self; - typedef cpExtensions::Interaction::ImageInteractorStyle TStyle; typedef TStyle::TMouseCommand TMouseCommand; typedef TStyle::TMouseWheelCommand TMouseWheelCommand; @@ -52,7 +46,28 @@ namespace cpExtensions typedef void ( *TWindowLevelCommand )( double, double, void* ); typedef TVoidCommand TRenderCommand; - typedef cpExtensions::Visualization::ImageBlender TBlender; + template< class _TSource > + struct SourceActor + { + vtkSmartPointer< _TSource > Source; + vtkSmartPointer< vtkPolyDataMapper > Mapper; + vtkSmartPointer< vtkActor > Actor; + void Create( ) + { + this->Source = vtkSmartPointer< _TSource >::New( ); + this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->Actor = vtkSmartPointer< vtkActor >::New( ); + this->Mapper->SetInputConnection( this->Source->GetOutputPort( ) ); + this->Actor->SetMapper( this->Mapper ); + } + void Modified( ) + { + this->Source->Modified( ); + this->Mapper->Modified( ); + this->Actor->Modified( ); + } + }; + public: vtkTypeMacro( ImageSliceActors, vtkPropCollection ); @@ -62,91 +77,41 @@ namespace cpExtensions cpExtensions_BaseInteractorStyle_Commands( Render ); public: - // Creation - static ImageSliceActors* New( ); - - void SetAxis( int axis ); - void SetInputConnection( vtkAlgorithmOutput* aout ); - void SetInputImage( vtkImageData* data ); - int AddBinaryConnection( - vtkAlgorithmOutput* aout, - const double& r, const double& g, const double& b - ); - int AddBinaryImage( - vtkImageData* data, - const double& r, const double& g, const double& b - ); + static Self* New( ); + void Clear( ); + void SetInputConnection( vtkAlgorithmOutput* aout, int orientation ); + void SetInputData( vtkImageData* data, int orientation ); void AssociateSlice( Self* slice ); + void CleanAssociatedSlices( ); - vtkImageData* GetInputImage( ); - const vtkImageData* GetInputImage( ) const; - - vtkInteractorStyle* GetStyle( ); - const vtkInteractorStyle* GetStyle( ) const; - - void PushActorsInto( vtkRenderWindow* window, bool force_style = true ); - void PopActorsFrom( vtkRenderWindow* window ); - unsigned int GetNumberOfImages( ) const; + TStyle* GetStyle( ); + void SetStyle( vtkInteractorStyle* st ); - vtkImageActor* GetImageActor( ); - const vtkImageActor* GetImageActor( ) const; - vtkImageActor* GetBinaryActor( ); - const vtkImageActor* GetBinaryActor( ) const; - vtkTextActor* GetTextActor( ); - const vtkTextActor* GetTextActor( ) const; - vtkActor* GetPlaneActor( ); - const vtkActor* GetPlaneActor( ) const; - vtkPlane* GetPlaneFunction( ); - const vtkPlane* GetPlaneFunction( ) const; + void PushInto( vtkRenderer* ren ); + void PopFrom( vtkRenderer* ren ); - void SetInterpolate( bool v ); - void InterpolateOn( ); - void InterpolateOff( ); + long GetSliceNumber( ) const; + void SetSliceNumber( long slice ); - double* GetDisplayBounds( ) const; - void GetDisplayBounds( double bounds[ 6 ] ) const; + void ShowPixelText( double* pos ); - void ResetCursor( ); - void SetCursor( double pos[ 3 ] ); - - void ResetAxesCursor( ); - void SetAxesCursor( double pos[ 3 ] ); - - double GetMinWindow( ) const; - double GetMaxWindow( ) const; - double GetMinLevel( ) const; - double GetMaxLevel( ) const; + void GetScalarRange( double r[ 2 ] ) const; + void SetScalarRange( const double& a, const double& b ); + void UnsetScalarRange( ); + void SetWindowLevel( const double& w, const double& l ); double GetWindow( ) const; double GetLevel( ) const; - void SetWindow( double w ); - void SetLevel( double l ); - void SetWindowLevel( double w, double l ); - void ResetWindowLevel( ); - - int GetAxis( ) const; - int GetSliceNumber( ) const; - int GetSliceNumberMinValue( ) const; - int GetSliceNumberMaxValue( ) const; - void SetSliceNumber( const int& slice ); - void SetSlice( double* pos ); - void UpdateText( ); - void UpdateText( double pos[ 3 ] ); - void UpdateText( const double& w, const double& l ); void Render( ); - void ResetCamera( ); protected: ImageSliceActors( ); virtual ~ImageSliceActors( ); - void _ConfigureStyle( ); - void _ConfigureInputImage( ); - void _ConfigureBinaryImage( - const double& r, const double& g, const double& b - ); + void _ConfigureInput( int orientation ); + void _ConfigureCursor( ); // Events static void _MouseMoveCommand( @@ -178,59 +143,37 @@ namespace cpExtensions Self& operator=( const Self& ); protected: - static double m_PlaneColors[ 3 ][ 3 ]; - - vtkSmartPointer< TStyle > m_Style; - vtkRenderWindow* m_Window; - - // Multiple actors - vtkSmartPointer< vtkImageSliceMapper > m_ImageMapper; - vtkSmartPointer< vtkImageActor > m_ImageActor; - - vtkSmartPointer< vtkImageData > m_BlenderBase; - vtkSmartPointer< TBlender > m_Blender; - vtkSmartPointer< vtkImageSliceMapper > m_BlenderMapper; - vtkSmartPointer< vtkLookupTable > m_BlenderLUT; - vtkSmartPointer< vtkImageActor > m_BlenderActor; - - bool m_Interpolate; - - double m_WLRange[ 4 ]; - - int m_VisibleExtent[ 6 ]; - double m_VisibleBounds[ 6 ]; - - // Associated slices - std::vector< Self* > m_AssociatedSlices; + // Main image + vtkSmartPointer< vtkImageSliceMapper > m_Mapper; + vtkSmartPointer< vtkImageActor > m_Actor; - // Unique objects - vtkSmartPointer< vtkPolyData > m_Cursor; - vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper; - vtkSmartPointer< vtkActor > m_CursorActor; + // Secondary slices + std::vector< vtkSmartPointer< Self > > m_AssociatedSlices; - vtkSmartPointer< vtkPolyData > m_Axis1; - vtkSmartPointer< vtkPolyDataMapper > m_Axis1Mapper; - vtkSmartPointer< vtkActor > m_Axis1Actor; + // Cursor + SourceActor< vtkCursor3D > m_Cursor; - vtkSmartPointer< vtkPolyData > m_Axis2; - vtkSmartPointer< vtkPolyDataMapper > m_Axis2Mapper; - vtkSmartPointer< vtkActor > m_Axis2Actor; + // Text + char m_TextBuffer[ MAX_TEXT_BUFFER ]; + vtkSmartPointer< vtkTextActor > m_TextActor; - vtkSmartPointer< vtkPolyData > m_Plane; - vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper; - vtkSmartPointer< vtkActor > m_PlaneActor; + // WindowLevel + double m_ScalarRange[ 2 ]; + bool m_ManualScalarRange; - char m_TextBuffer[ 1024 ]; - vtkSmartPointer< vtkTextActor > m_TextActor; + // Style + vtkSmartPointer< vtkInteractorStyle > m_Style; - double m_StartWindowLevelPos[ 3 ]; - double m_StartWindowLevel[ 2 ]; + // Events-related data + double m_StartMouseEvent[ 3 ]; + double m_StartWindow; + double m_StartLevel; }; } // ecapseman } // ecapseman -#endif // __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__ +#endif // __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__ // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index e26651b..d77543f 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -1,5 +1,6 @@ #include +/* #include #include #include @@ -496,5 +497,6 @@ _RenderCommand( void* data ) return; actors->Render( ); } +*/ // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index 91c0b50..295497c 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -10,6 +10,7 @@ namespace cpExtensions { /** */ + /* class cpExtensions_EXPORT MPRActors : public vtkPropCollection { @@ -118,6 +119,7 @@ namespace cpExtensions vtkSmartPointer< vtkActor > ImageOutlineActor; vtkSmartPointer< ImageSliceActors > Slices[ 2 ][ 3 ]; }; + */ } // ecapseman diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index 0727f22..49428e6 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -1,5 +1,6 @@ #include +/* #include #include #include @@ -90,6 +91,12 @@ Show( ) void cpExtensions::Visualization::MPRObjects:: Hide( ) { + this->m_MPRActors->PopActorsFrom( + this->m_Windows[ 0 ], + this->m_Windows[ 1 ], + this->m_Windows[ 2 ], + this->m_Windows[ 3 ] + ); } // ------------------------------------------------------------------------- @@ -306,7 +313,7 @@ cpExtensions::Visualization::MPRObjects:: { } - +*/ /* diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index c800fc1..10bf50b 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -21,6 +21,7 @@ namespace cpExtensions { /** */ + /* class cpExtensions_EXPORT MPRObjects : public vtkObject { @@ -127,6 +128,7 @@ namespace cpExtensions vtkSmartPointer< MPRActors > m_MPRActors; vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; }; + */ } // ecapseman diff --git a/lib/cpPipelineEditor/Editor.cxx b/lib/cpPipelineEditor/Editor.cxx index 319edb5..289ee46 100644 --- a/lib/cpPipelineEditor/Editor.cxx +++ b/lib/cpPipelineEditor/Editor.cxx @@ -283,6 +283,24 @@ showOutputData( emit showFilterOutput( filter_name, output_name ); } +// ------------------------------------------------------------------------- +void cpPipelineEditor::Editor:: +hideOutputData( + const std::string& filter_name, const std::string& output_name + ) +{ + emit hideFilterOutput( filter_name, output_name ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Editor:: +visualPropertiesOutputData( + const std::string& filter_name, const std::string& output_name + ) +{ + emit visualPropertiesFilterOutput( filter_name, output_name ); +} + // ------------------------------------------------------------------------- cpPipelineEditor_Editor_Callback_CODE( ContextMenu ) { diff --git a/lib/cpPipelineEditor/Editor.h b/lib/cpPipelineEditor/Editor.h index 3429477..cea95cb 100644 --- a/lib/cpPipelineEditor/Editor.h +++ b/lib/cpPipelineEditor/Editor.h @@ -71,6 +71,14 @@ namespace cpPipelineEditor const std::string& filter_name, const std::string& output_name ); + void hideOutputData( + const std::string& filter_name, + const std::string& output_name + ); + void visualPropertiesOutputData( + const std::string& filter_name, + const std::string& output_name + ); signals: void execFilter( const std::string& filter_name ); @@ -78,6 +86,14 @@ namespace cpPipelineEditor const std::string& filter_name, const std::string& output_name ); + void hideFilterOutput( + const std::string& filter_name, + const std::string& output_name + ); + void visualPropertiesFilterOutput( + const std::string& filter_name, + const std::string& output_name + ); private: QGraphicsItem* itemAt( const QPointF& pos ); diff --git a/lib/cpPipelineEditor/Port.cxx b/lib/cpPipelineEditor/Port.cxx index b447b0a..1eb2c78 100644 --- a/lib/cpPipelineEditor/Port.cxx +++ b/lib/cpPipelineEditor/Port.cxx @@ -275,6 +275,7 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) QMenu menu; QAction* showAction = menu.addAction( "Show" ); QAction* hideAction = menu.addAction( "Hide" ); + QAction* propertiesAction = menu.addAction( "Properties" ); QAction* selectedAction = menu.exec( evt->screenPos( ) ); if( selectedAction == showAction ) @@ -286,6 +287,18 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) } else if( selectedAction == hideAction ) { + this->m_Block->editor( )->hideOutputData( + this->m_Block->namePort( ).toStdString( ), + this->name( ).toStdString( ) + ); + } + else if( selectedAction == propertiesAction ) + { + this->m_Block->editor( )->visualPropertiesOutputData( + this->m_Block->namePort( ).toStdString( ), + this->name( ).toStdString( ) + ); + } // fi } diff --git a/lib/cpPlugins/BaseWidget.cxx b/lib/cpPlugins/BaseWidget.cxx index faebdce..b8485c4 100644 --- a/lib/cpPlugins/BaseWidget.cxx +++ b/lib/cpPlugins/BaseWidget.cxx @@ -1,5 +1,7 @@ #include +#ifdef cpPlugins_QT4 + // ------------------------------------------------------------------------- const cpPlugins::BaseWidget::TMPRWidget* cpPlugins::BaseWidget:: GetMPRViewer( ) const @@ -81,4 +83,6 @@ cpPlugins::BaseWidget:: this->m_SingleInteractor = NULL; } +#endif // cpPlugins_QT4 + // eof - $RCSfile$ diff --git a/lib/cpPlugins/BaseWidget.h b/lib/cpPlugins/BaseWidget.h index 0d679c0..a2b8bd2 100644 --- a/lib/cpPlugins/BaseWidget.h +++ b/lib/cpPlugins/BaseWidget.h @@ -1,6 +1,10 @@ #ifndef __CPPLUGINS__BASEWIDGET__H__ #define __CPPLUGINS__BASEWIDGET__H__ +#include + +#ifdef cpPlugins_QT4 + #include // Some forward declarations @@ -60,6 +64,8 @@ namespace cpPlugins } // ecapseman +#endif // cpPlugins_QT4 + #endif // __CPPLUGINS__BASEWIDGET__H__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 9a2f709..53b7b11 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -6,6 +6,7 @@ # include #endif // cpPlugins_SYS_WINDOWS #include +#include // ------------------------------------------------------------------------- cpPlugins::Interface:: diff --git a/plugins/cpPluginsIO/MeshReader.cxx b/plugins/cpPluginsIO/MeshReader.cxx index eead3da..6eb04da 100644 --- a/plugins/cpPluginsIO/MeshReader.cxx +++ b/plugins/cpPluginsIO/MeshReader.cxx @@ -1,6 +1,7 @@ #include #include +#include #include #include diff --git a/plugins/cpPluginsIO/MeshWriter.cxx b/plugins/cpPluginsIO/MeshWriter.cxx index 699d382..7cddc75 100644 --- a/plugins/cpPluginsIO/MeshWriter.cxx +++ b/plugins/cpPluginsIO/MeshWriter.cxx @@ -1,6 +1,7 @@ #include #include +#include #include #include