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