1 /*=========================================================================
4 Module: $RCSfile: wxMaracas_ViewerWidget.cxx,v $
6 Date: $Date: 2009/10/16 15:17:57 $
7 Version: $Revision: 1.18 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
18 //------------------------------------------------------------------------------------------------------------
19 // Definition includes
20 //------------------------------------------------------------------------------------------------------------
21 #include "wxMaracas_ViewerWidget.h"
23 //------------------------------------------------------------------------------------------------------------
25 //------------------------------------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------------------------------------
29 // Constructors & Destructors
30 //------------------------------------------------------------------------------------------------------------
33 wxMaracas_ViewerWidget::wxMaracas_ViewerWidget(wxWindow *parent, vtkImageData* imagedata, int type, vtkMPRBaseData *vtkmprbasedata)
34 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
36 wxPanel *panel = this;
37 wxWindow *wxwindow = NULL;
42 if (vtkmprbasedata==NULL)
44 minternalVtkmprbasedata = true;
45 mvtkmprbasedata = new vtkMPRBaseData();
46 marImageData *marimagedata = new marImageData( imagedata );
47 mvtkmprbasedata->SetMarImageData(marimagedata);
49 minternalVtkmprbasedata = false;
50 mvtkmprbasedata = vtkmprbasedata;
54 mvtk2Dbaseview = NULL;
55 mvtkmpr2Dview_X = NULL;
56 mvtkmpr2Dview_Y = NULL;
57 mvtkmpr2Dview_Z = NULL;
58 mvtkplane2Dview = NULL;
61 mwxvtkclipping3Dview = NULL;
62 mwxvtk3Dbaseview_Clipping3D = NULL;
63 mwxvtkmpr3Dview = NULL;
64 vtkmpr3Ddataviewer = NULL;
69 mvtk2Dbaseview = new wxVtk2DBaseView(panel);
70 mvtk2Dbaseview->SetVtkBaseData(mvtkmprbasedata);
71 wxwindow = mvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
77 mvtkmpr2Dview_Z = new wxVtkMPR2DView(panel,2);
78 mvtkmpr2Dview_Z->SetVtkBaseData(mvtkmprbasedata);
79 wxwindow = mvtkmpr2Dview_Z->GetWxVTKRenderWindowInteractor();
83 mvtkmpr2Dview_X = new wxVtkMPR2DView(panel,0);
84 mvtkmpr2Dview_X->SetVtkBaseData(mvtkmprbasedata);
85 wxwindow = mvtkmpr2Dview_X->GetWxVTKRenderWindowInteractor();
90 mvtkmpr2Dview_Y = new wxVtkMPR2DView(panel,1);
91 mvtkmpr2Dview_Y->SetVtkBaseData(mvtkmprbasedata);
92 wxwindow = mvtkmpr2Dview_Y->GetWxVTKRenderWindowInteractor();
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;
107 mwxsphereview = new wxSphereView( panel , mvtkmprbasedata, mvtkmprbasedata->GetImageData() );
108 wxwindow=mwxsphereview->GetWxVTKRenderWindowInteractor();
114 wxSplitterWindow *panelClipping3D = new wxSplitterWindow( panel , -1);
115 mwxvtk3Dbaseview_Clipping3D = new wxVtk3DBaseView( panelClipping3D );
117 mwxvtkclipping3Dview = new wxVtkClipping3DView(mwxvtk3Dbaseview_Clipping3D);
118 vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer();
119 vtkclipping3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
120 vtkclipping3Ddataviewer->Configure();
121 mwxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
123 mwxvtkmpr3Dview = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
124 vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer();
125 vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
126 vtkmpr3Ddataviewer->Configure();
127 mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
129 wxWindow *window3D = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
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 );
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);
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;
153 wxSplitterWindow *panelClipping3D = new wxSplitterWindow( panel , -1);
154 mwxvtk3Dbaseview_Clipping3D = new wxVtk3DBaseView( panelClipping3D );
156 mwxvtkmpr3Dview = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
159 vtkmpr3Ddataviewer = new vtkMPR3DDataViewer();
163 wxWindow *window3D = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
165 wxPanel *panelControl = new wxPanel(panelClipping3D,-1);
166 wxPanel *controlPanelMPR3D = mwxvtkmpr3Dview->CreateControlPanel(panelControl);
168 wxFlexGridSizer *sizerCtrol = new wxFlexGridSizer(1);
169 sizerCtrol->Add(controlPanelMPR3D , 1, wxALL|wxEXPAND, 2);
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;
180 vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
181 //vtkmpr3Ddataviewer->Configure();
183 mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
189 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
190 sizer->Add( wxwindow , 1, wxGROW);
191 panel->SetSizer(sizer);
192 panel->SetAutoLayout(true);
197 // mbbtkViewerMaracas= NULL;
199 //-------------------------------------------------------------------------
201 wxMaracas_ViewerWidget::~wxMaracas_ViewerWidget()
204 if (minternalVtkmprbasedata==true)
206 if (mvtkmprbasedata) { delete mvtkmprbasedata; }
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; }
220 //------------------------------------------------------------------------------------------------------------
222 //------------------------------------------------------------------------------------------------------------
224 //-------------------------------------------------------------------------
226 void wxMaracas_ViewerWidget::ConfigureVTK()
236 double org[3],spc[3];
246 if (mvtkmprbasedata!=NULL)
248 mvtkmprbasedata->Configure();
249 /*x = mvtkmprbasedata -> GetMaxPositionX()/2;
250 y = mvtkmprbasedata -> GetMaxPositionY()/2;
251 z = mvtkmprbasedata -> GetMaxPositionZ()/2; */
253 mvtkmprbasedata->GetImageData()->GetExtent(ext);
254 mvtkmprbasedata->GetImageData()->GetOrigin(org);
255 mvtkmprbasedata->GetImageData()->GetSpacing(spc);
257 x = (ext[0]+ext[1])/2;
258 y = (ext[2]+ext[3])/2;
259 z = (ext[4]+ext[5])/2;
261 mvtkmprbasedata->SetX( x );
262 mvtkmprbasedata->SetY( y );
263 mvtkmprbasedata->SetZ( z );
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(); }
279 if (mwxvtk3Dbaseview_Clipping3D !=NULL) { mwxvtk3Dbaseview_Clipping3D -> Configure(); }
281 if (vtkmpr3Ddataviewer !=NULL) {
282 vtkmpr3Ddataviewer->Configure();
285 if (mwxvtkmpr3Dview !=NULL) {
287 mwxvtkmpr3Dview -> Configure();
288 mwxvtkmpr3Dview ->ResetCamera(ext,org,spc);
293 if (mwxvtkclipping3Dview !=NULL) { mwxvtkclipping3Dview -> Configure(); }
299 //if(vtkmpr3Ddataviewer!=NULL){vtkmpr3Ddataviewer->Configure();}
302 //if (mwxvtkmpr3Dview !=NULL) {
303 // mwxvtkmpr3Dview->ResetCamera();
308 //-------------------------------------------------------------------------
310 void wxMaracas_ViewerWidget::Refresh(bool eraseBackground ,const wxRect* rect ) // virtual eraseBackground=true , rect=NULL
312 wxPanel::Refresh(false);
315 //-------------------------------------------------------------------------
316 void wxMaracas_ViewerWidget::RefreshView()
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(); }
326 if (mwxvtkmpr3Dview !=NULL ){ mwxvtkmpr3Dview -> RefreshView(); }
327 if (mwxvtkclipping3Dview !=NULL ){ mwxvtkclipping3Dview -> Refresh(); }
328 if (mwxvtk3Dbaseview_Clipping3D !=NULL ){ mwxvtk3Dbaseview_Clipping3D -> Refresh(); }
332 //-------------------------------------------------------------------------
334 wxVtkBaseView *wxMaracas_ViewerWidget::GetwxVtkBaseView()
336 wxVtkBaseView *wxvtkbaseview=NULL;
337 if (mvtk2Dbaseview!=NULL) {
338 wxvtkbaseview = mvtk2Dbaseview;
340 if (mvtkmpr2Dview_X!=NULL){
341 wxvtkbaseview = mvtkmpr2Dview_X;
343 if (mvtkmpr2Dview_Y!=NULL){
344 wxvtkbaseview = mvtkmpr2Dview_Y;
346 if (mvtkmpr2Dview_Z!=NULL){
347 wxvtkbaseview = mvtkmpr2Dview_Z;
349 if (mvtkplane2Dview!=NULL){
350 wxvtkbaseview = mvtkplane2Dview;
352 if (mwxsphereview!=NULL){
353 wxvtkbaseview = mwxsphereview;
355 if (mwxvtk3Dbaseview_Clipping3D!=NULL) {
356 wxvtkbaseview = mwxvtk3Dbaseview_Clipping3D;
358 return wxvtkbaseview ;
361 void wxMaracas_ViewerWidget::SetImage( vtkImageData *image )
363 marImageData* mar = mvtkmprbasedata->GetMarImageData();
364 mar->removeImageData(0);
365 mar->AddImageData(image);
374 double wxMaracas_ViewerWidget :: GetX()
376 return mvtkmprbasedata->GetX();
379 double wxMaracas_ViewerWidget :: GetY()
381 return mvtkmprbasedata->GetY();
384 double wxMaracas_ViewerWidget :: GetZ()
386 return mvtkmprbasedata->GetZ();
387 // return mvtk2Dbaseview->GetVtkBaseData()->GetZ();
390 void wxMaracas_ViewerWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){
391 if(mvtkmpr2Dview_X!=NULL){
392 mvtkmpr2Dview_X->setColorTransferFunction(colortable);
394 if(mvtkmpr2Dview_Y!=NULL){
395 mvtkmpr2Dview_Y->setColorTransferFunction(colortable);
397 if(mvtkmpr2Dview_Z!=NULL){
398 mvtkmpr2Dview_Z->setColorTransferFunction(colortable);
400 if(mwxvtkmpr3Dview!=NULL){
401 mwxvtkmpr3Dview->setColorTransferFunction(colortable);
405 void wxMaracas_ViewerWidget::setWindowLevel(double level){
406 if(mvtkmpr2Dview_X!=NULL){
407 mvtkmpr2Dview_X->setWindowLevel(level);
409 if(mvtkmpr2Dview_Y!=NULL){
410 mvtkmpr2Dview_Y->setWindowLevel(level);
412 if(mvtkmpr2Dview_Z!=NULL){
413 mvtkmpr2Dview_Z->setWindowLevel(level);
415 /*if(mwxvtkmpr3Dview!=NULL){
416 mwxvtkmpr3Dview->setWindowLevel(level);
420 void wxMaracas_ViewerWidget::setColorLevel(double level){
421 if(mvtkmpr2Dview_X!=NULL){
422 mvtkmpr2Dview_X->setColorLevel(level);
424 if(mvtkmpr2Dview_Y!=NULL){
425 mvtkmpr2Dview_Y->setColorLevel(level);
427 if(mvtkmpr2Dview_Z!=NULL){
428 mvtkmpr2Dview_Z->setColorLevel(level);
430 /*if(mwxvtkmpr3Dview!=NULL){
431 mwxvtkmpr3Dview->setColorLevel(level);