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