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: wxSurfaceSTLWidget.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 "wxSurfaceSTLWidget.h"
46 #include <wx/dialog.h>
47 #include <wx/colordlg.h>
50 # include "../res/bitmaps/extract.xpm"
51 # include "../res/bitmaps/del_axis.xpm"
52 # include "../res/bitmaps/vessels.xpm"
53 # include "../res/bitmaps/cutter.xpm"
54 # include "../res/bitmaps/stl.xpm"
57 //----------------------------------------------------------------------------
58 BEGIN_EVENT_TABLE( wxSurfaceSTLWidget, wxPanel )
60 EVT_TOOL(ID_BUTTON_VESSELS_CONSTRUCTION, wxSurfaceSTLWidget::OnVesselConstruction )
61 EVT_TOOL(ID_BUTTON_3D_CUTTER, wxSurfaceSTLWidget::On3DCutter )
62 EVT_TOOL(ID_BUTTON_EXPORT_STL, wxSurfaceSTLWidget::OnExportAsSTL )
64 EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR, wxSurfaceSTLWidget::OnChooseSurfaceColor )
65 EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE, wxSurfaceSTLWidget::OnIsoVisible )
66 EVT_CHECKBOX(ID_CHECKBOX_STL_VISIBLE, wxSurfaceSTLWidget::OnSTLSurfaceVisible )
68 EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease)
70 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease)
71 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_STL_THRESH, wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease)
73 EVT_CHECKBOX(ID_CHECKBOX_INVERT_SLICE_ORDER, wxSurfaceSTLWidget::OnInvertSliceOrder )
77 //----------------------------------------------------------------------------
78 wxSurfaceSTLWidget::wxSurfaceSTLWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
79 const wxString& name) : wxPanel( parent, id, pos, size, style, name )
83 _3DWorldSTL = new vtk3DSurfaceSTLWidget( this, ID_WORLD3D );
85 // Set up axis toolbar
86 wxBitmap axisToolBarBitmaps[ 2 ];
87 axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
88 axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase );
91 //By default the Iso value is visible.
92 _isoVisible = new wxCheckBox( this, ID_CHECKBOX_ISOVISIBLE, _T("Iso visible") );
93 _isoVisible->SetValue( true );
94 _isoValue = new wxSlider( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
95 _opacity = new wxSlider( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
96 _isoValue->SetLabel( _T("IsoValue") );
97 _opacity->SetLabel( _T("Surface opacity") );
99 //I can't get to brighten the button when mouse over:
100 //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
101 //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
103 // Set up vessels toolbar
104 wxBitmap vesselsToolBarBitmaps[ 3 ];
105 vesselsToolBarBitmaps[ 0 ] = wxBITMAP( vesselstoolbar_extract );
106 vesselsToolBarBitmaps[ 1 ] = wxBITMAP( vesselstoolbar_cutter );
107 vesselsToolBarBitmaps[ 2 ] = wxBITMAP( vesselstoolbar_stl );
109 _vessels_tb = new wxToolBar( this, -1);
110 _vessels_tb->SetMargins( 4, 4 );
111 _vessels_tb->SetToolBitmapSize( wxSize( vesselsToolBarBitmaps[ 0 ].GetWidth( ), vesselsToolBarBitmaps[ 0 ].GetHeight( ) ) );
112 _vessels_tb->AddTool(ID_BUTTON_VESSELS_CONSTRUCTION, _T("Construct Surface"), vesselsToolBarBitmaps[ 0 ], _T("Construct Surface"));
113 _vessels_tb->AddSeparator( );
114 //_vessels_tb->AddTool(ID_BUTTON_3D_CUTTER, vesselsToolBarBitmaps[ 1 ], "Delete axis", "short help string");
115 _vessels_tb->AddCheckTool(ID_BUTTON_3D_CUTTER, _T("Delete axis"), vesselsToolBarBitmaps[ 1 ], wxNullBitmap, _T("Delete axis") ); //, "short help string"
116 _vessels_tb->AddSeparator( );
117 _vessels_tb->AddTool(ID_BUTTON_EXPORT_STL, _T("Export as STL"), vesselsToolBarBitmaps[ 2 ], _T("Export as STL"));
118 _vessels_tb->Realize( );
119 _vessels_tb->SetRows( 1 ); ///\todo : what that ? mat
123 _isoValue->SetSize(wxSize(64, 16));
127 wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("Iso Surface values")), wxVERTICAL);
128 //Some borders are needed on wxGTK otherwise static text and slider labels collides.
129 sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
130 sizer_3->Add(new wxStaticText(this, -1, _T("Isovalue")), 1, wxALL|wxEXPAND, 2);
131 sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
132 sizer_3->Add(new wxStaticText(this, -1, _T("Opacity (%)")), 1, wxALL|wxEXPAND, 2);
133 sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
135 //By default the STL Iso value is visible.
136 _stlIntSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("Internal STL Surface visible") );
137 _stlIntSurfaceVisible->SetValue( true );
138 _stlExtSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("External STL Surface visible") );
139 _stlExtSurfaceVisible->SetValue( true );
140 _stlSurfaceValue = new wxSlider( this, ID_SLIDER_STL_THRESH, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
141 _stlSurfaceValue->SetLabel( _T("STL Surface Value") );
142 _stlSurfaceValue->SetRange(0, 100);
143 //hard coded value 'cause thie is still not reachable: (int)_3DWorldSTL->GetSTLThreshold()
144 _stlSurfaceValue->SetValue( 45 ); //100*.45 remember to multiply by 100
148 wxStaticBoxSizer* sizer_4 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("STL Surface values")), wxVERTICAL);
149 sizer_4->Add(_stlIntSurfaceVisible, 1, wxALL|wxEXPAND, 2);
150 sizer_4->Add(_stlExtSurfaceVisible, 1, wxALL|wxEXPAND, 2);
151 sizer_4->Add(new wxStaticText(this, -1, _T("STL Isovalue")), 1, wxALL|wxEXPAND, 2);
152 sizer_4->Add(_stlSurfaceValue, 1, wxALL|wxEXPAND, 2);
154 _stlIntSurfaceVisible->Disable();
155 _stlExtSurfaceVisible->Disable();
156 _stlSurfaceValue->Disable();
158 _chkInvertSliceOrder = new wxCheckBox(this, ID_CHECKBOX_INVERT_SLICE_ORDER, _T("Invert slice order"));
160 wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
161 sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
163 // sizer_2->Add(_axis_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
164 sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
165 sizer_2->Add(_vessels_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
166 sizer_2->Add(_chkInvertSliceOrder, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
168 wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
169 sizer_1->Add(_3DWorldSTL, 1, wxEXPAND, 0);
170 sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
178 //----------------------------------------------------------------------------
179 wxSurfaceSTLWidget::~wxSurfaceSTLWidget( )
181 _3DWorldSTL->Delete();
184 //----------------------------------------------------------------------------
185 /*void wxSurfaceSTLWidget::ShowMARACASDataDebug( vtkImageData *ima )
187 _3DWorldSTL->ShowMARACASData2Debug( ima );
192 ima->GetScalarRange( minmax );
197 _isoValue->SetRange((int)min, (int)max);
198 _isoValue->SetValue( (int)(max/2) );
201 //----------------------------------------------------------------------------
202 void wxSurfaceSTLWidget::ShowMARACASData( marInterface* mar )
207 // _width = _mar->_experiment->getDynData( )->getVolume( )->getWidth( );
208 // _height = _mar->_experiment->getDynData( )->getVolume( )->getHeight( );
209 // _depth = _mar->_experiment->getDynData( )->getVolume( )->getDepth( );
212 double min, max; //backward compatibility
215 //_3DWorldSTL->_mar = mar;
216 // _3DWorldSTL->ShowMARACASData( mar );
217 _3DWorldSTL->ShowMARACASDataAndAxe( mar );
221 _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
223 _isoValue->SetRange((int)min, (int)max);
224 _isoValue->SetValue( (int)(max/4) );
226 _opacity->SetValue( 50 );
227 _chkInvertSliceOrder->SetValue( _mar->_parameters->getBoolParam( marParameters::e_invest_slice_order ) );
230 //----------------------------------------------------------------------------
231 void wxSurfaceSTLWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
234 data.SetChooseFull( true );
235 for( int i = 0; i < 16; i++ )
237 wxColour colour( i * 16, i * 16, i * 16 );
238 data.SetCustomColour( i, colour );
241 wxColourDialog dialog ( this, &data );
242 dialog.SetTitle( _T("choose color") );
244 if( dialog.ShowModal( ) == wxID_OK )
246 wxColourData retData = dialog.GetColourData( );
247 wxColour col = retData.GetColour( );
248 //_surface_color->SetBackgroundColour( col );
250 _3DWorldSTL->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
257 //----------------------------------------------------------------------------
258 void wxSurfaceSTLWidget::OnInvertSliceOrder(wxCommandEvent& WXUNUSED(event)){
259 wxMessageDialog *msgDlg = new wxMessageDialog(this, _T("You have to restart the application!"), _T("WARNING!!"), wxOK );
262 _mar->_parameters->setBoolParam( marParameters::e_invest_slice_order, _chkInvertSliceOrder->GetValue( ) );
263 _mar->saveParameters( );
265 //----------------------------------------------------------------------------
266 void wxSurfaceSTLWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
268 _3DWorldSTL->SetSurfaceVisibility( _isoVisible->GetValue() );
270 //----------------------------------------------------------------------------
271 void wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease(wxScrollEvent& WXUNUSED(event))
274 double tmp=(double)_stlSurfaceValue->GetValue();
275 _3DWorldSTL->SetSTLThresholdRatio( tmp );
277 //----------------------------------------------------------------------------
278 void wxSurfaceSTLWidget::OnSTLSurfaceVisible(wxCommandEvent& WXUNUSED(event))
280 _3DWorldSTL->SetSTLSurfaceVisibility( _stlIntSurfaceVisible->GetValue(), _stlExtSurfaceVisible->GetValue() );
282 //----------------------------------------------------------------------------
283 void wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
286 _3DWorldSTL->SetSurfaceIsoValue( event.GetPosition() );
288 //----------------------------------------------------------------------------
289 void wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
291 _3DWorldSTL->SetSurfaceOpacity( event.GetPosition() );
294 //----------------------------------------------------------------------------
295 void wxSurfaceSTLWidget::OnVesselConstruction(wxCommandEvent& WXUNUSED(event))
298 _3DWorldSTL->ConstructVessel( );
299 _vessels_tb->EnableTool(ID_BUTTON_3D_CUTTER, true);
300 _vessels_tb->EnableTool(ID_BUTTON_EXPORT_STL, true);
302 _stlIntSurfaceVisible->Enable();
303 _stlExtSurfaceVisible->Enable();
304 _stlSurfaceValue->Enable();
305 _vessels_tb->EnableTool(ID_BUTTON_VESSELS_CONSTRUCTION, false);
306 // this->GetParent()->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, false);
308 //----------------------------------------------------------------------------
309 void wxSurfaceSTLWidget::On3DCutter(wxCommandEvent& event)
312 _3DWorldSTL->SetCuttingMode( event.IsChecked() );
315 //----------------------------------------------------------------------------
316 void wxSurfaceSTLWidget::OnExportAsSTL(wxCommandEvent& WXUNUSED(event))
319 wxString dirSTL = _mar->_parameters->getStringParam(
320 marParameters::e_installation_directory );
321 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
322 wxDirDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
323 dirSTL: wxGetHomeDir( ) );
325 if( dialog.ShowModal( ) == wxID_OK )
327 wxString tmpSTR(dialog.GetPath( ) + _T("/") + _mar->_dicom->GetPatientName() );
328 _3DWorldSTL->ExportSurfaceAsSTL( (const char*)(tmpSTR.mb_str()) );
331 //By default *always* update e_installation_directory:
332 _mar->_parameters->setStringParam( marParameters::e_installation_directory,
334 _mar->saveParameters( );