1 #include <cpExtensions/QT/SimpleMPRWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <cpExtensions/ui_SimpleMPRWidget.h>
6 #include <vtkRenderWindow.h>
8 // -------------------------------------------------------------------------
9 cpExtensions::QT::SimpleMPRWidget::
10 SimpleMPRWidget( QWidget* parent )
12 m_UI( new Ui::SimpleMPRWidget )
14 this->m_UI->setupUi( this );
16 // Configure VTK widgets
17 this->m_VTK[ 0 ] = this->m_UI->VTK_X;
18 this->m_VTK[ 1 ] = this->m_UI->VTK_Y;
19 this->m_VTK[ 2 ] = this->m_UI->VTK_Z;
20 this->m_VTK[ 3 ] = this->m_UI->VTK_3D;
22 for( unsigned int i = 0; i < 4; ++i )
24 this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
25 this->m_VTK[ i ]->GetRenderWindow( )->
26 AddRenderer( this->m_Renderers[ i ] );
32 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
33 this, SLOT( _SyncBottom( int, int ) )
36 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
37 this, SLOT( _SyncTop( int, int ) )
41 // -------------------------------------------------------------------------
42 cpExtensions::QT::SimpleMPRWidget::
48 // -------------------------------------------------------------------------
49 void cpExtensions::QT::SimpleMPRWidget::
52 for( unsigned int i = 0; i < 4; ++i )
53 this->m_Renderers[ i ]->RemoveAllViewProps( );
54 for( unsigned int i = 0; i < 3; ++i )
56 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
57 this->m_2DSlices[ i ]->Clear( );
58 if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
59 this->m_3DSlices[ i ]->Clear( );
62 this->m_PolyDatas.clear( );
65 // -------------------------------------------------------------------------
66 void cpExtensions::QT::SimpleMPRWidget::
67 SetMainImage( vtkImageData* image )
70 for( unsigned int i = 0; i < 3; ++i )
72 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
73 this->m_2DSlices[ i ]->SetInputData( image, i );
74 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
75 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
76 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
78 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
79 this->m_3DSlices[ i ]->SetInputData( image, i );
80 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
81 this->m_3DSlices[ i ]->SetStyle(
82 dynamic_cast< vtkInteractorStyle* >(
83 this->m_Renderers[ 3 ]->GetRenderWindow( )->
84 GetInteractor( )->GetInteractorStyle( )
89 this->_AssociateSlices( );
92 // -------------------------------------------------------------------------
93 void cpExtensions::QT::SimpleMPRWidget::
94 SetMainActor( vtkImageActor* actor )
97 vtkImageData* image = NULL;
98 for( unsigned int i = 0; i < 3; ++i )
100 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
103 this->m_2DSlices[ i ]->SetInputActor( actor, i );
104 image = this->m_2DSlices[ i ]->GetInputData( );
107 this->m_2DSlices[ i ]->SetInputData( image, i );
108 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
109 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
110 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
112 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
113 this->m_3DSlices[ i ]->SetInputData( image, i );
114 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
115 this->m_3DSlices[ i ]->SetStyle(
116 dynamic_cast< vtkInteractorStyle* >(
117 this->m_Renderers[ 3 ]->GetRenderWindow( )->
118 GetInteractor( )->GetInteractorStyle( )
123 this->_AssociateSlices( );
126 // -------------------------------------------------------------------------
127 void cpExtensions::QT::SimpleMPRWidget::
128 AddImage( vtkImageData* image )
130 std::cerr << "SimpleMPR: adding image" << std::endl;
134 // -------------------------------------------------------------------------
135 void cpExtensions::QT::SimpleMPRWidget::
136 AddImageActor( vtkImageActor* actor )
140 while( i < 3 && cont )
142 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
144 if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL )
146 // TODO: add image actor
156 // Add if no actors were found
158 this->SetMainActor( actor );
161 // -------------------------------------------------------------------------
162 void cpExtensions::QT::SimpleMPRWidget::
163 AddMesh( vtkPolyData* mesh )
165 std::cerr << "SimpleMPR: adding mesh" << std::endl;
170 this->m_PolyDatas[ mesh ] = a;
171 this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
173 bool has_main_image = false;
174 for( unsigned int i = 0; i < 3; ++i )
176 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
178 if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
180 has_main_image = true;
181 this->m_2DSlices[ i ]->AddMesh( mesh );
182 this->m_2DSlices[ i ]->Render( );
189 if( !has_main_image )
190 this->m_Renderers[ 3 ]->ResetCamera( );
191 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
195 // -------------------------------------------------------------------------
196 void cpExtensions::QT::SimpleMPRWidget::
197 AddMeshActor( vtkActor* actor )
199 std::cerr << "SimpleMPR: adding mesh actor" << std::endl;
203 // -------------------------------------------------------------------------
204 void cpExtensions::QT::SimpleMPRWidget::
205 AddActor( vtkProp* actor )
207 auto ia = dynamic_cast< vtkImageActor* >( actor );
210 auto ma = dynamic_cast< vtkActor* >( actor );
212 this->AddMeshActor( ma );
215 this->AddImageActor( ia );
218 // -------------------------------------------------------------------------
219 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
220 GetInteractor( unsigned int i )
223 return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
228 // -------------------------------------------------------------------------
229 vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
230 GetRenderer( unsigned int i )
233 return( this->m_Renderers[ i ] );
238 // -------------------------------------------------------------------------
239 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
240 GetRenderWindow( unsigned int i )
244 if( this->m_Renderers[ i ].GetPointer( ) != NULL )
245 return( this->m_Renderers[ i ]->GetRenderWindow( ) );
253 // -------------------------------------------------------------------------
255 std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
256 cpExtensions::QT::SimpleMPRWidget::
257 GetMainImageActors( )
259 std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
260 for( unsigned int i = 0; i < 3; ++i )
263 std::pair< vtkImageActor*, vtkRenderer* >(
264 this->m_2DSlices[ i ]->GetImageActor( ),
265 this->m_Renderers[ i ]
269 std::pair< vtkImageActor*, vtkRenderer* >(
270 this->m_3DSlices[ i ]->GetImageActor( ),
271 this->m_Renderers[ 3 ]
280 // -------------------------------------------------------------------------
282 vtkActor* cpExtensions::QT::SimpleMPRWidget::
283 GetActor( vtkPolyData* mesh )
285 auto i = this->m_PolyDatas.find( mesh );
286 if( i != this->m_PolyDatas.end( ) )
287 return( i->second.Actor.GetPointer( ) );
293 // -------------------------------------------------------------------------
294 void cpExtensions::QT::SimpleMPRWidget::
297 for( unsigned int i = 0; i < 3; ++i )
299 for( unsigned int j = 0; j < 3; ++j )
302 this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
303 this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
308 for( unsigned int i = 0; i < 3; ++i )
310 this->m_2DSlices[ i ]->GetStyle( )->
311 SetCurrentRenderer( this->m_Renderers[ i ] );
312 this->m_Renderers[ i ]->ResetCamera( );
313 this->m_VTK[ i ]->GetRenderWindow( )->Render( );
316 this->m_Renderers[ 3 ]->ResetCamera( );
317 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
320 // -------------------------------------------------------------------------
321 void cpExtensions::QT::SimpleMPRWidget::
322 _SyncBottom( int a, int b )
324 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
327 // -------------------------------------------------------------------------
328 void cpExtensions::QT::SimpleMPRWidget::
329 _SyncTop( int a, int b )
331 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
334 #endif // cpExtensions_QT4