]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracas_ViewerWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracas_ViewerWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/08/21 15:19:14 $
7   Version:   $Revision: 1.29 $
8
9   Copyright: (c) 2002, 2003
10   License:
11   
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18 //------------------------------------------------------------------------------------------------------------
19 // Definition includes
20 //------------------------------------------------------------------------------------------------------------
21 #include "wxMaracas_ViewerWidget.h"
22 #include <wx/notebook.h>
23 //------------------------------------------------------------------------------------------------------------
24 // Other includes
25 //------------------------------------------------------------------------------------------------------------
26
27         //------------------------------------------------------------------------------------------------------------
28         // Constructors & Destructors
29         //------------------------------------------------------------------------------------------------------------
30
31         wxMaracas_ViewerWidget::wxMaracas_ViewerWidget(wxWindow *parent, vtkImageData* imagedata, int type, vtkMPRBaseData *vtkmprbasedata)
32                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
33         {
34                 wxPanel *panel = this;
35                 wxWindow *wxwindow = NULL, *window3D    = 0;
36                 wxSplitterWindow        *panelClipping3D= 0;
37 //              wxPanel *panelControl                   = 0;
38 //              wxFlexGridSizer  *sizerCtrol            = 0;            
39                 wxPanel *controlPanelMPR3D              = 0;
40                 wxPanel *controlPanelClippingSurf3D     = 0;
41                 //RaC 03-2010 Adding a tab
42                 wxPanel *controlPanelClippingVol3D      = 0;
43
44                 wxBoxSizer *sizer                       = 0;
45
46                 mType = type;
47
48                 if (vtkmprbasedata==NULL)
49                 {
50                         minternalVtkmprbasedata = true;
51                         mvtkmprbasedata         = new vtkMPRBaseData();
52                         marImageData    *marimagedata   = new marImageData( imagedata );                        
53                         mvtkmprbasedata->SetMarImageData(marimagedata);
54                 } else {
55                         minternalVtkmprbasedata         = false;
56                         mvtkmprbasedata                 = vtkmprbasedata;
57                 }
58
59                 mvtk2Dbaseview                  = NULL;
60                 mvtkmpr2Dview_X                 = NULL;
61                 mvtkmpr2Dview_Y                 = NULL;
62                 mvtkmpr2Dview_Z                 = NULL;
63                 mvtkplane2Dview                 = NULL;
64                 mwidgetMesure                   = NULL;
65                 mwxsphereview                   = NULL;
66                 mwxvtkclipping3Dview            = NULL;
67                 mwxvtk3Dbaseview_Clipping3D     = NULL;
68                 mwxvtkmpr3Dview                     = NULL;
69                 vtkmpr3Ddataviewer                  = NULL;
70
71                 if (type==-1)
72                 {
73                         mvtk2Dbaseview  = new wxVtk2DBaseView(panel);
74                         mvtk2Dbaseview->SetVtkBaseData(mvtkmprbasedata);
75                         wxwindow        = mvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
76                 }else if (type==0)
77                 {
78                         mvtkmpr2Dview_Z = new wxVtkMPR2DView(panel,2);
79                         mvtkmpr2Dview_Z->SetVtkBaseData(mvtkmprbasedata);
80                         wxwindow        = mvtkmpr2Dview_Z->GetWxVTKRenderWindowInteractor();
81                 }else if (type==1)
82                 {
83                         mvtkmpr2Dview_X = new wxVtkMPR2DView(panel,0);
84                         mvtkmpr2Dview_X->SetVtkBaseData(mvtkmprbasedata);
85                         wxwindow        = mvtkmpr2Dview_X->GetWxVTKRenderWindowInteractor();
86                 }else if (type==2)
87                 {
88                         mvtkmpr2Dview_Y = new wxVtkMPR2DView(panel,1);
89                         mvtkmpr2Dview_Y->SetVtkBaseData(mvtkmprbasedata);
90                         wxwindow        = mvtkmpr2Dview_Y->GetWxVTKRenderWindowInteractor();
91                 }else if (type==3)
92                 {
93                         mwidgetMesure   = new wxWidgetMesure2D_Plane_in_MPR(panel);
94                         mvtkplane2Dview = new vtkPlane2DView( mwidgetMesure->GetWindow2());
95                         mwidgetMesure   -> SetVtkPlane2DView( mvtkplane2Dview );
96                         mvtkplane2Dview -> SetImgSize( 200 );
97                         mvtkplane2Dview -> SetVtkBaseData(mvtkmprbasedata);
98                         wxwindow        = mwidgetMesure;
99                 }else if (type==4)
100                 {
101                         mwxsphereview   = new wxSphereView( panel , mvtkmprbasedata, mvtkmprbasedata->GetImageData() );
102                         wxwindow=mwxsphereview->GetWxVTKRenderWindowInteractor();
103                 }else if (type==5)
104                 {
105                         panelClipping3D = new wxSplitterWindow( panel , -1);
106                         mwxvtk3Dbaseview_Clipping3D             = new wxVtk3DBaseView( panelClipping3D );
107
108                         mwxvtkclipping3Dview                    = new wxVtkClipping3DView(mwxvtk3Dbaseview_Clipping3D);
109                         vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
110                         vtkclipping3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
111                         vtkclipping3Ddataviewer->Configure();
112                         mwxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
113
114                         mwxvtkmpr3Dview                         = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
115                         vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
116                         vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
117                         vtkmpr3Ddataviewer->Configure();
118                         mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
119
120                         window3D = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
121
122 //--
123                         wxNotebook *notebook = new wxNotebook(panelClipping3D, -1);
124
125                         // First tab
126                         controlPanelMPR3D               = mwxvtkmpr3Dview->CreateControlPanel(notebook, true);
127                         notebook->AddPage(controlPanelMPR3D, _T("Planes") );
128
129                         // Second Tab
130                         controlPanelClippingSurf3D      = mwxvtkclipping3Dview->CreateSurfControlPanel(notebook);                       
131                         notebook->AddPage(controlPanelClippingSurf3D, _T("Surface") );
132                         
133                         //Third tab
134                         //RaC 03-2010 Moving the volume functionnality to other tab. The changes were realized only in the wxVtkClipping3DViewCntrlPanel class
135                         controlPanelClippingVol3D       = mwxvtkclipping3Dview->CreateVolControlPanel(notebook);
136                         notebook->AddPage(controlPanelClippingVol3D, _T("Volume") );
137
138                         panelClipping3D->SplitHorizontally( notebook , window3D , 10  );
139                         //panelClipping3D->SetMinimumPaneSize( 15 );
140                         panelClipping3D->SetMinimumPaneSize( 70 ); // JPR 
141                         
142         /*              EED 04 / Febrary / 2010
143                         panelControl                    = new wxPanel(panelClipping3D,-1);      
144                         controlPanelMPR3D               = mwxvtkmpr3Dview->CreateControlPanel(panelControl, false);
145                         controlPanelClipping3D  = mwxvtkclipping3Dview->CreateControlPanel(panelControl);
146         //                               mbtnCutImageData               = new wxCheckBox(panelControl,-1,_T("Cut Module"));
147         //              Connect(_btnCutImageData->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &wxMPRWidget::OnCutImagaData );
148                         sizerCtrol             = new wxFlexGridSizer(1);
149                         sizerCtrol->Add(controlPanelMPR3D       , 1, wxALL|wxEXPAND, 2);
150                         sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
151         //              sizerCtrol->Add( mbtnCutImageData       , 1, wxALL, 2);
152                         panelControl->SetAutoLayout(true);
153                         panelControl->SetSizer(sizerCtrol);
154                         panelControl->SetSize(400,350);
155                         panelControl->Layout();
156                         panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
157                         panelClipping3D -> SetMinimumPaneSize( 5 );
158          */
159                         wxwindow=panelClipping3D;
160                         
161                 } else if (type==6)             {
162                         panelClipping3D = new wxSplitterWindow( panel , -1);
163                         mwxvtk3Dbaseview_Clipping3D     = new wxVtk3DBaseView( panelClipping3D );
164
165                         mwxvtkmpr3Dview         = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
166
167                         vtkmpr3Ddataviewer      = new vtkMPR3DDataViewer();     
168                         
169                         wxWindow *window3D = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
170
171                         wxPanel *panelControl   = new wxPanel(panelClipping3D,-1);      
172                         wxPanel *controlPanelMPR3D = mwxvtkmpr3Dview->CreateControlPanel(panelControl, false);
173
174                         wxFlexGridSizer  *sizerCtrol     = new wxFlexGridSizer(1);
175                         sizerCtrol->Add(controlPanelMPR3D, 1, wxALL|wxEXPAND, 2);
176
177                         panelControl->SetAutoLayout(true);
178                         panelControl->SetSizer(sizerCtrol);
179                         panelControl->SetSize(400,350);
180                         panelControl->Layout();
181                         //panelClipping3D->SetMinimumPaneSize( 5 );
182                         panelClipping3D->SetMinimumPaneSize( 100 );  // JPR
183
184                         panelClipping3D->SplitHorizontally( panelControl , window3D , 10  );
185                         wxwindow=panelClipping3D;
186
187                         vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);                 
188                         //vtkmpr3Ddataviewer->Configure();
189
190                         mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
191                         
192                 }else if (type==7)
193                 {
194                         mwxvtk3Dbaseview_Clipping3D = new wxVtk3DBaseView( panel );                                             
195                         wxwindow = (wxWindow*) mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
196                 }
197
198         sizer = new wxBoxSizer(wxVERTICAL);
199         sizer->Add( wxwindow, 1, wxGROW);       
200         panel->SetSizer(sizer);
201         panel->SetAutoLayout(true);
202         sizer->Layout();
203         panel->Layout();
204         panel->Refresh();
205
206         //   mbbtkViewerMaracas= NULL;
207         }
208         //-------------------------------------------------------------------------
209
210         wxMaracas_ViewerWidget::~wxMaracas_ViewerWidget()
211         {
212                 if (minternalVtkmprbasedata==true)
213                 {
214                    if (mvtkmprbasedata)         { delete mvtkmprbasedata;}
215                 }       
216
217                 if (mvtk2Dbaseview)             { delete mvtk2Dbaseview; }
218                 if (mvtkmpr2Dview_X)            { delete mvtkmpr2Dview_X;}
219                 if (mvtkmpr2Dview_Y)            { delete mvtkmpr2Dview_Y;}
220                 if (mvtkmpr2Dview_Z)            { delete mvtkmpr2Dview_Z;}
221                 if (mwidgetMesure)              { delete mwidgetMesure;  }
222                 if (mvtkplane2Dview)            { delete mvtkplane2Dview;}
223                 if (mwxsphereview)              { delete mwxsphereview;  }
224                 if (mwxvtkmpr3Dview)            { delete mwxvtkmpr3Dview;}
225                 if (mwxvtkclipping3Dview)       { delete mwxvtkclipping3Dview;}
226                 if (mwxvtk3Dbaseview_Clipping3D){ delete mwxvtk3Dbaseview_Clipping3D; mwxvtk3Dbaseview_Clipping3D=NULL;}
227         }
228         //------------------------------------------------------------------------------------------------------------
229         // Methods
230         //------------------------------------------------------------------------------------------------------------
231
232         //-------------------------------------------------------------------------
233
234         void wxMaracas_ViewerWidget::ConfigureVTK()
235         {
236                 int x=0,y=0,z=0;
237                 /*
238                 int ext[6];
239                 ext[0]=0;
240                 ext[1]=0;
241                 ext[2]=0;
242                 ext[3]=0;
243                 ext[4]=0;
244                 ext[5]=0;
245                 */
246                 int ext[] = {0, 0, 0, 0, 0, 0}; //JPR
247                 
248                 /*double org[3],spc[3];
249                 org[0]=0;
250                 org[1]=0;
251                 org[2]=0;
252                 spc[0]=0;
253                 spc[1]=0;
254                 spc[2]=0;
255                 */
256                 double org[]={0.0, 0.0, 0.0}; //JPR
257                 double spc[]={0.0, 0.0, 0.0}; //JPR
258                 if (mvtkmprbasedata!=NULL)
259                 {
260                         mvtkmprbasedata->Configure();
261                         /*
262                         x = mvtkmprbasedata->GetMaxPositionX()/2;
263                         y = mvtkmprbasedata->GetMaxPositionY()/2;
264                         z = mvtkmprbasedata->GetMaxPositionZ()/2;               
265                         */      
266
267                         if(mvtkmprbasedata->GetImageData() != NULL)
268                         {
269                                 mvtkmprbasedata->GetImageData()->GetExtent(ext);
270                                 mvtkmprbasedata->GetImageData()->GetOrigin(org);
271                                 mvtkmprbasedata->GetImageData()->GetSpacing(spc);
272
273                                 x = (ext[0]+ext[1])/2;
274                                 y = (ext[2]+ext[3])/2;
275                                 z = (ext[4]+ext[5])/2;
276
277                                 mvtkmprbasedata->SetX( x );
278                                 mvtkmprbasedata->SetY( y );
279                                 mvtkmprbasedata->SetZ( z );
280                         }
281                         else
282                         {
283                                 mvtkmprbasedata->SetX( 0 );
284                                 mvtkmprbasedata->SetY( 0 );
285                                 mvtkmprbasedata->SetZ( 0 );
286                         }
287                 }
288                 
289                 if ( mvtk2Dbaseview      !=NULL ) { mvtk2Dbaseview->Configure();                }
290                 if ( mvtkmpr2Dview_X     !=NULL ) { mvtkmpr2Dview_X->Configure();               }
291                 if ( mvtkmpr2Dview_Y     !=NULL ) { mvtkmpr2Dview_Y->Configure();               }
292                 if ( mvtkmpr2Dview_Z     !=NULL ) { mvtkmpr2Dview_Z->Configure();               }
293                 if ( mvtkplane2Dview     !=NULL ) { mvtkplane2Dview->Configure();               }
294                 if ( mwidgetMesure       !=NULL ) { mwidgetMesure->ConfigureA(mvtkplane2Dview); }
295                 if ( mwidgetMesure       !=NULL ) { mwidgetMesure->ConfigureA(mvtkplane2Dview); }
296                 if ( mwidgetMesure       !=NULL ) { mwidgetMesure->SetActiveLink(true);         }
297                 if ( mwidgetMesure       !=NULL ) { mwidgetMesure->SetMesureScale( 1 );         }
298                 if ( mwxsphereview       !=NULL ) { mwxsphereview->Configure();                 }
299
300                 if (mwxvtk3Dbaseview_Clipping3D !=NULL) 
301                 {
302                         mwxvtk3Dbaseview_Clipping3D->Configure();                               
303                 }
304
305                 if (vtkmpr3Ddataviewer                  !=NULL)
306                 {                       
307                         vtkmpr3Ddataviewer->Configure();                        
308                 }
309
310                 if (mwxvtkmpr3Dview                     !=NULL)
311                 {                       
312                         mwxvtkmpr3Dview->Configure();
313                         mwxvtkmpr3Dview->ResetCamera(ext,org,spc);
314                 }
315
316                 if (mwxvtkclipping3Dview                !=NULL) 
317                 { 
318                         mwxvtkclipping3Dview->Configure();      
319                 }
320                 
321                 //if(vtkmpr3Ddataviewer!=NULL){vtkmpr3Ddataviewer->Configure();}
322 //              RefreshView();
323
324                 //if (mwxvtkmpr3Dview                           !=NULL) {
325                 //      mwxvtkmpr3Dview->ResetCamera();
326                 //}
327         }
328
329         //-------------------------------------------------------------------------
330
331   void wxMaracas_ViewerWidget::Refresh(bool eraseBackground ,const wxRect* rect  )  // virtual  eraseBackground=true , rect=NULL
332   {
333     wxPanel::Refresh(false);
334   }
335
336         //-------------------------------------------------------------------------
337         void wxMaracas_ViewerWidget::RefreshView()
338         {
339                 
340                         if (mvtk2Dbaseview              !=NULL ){ mvtk2Dbaseview->Refresh();            }
341                         if (mvtkmpr2Dview_X             !=NULL ){ mvtkmpr2Dview_X->Refresh();           }
342                         if (mvtkmpr2Dview_Y             !=NULL ){ mvtkmpr2Dview_Y->Refresh();           }
343                         if (mvtkmpr2Dview_Z             !=NULL ){ mvtkmpr2Dview_Z->Refresh();           }
344                         if (mvtkplane2Dview             !=NULL ){ mvtkplane2Dview->Refresh();           }
345                         if (mwxsphereview               !=NULL ){ mwxsphereview ->Refresh();            }
346
347                         if (mwxvtkmpr3Dview             !=NULL ){ mwxvtkmpr3Dview->RefreshView();       }
348                         if (mwxvtkclipping3Dview        !=NULL ){ mwxvtkclipping3Dview->Refresh();      }
349                         if (mwxvtk3Dbaseview_Clipping3D !=NULL ){ mwxvtk3Dbaseview_Clipping3D->Refresh();}
350         }
351
352         //-------------------------------------------------------------------------
353
354         wxVtkBaseView *wxMaracas_ViewerWidget::GetwxVtkBaseView()
355         {
356                 wxVtkBaseView *wxvtkbaseview=NULL;
357                 if (mvtk2Dbaseview!=NULL){ 
358                         wxvtkbaseview = mvtk2Dbaseview;                 
359                 }
360                 if (mvtkmpr2Dview_X!=NULL){ 
361                         wxvtkbaseview = mvtkmpr2Dview_X;
362                 }
363                 if (mvtkmpr2Dview_Y!=NULL){ 
364                         wxvtkbaseview = mvtkmpr2Dview_Y;
365                 }
366                 if (mvtkmpr2Dview_Z!=NULL){ 
367                         wxvtkbaseview = mvtkmpr2Dview_Z;                
368                 }
369                 if (mvtkplane2Dview!=NULL){
370                         wxvtkbaseview = mvtkplane2Dview;                
371                 }
372                 if (mwxsphereview!=NULL){ 
373                         wxvtkbaseview = mwxsphereview;
374                 }
375                 if (mwxvtk3Dbaseview_Clipping3D!=NULL){ 
376                         wxvtkbaseview = mwxvtk3Dbaseview_Clipping3D;
377                 }
378                 return wxvtkbaseview   ;
379         }
380
381         void wxMaracas_ViewerWidget::SetImage( vtkImageData *image )
382         {
383                 if(mvtkmprbasedata !=NULL)
384                 {
385                         marImageData* mar = mvtkmprbasedata->GetMarImageData();
386                         mar->removeImageData(0);
387                         mar->AddImageData(image);
388                 }
389
390 //EED 26/11/2009
391 //              ConfigureVTK();
392 //              RefreshView();
393         }
394
395         double wxMaracas_ViewerWidget :: GetX()
396         {
397                 double value = -1;
398                 if(mvtkmprbasedata !=NULL)
399                 {
400                         value = mvtkmprbasedata->GetX();
401                 }
402                 return value;
403         }
404
405         double wxMaracas_ViewerWidget::GetY()
406         {
407                 double value = -1;
408                 if(mvtkmprbasedata !=NULL)
409                 {
410                         value = mvtkmprbasedata->GetY();
411                 }
412                 return value;
413         }
414
415         double wxMaracas_ViewerWidget::GetZ()
416         {
417                 double value = -1;
418                 if(mvtkmprbasedata !=NULL)
419                 {
420                         value = mvtkmprbasedata->GetZ();
421                 }
422                 return value;
423 //              return mvtk2Dbaseview->GetVtkBaseData()->GetZ();
424         }
425
426         void wxMaracas_ViewerWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){            
427                 if(mvtkmpr2Dview_X!=NULL){
428                         mvtkmpr2Dview_X->setColorTransferFunction(colortable);
429                 }
430                 if(mvtkmpr2Dview_Y!=NULL){
431                         mvtkmpr2Dview_Y->setColorTransferFunction(colortable);
432                 }
433                 if(mvtkmpr2Dview_Z!=NULL){
434                         mvtkmpr2Dview_Z->setColorTransferFunction(colortable);
435                 }
436                 if(mwxvtkmpr3Dview!=NULL){
437                         mwxvtkmpr3Dview->setColorTransferFunction(colortable);
438                 }
439         }
440
441         void wxMaracas_ViewerWidget::setWindowLevel(double level){
442                 if(mvtkmpr2Dview_X!=NULL){
443                         mvtkmpr2Dview_X->setWindowLevel(level);
444                 }
445                 if(mvtkmpr2Dview_Y!=NULL){
446                         mvtkmpr2Dview_Y->setWindowLevel(level);
447                 }
448                 if(mvtkmpr2Dview_Z!=NULL){
449                         mvtkmpr2Dview_Z->setWindowLevel(level);
450                 }
451                 /*if(mwxvtkmpr3Dview!=NULL){
452                         mwxvtkmpr3Dview->setWindowLevel(level);
453                 }*/
454         }
455
456         void wxMaracas_ViewerWidget::setColorLevel(double level){
457                 if(mvtkmpr2Dview_X!=NULL){
458                         mvtkmpr2Dview_X->setColorLevel(level);
459                 }
460                 if(mvtkmpr2Dview_Y!=NULL){
461                         mvtkmpr2Dview_Y->setColorLevel(level);
462                 }
463                 if(mvtkmpr2Dview_Z!=NULL){
464                         mvtkmpr2Dview_Z->setColorLevel(level);
465                 }
466                 /*if(mwxvtkmpr3Dview!=NULL){
467                         mwxvtkmpr3Dview->setColorLevel(level);
468                 }*/
469     }