]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
0cede9d8e5f167a3207e92f922efe738561faea5
[cpPlugins.git] / lib / cpExtensions / QT / SimpleMPRWidget.cxx
1 #include <cpExtensions/QT/SimpleMPRWidget.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <cpExtensions/ui_SimpleMPRWidget.h>
6 #include <vtkRenderWindow.h>
7
8 // -------------------------------------------------------------------------
9 cpExtensions::QT::SimpleMPRWidget::
10 SimpleMPRWidget( QWidget* parent )
11   : QWidget( parent ),
12     m_UI( new Ui::SimpleMPRWidget )
13 {
14   this->m_UI->setupUi( this );
15
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;
21
22   for( unsigned int i = 0; i < 4; ++i )
23   {
24     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
25     this->m_VTK[ i ]->GetRenderWindow( )->
26       AddRenderer( this->m_Renderers[ i ] );
27
28   } // rof
29
30   // Connect slots
31   QObject::connect(
32     this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
33     this, SLOT( _SyncBottom( int, int ) )
34     );
35   QObject::connect(
36     this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
37     this, SLOT( _SyncTop( int, int ) )
38     );
39 }
40
41 // -------------------------------------------------------------------------
42 cpExtensions::QT::SimpleMPRWidget::
43 ~SimpleMPRWidget( )
44 {
45   delete this->m_UI;
46 }
47
48 // -------------------------------------------------------------------------
49 void cpExtensions::QT::SimpleMPRWidget::
50 Clear( )
51 {
52   for( unsigned int i = 0; i < 4; ++i )
53     this->m_Renderers[ i ]->RemoveAllViewProps( );
54   for( unsigned int i = 0; i < 3; ++i )
55   {
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( );
60
61   } // rof
62   this->m_PolyDatas.clear( );
63 }
64
65 // -------------------------------------------------------------------------
66 void cpExtensions::QT::SimpleMPRWidget::
67 SetMainImage( vtkImageData* image )
68 {
69   for( unsigned int i = 0; i < 3; ++i )
70   {
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( ) );
76
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( )
84         )
85       );
86
87   } // rof
88
89   for( unsigned int i = 0; i < 3; ++i )
90   {
91     for( unsigned int j = 0; j < 3; ++j )
92     {
93       if( i != j )
94         this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
95       this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
96
97     } // rof
98
99   } // rof
100   for( unsigned int i = 0; i < 3; ++i )
101   {
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( );
106
107   } // rof
108   this->m_Renderers[ 3 ]->ResetCamera( );
109   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
110 }
111
112 // -------------------------------------------------------------------------
113 void cpExtensions::QT::SimpleMPRWidget::
114 AddMesh( vtkPolyData* mesh )
115 {
116   PolyDataActor a;
117   a.Configure( mesh );
118   this->m_PolyDatas[ mesh ] = a;
119   this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
120
121   bool has_main_image = false;
122   for( unsigned int i = 0; i < 3; ++i )
123   {
124     if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
125     {
126       if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
127       {
128         has_main_image = true;
129         this->m_2DSlices[ i ]->AddMesh( mesh );
130         this->m_2DSlices[ i ]->Render( );
131
132       } // fi
133
134     } // fi
135
136   } // rof
137   if( !has_main_image )
138     this->m_Renderers[ 3 ]->ResetCamera( );
139   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
140 }
141
142 // -------------------------------------------------------------------------
143 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
144 GetInteractor( unsigned int i )
145 {
146   if( i < 4 )
147     return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
148   else
149     return( NULL );
150 }
151
152 // -------------------------------------------------------------------------
153 vtkActor* cpExtensions::QT::SimpleMPRWidget::
154 GetActor( vtkPolyData* mesh )
155 {
156   auto i = this->m_PolyDatas.find( mesh );
157   if( i != this->m_PolyDatas.end( ) )
158     return( i->second.Actor.GetPointer( ) );
159   else
160     return( NULL );
161 }
162
163 // -------------------------------------------------------------------------
164 void cpExtensions::QT::SimpleMPRWidget::
165 _SyncBottom( int a, int b )
166 {
167   this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
168 }
169
170 // -------------------------------------------------------------------------
171 void cpExtensions::QT::SimpleMPRWidget::
172 _SyncTop( int a, int b )
173 {
174   this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
175 }
176
177 #endif // cpExtensions_QT4
178
179 // eof - $RCSfile$