1 #include <cpExtensions/QT/SimpleMPRWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <cpExtensions/ui_SimpleMPRWidget.h>
6 #include <vtkRenderer.h>
7 #include <vtkRenderWindow.h>
9 // -------------------------------------------------------------------------
10 cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle*
11 cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle::
14 return( new _3DInteractorStyle( ) );
17 // -------------------------------------------------------------------------
18 void cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle::
21 vtkRenderWindowInteractor* i = this->Interactor;
22 std::string key = i->GetKeySym( );
23 if( key == "r" || key == "R" )
25 this->CurrentRenderer->ResetCamera( );
31 // -------------------------------------------------------------------------
32 cpExtensions::QT::SimpleMPRWidget::
33 SimpleMPRWidget( QWidget* parent )
35 m_UI( new Ui::SimpleMPRWidget )
37 this->m_UI->setupUi( this );
39 // Configure VTK widgets
40 this->m_VTK[ 0 ] = this->m_UI->VTK_X;
41 this->m_VTK[ 1 ] = this->m_UI->VTK_Y;
42 this->m_VTK[ 2 ] = this->m_UI->VTK_Z;
43 this->m_VTK[ 3 ] = this->m_UI->VTK_3D;
44 for( unsigned int i = 0; i < 4; ++i )
46 this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
47 this->m_VTK[ i ]->GetRenderWindow( )->
48 AddRenderer( this->m_Renderers[ i ] );
51 vtkSmartPointer< _3DInteractorStyle > style =
52 vtkSmartPointer< _3DInteractorStyle >::New( );
53 this->m_VTK[ 3 ]->GetRenderWindow( )->
54 GetInteractor( )->SetInteractorStyle( style );
55 style->SetCurrentRenderer( this->m_Renderers[ 3 ] );
59 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
60 this, SLOT( _SyncBottom( int, int ) )
63 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
64 this, SLOT( _SyncTop( int, int ) )
68 // -------------------------------------------------------------------------
69 cpExtensions::QT::SimpleMPRWidget::
76 // -------------------------------------------------------------------------
77 void cpExtensions::QT::SimpleMPRWidget::
80 for( unsigned int i = 0; i < 4; ++i )
81 this->m_Renderers[ i ]->RemoveAllViewProps( );
82 for( unsigned int i = 0; i < 3; ++i )
84 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
85 this->m_2DSlices[ i ]->Clear( );
86 if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
87 this->m_3DSlices[ i ]->Clear( );
90 this->m_NamedActors.clear( );
93 // -------------------------------------------------------------------------
94 void cpExtensions::QT::SimpleMPRWidget::
95 SetMainImage( vtkImageData* image, const std::string& name )
98 for( unsigned int i = 0; i < 3; ++i )
100 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
101 this->m_2DSlices[ i ]->SetInputData( image, i );
102 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
103 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
104 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
106 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
107 this->m_3DSlices[ i ]->SetInputData( image, i );
108 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
109 this->m_3DSlices[ i ]->SetStyle(
110 dynamic_cast< vtkInteractorStyle* >(
111 this->m_Renderers[ 3 ]->GetRenderWindow( )->
112 GetInteractor( )->GetInteractorStyle( )
116 this->m_NamedActors[ name ].insert(
117 this->m_2DSlices[ i ]->GetImageActor( )
119 this->m_NamedActors[ name ].insert(
120 this->m_3DSlices[ i ]->GetImageActor( )
124 this->_AssociateSlices( );
127 // -------------------------------------------------------------------------
128 void cpExtensions::QT::SimpleMPRWidget::
129 SetMainActor( vtkImageActor* actor, const std::string& name )
132 vtkImageData* image = NULL;
133 for( unsigned int i = 0; i < 3; ++i )
135 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
138 this->m_2DSlices[ i ]->SetInputActor( actor, i );
139 image = this->m_2DSlices[ i ]->GetInputData( );
142 this->m_2DSlices[ i ]->SetInputData( image, i );
143 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
144 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
145 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
147 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
148 this->m_3DSlices[ i ]->SetInputData( image, i );
149 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
150 this->m_3DSlices[ i ]->SetStyle(
151 dynamic_cast< vtkInteractorStyle* >(
152 this->m_Renderers[ 3 ]->GetRenderWindow( )->
153 GetInteractor( )->GetInteractorStyle( )
157 this->m_NamedActors[ name ].insert(
158 this->m_2DSlices[ i ]->GetImageActor( )
160 this->m_NamedActors[ name ].insert(
161 this->m_3DSlices[ i ]->GetImageActor( )
165 this->_AssociateSlices( );
168 // -------------------------------------------------------------------------
169 void cpExtensions::QT::SimpleMPRWidget::
170 AddImage( vtkImageData* image, const std::string& name )
172 std::cerr << "SimpleMPR: adding image" << std::endl;
176 // -------------------------------------------------------------------------
177 void cpExtensions::QT::SimpleMPRWidget::
178 AddImageActor( vtkImageActor* actor, const std::string& name )
182 while( i < 3 && cont )
184 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
186 if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL )
188 // TODO: add image actor
198 // Add if no actors were found
200 this->SetMainActor( actor, name );
203 // -------------------------------------------------------------------------
204 void cpExtensions::QT::SimpleMPRWidget::
205 AddMesh( vtkPolyData* mesh, const std::string& name )
207 std::cerr << "SimpleMPR: adding mesh" << std::endl;
212 this->m_PolyDatas[ mesh ] = a;
213 this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
215 bool has_main_image = false;
216 for( unsigned int i = 0; i < 3; ++i )
218 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
220 if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
222 has_main_image = true;
223 this->m_2DSlices[ i ]->AddMesh( mesh );
224 this->m_2DSlices[ i ]->Render( );
231 if( !has_main_image )
232 this->m_Renderers[ 3 ]->ResetCamera( );
233 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
237 // -------------------------------------------------------------------------
238 void cpExtensions::QT::SimpleMPRWidget::
239 AddMeshActor( vtkProp3D* actor, const std::string& name )
243 std::cout << name << " " << actor << std::endl;
245 this->m_Renderers[ 3 ]->AddViewProp( actor );
246 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
247 this->m_NamedActors[ name ].insert( actor );
248 std::cout << "Size: " << this->m_NamedActors.size( ) << " " << this->m_NamedActors[ name ].size( ) << std::endl;
252 this->m_Renderers[ 3 ]->ComputeVisiblePropBounds( bounds );
254 << bounds[ 0 ] << " " << bounds[ 1 ] << " "
255 << bounds[ 2 ] << " " << bounds[ 3 ] << " "
256 << bounds[ 4 ] << " " << bounds[ 5 ] << std::endl;
261 // -------------------------------------------------------------------------
262 void cpExtensions::QT::SimpleMPRWidget::
263 AddActor( vtkProp* actor, const std::string& name )
265 auto ia = dynamic_cast< vtkImageActor* >( actor );
268 auto ma = dynamic_cast< vtkProp3D* >( actor );
270 this->AddMeshActor( ma, name );
273 this->AddImageActor( ia, name );
276 // -------------------------------------------------------------------------
277 const cpExtensions::QT::SimpleMPRWidget::
278 TActors& cpExtensions::QT::SimpleMPRWidget::
279 GetActors( const std::string& name ) const
281 static const TActors empty;
282 auto i = this->m_NamedActors.find( name );
283 if( i != this->m_NamedActors.end( ) )
289 // -------------------------------------------------------------------------
290 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
291 GetInteractor( unsigned int i )
294 return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
299 // -------------------------------------------------------------------------
300 vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
301 GetRenderer( unsigned int i )
304 return( this->m_Renderers[ i ] );
309 // -------------------------------------------------------------------------
310 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
311 GetRenderWindow( unsigned int i )
315 if( this->m_Renderers[ i ].GetPointer( ) != NULL )
316 return( this->m_Renderers[ i ]->GetRenderWindow( ) );
324 // -------------------------------------------------------------------------
326 std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
327 cpExtensions::QT::SimpleMPRWidget::
328 GetMainImageActors( )
330 std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
331 for( unsigned int i = 0; i < 3; ++i )
334 std::pair< vtkImageActor*, vtkRenderer* >(
335 this->m_2DSlices[ i ]->GetImageActor( ),
336 this->m_Renderers[ i ]
340 std::pair< vtkImageActor*, vtkRenderer* >(
341 this->m_3DSlices[ i ]->GetImageActor( ),
342 this->m_Renderers[ 3 ]
351 // -------------------------------------------------------------------------
353 vtkActor* cpExtensions::QT::SimpleMPRWidget::
354 GetActor( vtkPolyData* mesh )
356 auto i = this->m_PolyDatas.find( mesh );
357 if( i != this->m_PolyDatas.end( ) )
358 return( i->second.Actor.GetPointer( ) );
364 // -------------------------------------------------------------------------
365 void cpExtensions::QT::SimpleMPRWidget::
368 for( unsigned int i = 0; i < 3; ++i )
370 for( unsigned int j = 0; j < 3; ++j )
373 this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
374 this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
379 for( unsigned int i = 0; i < 3; ++i )
381 this->m_2DSlices[ i ]->GetStyle( )->
382 SetCurrentRenderer( this->m_Renderers[ i ] );
383 this->m_Renderers[ i ]->ResetCamera( );
384 this->m_VTK[ i ]->GetRenderWindow( )->Render( );
387 this->m_Renderers[ 3 ]->ResetCamera( );
388 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
391 // -------------------------------------------------------------------------
392 void cpExtensions::QT::SimpleMPRWidget::
393 _SyncBottom( int a, int b )
395 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
398 // -------------------------------------------------------------------------
399 void cpExtensions::QT::SimpleMPRWidget::
400 _SyncTop( int a, int b )
402 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
405 #endif // cpExtensions_QT4