]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx
ok
[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/04/23 16:03:30 $
7   Version:   $Revision: 1.7 $
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
56
57                 if (type==-1)
58                 {
59                         mvtk2Dbaseview  = new wxVtk2DBaseView(panel);
60                         mvtk2Dbaseview->SetVtkBaseData(mvtkmprbasedata);
61                         wxwindow                = mvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
62                 }
63
64
65                 if (type==0)
66                 {
67                         mvtkmpr2Dview_Z = new wxVtkMPR2DView(panel,2);
68                         mvtkmpr2Dview_Z->SetVtkBaseData(mvtkmprbasedata);
69                         wxwindow                = mvtkmpr2Dview_Z->GetWxVTKRenderWindowInteractor();
70                 }
71                 if (type==1)
72                 {
73                         mvtkmpr2Dview_X = new wxVtkMPR2DView(panel,0);
74                         mvtkmpr2Dview_X->SetVtkBaseData(mvtkmprbasedata);
75                         wxwindow                =       mvtkmpr2Dview_X->GetWxVTKRenderWindowInteractor();
76                 }
77
78                 if (type==2)
79                 {
80                         mvtkmpr2Dview_Y = new wxVtkMPR2DView(panel,1);
81                         mvtkmpr2Dview_Y->SetVtkBaseData(mvtkmprbasedata);
82                         wxwindow                = mvtkmpr2Dview_Y->GetWxVTKRenderWindowInteractor();
83                 }
84
85
86                 if (type==3)
87                 {
88                         mwidgetMesure           = new wxWidgetMesure2D_Plane_in_MPR(panel);
89                         mvtkplane2Dview         = new vtkPlane2DView( mwidgetMesure->GetWindow2());
90                         mwidgetMesure   -> SetVtkPlane2DView( mvtkplane2Dview );
91                         mvtkplane2Dview -> SetImgSize( 200 );
92                         mvtkplane2Dview -> SetVtkBaseData(mvtkmprbasedata);
93                         wxwindow                        = mwidgetMesure;
94                 }
95                 if (type==4)
96                 {
97                         mwxsphereview           = new wxSphereView( panel , mvtkmprbasedata, mvtkmprbasedata->GetImageData() );
98                         wxwindow=mwxsphereview->GetWxVTKRenderWindowInteractor();
99                 }
100
101
102                 if (type==5)
103                 {
104                         wxSplitterWindow        *panelClipping3D        = new wxSplitterWindow( panel , -1);
105                         mwxvtk3Dbaseview_Clipping3D                             = new wxVtk3DBaseView( panelClipping3D );
106
107                         mwxvtkclipping3Dview                                            = new wxVtkClipping3DView(mwxvtk3Dbaseview_Clipping3D);
108                         vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
109                         vtkclipping3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
110                         vtkclipping3Ddataviewer->Configure();
111                         mwxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
112
113                         mwxvtkmpr3Dview                                                 = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
114                         vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
115                         vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
116                         vtkmpr3Ddataviewer->Configure();
117                         mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
118
119                         wxWindow        *window3D                                       = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
120
121                         wxPanel                 *panelControl                   = new wxPanel(panelClipping3D,-1);      
122                         wxPanel                 *controlPanelMPR3D              = mwxvtkmpr3Dview->CreateControlPanel(panelControl);
123                         wxPanel                 *controlPanelClipping3D = mwxvtkclipping3Dview->CreateControlPanel(panelControl);
124         //                               mbtnCutImageData               = new wxCheckBox(panelControl,-1,_T("Cut Module"));
125         //              Connect(_btnCutImageData->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &wxMPRWidget::OnCutImagaData );
126
127                         wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
128                         sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
129                         sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
130         //              sizerCtrol->Add( mbtnCutImageData               , 1, wxALL, 2);
131
132                         panelControl->SetAutoLayout(true);
133                         panelControl->SetSizer(sizerCtrol);
134                         panelControl->SetSize(400,350);
135                         panelControl->Layout();
136                         panelClipping3D -> SetMinimumPaneSize( 5 );
137                         panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
138                         wxwindow=panelClipping3D;
139                 }
140
141                 if (type==6)
142                 {
143                         wxSplitterWindow        *panelClipping3D        = new wxSplitterWindow( panel , -1);
144                         mwxvtk3Dbaseview_Clipping3D                             = new wxVtk3DBaseView( panelClipping3D );
145
146                         mwxvtkmpr3Dview                                                 = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
147                         vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
148                         vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
149                         vtkmpr3Ddataviewer->Configure();
150                         mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
151
152                         wxWindow        *window3D                                       = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
153
154                         wxPanel                 *panelControl                   = new wxPanel(panelClipping3D,-1);      
155                         wxPanel                 *controlPanelMPR3D              = mwxvtkmpr3Dview->CreateControlPanel(panelControl);
156
157                         wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
158                         sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
159
160                         panelControl->SetAutoLayout(true);
161                         panelControl->SetSizer(sizerCtrol);
162                         panelControl->SetSize(400,350);
163                         panelControl->Layout();
164                         panelClipping3D -> SetMinimumPaneSize( 5 );
165                         panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
166                         wxwindow=panelClipping3D;
167                 }
168
169
170
171         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
172         sizer->Add( wxwindow , 1, wxGROW);      
173         panel->SetSizer(sizer);
174         panel->SetAutoLayout(true);
175         sizer->Layout();
176         panel->Layout();
177         panel->Refresh();
178
179         //   mbbtkViewerMaracas= NULL;
180         }
181         //-------------------------------------------------------------------------
182           
183         wxMaracas_ViewerWidget::~wxMaracas_ViewerWidget()
184         {
185
186                 testDelete(mvtkmprbasedata);
187                 testDelete(mvtk2Dbaseview);
188                 testDelete(mvtkmpr2Dview_X); 
189                 testDelete(mvtkmpr2Dview_Y); 
190                 testDelete(mvtkmpr2Dview_Z); 
191                 testDelete(mwidgetMesure);
192                 testDelete(mvtkplane2Dview);
193                 testDelete(mwxsphereview); 
194                 testDelete(mwxvtkclipping3Dview);
195                 testDelete(mwxvtk3Dbaseview_Clipping3D);
196                 testDelete(mwxvtkmpr3Dview);
197
198         }
199
200         void wxMaracas_ViewerWidget::testDelete(void* point){
201                 if(point!=NULL){
202                         delete point;  ///EED ??????
203                 }
204         }
205             
206         //------------------------------------------------------------------------------------------------------------
207         // Methods
208         //------------------------------------------------------------------------------------------------------------
209
210         //-------------------------------------------------------------------------
211
212         void wxMaracas_ViewerWidget::ConfigureVTK()
213         {
214                 int x=0,y=0,z=0;
215
216                 if ( mvtk2Dbaseview                             !=NULL ) { mvtk2Dbaseview                               ->      Configure();                            }
217                 if ( mvtkmpr2Dview_X                    !=NULL ) { mvtkmpr2Dview_X                              ->      Configure();                            }
218                 if ( mvtkmpr2Dview_Y                    !=NULL ) { mvtkmpr2Dview_Y                              ->      Configure();                            }
219                 if ( mvtkmpr2Dview_Z                    !=NULL ) { mvtkmpr2Dview_Z                              ->      Configure();                            }
220                 if ( mvtkplane2Dview                    !=NULL ) { mvtkplane2Dview                              ->      Configure();                            }
221                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      ConfigureA(mvtkplane2Dview);}
222                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      ConfigureA(mvtkplane2Dview);}
223                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      SetActiveLink(true);            }
224                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      SetMesureScale( 1 );            }
225                 if ( mwxsphereview                              !=NULL ) { mwxsphereview                                ->      Configure();                            }
226
227                 if (mwxvtk3Dbaseview_Clipping3D !=NULL) { mwxvtk3Dbaseview_Clipping3D   ->      Configure();                            }
228                 if (mwxvtkmpr3Dview                             !=NULL) { mwxvtkmpr3Dview                               ->      Configure();                            }
229                 if (mwxvtkclipping3Dview                !=NULL) { mwxvtkclipping3Dview                  ->      Configure();                            }
230
231                 if (mvtkmprbasedata!=NULL)
232                 {
233                         x = mvtkmprbasedata     ->      GetMaxPositionX()/2;
234                         y = mvtkmprbasedata     ->      GetMaxPositionY()/2;
235                         z = mvtkmprbasedata     ->      GetMaxPositionZ()/2;
236                         mvtkmprbasedata->SetX( x );
237                         mvtkmprbasedata->SetY( y );
238                         mvtkmprbasedata->SetZ( z );
239                 }
240 //              RefreshView();
241         }
242
243         //-------------------------------------------------------------------------
244
245   void wxMaracas_ViewerWidget::Refresh(bool eraseBackground ,const wxRect* rect  )  // virtual  eraseBackground=true , rect=NULL
246   {
247     wxPanel::Refresh(false);
248   }
249
250         //-------------------------------------------------------------------------
251         void wxMaracas_ViewerWidget::RefreshView()
252         {
253                 
254                         if (mvtk2Dbaseview                              !=NULL ){ mvtk2Dbaseview                                -> Refresh();           }
255                         if (mvtkmpr2Dview_X                             !=NULL ){ mvtkmpr2Dview_X                               -> Refresh();           }
256                         if (mvtkmpr2Dview_Y                             !=NULL ){ mvtkmpr2Dview_Y                               -> Refresh();           }
257                         if (mvtkmpr2Dview_Z                             !=NULL ){ mvtkmpr2Dview_Z                               -> Refresh();           }
258                         if (mvtkplane2Dview                             !=NULL ){ mvtkplane2Dview                               -> Refresh();           }
259                         if (mwxsphereview                               !=NULL ){ mwxsphereview                                 -> Refresh();           }
260
261                         if (mwxvtkmpr3Dview                             !=NULL ){ mwxvtkmpr3Dview                               -> RefreshView();       }
262                         if (mwxvtkclipping3Dview                !=NULL ){ mwxvtkclipping3Dview                  -> Refresh();           }
263                         if (mwxvtk3Dbaseview_Clipping3D !=NULL ){ mwxvtk3Dbaseview_Clipping3D   -> Refresh();           }
264
265         }
266
267         //-------------------------------------------------------------------------
268
269         wxVtkBaseView *wxMaracas_ViewerWidget::GetwxVtkBaseView()
270         {
271                 wxVtkBaseView *wxvtkbaseview=NULL;
272                 if (mvtk2Dbaseview!=NULL)                               { wxvtkbaseview = mvtk2Dbaseview;                       }
273                 if (mvtkmpr2Dview_X!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_X;                      }
274                 if (mvtkmpr2Dview_Y!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_Y;                      }
275                 if (mvtkmpr2Dview_Z!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_Z;                      }
276                 if (mvtkplane2Dview!=NULL)                              { wxvtkbaseview = mvtkplane2Dview;                      }
277                 if (mwxsphereview!=NULL)                                { wxvtkbaseview = mwxsphereview;                        }
278                 if (mwxvtk3Dbaseview_Clipping3D!=NULL)  { wxvtkbaseview = mwxvtk3Dbaseview_Clipping3D;}
279                 return wxvtkbaseview   ;
280         }
281
282         void wxMaracas_ViewerWidget::SetImage( vtkImageData *image      )
283         {
284                 marImageData* mar = mvtkmprbasedata->GetMarImageData();
285                 mar->removeImageData(0);
286                 mar->AddImageData(image);
287
288                 ConfigureVTK();
289                 RefreshView();
290
291
292
293         }
294
295         double wxMaracas_ViewerWidget :: GetX()
296         {
297                 return mvtkmprbasedata->GetX();
298         }
299
300         double wxMaracas_ViewerWidget :: GetY()
301         {
302                 return mvtkmprbasedata->GetY();
303         }
304
305         double wxMaracas_ViewerWidget :: GetZ()
306         {
307                 return mvtkmprbasedata->GetZ();
308 //              return mvtk2Dbaseview->GetVtkBaseData()->GetZ();
309         }
310