1 /*=========================================================================
4 Module: $RCSfile: wxSurfaceWidget.cxx,v $
6 Date: $Date: 2009/05/14 13:54:57 $
7 Version: $Revision: 1.1 $
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 #include "../res/bitmaps/extract.xpm"
19 #include "../res/bitmaps/del_axis.xpm"
20 #include "../res/bitmaps/plans.xpm"
21 #include "wxSurfaceWidget.h"
22 #include "../marDictionary.h"
23 #include "../wxMaracas_ManualTree_MPRDlg.h"
28 #include <wx/dialog.h>
29 #include <wx/colordlg.h>
31 // PS -> #ifndef __WXMSW__
32 // PS -> # include "../res/bitmaps/extract.xpm"
33 // PS -> # include "../res/bitmaps/del_axis.xpm"
36 //----------------------------------------------------------------------------
37 BEGIN_EVENT_TABLE( wxSurfaceWidget, wxPanel )
39 EVT_BUTTON(ID_BUTTON_NEW_AXIS , wxSurfaceWidget::OnExtractAxis )
40 EVT_BUTTON(ID_BUTTON_DELETE_AXIS , wxSurfaceWidget::OnDeleteAxis )
41 EVT_BUTTON(ID_BUTTON_QUANTIFICATION , wxSurfaceWidget::OnQuantification )
42 EVT_BUTTON(ID_BUTTON_MANUAL_AXIS , wxSurfaceWidget::OnManualAxis )
45 EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR , wxSurfaceWidget::OnChooseSurfaceColor )
46 EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE , wxSurfaceWidget::OnIsoVisible )
48 EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceWidget::OnSliderOpacityScrollThumbrelease)
49 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease)
52 //----------------------------------------------------------------------------
53 wxSurfaceWidget::wxSurfaceWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos,
54 const wxSize& size, long style, const wxString& name)
55 : wxPanel( parent, id, pos, size, style, name )
57 printf("EED wxSurfaceWidget::wxSurfaceWidget 1 \n" );
59 marDictionary marDict;
65 _3DWorld = new vtk3DSurfaceWidget( this, ID_WORLD3D );
66 _3DWorld->SetInterfaceVtkPanelWidgets(this);
68 // Set up axis toolbar
69 wxBitmap axisToolBarBitmaps[ 3 ];
70 axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
71 axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase );
72 axisToolBarBitmaps[ 2 ] = wxBITMAP( toolbar_plans );
75 _bt_new_axis = new wxBitmapButton( this, ID_BUTTON_NEW_AXIS , axisToolBarBitmaps[ 0 ] );
76 _bt_delete_axis = new wxBitmapButton( this, ID_BUTTON_DELETE_AXIS , axisToolBarBitmaps[ 1 ] );
77 _bt_call_quantification = new wxBitmapButton( this, ID_BUTTON_QUANTIFICATION, axisToolBarBitmaps[ 2 ],wxDefaultPosition,wxSize(70,70));
79 _bt_manual_axis = new wxButton(this, ID_BUTTON_MANUAL_AXIS, _T("Manual Axis"));
80 // _bt_manual_axis->SetSize(80,40);
86 //By default the Iso value is visible.
87 _isoVisible = new wxCheckBox ( this, ID_CHECKBOX_ISOVISIBLE, wxString(marDict.GetString(15), wxConvUTF8) ); //"Iso visible"
88 _isoValue = new wxSlider ( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
89 _opacity = new wxSlider ( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
90 _isoVisible->SetValue( true );
91 _isoValue->SetLabel( wxString(marDict.GetString(25), wxConvUTF8) ); // "IsoValue"
92 _opacity->SetLabel( wxString(marDict.GetString(0), wxConvUTF8) ); //"Surface opacity"
95 //I can't get to brighten the button when mouse over:
96 //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
97 //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
101 _isoValue->SetSize(wxSize(64, 16));
105 wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1,wxString(marDict.GetString(10), wxConvUTF8) ), wxVERTICAL);//"Iso Surface values"
106 //Some borders are needed on wxGTK otherwise static text and slider labels collides.
107 sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
108 sizer_3->Add(new wxStaticText(this, -1, wxString(marDict.GetString(20), wxConvUTF8)), 1, wxALL|wxEXPAND, 2); // "Opacity (%)"
109 sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
110 sizer_3->Add(new wxStaticText(this, -1,wxString(marDict.GetString(25), wxConvUTF8) ), 1, wxALL|wxEXPAND, 2); // "Isovalue"
111 sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
114 strcpy( tmp , marDict.GetString(30) );
115 _st_cero = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE ); // "0"
117 strcpy( tmp , marDict.GetString(35) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(40) );
118 _st_text = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE); // "Select\n artery"
120 strcpy( tmp , marDict.GetString(45) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(50) );
121 _st_one = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE ); // "1 \n Axis Extraction"
123 strcpy( tmp , marDict.GetString(55) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(60) );
124 _st_two = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE); // " 2 \n Quantification"
127 // wxFont font(12,wxDEFAULT ,wxNORMAL,wxBOLD);
128 // st_blank->SetFont(font);
129 // st_next1->SetFont(font);
130 // st_next2->SetFont(font);
131 // _st_one->SetFont(font);
132 // _st_two->SetFont(font);
133 // _st_cero->SetFont(font);
136 _bt_new_axis->Disable();
137 _bt_delete_axis->Disable();
139 _bt_call_quantification->Disable();
143 wxFlexGridSizer *axis_sizer = new wxFlexGridSizer(3,5,5,5);
144 axis_sizer->Add(_st_cero ,0,wxALIGN_CENTER_HORIZONTAL);
145 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTER_HORIZONTAL);
146 axis_sizer->Add(_st_one ,0,wxALIGN_CENTER_HORIZONTAL);
147 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTER_HORIZONTAL);
148 axis_sizer->Add(_st_two ,0,wxALIGN_CENTER_HORIZONTAL);
150 axis_sizer->Add(_st_text ,0,wxALIGN_CENTRE_VERTICAL);
151 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTRE_VERTICAL);
152 axis_sizer->Add(_bt_new_axis ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
153 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTRE_VERTICAL);
154 axis_sizer->Add(_bt_call_quantification ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
156 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTRE_VERTICAL);
157 axis_sizer->Add(new wxStaticText(this,-1 , _T(" ")) ,0,wxALIGN_CENTRE_VERTICAL);
158 axis_sizer->Add(_bt_delete_axis ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
159 wxBoxSizer *sizer_2 = new wxBoxSizer(wxVERTICAL);
160 sizer_2->Add(sizer_3 , 1, wxEXPAND, 0);
161 sizer_2->Add(new wxStaticText(this,-1 , _T(" ")) );
162 sizer_2->Add(new wxStaticText(this,-1 , _T(" ")) );
163 sizer_2->Add(new wxStaticText(this,-1 , _T(" ")) );
164 sizer_2->Add(new wxStaticText(this,-1 , _T(" ")) );
165 sizer_2->Add(axis_sizer , 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
166 sizer_2->Add(_bt_manual_axis);
169 wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
170 sizer_1->Add(_3DWorld, 1, wxEXPAND, 0);
171 sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
181 //----------------------------------------------------------------------------
182 wxSurfaceWidget::~wxSurfaceWidget( )
187 //----------------------------------------------------------------------------
188 void wxSurfaceWidget::ShowMARACASData( marInterface* mar )
192 double min, max; //backward compatibility
194 _3DWorld->ShowMARACASData( mar );
195 _3DWorld->ConfigureVTK( );
196 _3DWorld->InitCameraReset( );
199 _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
201 _isoValue->SetRange((int)min, (int)max);
202 _isoValue->SetValue( (int)(max/4) );
204 _opacity->SetValue( 50 );
207 // _3DWorld->Render();
210 //----------------------------------------------------------------------------
211 void wxSurfaceWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
214 data.SetChooseFull( true );
215 for( int i = 0; i < 16; i++ )
217 wxColour colour( i * 16, i * 16, i * 16 );
218 data.SetCustomColour( i, colour );
221 wxColourDialog dialog ( this, &data );
222 dialog.SetTitle( _T("choose color") );
224 if( dialog.ShowModal( ) == wxID_OK )
226 wxColourData retData = dialog.GetColourData( );
227 wxColour col = retData.GetColour( );
228 //_surface_color->SetBackgroundColour( col );
230 _3DWorld->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
235 //----------------------------------------------------------------------------
236 void wxSurfaceWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
238 _3DWorld->SetSurfaceVisibility( _isoVisible->GetValue() );
240 //----------------------------------------------------------------------------
241 void wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
244 _3DWorld->SetSurfaceIsoValue( event.GetPosition() );
246 //----------------------------------------------------------------------------
247 void wxSurfaceWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
249 _3DWorld->SetSurfaceOpacity( event.GetPosition() );
251 //----------------------------------------------------------------------------
252 void wxSurfaceWidget::OnExtractAxis(wxCommandEvent& event)
254 if(_3DWorld->GetInitialSphere() )
257 long int startTimeAE = clock();;
262 gtm::TVector< double > xc( 3 );
266 // PS -> vtkPolyData* allData; //PS
268 vtkImageData *imageData=_mar->_experiment->getDynData( )->getVolume( )->castVtk();
269 imageData->GetExtent( extent );
270 imageData->GetSpacing( spc );
271 _3DWorld->GetSphereCenter( data );
275 // _mar->_experiment->setStartPoint( (int)data[0] - extent[0], (int)data[1] - extent[2], (int)data[2] - extent[4]);
277 x= (data[0] - extent[0]) / spc[0];
278 y= (data[1] - extent[2]) / spc[1];
279 z= (data[2] - extent[4]) / spc[2];
280 _mar->_experiment->setStartPoint( (int)x, (int)y, (int)z);
282 _mar->_experiment->extractVascularTree( );
284 _mar->_experiment->setAxis( 0 );
287 // PS -> allData = temp->Draw( ); //PS
288 // PS -> _3DWorld->SetAxis( allData );//PS
292 //EED _axis_tb->EnableTool(ID_BUTTON_NEW_AXIS, false);
293 //EED _axis_tb->EnableTool(ID_BUTTON_DELETE_AXIS, true);
295 _bt_new_axis->Disable();
297 _bt_delete_axis->Enable();
298 _bt_call_quantification->Enable();
301 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
307 ff = fopen("c:/temp/MaracasStadistics.txt","a+");
308 long int endtime = clock();
309 double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
310 fprintf(ff,"EED %p wxSurfaceWidget::OnExtractAxis > AE_t = %f \n",this,sg);
317 wxMessageBox( _T("Set an initial point.\n \n (Double click over the interest artery.)"),
318 _T("DxMM : MARACAS"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
322 //----------------------------------------------------------------------------
323 void wxSurfaceWidget::AddAxisActors(){
325 marAxis *maraxis = _mar->_experiment->getAxis( );
326 vtkPolyData *vtkpolydata = maraxis->Draw();
327 vtkPoints *vtkpoints = vtkpolydata->GetPoints();
328 int size = vtkpoints->GetNumberOfPoints();
332 double voxelSize = _mar->_parameters->getVoxelSize();
337 vtkpoints->GetPoint(i,pp);
338 pp[0]=pp[0] * voxelSize;
339 pp[1]=pp[1] * voxelSize;
340 pp[2]=pp[2] * voxelSize;
344 if (maraxis!=NULL) _3DWorld->SetAxis( vtkpolydata );
348 //----------------------------------------------------------------------------
349 void wxSurfaceWidget::Clean3D(){
350 _3DWorld->RemoveAxis( );
352 //----------------------------------------------------------------------------
353 void wxSurfaceWidget::RefreshAxis() {
356 //----------------------------------------------------------------------------
357 void wxSurfaceWidget::OnDeleteAxis(wxCommandEvent& event)
361 _mar->_experiment->DeleteAxis( 0 );
364 //wxToolBar::EnableTool This function should only be called after Realize.
366 _bt_new_axis->Enable();
367 _bt_delete_axis->Disable();
368 _bt_call_quantification->Disable();
373 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_DELETE_AXIS);
377 //----------------------------------------------------------------------------
378 void wxSurfaceWidget::CallBackOnLeftDClick( wxMouseEvent& event ){
379 _3DWorld->SetInitialPoint();
380 if ( _3DWorld->GetInitialSphere() ){
381 marAxis *maraxis = _mar->_experiment->getAxis( );
385 _bt_new_axis->Enable();
388 _bt_new_axis->Disable();
394 if ( !_3DWorld->GetInitialSphere() ) {
396 _bt_new_axis->Disable();
400 //----------------------------------------------------------------------------
401 void wxSurfaceWidget::OnQuantification(wxCommandEvent& event){
402 if (_id_toolbar_plans!=-1){
403 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,_id_toolbar_plans);
407 //----------------------------------------------------------------------------
408 void wxSurfaceWidget::SetId_toolbar_plans(int id_toolbar_plans ){
409 _id_toolbar_plans=id_toolbar_plans;
411 //----------------------------------------------------------------------------
412 int wxSurfaceWidget::GetIsovalue(){
413 return _isoValue->GetValue();
415 //----------------------------------------------------------------------------
416 int wxSurfaceWidget::GetOpacity(){
417 return _opacity->GetValue();
419 //----------------------------------------------------------------------------
420 vtk3DSurfaceWidget *wxSurfaceWidget::GetVtk3DSurfaceWidget(){
423 //----------------------------------------------------------------------------
424 void wxSurfaceWidget::OnManualAxis(wxCommandEvent& event)
427 if ( _bt_delete_axis->IsEnabled() )
432 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
433 wxMaracas_ManualTree_MPRDlg *maracasManualTreeMPRDlg = new wxMaracas_ManualTree_MPRDlg( this , new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
434 marAxis *maraxis = new marAxis( _mar->_experiment->getParameters() );
435 maracasManualTreeMPRDlg->SetMarAxis( maraxis );
436 maracasManualTreeMPRDlg->ConfigureVTK();
437 if (maracasManualTreeMPRDlg->ShowModal()==wxID_OK)
439 if (maracasManualTreeMPRDlg->ExportPoints()==true){
440 _mar->_experiment->appendAxis(maraxis);
441 _bt_new_axis->Disable();
443 _bt_delete_axis->Enable();
444 _bt_call_quantification->Enable();
447 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
453 maracasManualTreeMPRDlg->Destroy();