X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FQT%2FSimpleMPRWidget.cxx;h=7e338bc0b77c486e8f2c813f3f20383b838e0580;hb=f47059eb39b5c9eef5cd2ee1b6c013cd75eff97f;hp=f838a2ea704c118576580bd39897728d1f5277f1;hpb=28f9b7dc84eb4b09e985ad7e43a9f0001a6be928;p=cpPlugins.git diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index f838a2e..7e338bc 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,8 +3,31 @@ #ifdef cpExtensions_QT4 #include +#include #include +// ------------------------------------------------------------------------- +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle* +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +New( ) +{ + return( new _3DInteractorStyle( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +OnKeyPress( ) +{ + vtkRenderWindowInteractor* i = this->Interactor; + std::string key = i->GetKeySym( ); + if( key == "r" || key == "R" ) + { + this->CurrentRenderer->ResetCamera( ); + i->Render( ); + + } // fi +} + // ------------------------------------------------------------------------- cpExtensions::QT::SimpleMPRWidget:: SimpleMPRWidget( QWidget* parent ) @@ -18,7 +41,6 @@ SimpleMPRWidget( QWidget* parent ) this->m_VTK[ 1 ] = this->m_UI->VTK_Y; this->m_VTK[ 2 ] = this->m_UI->VTK_Z; this->m_VTK[ 3 ] = this->m_UI->VTK_3D; - for( unsigned int i = 0; i < 4; ++i ) { this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); @@ -26,6 +48,11 @@ SimpleMPRWidget( QWidget* parent ) AddRenderer( this->m_Renderers[ i ] ); } // rof + vtkSmartPointer< _3DInteractorStyle > style = + vtkSmartPointer< _3DInteractorStyle >::New( ); + this->m_VTK[ 3 ]->GetRenderWindow( )-> + GetInteractor( )->SetInteractorStyle( style ); + style->SetCurrentRenderer( this->m_Renderers[ 3 ] ); // Connect slots QObject::connect( @@ -42,6 +69,7 @@ SimpleMPRWidget( QWidget* parent ) cpExtensions::QT::SimpleMPRWidget:: ~SimpleMPRWidget( ) { + this->Clear( ); delete this->m_UI; } @@ -59,12 +87,12 @@ Clear( ) this->m_3DSlices[ i ]->Clear( ); } // rof - this->m_PolyDatas.clear( ); + this->m_NamedActors.clear( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -SetMainImage( vtkImageData* image ) +SetMainImage( vtkImageData* image, const std::string& name ) { this->Clear( ); for( unsigned int i = 0; i < 3; ++i ) @@ -85,13 +113,20 @@ SetMainImage( vtkImageData* image ) ) ); + this->m_NamedActors[ name ].insert( + this->m_2DSlices[ i ]->GetImageActor( ) + ); + this->m_NamedActors[ name ].insert( + this->m_3DSlices[ i ]->GetImageActor( ) + ); + } // rof this->_AssociateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -SetMainActor( vtkImageActor* actor ) +SetMainActor( vtkImageActor* actor, const std::string& name ) { this->Clear( ); vtkImageData* image = NULL; @@ -119,13 +154,20 @@ SetMainActor( vtkImageActor* actor ) ) ); + this->m_NamedActors[ name ].insert( + this->m_2DSlices[ i ]->GetImageActor( ) + ); + this->m_NamedActors[ name ].insert( + this->m_3DSlices[ i ]->GetImageActor( ) + ); + } // rof this->_AssociateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddImage( vtkImageData* image ) +AddImage( vtkImageData* image, const std::string& name ) { std::cerr << "SimpleMPR: adding image" << std::endl; std::exit( 1 ); @@ -133,7 +175,7 @@ AddImage( vtkImageData* image ) // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddImageActor( vtkImageActor* actor ) +AddImageActor( vtkImageActor* actor, const std::string& name ) { unsigned int i = 0; bool cont = true; @@ -155,12 +197,12 @@ AddImageActor( vtkImageActor* actor ) // Add if no actors were found if( cont ) - this->SetMainActor( actor ); + this->SetMainActor( actor, name ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddMesh( vtkPolyData* mesh ) +AddMesh( vtkPolyData* mesh, const std::string& name ) { std::cerr << "SimpleMPR: adding mesh" << std::endl; std::exit( 1 ); @@ -194,25 +236,54 @@ AddMesh( vtkPolyData* mesh ) // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddMeshActor( vtkActor* actor ) +AddMeshActor( vtkProp3D* actor, const std::string& name ) { - std::cerr << "SimpleMPR: adding mesh actor" << std::endl; - std::exit( 1 ); + if( actor != NULL ) + { + std::cout << name << " " << actor << std::endl; + + this->m_Renderers[ 3 ]->AddViewProp( actor ); + this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + this->m_NamedActors[ name ].insert( actor ); + std::cout << "Size: " << this->m_NamedActors.size( ) << " " << this->m_NamedActors[ name ].size( ) << std::endl; + + + double bounds[ 6 ]; + this->m_Renderers[ 3 ]->ComputeVisiblePropBounds( bounds ); + std::cout + << bounds[ 0 ] << " " << bounds[ 1 ] << " " + << bounds[ 2 ] << " " << bounds[ 3 ] << " " + << bounds[ 4 ] << " " << bounds[ 5 ] << std::endl; + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddActor( vtkProp* actor ) +AddActor( vtkProp* actor, const std::string& name ) { auto ia = dynamic_cast< vtkImageActor* >( actor ); if( ia == NULL ) { - auto ma = dynamic_cast< vtkActor* >( actor ); + auto ma = dynamic_cast< vtkProp3D* >( actor ); if( ma != NULL ) - this->AddMeshActor( ma ); + this->AddMeshActor( ma, name ); } else - this->AddImageActor( ia ); + this->AddImageActor( ia, name ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::QT::SimpleMPRWidget:: +TActors& cpExtensions::QT::SimpleMPRWidget:: +GetActors( const std::string& name ) const +{ + static const TActors empty; + auto i = this->m_NamedActors.find( name ); + if( i != this->m_NamedActors.end( ) ) + return( i->second ); + else + return( empty ); } // -------------------------------------------------------------------------