]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
...
[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 /* TODO
9    #include <vtkProperty.h>
10    #include <vtkRendererCollection.h>
11    double cpExtensions::QT::SimpleMPRWidget::
12    cm_Colors[ 8 ][ 3 ] =
13    {
14    { 1.0, 0.0, 0.0 },
15    { 0.0, 1.0, 0.0 },
16    { 0.0, 0.0, 1.0 },
17    { 0.0, 1.0, 1.0 },
18    { 1.0, 0.0, 1.0 },
19    { 1.0, 1.0, 0.0 },
20    { 1.0, 0.5, 0.0 },
21    { 1.0, 0.0, 0.5 }
22    };
23 */
24
25 // -------------------------------------------------------------------------
26 cpExtensions::QT::SimpleMPRWidget::
27 SimpleMPRWidget( QWidget* parent )
28   : QWidget( parent ),
29     m_UI( new Ui::SimpleMPRWidget )
30     /*
31       ,
32       m_MainImage( "" )
33     */
34 {
35   this->m_UI->setupUi( this );
36
37   // Configure VTK widgets
38   this->m_VTK[ 0 ] = this->m_UI->VTK01;
39   this->m_VTK[ 1 ] = this->m_UI->VTK00;
40   this->m_VTK[ 2 ] = this->m_UI->VTK10;
41   this->m_VTK[ 3 ] = this->m_UI->VTK11;
42
43   for( unsigned int i = 0; i < 4; ++i )
44   {
45     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
46     this->m_VTK[ i ]->GetRenderWindow( )->AddRenderer( this->m_Renderers[ i ] );
47
48   } // rof
49
50   /*
51     this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
52     this->m_MPRObjects->SetRenderWindows(
53     this->m_VTK[ 0 ]->GetRenderWindow( ),
54     this->m_VTK[ 1 ]->GetRenderWindow( ),
55     this->m_VTK[ 2 ]->GetRenderWindow( ),
56     this->m_VTK[ 3 ]->GetRenderWindow( )
57     );
58   */
59
60   // Connect slots
61   QObject::connect(
62     this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
63     this, SLOT( _SyncBottom( int, int ) )
64     );
65   QObject::connect(
66     this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
67     this, SLOT( _SyncTop( int, int ) )
68     );
69 }
70
71 // -------------------------------------------------------------------------
72 cpExtensions::QT::SimpleMPRWidget::
73 ~SimpleMPRWidget( )
74 {
75   delete this->m_UI;
76 }
77
78 // -------------------------------------------------------------------------
79 void cpExtensions::QT::SimpleMPRWidget::
80 Clear( )
81 {
82   for( unsigned int i = 0; i < 4; ++i )
83     this->m_Renderers[ i ]->RemoveAllViewProps( );
84   for( unsigned int i = 0; i < 3; ++i )
85   {
86     if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
87       this->m_2DSlices[ i ]->Clear( );
88     if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
89       this->m_3DSlices[ i ]->Clear( );
90
91   } // rof
92   this->m_PolyDatas.clear( );
93 }
94
95 // -------------------------------------------------------------------------
96 void cpExtensions::QT::SimpleMPRWidget::
97 SetMainImage( vtkImageData* image )
98 {
99   for( unsigned int i = 0; i < 3; ++i )
100   {
101     this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
102     this->m_2DSlices[ i ]->SetInputData( image, i );
103     this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
104     this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
105       SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
106
107     this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
108     this->m_3DSlices[ i ]->SetInputData( image, i );
109     this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
110     this->m_3DSlices[ i ]->SetStyle(
111       dynamic_cast< vtkInteractorStyle* >(
112         this->m_Renderers[ 3 ]->GetRenderWindow( )->
113         GetInteractor( )->GetInteractorStyle( )
114         )
115       );
116
117   } // rof
118
119   for( unsigned int i = 0; i < 3; ++i )
120   {
121     for( unsigned int j = 0; j < 3; ++j )
122     {
123       if( i != j )
124         this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
125       this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
126
127     } // rof
128
129   } // rof
130   for( unsigned int i = 0; i < 3; ++i )
131   {
132     this->m_2DSlices[ i ]->GetStyle( )->
133       SetCurrentRenderer( this->m_Renderers[ i ] );
134     this->m_Renderers[ i ]->ResetCamera( );
135     this->m_VTK[ i ]->GetRenderWindow( )->Render( );
136
137   } // rof
138   this->m_Renderers[ 3 ]->ResetCamera( );
139   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
140 }
141
142 // -------------------------------------------------------------------------
143 void cpExtensions::QT::SimpleMPRWidget::
144 AddMesh( vtkPolyData* mesh )
145 {
146   PolyDataActor a;
147   a.Configure( mesh );
148   this->m_PolyDatas[ mesh ] = a;
149   this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
150
151   bool has_main_image = false;
152   for( unsigned int i = 0; i < 3; ++i )
153   {
154     if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
155     {
156       if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
157       {
158         has_main_image = true;
159         this->m_2DSlices[ i ]->AddMesh( mesh );
160         this->m_2DSlices[ i ]->Render( );
161
162       } // fi
163
164     } // fi
165
166   } // rof
167   if( !has_main_image )
168     this->m_Renderers[ 3 ]->ResetCamera( );
169   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
170 }
171
172 // -------------------------------------------------------------------------
173 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
174 GetInteractor( unsigned int i )
175 {
176   if( i < 4 )
177     return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
178   else
179     return( NULL );
180 }
181
182 // -------------------------------------------------------------------------
183 void cpExtensions::QT::SimpleMPRWidget::
184 _SyncBottom( int a, int b )
185 {
186   this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
187 }
188
189 // -------------------------------------------------------------------------
190 void cpExtensions::QT::SimpleMPRWidget::
191 _SyncTop( int a, int b )
192 {
193   this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
194 }
195
196 #endif // cpExtensions_QT4
197
198 // eof - $RCSfile$