1 #include <cpExtensions/QT/SimpleMPRWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <cpExtensions/ui_SimpleMPRWidget.h>
6 #include <vtkRenderWindow.h>
9 #include <vtkProperty.h>
10 #include <vtkRendererCollection.h>
11 double cpExtensions::QT::SimpleMPRWidget::
25 // -------------------------------------------------------------------------
26 cpExtensions::QT::SimpleMPRWidget::
27 SimpleMPRWidget( QWidget* parent )
29 m_UI( new Ui::SimpleMPRWidget )
35 this->m_UI->setupUi( this );
37 // Configure VTK widgets
38 this->m_VTK[ 0 ] = this->m_UI->VTK01;
39 this->m_VTK[ 1 ] = this->m_UI->VTK00;
40 this->m_VTK[ 2 ] = this->m_UI->VTK10;
41 this->m_VTK[ 3 ] = this->m_UI->VTK11;
43 for( unsigned int i = 0; i < 4; ++i )
45 this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
46 this->m_VTK[ i ]->GetRenderWindow( )->AddRenderer( this->m_Renderers[ i ] );
51 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
52 this->m_MPRObjects->SetRenderWindows(
53 this->m_VTK[ 0 ]->GetRenderWindow( ),
54 this->m_VTK[ 1 ]->GetRenderWindow( ),
55 this->m_VTK[ 2 ]->GetRenderWindow( ),
56 this->m_VTK[ 3 ]->GetRenderWindow( )
62 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
63 this, SLOT( _SyncBottom( int, int ) )
66 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
67 this, SLOT( _SyncTop( int, int ) )
71 // -------------------------------------------------------------------------
72 cpExtensions::QT::SimpleMPRWidget::
78 // -------------------------------------------------------------------------
79 void cpExtensions::QT::SimpleMPRWidget::
82 for( unsigned int i = 0; i < 4; ++i )
83 this->m_Renderers[ i ]->RemoveAllViewProps( );
84 for( unsigned int i = 0; i < 3; ++i )
86 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
87 this->m_2DSlices[ i ]->Clear( );
88 if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
89 this->m_3DSlices[ i ]->Clear( );
92 this->m_PolyDatas.clear( );
95 // -------------------------------------------------------------------------
96 void cpExtensions::QT::SimpleMPRWidget::
97 SetMainImage( vtkImageData* image )
99 for( unsigned int i = 0; i < 3; ++i )
101 this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
102 this->m_2DSlices[ i ]->SetInputData( image, i );
103 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
104 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
105 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
107 this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
108 this->m_3DSlices[ i ]->SetInputData( image, i );
109 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
110 this->m_3DSlices[ i ]->SetStyle(
111 dynamic_cast< vtkInteractorStyle* >(
112 this->m_Renderers[ 3 ]->GetRenderWindow( )->
113 GetInteractor( )->GetInteractorStyle( )
119 for( unsigned int i = 0; i < 3; ++i )
121 for( unsigned int j = 0; j < 3; ++j )
124 this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
125 this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
130 for( unsigned int i = 0; i < 3; ++i )
132 this->m_2DSlices[ i ]->GetStyle( )->
133 SetCurrentRenderer( this->m_Renderers[ i ] );
134 this->m_Renderers[ i ]->ResetCamera( );
135 this->m_VTK[ i ]->GetRenderWindow( )->Render( );
138 this->m_Renderers[ 3 ]->ResetCamera( );
139 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
142 // -------------------------------------------------------------------------
143 void cpExtensions::QT::SimpleMPRWidget::
144 AddMesh( vtkPolyData* mesh )
148 this->m_PolyDatas[ mesh ] = a;
149 this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
151 bool has_main_image = false;
152 for( unsigned int i = 0; i < 3; ++i )
154 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
156 if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
158 has_main_image = true;
159 this->m_2DSlices[ i ]->AddMesh( mesh );
160 this->m_2DSlices[ i ]->Render( );
167 if( !has_main_image )
168 this->m_Renderers[ 3 ]->ResetCamera( );
169 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
172 // -------------------------------------------------------------------------
173 void cpExtensions::QT::SimpleMPRWidget::
174 _SyncBottom( int a, int b )
176 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
179 // -------------------------------------------------------------------------
180 void cpExtensions::QT::SimpleMPRWidget::
181 _SyncTop( int a, int b )
183 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
186 #endif // cpExtensions_QT4