]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/wxSurfaceWidget.cxx
ef497f60d8b2f7beceec05ddaeafd7ba7617439f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / wxSurfaceWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxSurfaceWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/05/14 13:54:57 $
7   Version:   $Revision: 1.1 $
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 #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"
24
25
26 #include <matrix.h>
27
28 #include <wx/dialog.h>
29 #include <wx/colordlg.h>
30
31 // PS -> #ifndef __WXMSW__
32 // PS -> #   include "../res/bitmaps/extract.xpm"
33 // PS -> #   include "../res/bitmaps/del_axis.xpm"
34 // PS -> #endif
35
36 //----------------------------------------------------------------------------
37 BEGIN_EVENT_TABLE( wxSurfaceWidget, wxPanel )
38
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                         )
43
44
45     EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR   , wxSurfaceWidget::OnChooseSurfaceColor         )
46     EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE , wxSurfaceWidget::OnIsoVisible                         )
47
48     EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceWidget::OnSliderOpacityScrollThumbrelease)
49     EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease)
50 END_EVENT_TABLE( );
51
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 )
56 {
57 printf("EED wxSurfaceWidget::wxSurfaceWidget  1 \n" );
58
59         marDictionary marDict;
60         char tmp[256];
61
62         _id_toolbar_plans=-1;
63         _mar = NULL;
64
65         _3DWorld = new vtk3DSurfaceWidget( this, ID_WORLD3D );
66         _3DWorld->SetInterfaceVtkPanelWidgets(this);
67
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       );
73
74
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));
78
79         _bt_manual_axis         = new wxButton(this, ID_BUTTON_MANUAL_AXIS, _T("Manual Axis")); 
80 //      _bt_manual_axis->SetSize(80,40);
81
82
83
84
85
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"
93
94
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));
98
99
100     //Set Properties:
101     _isoValue->SetSize(wxSize(64, 16));
102     //End set properties
103
104     //Do the layout:
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);
112
113     //Do the layout:
114         strcpy( tmp , marDict.GetString(30) ); 
115         _st_cero        = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE );     // "0"
116
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" 
119
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" 
122
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"
125
126
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);
134  
135         _st_one->Disable();
136         _bt_new_axis->Disable();
137         _bt_delete_axis->Disable();
138         _st_two->Disable();
139         _bt_call_quantification->Disable();
140
141
142
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);
149
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);
155
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);
167
168
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);
172
173     SetSizer(sizer_1);
174     SetAutoLayout(true);
175     Layout();
176
177
178
179 }
180
181 //----------------------------------------------------------------------------
182 wxSurfaceWidget::~wxSurfaceWidget( )
183 {
184         _3DWorld->Delete();
185 }
186
187 //----------------------------------------------------------------------------
188 void wxSurfaceWidget::ShowMARACASData( marInterface* mar )
189 {
190   wxBusyCursor wait;
191
192    double min, max; //backward compatibility
193   _mar = mar;
194   _3DWorld->ShowMARACASData( mar );
195   _3DWorld->ConfigureVTK( );
196   _3DWorld->InitCameraReset( );
197
198   //GUI stuff:
199   _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
200
201   _isoValue->SetRange((int)min, (int)max);
202   _isoValue->SetValue( (int)(max/4) );
203
204   _opacity->SetValue( 50 );
205
206 //EED 31 Mai 2007
207 //  _3DWorld->Render();
208
209 }
210 //----------------------------------------------------------------------------
211 void wxSurfaceWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
212 {
213     wxColourData data;
214     data.SetChooseFull( true );
215     for( int i = 0; i < 16; i++ )
216     {
217         wxColour colour( i * 16, i * 16, i * 16 );
218         data.SetCustomColour( i, colour );
219     } // rof
220
221     wxColourDialog dialog ( this, &data );
222     dialog.SetTitle( _T("choose color") );
223
224     if( dialog.ShowModal( ) == wxID_OK )
225     {
226         wxColourData retData = dialog.GetColourData( );
227         wxColour col = retData.GetColour( );
228       //_surface_color->SetBackgroundColour( col );
229
230       _3DWorld->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
231
232     } // fi
233
234 }
235 //----------------------------------------------------------------------------
236 void wxSurfaceWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
237 {
238   _3DWorld->SetSurfaceVisibility( _isoVisible->GetValue() );
239 }
240 //----------------------------------------------------------------------------
241 void wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
242 {
243   wxBusyCursor wait;
244   _3DWorld->SetSurfaceIsoValue( event.GetPosition() );
245 }
246 //----------------------------------------------------------------------------
247 void wxSurfaceWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
248 {
249   _3DWorld->SetSurfaceOpacity( event.GetPosition() );
250 }
251 //----------------------------------------------------------------------------
252 void wxSurfaceWidget::OnExtractAxis(wxCommandEvent& event)
253 {
254   if(_3DWorld->GetInitialSphere() )
255   {
256 // EED Borrame
257 long int startTimeAE = clock();;
258
259
260    wxBusyCursor wait;
261
262         gtm::TVector< double > xc( 3 );
263         double data[3];
264         int extent[ 6 ];
265         double spc[ 3 ];
266 // PS ->        vtkPolyData* allData; //PS
267
268         vtkImageData *imageData=_mar->_experiment->getDynData( )->getVolume( )->castVtk();
269     imageData->GetExtent( extent );
270     imageData->GetSpacing( spc );
271     _3DWorld->GetSphereCenter( data );
272
273
274 //EED 20 Sep 2006
275 //      _mar->_experiment->setStartPoint( (int)data[0] - extent[0], (int)data[1] - extent[2], (int)data[2] - extent[4]);
276         double x,y,z;
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);
281
282         _mar->_experiment->extractVascularTree( );
283
284         _mar->_experiment->setAxis( 0 );
285
286         AddAxisActors();
287 // PS ->         allData = temp->Draw( ); //PS
288 // PS ->      _3DWorld->SetAxis( allData );//PS
289
290     //Disabling tool
291
292 //EED    _axis_tb->EnableTool(ID_BUTTON_NEW_AXIS, false);
293 //EED    _axis_tb->EnableTool(ID_BUTTON_DELETE_AXIS, true);
294
295         _bt_new_axis->Disable();
296     _st_two->Enable();
297         _bt_delete_axis->Enable();
298         _bt_call_quantification->Enable();
299
300         event.Skip();
301         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
302         ProcessEvent( ev );
303
304 /*
305 //EED Borrame
306 FILE *ff;
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);
311 fclose(ff);
312 */
313
314   }
315   else
316   {
317         wxMessageBox( _T("Set an initial point.\n \n (Double click over the interest artery.)"),
318                                           _T("DxMM : MARACAS"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
319   }
320
321 }
322 //----------------------------------------------------------------------------
323 void wxSurfaceWidget::AddAxisActors(){
324         // Axes ...
325         marAxis         *maraxis                = _mar->_experiment->getAxis( );
326         vtkPolyData *vtkpolydata        = maraxis->Draw();
327         vtkPoints       *vtkpoints              = vtkpolydata->GetPoints();
328         int                     size                    = vtkpoints->GetNumberOfPoints();
329
330 // EED 22 sep 2006
331 // EED 07 dic 2006
332         double voxelSize = _mar->_parameters->getVoxelSize();
333         double pp[3];
334         int i;
335         for (i=0;i<size;i++)
336         {
337                 vtkpoints->GetPoint(i,pp);
338                 pp[0]=pp[0] * voxelSize;
339                 pp[1]=pp[1] * voxelSize;
340                 pp[2]=pp[2] * voxelSize;
341         }
342
343
344         if (maraxis!=NULL) _3DWorld->SetAxis( vtkpolydata );
345         // Other Actors..
346         // ..
347 }
348 //----------------------------------------------------------------------------
349 void wxSurfaceWidget::Clean3D(){
350   _3DWorld->RemoveAxis( );
351 }
352 //----------------------------------------------------------------------------
353 void wxSurfaceWidget::RefreshAxis() {   
354         _3DWorld->Render(); 
355 }
356 //----------------------------------------------------------------------------
357 void wxSurfaceWidget::OnDeleteAxis(wxCommandEvent& event)
358 {
359         wxBusyCursor wait;
360         Clean3D();
361         _mar->_experiment->DeleteAxis( 0 );
362
363     //Disabling tool
364     //wxToolBar::EnableTool This function should only be called after Realize.
365
366         _bt_new_axis->Enable();
367         _bt_delete_axis->Disable();
368         _bt_call_quantification->Disable();
369         _st_one->Enable();
370         _st_two->Disable();
371
372         event.Skip();
373         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_DELETE_AXIS);
374         ProcessEvent(  ev );
375
376 }
377 //----------------------------------------------------------------------------
378 void wxSurfaceWidget::CallBackOnLeftDClick( wxMouseEvent& event ){
379         _3DWorld->SetInitialPoint();
380         if ( _3DWorld->GetInitialSphere() ){  
381                 marAxis *maraxis = _mar->_experiment->getAxis( );
382
383                 if (maraxis==NULL) {
384                         _st_one->Enable();
385                         _bt_new_axis->Enable();
386                 } else {
387                         _st_one->Disable();
388                         _bt_new_axis->Disable();
389                 }
390
391         }
392
393
394         if ( !_3DWorld->GetInitialSphere() ) {
395                         _st_one->Disable();
396                         _bt_new_axis->Disable();
397         }
398
399 }
400 //----------------------------------------------------------------------------
401 void wxSurfaceWidget::OnQuantification(wxCommandEvent& event){
402         if (_id_toolbar_plans!=-1){
403            wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,_id_toolbar_plans);
404            ProcessEvent(  ev );
405         }
406 }
407 //----------------------------------------------------------------------------
408 void wxSurfaceWidget::SetId_toolbar_plans(int id_toolbar_plans ){
409         _id_toolbar_plans=id_toolbar_plans;
410 }
411 //----------------------------------------------------------------------------
412 int wxSurfaceWidget::GetIsovalue(){
413         return _isoValue->GetValue();
414 }
415 //----------------------------------------------------------------------------
416 int wxSurfaceWidget::GetOpacity(){
417         return _opacity->GetValue();
418 }
419 //----------------------------------------------------------------------------
420 vtk3DSurfaceWidget *wxSurfaceWidget::GetVtk3DSurfaceWidget(){
421         return _3DWorld;
422 }
423 //----------------------------------------------------------------------------
424 void wxSurfaceWidget::OnManualAxis(wxCommandEvent& event)
425 {
426         wxBusyCursor wait;
427         if ( _bt_delete_axis->IsEnabled() )
428         {
429                 OnDeleteAxis(event);
430         }
431
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)
438         {
439                 if (maracasManualTreeMPRDlg->ExportPoints()==true){
440                         _mar->_experiment->appendAxis(maraxis);
441                         _bt_new_axis->Disable();
442                         _st_two->Enable();
443                         _bt_delete_axis->Enable();
444                         _bt_call_quantification->Enable();
445                         AddAxisActors();
446                         event.Skip();
447                         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
448                         ProcessEvent(  ev );
449                 } else {
450                         delete maraxis;
451                 }
452         }
453         maracasManualTreeMPRDlg->Destroy();
454
455 }