1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: wxSurfaceWidget.cxx,v $
31 Date: $Date: 2012/11/15 14:15:18 $
32 Version: $Revision: 1.2 $
34 Copyright: (c) 2002, 2003
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.
41 =========================================================================*/
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"
53 #include <wx/dialog.h>
54 #include <wx/colordlg.h>
56 // PS -> #ifndef __WXMSW__
57 // PS -> # include "../res/bitmaps/extract.xpm"
58 // PS -> # include "../res/bitmaps/del_axis.xpm"
61 //----------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE( wxSurfaceWidget, wxPanel )
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 )
70 EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR , wxSurfaceWidget::OnChooseSurfaceColor )
71 EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE , wxSurfaceWidget::OnIsoVisible )
73 EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceWidget::OnSliderOpacityScrollThumbrelease)
74 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease)
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 )
82 printf("EED wxSurfaceWidget::wxSurfaceWidget 1 \n" );
84 marDictionary marDict;
90 _3DWorld = new vtk3DSurfaceWidget( this, ID_WORLD3D );
91 _3DWorld->SetInterfaceVtkPanelWidgets(this);
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 );
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));
104 _bt_manual_axis = new wxButton(this, ID_BUTTON_MANUAL_AXIS, _T("Manual Axis"));
105 // _bt_manual_axis->SetSize(80,40);
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"
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));
126 _isoValue->SetSize(wxSize(64, 16));
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);
139 strcpy( tmp , marDict.GetString(30) );
140 _st_cero = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE ); // "0"
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"
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"
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"
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);
161 _bt_new_axis->Disable();
162 _bt_delete_axis->Disable();
164 _bt_call_quantification->Disable();
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);
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);
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);
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);
206 //----------------------------------------------------------------------------
207 wxSurfaceWidget::~wxSurfaceWidget( )
212 //----------------------------------------------------------------------------
213 void wxSurfaceWidget::ShowMARACASData( marInterface* mar )
217 double min, max; //backward compatibility
219 _3DWorld->ShowMARACASData( mar );
220 _3DWorld->ConfigureVTK( );
221 _3DWorld->InitCameraReset( );
224 _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
226 _isoValue->SetRange((int)min, (int)max);
227 _isoValue->SetValue( (int)(max/4) );
229 _opacity->SetValue( 50 );
232 // _3DWorld->Render();
235 //----------------------------------------------------------------------------
236 void wxSurfaceWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
239 data.SetChooseFull( true );
240 for( int i = 0; i < 16; i++ )
242 wxColour colour( i * 16, i * 16, i * 16 );
243 data.SetCustomColour( i, colour );
246 wxColourDialog dialog ( this, &data );
247 dialog.SetTitle( _T("choose color") );
249 if( dialog.ShowModal( ) == wxID_OK )
251 wxColourData retData = dialog.GetColourData( );
252 wxColour col = retData.GetColour( );
253 //_surface_color->SetBackgroundColour( col );
255 _3DWorld->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
260 //----------------------------------------------------------------------------
261 void wxSurfaceWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
263 _3DWorld->SetSurfaceVisibility( _isoVisible->GetValue() );
265 //----------------------------------------------------------------------------
266 void wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
269 _3DWorld->SetSurfaceIsoValue( event.GetPosition() );
271 //----------------------------------------------------------------------------
272 void wxSurfaceWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
274 _3DWorld->SetSurfaceOpacity( event.GetPosition() );
276 //----------------------------------------------------------------------------
277 void wxSurfaceWidget::OnExtractAxis(wxCommandEvent& event)
279 if(_3DWorld->GetInitialSphere() )
282 long int startTimeAE = clock();;
287 gtm::TVector< double > xc( 3 );
291 // PS -> vtkPolyData* allData; //PS
293 vtkImageData *imageData=_mar->_experiment->getDynData( )->getVolume( )->castVtk();
294 imageData->GetExtent( extent );
295 imageData->GetSpacing( spc );
296 _3DWorld->GetSphereCenter( data );
300 // _mar->_experiment->setStartPoint( (int)data[0] - extent[0], (int)data[1] - extent[2], (int)data[2] - extent[4]);
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);
307 _mar->_experiment->extractVascularTree( );
309 _mar->_experiment->setAxis( 0 );
312 // PS -> allData = temp->Draw( ); //PS
313 // PS -> _3DWorld->SetAxis( allData );//PS
317 //EED _axis_tb->EnableTool(ID_BUTTON_NEW_AXIS, false);
318 //EED _axis_tb->EnableTool(ID_BUTTON_DELETE_AXIS, true);
320 _bt_new_axis->Disable();
322 _bt_delete_axis->Enable();
323 _bt_call_quantification->Enable();
326 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
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);
342 wxMessageBox( _T("Set an initial point.\n \n (Double click over the interest artery.)"),
343 _T("DxMM : MARACAS"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
347 //----------------------------------------------------------------------------
348 void wxSurfaceWidget::AddAxisActors(){
350 marAxis *maraxis = _mar->_experiment->getAxis( );
351 vtkPolyData *vtkpolydata = maraxis->Draw();
352 vtkPoints *vtkpoints = vtkpolydata->GetPoints();
353 int size = vtkpoints->GetNumberOfPoints();
357 double voxelSize = _mar->_parameters->getVoxelSize();
362 vtkpoints->GetPoint(i,pp);
363 pp[0]=pp[0] * voxelSize;
364 pp[1]=pp[1] * voxelSize;
365 pp[2]=pp[2] * voxelSize;
369 if (maraxis!=NULL) _3DWorld->SetAxis( vtkpolydata );
373 //----------------------------------------------------------------------------
374 void wxSurfaceWidget::Clean3D(){
375 _3DWorld->RemoveAxis( );
377 //----------------------------------------------------------------------------
378 void wxSurfaceWidget::RefreshAxis() {
381 //----------------------------------------------------------------------------
382 void wxSurfaceWidget::OnDeleteAxis(wxCommandEvent& event)
386 _mar->_experiment->DeleteAxis( 0 );
389 //wxToolBar::EnableTool This function should only be called after Realize.
391 _bt_new_axis->Enable();
392 _bt_delete_axis->Disable();
393 _bt_call_quantification->Disable();
398 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_DELETE_AXIS);
402 //----------------------------------------------------------------------------
403 void wxSurfaceWidget::CallBackOnLeftDClick( wxMouseEvent& event ){
404 _3DWorld->SetInitialPoint();
405 if ( _3DWorld->GetInitialSphere() ){
406 marAxis *maraxis = _mar->_experiment->getAxis( );
410 _bt_new_axis->Enable();
413 _bt_new_axis->Disable();
419 if ( !_3DWorld->GetInitialSphere() ) {
421 _bt_new_axis->Disable();
425 //----------------------------------------------------------------------------
426 void wxSurfaceWidget::OnQuantification(wxCommandEvent& event){
427 if (_id_toolbar_plans!=-1){
428 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,_id_toolbar_plans);
432 //----------------------------------------------------------------------------
433 void wxSurfaceWidget::SetId_toolbar_plans(int id_toolbar_plans ){
434 _id_toolbar_plans=id_toolbar_plans;
436 //----------------------------------------------------------------------------
437 int wxSurfaceWidget::GetIsovalue(){
438 return _isoValue->GetValue();
440 //----------------------------------------------------------------------------
441 int wxSurfaceWidget::GetOpacity(){
442 return _opacity->GetValue();
444 //----------------------------------------------------------------------------
445 vtk3DSurfaceWidget *wxSurfaceWidget::GetVtk3DSurfaceWidget(){
448 //----------------------------------------------------------------------------
449 void wxSurfaceWidget::OnManualAxis(wxCommandEvent& event)
452 if ( _bt_delete_axis->IsEnabled() )
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)
464 if (maracasManualTreeMPRDlg->ExportPoints()==true){
465 _mar->_experiment->appendAxis(maraxis);
466 _bt_new_axis->Disable();
468 _bt_delete_axis->Enable();
469 _bt_call_quantification->Enable();
472 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
478 maracasManualTreeMPRDlg->Destroy();