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::
11 SimpleMPRWidget( QWidget* parent )
13 m_UI( new Ui::SimpleMPRWidget )
15 this->m_UI->setupUi( this );
17 // Configure VTK widgets
18 this->m_VTK[ 0 ] = this->m_UI->VTK_X;
19 this->m_VTK[ 1 ] = this->m_UI->VTK_Y;
20 this->m_VTK[ 2 ] = this->m_UI->VTK_Z;
21 this->m_VTK[ 3 ] = this->m_UI->VTK_3D;
23 for( unsigned int i = 0; i < 4; ++i )
25 this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
26 this->m_VTK[ i ]->GetRenderWindow( )->
27 AddRenderer( this->m_Renderers[ i ] );
33 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
34 this, SLOT( _SyncBottom( int, int ) )
37 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
38 this, SLOT( _SyncTop( int, int ) )
42 // -------------------------------------------------------------------------
43 cpExtensions::QT::SimpleMPRWidget::
50 // -------------------------------------------------------------------------
51 void cpExtensions::QT::SimpleMPRWidget::
54 for( unsigned int i = 0; i < 4; ++i )
55 this->m_Renderers[ i ]->RemoveAllViewProps( );
56 for( unsigned int i = 0; i < 3; ++i )
58 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
59 this->m_2DSlices[ i ]->Clear( );
60 if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
61 this->m_3DSlices[ i ]->Clear( );
64 this->m_NamedActors.clear( );
67 // -------------------------------------------------------------------------
68 void cpExtensions::QT::SimpleMPRWidget::
69 SetMainImage( vtkImageData* image, const std::string& name )
72 for( unsigned int i = 0; i < 3; ++i )
74 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
75 this->m_2DSlices[ i ]->SetInputData( image, i );
76 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
77 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
78 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
80 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
81 this->m_3DSlices[ i ]->SetInputData( image, i );
82 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
83 this->m_3DSlices[ i ]->SetStyle(
84 dynamic_cast< vtkInteractorStyle* >(
85 this->m_Renderers[ 3 ]->GetRenderWindow( )->
86 GetInteractor( )->GetInteractorStyle( )
90 this->m_NamedActors[ name ].insert(
91 this->m_2DSlices[ i ]->GetImageActor( )
93 this->m_NamedActors[ name ].insert(
94 this->m_3DSlices[ i ]->GetImageActor( )
98 this->_AssociateSlices( );
101 // -------------------------------------------------------------------------
102 void cpExtensions::QT::SimpleMPRWidget::
103 SetMainActor( vtkImageActor* actor, const std::string& name )
106 vtkImageData* image = NULL;
107 for( unsigned int i = 0; i < 3; ++i )
109 this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
112 this->m_2DSlices[ i ]->SetInputActor( actor, i );
113 image = this->m_2DSlices[ i ]->GetInputData( );
116 this->m_2DSlices[ i ]->SetInputData( image, i );
117 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
118 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
119 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
121 this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
122 this->m_3DSlices[ i ]->SetInputData( image, i );
123 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
124 this->m_3DSlices[ i ]->SetStyle(
125 dynamic_cast< vtkInteractorStyle* >(
126 this->m_Renderers[ 3 ]->GetRenderWindow( )->
127 GetInteractor( )->GetInteractorStyle( )
131 this->m_NamedActors[ name ].insert(
132 this->m_2DSlices[ i ]->GetImageActor( )
134 this->m_NamedActors[ name ].insert(
135 this->m_3DSlices[ i ]->GetImageActor( )
139 this->_AssociateSlices( );
142 // -------------------------------------------------------------------------
143 void cpExtensions::QT::SimpleMPRWidget::
144 AddImage( vtkImageData* image, const std::string& name )
146 std::cerr << "SimpleMPR: adding image" << std::endl;
150 // -------------------------------------------------------------------------
151 void cpExtensions::QT::SimpleMPRWidget::
152 AddImageActor( vtkImageActor* actor, const std::string& name )
156 while( i < 3 && cont )
158 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
160 if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL )
162 // TODO: add image actor
172 // Add if no actors were found
174 this->SetMainActor( actor, name );
177 // -------------------------------------------------------------------------
178 void cpExtensions::QT::SimpleMPRWidget::
179 AddMesh( vtkPolyData* mesh, const std::string& name )
181 std::cerr << "SimpleMPR: adding mesh" << std::endl;
186 this->m_PolyDatas[ mesh ] = a;
187 this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
189 bool has_main_image = false;
190 for( unsigned int i = 0; i < 3; ++i )
192 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
194 if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
196 has_main_image = true;
197 this->m_2DSlices[ i ]->AddMesh( mesh );
198 this->m_2DSlices[ i ]->Render( );
205 if( !has_main_image )
206 this->m_Renderers[ 3 ]->ResetCamera( );
207 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
211 // -------------------------------------------------------------------------
212 void cpExtensions::QT::SimpleMPRWidget::
213 AddMeshActor( vtkProp3D* actor, const std::string& name )
217 this->m_Renderers[ 3 ]->AddViewProp( actor );
218 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
219 this->m_NamedActors[ name ].insert( actor );
224 // -------------------------------------------------------------------------
225 void cpExtensions::QT::SimpleMPRWidget::
226 AddActor( vtkProp* actor, const std::string& name )
228 auto ia = dynamic_cast< vtkImageActor* >( actor );
231 auto ma = dynamic_cast< vtkActor* >( actor );
233 this->AddMeshActor( ma, name );
236 this->AddImageActor( ia, name );
239 // -------------------------------------------------------------------------
240 const cpExtensions::QT::SimpleMPRWidget::
241 TActors& cpExtensions::QT::SimpleMPRWidget::
242 GetActors( const std::string& name ) const
244 static const TActors empty;
245 auto i = this->m_NamedActors.find( name );
246 if( i != this->m_NamedActors.end( ) )
252 // -------------------------------------------------------------------------
253 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
254 GetInteractor( unsigned int i )
257 return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
262 // -------------------------------------------------------------------------
263 vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
264 GetRenderer( unsigned int i )
267 return( this->m_Renderers[ i ] );
272 // -------------------------------------------------------------------------
273 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
274 GetRenderWindow( unsigned int i )
278 if( this->m_Renderers[ i ].GetPointer( ) != NULL )
279 return( this->m_Renderers[ i ]->GetRenderWindow( ) );
287 // -------------------------------------------------------------------------
289 std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
290 cpExtensions::QT::SimpleMPRWidget::
291 GetMainImageActors( )
293 std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
294 for( unsigned int i = 0; i < 3; ++i )
297 std::pair< vtkImageActor*, vtkRenderer* >(
298 this->m_2DSlices[ i ]->GetImageActor( ),
299 this->m_Renderers[ i ]
303 std::pair< vtkImageActor*, vtkRenderer* >(
304 this->m_3DSlices[ i ]->GetImageActor( ),
305 this->m_Renderers[ 3 ]
314 // -------------------------------------------------------------------------
316 vtkActor* cpExtensions::QT::SimpleMPRWidget::
317 GetActor( vtkPolyData* mesh )
319 auto i = this->m_PolyDatas.find( mesh );
320 if( i != this->m_PolyDatas.end( ) )
321 return( i->second.Actor.GetPointer( ) );
327 // -------------------------------------------------------------------------
328 void cpExtensions::QT::SimpleMPRWidget::
331 for( unsigned int i = 0; i < 3; ++i )
333 for( unsigned int j = 0; j < 3; ++j )
336 this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
337 this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
342 for( unsigned int i = 0; i < 3; ++i )
344 this->m_2DSlices[ i ]->GetStyle( )->
345 SetCurrentRenderer( this->m_Renderers[ i ] );
346 this->m_Renderers[ i ]->ResetCamera( );
347 this->m_VTK[ i ]->GetRenderWindow( )->Render( );
350 this->m_Renderers[ 3 ]->ResetCamera( );
351 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
354 // -------------------------------------------------------------------------
355 void cpExtensions::QT::SimpleMPRWidget::
356 _SyncBottom( int a, int b )
358 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
361 // -------------------------------------------------------------------------
362 void cpExtensions::QT::SimpleMPRWidget::
363 _SyncTop( int a, int b )
365 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
368 #endif // cpExtensions_QT4