#include #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 ) : QWidget( parent ), m_UI( new Ui::SimpleMPRWidget ) { this->m_UI->setupUi( this ); // Configure VTK widgets this->m_VTK[ 0 ] = this->m_UI->VTK_X; 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( ); this->m_VTK[ i ]->GetRenderWindow( )-> 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( this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncBottom( int, int ) ) ); QObject::connect( this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncTop( int, int ) ) ); } // ------------------------------------------------------------------------- cpExtensions::QT::SimpleMPRWidget:: ~SimpleMPRWidget( ) { this->Clear( ); delete this->m_UI; } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: Clear( ) { for( unsigned int i = 0; i < 4; ++i ) this->m_Renderers[ i ]->RemoveAllViewProps( ); for( unsigned int i = 0; i < 3; ++i ) { if( this->m_2DSlices[ i ].GetPointer( ) != NULL ) this->m_2DSlices[ i ]->Clear( ); if( this->m_3DSlices[ i ].GetPointer( ) != NULL ) this->m_3DSlices[ i ]->Clear( ); } // rof this->m_NamedActors.clear( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: SetMainImage( vtkImageData* image, const std::string& name ) { this->Clear( ); for( unsigned int i = 0; i < 3; ++i ) { this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::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< TSliceActors >::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( ) ) ); 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, const std::string& name ) { this->Clear( ); vtkImageData* image = NULL; for( unsigned int i = 0; i < 3; ++i ) { this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); if( i == 0 ) { this->m_2DSlices[ i ]->SetInputActor( actor, i ); image = this->m_2DSlices[ i ]->GetInputData( ); } else 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< TSliceActors >::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( ) ) ); 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, const std::string& name ) { std::cerr << "SimpleMPR: adding image" << std::endl; std::exit( 1 ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: AddImageActor( vtkImageActor* actor, const std::string& name ) { unsigned int i = 0; bool cont = true; while( i < 3 && cont ) { if( this->m_2DSlices[ i ].GetPointer( ) != NULL ) { if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL ) { // TODO: add image actor } else cont = false; } // fi i++; } // rof // Add if no actors were found if( cont ) this->SetMainActor( actor, name ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: AddMesh( vtkPolyData* mesh, const std::string& name ) { std::cerr << "SimpleMPR: adding mesh" << std::endl; std::exit( 1 ); /* TODO PolyDataActor a; a.Configure( mesh ); this->m_PolyDatas[ mesh ] = a; this->m_Renderers[ 3 ]->AddViewProp( a.Actor ); bool has_main_image = false; for( unsigned int i = 0; i < 3; ++i ) { if( this->m_2DSlices[ i ].GetPointer( ) != NULL ) { if( this->m_2DSlices[ i ]->GetInputData( ) != NULL ) { has_main_image = true; this->m_2DSlices[ i ]->AddMesh( mesh ); this->m_2DSlices[ i ]->Render( ); } // fi } // fi } // rof if( !has_main_image ) this->m_Renderers[ 3 ]->ResetCamera( ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); */ } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: AddMeshActor( vtkProp3D* actor, const std::string& name ) { 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, const std::string& name ) { auto ia = dynamic_cast< vtkImageActor* >( actor ); if( ia == NULL ) { auto ma = dynamic_cast< vtkProp3D* >( actor ); if( ma != NULL ) this->AddMeshActor( ma, name ); } else 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 ); } // ------------------------------------------------------------------------- vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget:: GetInteractor( unsigned int i ) { if( i < 4 ) return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) ); else return( NULL ); } // ------------------------------------------------------------------------- vtkRenderer* cpExtensions::QT::SimpleMPRWidget:: GetRenderer( unsigned int i ) { if( i < 4 ) return( this->m_Renderers[ i ] ); else return( NULL ); } // ------------------------------------------------------------------------- vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget:: GetRenderWindow( unsigned int i ) { if( i < 4 ) { if( this->m_Renderers[ i ].GetPointer( ) != NULL ) return( this->m_Renderers[ i ]->GetRenderWindow( ) ); else return( NULL ); } else return( NULL ); } // ------------------------------------------------------------------------- /* TODO std::vector< std::pair< vtkImageActor*, vtkRenderer* > > cpExtensions::QT::SimpleMPRWidget:: GetMainImageActors( ) { std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors; for( unsigned int i = 0; i < 3; ++i ) { actors.push_back( std::pair< vtkImageActor*, vtkRenderer* >( this->m_2DSlices[ i ]->GetImageActor( ), this->m_Renderers[ i ] ) ); actors.push_back( std::pair< vtkImageActor*, vtkRenderer* >( this->m_3DSlices[ i ]->GetImageActor( ), this->m_Renderers[ 3 ] ) ); } // rof return( actors ); } */ // ------------------------------------------------------------------------- /* TODO vtkActor* cpExtensions::QT::SimpleMPRWidget:: GetActor( vtkPolyData* mesh ) { auto i = this->m_PolyDatas.find( mesh ); if( i != this->m_PolyDatas.end( ) ) return( i->second.Actor.GetPointer( ) ); else return( NULL ); } */ // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: _AssociateSlices( ) { for( unsigned int i = 0; i < 3; ++i ) { for( unsigned int j = 0; j < 3; ++j ) { if( i != j ) this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] ); this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] ); } // rof } // rof for( unsigned int i = 0; i < 3; ++i ) { this->m_2DSlices[ i ]->GetStyle( )-> SetCurrentRenderer( this->m_Renderers[ i ] ); this->m_Renderers[ i ]->ResetCamera( ); this->m_VTK[ i ]->GetRenderWindow( )->Render( ); } // rof this->m_Renderers[ 3 ]->ResetCamera( ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: _SyncBottom( int a, int b ) { this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: _SyncTop( int a, int b ) { this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) ); } #endif // cpExtensions_QT4 // eof - $RCSfile$