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->VTK01;
18 this->m_VTK[ 1 ] = this->m_UI->VTK00;
19 this->m_VTK[ 2 ] = this->m_UI->VTK10;
20 this->m_VTK[ 3 ] = this->m_UI->VTK11;
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 )
69 for( unsigned int i = 0; i < 3; ++i )
71 this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
72 this->m_2DSlices[ i ]->SetInputData( image, i );
73 this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
74 this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
75 SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
77 this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
78 this->m_3DSlices[ i ]->SetInputData( image, i );
79 this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
80 this->m_3DSlices[ i ]->SetStyle(
81 dynamic_cast< vtkInteractorStyle* >(
82 this->m_Renderers[ 3 ]->GetRenderWindow( )->
83 GetInteractor( )->GetInteractorStyle( )
89 for( unsigned int i = 0; i < 3; ++i )
91 for( unsigned int j = 0; j < 3; ++j )
94 this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
95 this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
100 for( unsigned int i = 0; i < 3; ++i )
102 this->m_2DSlices[ i ]->GetStyle( )->
103 SetCurrentRenderer( this->m_Renderers[ i ] );
104 this->m_Renderers[ i ]->ResetCamera( );
105 this->m_VTK[ i ]->GetRenderWindow( )->Render( );
108 this->m_Renderers[ 3 ]->ResetCamera( );
109 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
112 // -------------------------------------------------------------------------
113 void cpExtensions::QT::SimpleMPRWidget::
114 AddMesh( vtkPolyData* mesh )
118 this->m_PolyDatas[ mesh ] = a;
119 this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
121 bool has_main_image = false;
122 for( unsigned int i = 0; i < 3; ++i )
124 if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
126 if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
128 has_main_image = true;
129 this->m_2DSlices[ i ]->AddMesh( mesh );
130 this->m_2DSlices[ i ]->Render( );
137 if( !has_main_image )
138 this->m_Renderers[ 3 ]->ResetCamera( );
139 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
142 // -------------------------------------------------------------------------
143 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
144 GetInteractor( unsigned int i )
147 return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
152 // -------------------------------------------------------------------------
153 vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
154 GetRenderer( unsigned int i )
157 return( this->m_Renderers[ i ] );
162 // -------------------------------------------------------------------------
163 std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
164 cpExtensions::QT::SimpleMPRWidget::
165 GetMainImageActors( )
167 std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
168 for( unsigned int i = 0; i < 3; ++i )
171 std::pair< vtkImageActor*, vtkRenderer* >(
172 this->m_2DSlices[ i ]->GetImageActor( ),
173 this->m_Renderers[ i ]
177 std::pair< vtkImageActor*, vtkRenderer* >(
178 this->m_3DSlices[ i ]->GetImageActor( ),
179 this->m_Renderers[ 3 ]
187 // -------------------------------------------------------------------------
188 vtkActor* cpExtensions::QT::SimpleMPRWidget::
189 GetActor( vtkPolyData* mesh )
191 auto i = this->m_PolyDatas.find( mesh );
192 if( i != this->m_PolyDatas.end( ) )
193 return( i->second.Actor.GetPointer( ) );
198 // -------------------------------------------------------------------------
199 void cpExtensions::QT::SimpleMPRWidget::
200 _SyncBottom( int a, int b )
202 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
205 // -------------------------------------------------------------------------
206 void cpExtensions::QT::SimpleMPRWidget::
207 _SyncTop( int a, int b )
209 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
212 #endif // cpExtensions_QT4