]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/wxSurfaceWidget.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / wxSurfaceWidget.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: wxSurfaceWidget.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:15:18 $
32   Version:   $Revision: 1.2 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43 #include "../res/bitmaps/extract.xpm"
44 #include "../res/bitmaps/del_axis.xpm"
45 #include "../res/bitmaps/plans.xpm"
46 #include "wxSurfaceWidget.h"
47 #include "../marDictionary.h"
48 #include "../wxMaracas_ManualTree_MPRDlg.h"
49
50
51 #include <matrix.h>
52
53 #include <wx/dialog.h>
54 #include <wx/colordlg.h>
55
56 // PS -> #ifndef __WXMSW__
57 // PS -> #   include "../res/bitmaps/extract.xpm"
58 // PS -> #   include "../res/bitmaps/del_axis.xpm"
59 // PS -> #endif
60
61 //----------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE( wxSurfaceWidget, wxPanel )
63
64     EVT_BUTTON(ID_BUTTON_NEW_AXIS               , wxSurfaceWidget::OnExtractAxis                        )
65     EVT_BUTTON(ID_BUTTON_DELETE_AXIS    , wxSurfaceWidget::OnDeleteAxis                         )
66     EVT_BUTTON(ID_BUTTON_QUANTIFICATION , wxSurfaceWidget::OnQuantification                     )
67     EVT_BUTTON(ID_BUTTON_MANUAL_AXIS    , wxSurfaceWidget::OnManualAxis                         )
68
69
70     EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR   , wxSurfaceWidget::OnChooseSurfaceColor         )
71     EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE , wxSurfaceWidget::OnIsoVisible                         )
72
73     EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceWidget::OnSliderOpacityScrollThumbrelease)
74     EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease)
75 END_EVENT_TABLE( );
76
77 //----------------------------------------------------------------------------
78 wxSurfaceWidget::wxSurfaceWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, 
79                                                                  const wxSize& size, long style, const wxString& name) 
80                                                                  : wxPanel( parent, id, pos, size, style, name )
81 {
82 printf("EED wxSurfaceWidget::wxSurfaceWidget  1 \n" );
83
84         marDictionary marDict;
85         char tmp[256];
86
87         _id_toolbar_plans=-1;
88         _mar = NULL;
89
90         _3DWorld = new vtk3DSurfaceWidget( this, ID_WORLD3D );
91         _3DWorld->SetInterfaceVtkPanelWidgets(this);
92
93     // Set up axis toolbar
94     wxBitmap axisToolBarBitmaps[ 3 ];
95     axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
96     axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase   );
97     axisToolBarBitmaps[ 2 ] = wxBITMAP( toolbar_plans       );
98
99
100    _bt_new_axis                 = new wxBitmapButton( this, ID_BUTTON_NEW_AXIS          , axisToolBarBitmaps[ 0 ] );
101    _bt_delete_axis              = new wxBitmapButton( this, ID_BUTTON_DELETE_AXIS       , axisToolBarBitmaps[ 1 ] );
102    _bt_call_quantification      = new wxBitmapButton( this, ID_BUTTON_QUANTIFICATION, axisToolBarBitmaps[ 2 ],wxDefaultPosition,wxSize(70,70));
103
104         _bt_manual_axis         = new wxButton(this, ID_BUTTON_MANUAL_AXIS, _T("Manual Axis")); 
105 //      _bt_manual_axis->SetSize(80,40);
106
107
108
109
110
111     //By default the Iso value is visible.
112     _isoVisible = new wxCheckBox ( this, ID_CHECKBOX_ISOVISIBLE, wxString(marDict.GetString(15), wxConvUTF8) );  //"Iso visible"
113     _isoValue   = new wxSlider   ( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
114     _opacity    = new wxSlider   ( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
115     _isoVisible->SetValue( true );
116     _isoValue->SetLabel( wxString(marDict.GetString(25), wxConvUTF8) ); // "IsoValue"
117     _opacity->SetLabel( wxString(marDict.GetString(0), wxConvUTF8) ); //"Surface opacity"
118
119
120     //I can't get to brighten the button when mouse over:
121     //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
122     //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
123
124
125     //Set Properties:
126     _isoValue->SetSize(wxSize(64, 16));
127     //End set properties
128
129     //Do the layout:
130     wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1,wxString(marDict.GetString(10), wxConvUTF8)  ), wxVERTICAL);//"Iso Surface values"
131     //Some borders are needed on wxGTK otherwise static text and slider labels collides.
132     sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
133     sizer_3->Add(new wxStaticText(this, -1, wxString(marDict.GetString(20), wxConvUTF8)), 1, wxALL|wxEXPAND, 2); // "Opacity (%)"
134     sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
135     sizer_3->Add(new wxStaticText(this, -1,wxString(marDict.GetString(25), wxConvUTF8) ), 1, wxALL|wxEXPAND, 2); // "Isovalue"
136     sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
137
138     //Do the layout:
139         strcpy( tmp , marDict.GetString(30) ); 
140         _st_cero        = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE );     // "0"
141
142         strcpy( tmp , marDict.GetString(35) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(40) );
143         _st_text        = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE);      // "Select\n artery" 
144
145         strcpy( tmp , marDict.GetString(45) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(50) );
146         _st_one = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE );             // "1 \n Axis Extraction" 
147
148         strcpy( tmp , marDict.GetString(55) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(60) );
149         _st_two = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE);              // " 2 \n Quantification"
150
151
152 //      wxFont font(12,wxDEFAULT ,wxNORMAL,wxBOLD);
153 //      st_blank->SetFont(font);
154 //      st_next1->SetFont(font);
155 //      st_next2->SetFont(font);
156 //      _st_one->SetFont(font);
157 //      _st_two->SetFont(font);
158 //      _st_cero->SetFont(font);
159  
160         _st_one->Disable();
161         _bt_new_axis->Disable();
162         _bt_delete_axis->Disable();
163         _st_two->Disable();
164         _bt_call_quantification->Disable();
165
166
167
168         wxFlexGridSizer *axis_sizer = new wxFlexGridSizer(3,5,5,5);
169         axis_sizer->Add(_st_cero                                ,0,wxALIGN_CENTER_HORIZONTAL);
170         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTER_HORIZONTAL);
171         axis_sizer->Add(_st_one                                 ,0,wxALIGN_CENTER_HORIZONTAL);
172         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTER_HORIZONTAL);
173         axis_sizer->Add(_st_two                                 ,0,wxALIGN_CENTER_HORIZONTAL);
174
175         axis_sizer->Add(_st_text                                ,0,wxALIGN_CENTRE_VERTICAL);
176         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))     ,0,wxALIGN_CENTRE_VERTICAL);
177         axis_sizer->Add(_bt_new_axis                    ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
178         axis_sizer->Add(new wxStaticText(this,-1 , _T("  "))                            ,0,wxALIGN_CENTRE_VERTICAL);
179         axis_sizer->Add(_bt_call_quantification ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
180
181         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTRE_VERTICAL);
182         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTRE_VERTICAL);
183         axis_sizer->Add(_bt_delete_axis                 ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
184     wxBoxSizer *sizer_2 = new wxBoxSizer(wxVERTICAL);
185     sizer_2->Add(sizer_3        , 1, wxEXPAND, 0);
186     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
187     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
188     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
189     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
190     sizer_2->Add(axis_sizer     , 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
191     sizer_2->Add(_bt_manual_axis);
192
193
194     wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
195     sizer_1->Add(_3DWorld, 1, wxEXPAND, 0);
196     sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
197
198     SetSizer(sizer_1);
199     SetAutoLayout(true);
200     Layout();
201
202
203
204 }
205
206 //----------------------------------------------------------------------------
207 wxSurfaceWidget::~wxSurfaceWidget( )
208 {
209         _3DWorld->Delete();
210 }
211
212 //----------------------------------------------------------------------------
213 void wxSurfaceWidget::ShowMARACASData( marInterface* mar )
214 {
215   wxBusyCursor wait;
216
217    double min, max; //backward compatibility
218   _mar = mar;
219   _3DWorld->ShowMARACASData( mar );
220   _3DWorld->ConfigureVTK( );
221   _3DWorld->InitCameraReset( );
222
223   //GUI stuff:
224   _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
225
226   _isoValue->SetRange((int)min, (int)max);
227   _isoValue->SetValue( (int)(max/4) );
228
229   _opacity->SetValue( 50 );
230
231 //EED 31 Mai 2007
232 //  _3DWorld->Render();
233
234 }
235 //----------------------------------------------------------------------------
236 void wxSurfaceWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
237 {
238     wxColourData data;
239     data.SetChooseFull( true );
240     for( int i = 0; i < 16; i++ )
241     {
242         wxColour colour( i * 16, i * 16, i * 16 );
243         data.SetCustomColour( i, colour );
244     } // rof
245
246     wxColourDialog dialog ( this, &data );
247     dialog.SetTitle( _T("choose color") );
248
249     if( dialog.ShowModal( ) == wxID_OK )
250     {
251         wxColourData retData = dialog.GetColourData( );
252         wxColour col = retData.GetColour( );
253       //_surface_color->SetBackgroundColour( col );
254
255       _3DWorld->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
256
257     } // fi
258
259 }
260 //----------------------------------------------------------------------------
261 void wxSurfaceWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
262 {
263   _3DWorld->SetSurfaceVisibility( _isoVisible->GetValue() );
264 }
265 //----------------------------------------------------------------------------
266 void wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
267 {
268   wxBusyCursor wait;
269   _3DWorld->SetSurfaceIsoValue( event.GetPosition() );
270 }
271 //----------------------------------------------------------------------------
272 void wxSurfaceWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
273 {
274   _3DWorld->SetSurfaceOpacity( event.GetPosition() );
275 }
276 //----------------------------------------------------------------------------
277 void wxSurfaceWidget::OnExtractAxis(wxCommandEvent& event)
278 {
279   if(_3DWorld->GetInitialSphere() )
280   {
281 // EED Borrame
282 long int startTimeAE = clock();;
283
284
285    wxBusyCursor wait;
286
287         gtm::TVector< double > xc( 3 );
288         double data[3];
289         int extent[ 6 ];
290         double spc[ 3 ];
291 // PS ->        vtkPolyData* allData; //PS
292
293         vtkImageData *imageData=_mar->_experiment->getDynData( )->getVolume( )->castVtk();
294     imageData->GetExtent( extent );
295     imageData->GetSpacing( spc );
296     _3DWorld->GetSphereCenter( data );
297
298
299 //EED 20 Sep 2006
300 //      _mar->_experiment->setStartPoint( (int)data[0] - extent[0], (int)data[1] - extent[2], (int)data[2] - extent[4]);
301         double x,y,z;
302         x= (data[0] - extent[0]) / spc[0];
303         y= (data[1] - extent[2]) / spc[1];
304         z= (data[2] - extent[4]) / spc[2];
305         _mar->_experiment->setStartPoint( (int)x, (int)y, (int)z);
306
307         _mar->_experiment->extractVascularTree( );
308
309         _mar->_experiment->setAxis( 0 );
310
311         AddAxisActors();
312 // PS ->         allData = temp->Draw( ); //PS
313 // PS ->      _3DWorld->SetAxis( allData );//PS
314
315     //Disabling tool
316
317 //EED    _axis_tb->EnableTool(ID_BUTTON_NEW_AXIS, false);
318 //EED    _axis_tb->EnableTool(ID_BUTTON_DELETE_AXIS, true);
319
320         _bt_new_axis->Disable();
321     _st_two->Enable();
322         _bt_delete_axis->Enable();
323         _bt_call_quantification->Enable();
324
325         event.Skip();
326         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
327         ProcessEvent( ev );
328
329 /*
330 //EED Borrame
331 FILE *ff;
332 ff = fopen("c:/temp/MaracasStadistics.txt","a+");
333 long int endtime = clock();
334 double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
335 fprintf(ff,"EED %p wxSurfaceWidget::OnExtractAxis > AE_t = %f \n",this,sg);
336 fclose(ff);
337 */
338
339   }
340   else
341   {
342         wxMessageBox( _T("Set an initial point.\n \n (Double click over the interest artery.)"),
343                                           _T("DxMM : MARACAS"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
344   }
345
346 }
347 //----------------------------------------------------------------------------
348 void wxSurfaceWidget::AddAxisActors(){
349         // Axes ...
350         marAxis         *maraxis                = _mar->_experiment->getAxis( );
351         vtkPolyData *vtkpolydata        = maraxis->Draw();
352         vtkPoints       *vtkpoints              = vtkpolydata->GetPoints();
353         int                     size                    = vtkpoints->GetNumberOfPoints();
354
355 // EED 22 sep 2006
356 // EED 07 dic 2006
357         double voxelSize = _mar->_parameters->getVoxelSize();
358         double pp[3];
359         int i;
360         for (i=0;i<size;i++)
361         {
362                 vtkpoints->GetPoint(i,pp);
363                 pp[0]=pp[0] * voxelSize;
364                 pp[1]=pp[1] * voxelSize;
365                 pp[2]=pp[2] * voxelSize;
366         }
367
368
369         if (maraxis!=NULL) _3DWorld->SetAxis( vtkpolydata );
370         // Other Actors..
371         // ..
372 }
373 //----------------------------------------------------------------------------
374 void wxSurfaceWidget::Clean3D(){
375   _3DWorld->RemoveAxis( );
376 }
377 //----------------------------------------------------------------------------
378 void wxSurfaceWidget::RefreshAxis() {   
379         _3DWorld->Render(); 
380 }
381 //----------------------------------------------------------------------------
382 void wxSurfaceWidget::OnDeleteAxis(wxCommandEvent& event)
383 {
384         wxBusyCursor wait;
385         Clean3D();
386         _mar->_experiment->DeleteAxis( 0 );
387
388     //Disabling tool
389     //wxToolBar::EnableTool This function should only be called after Realize.
390
391         _bt_new_axis->Enable();
392         _bt_delete_axis->Disable();
393         _bt_call_quantification->Disable();
394         _st_one->Enable();
395         _st_two->Disable();
396
397         event.Skip();
398         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_DELETE_AXIS);
399         ProcessEvent(  ev );
400
401 }
402 //----------------------------------------------------------------------------
403 void wxSurfaceWidget::CallBackOnLeftDClick( wxMouseEvent& event ){
404         _3DWorld->SetInitialPoint();
405         if ( _3DWorld->GetInitialSphere() ){  
406                 marAxis *maraxis = _mar->_experiment->getAxis( );
407
408                 if (maraxis==NULL) {
409                         _st_one->Enable();
410                         _bt_new_axis->Enable();
411                 } else {
412                         _st_one->Disable();
413                         _bt_new_axis->Disable();
414                 }
415
416         }
417
418
419         if ( !_3DWorld->GetInitialSphere() ) {
420                         _st_one->Disable();
421                         _bt_new_axis->Disable();
422         }
423
424 }
425 //----------------------------------------------------------------------------
426 void wxSurfaceWidget::OnQuantification(wxCommandEvent& event){
427         if (_id_toolbar_plans!=-1){
428            wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,_id_toolbar_plans);
429            ProcessEvent(  ev );
430         }
431 }
432 //----------------------------------------------------------------------------
433 void wxSurfaceWidget::SetId_toolbar_plans(int id_toolbar_plans ){
434         _id_toolbar_plans=id_toolbar_plans;
435 }
436 //----------------------------------------------------------------------------
437 int wxSurfaceWidget::GetIsovalue(){
438         return _isoValue->GetValue();
439 }
440 //----------------------------------------------------------------------------
441 int wxSurfaceWidget::GetOpacity(){
442         return _opacity->GetValue();
443 }
444 //----------------------------------------------------------------------------
445 vtk3DSurfaceWidget *wxSurfaceWidget::GetVtk3DSurfaceWidget(){
446         return _3DWorld;
447 }
448 //----------------------------------------------------------------------------
449 void wxSurfaceWidget::OnManualAxis(wxCommandEvent& event)
450 {
451         wxBusyCursor wait;
452         if ( _bt_delete_axis->IsEnabled() )
453         {
454                 OnDeleteAxis(event);
455         }
456
457         vtkImageData *imagedata =  _mar->_experiment->getDynData( )->getVolume( )->castVtk();   
458         wxMaracas_ManualTree_MPRDlg  *maracasManualTreeMPRDlg = new wxMaracas_ManualTree_MPRDlg( this , new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
459         marAxis *maraxis = new marAxis( _mar->_experiment->getParameters() );
460         maracasManualTreeMPRDlg->SetMarAxis( maraxis );
461         maracasManualTreeMPRDlg->ConfigureVTK();
462         if (maracasManualTreeMPRDlg->ShowModal()==wxID_OK)
463         {
464                 if (maracasManualTreeMPRDlg->ExportPoints()==true){
465                         _mar->_experiment->appendAxis(maraxis);
466                         _bt_new_axis->Disable();
467                         _st_two->Enable();
468                         _bt_delete_axis->Enable();
469                         _bt_call_quantification->Enable();
470                         AddAxisActors();
471                         event.Skip();
472                         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
473                         ProcessEvent(  ev );
474                 } else {
475                         delete maraxis;
476                 }
477         }
478         maracasManualTreeMPRDlg->Destroy();
479
480 }