1 /*=========================================================================
4 Module: $RCSfile: wxSurfaceSTLWidget.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 "wxSurfaceSTLWidget.h"
21 #include <wx/dialog.h>
22 #include <wx/colordlg.h>
25 # include "../res/bitmaps/extract.xpm"
26 # include "../res/bitmaps/del_axis.xpm"
27 # include "../res/bitmaps/vessels.xpm"
28 # include "../res/bitmaps/cutter.xpm"
29 # include "../res/bitmaps/stl.xpm"
32 //----------------------------------------------------------------------------
33 BEGIN_EVENT_TABLE( wxSurfaceSTLWidget, wxPanel )
35 EVT_TOOL(ID_BUTTON_VESSELS_CONSTRUCTION, wxSurfaceSTLWidget::OnVesselConstruction )
36 EVT_TOOL(ID_BUTTON_3D_CUTTER, wxSurfaceSTLWidget::On3DCutter )
37 EVT_TOOL(ID_BUTTON_EXPORT_STL, wxSurfaceSTLWidget::OnExportAsSTL )
39 EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR, wxSurfaceSTLWidget::OnChooseSurfaceColor )
40 EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE, wxSurfaceSTLWidget::OnIsoVisible )
41 EVT_CHECKBOX(ID_CHECKBOX_STL_VISIBLE, wxSurfaceSTLWidget::OnSTLSurfaceVisible )
43 EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease)
45 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease)
46 EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_STL_THRESH, wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease)
48 EVT_CHECKBOX(ID_CHECKBOX_INVERT_SLICE_ORDER, wxSurfaceSTLWidget::OnInvertSliceOrder )
52 //----------------------------------------------------------------------------
53 wxSurfaceSTLWidget::wxSurfaceSTLWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
54 const wxString& name) : wxPanel( parent, id, pos, size, style, name )
58 _3DWorldSTL = new vtk3DSurfaceSTLWidget( this, ID_WORLD3D );
60 // Set up axis toolbar
61 wxBitmap axisToolBarBitmaps[ 2 ];
62 axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
63 axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase );
66 //By default the Iso value is visible.
67 _isoVisible = new wxCheckBox( this, ID_CHECKBOX_ISOVISIBLE, _T("Iso visible") );
68 _isoVisible->SetValue( true );
69 _isoValue = new wxSlider( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
70 _opacity = new wxSlider( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
71 _isoValue->SetLabel( _T("IsoValue") );
72 _opacity->SetLabel( _T("Surface opacity") );
74 //I can't get to brighten the button when mouse over:
75 //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
76 //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
78 // Set up vessels toolbar
79 wxBitmap vesselsToolBarBitmaps[ 3 ];
80 vesselsToolBarBitmaps[ 0 ] = wxBITMAP( vesselstoolbar_extract );
81 vesselsToolBarBitmaps[ 1 ] = wxBITMAP( vesselstoolbar_cutter );
82 vesselsToolBarBitmaps[ 2 ] = wxBITMAP( vesselstoolbar_stl );
84 _vessels_tb = new wxToolBar( this, -1);
85 _vessels_tb->SetMargins( 4, 4 );
86 _vessels_tb->SetToolBitmapSize( wxSize( vesselsToolBarBitmaps[ 0 ].GetWidth( ), vesselsToolBarBitmaps[ 0 ].GetHeight( ) ) );
87 _vessels_tb->AddTool(ID_BUTTON_VESSELS_CONSTRUCTION, _T("Construct Surface"), vesselsToolBarBitmaps[ 0 ], _T("Construct Surface"));
88 _vessels_tb->AddSeparator( );
89 //_vessels_tb->AddTool(ID_BUTTON_3D_CUTTER, vesselsToolBarBitmaps[ 1 ], "Delete axis", "short help string");
90 _vessels_tb->AddCheckTool(ID_BUTTON_3D_CUTTER, _T("Delete axis"), vesselsToolBarBitmaps[ 1 ], wxNullBitmap, _T("Delete axis") ); //, "short help string"
91 _vessels_tb->AddSeparator( );
92 _vessels_tb->AddTool(ID_BUTTON_EXPORT_STL, _T("Export as STL"), vesselsToolBarBitmaps[ 2 ], _T("Export as STL"));
93 _vessels_tb->Realize( );
94 _vessels_tb->SetRows( 1 ); ///\todo : what that ? mat
98 _isoValue->SetSize(wxSize(64, 16));
102 wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("Iso Surface values")), wxVERTICAL);
103 //Some borders are needed on wxGTK otherwise static text and slider labels collides.
104 sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
105 sizer_3->Add(new wxStaticText(this, -1, _T("Isovalue")), 1, wxALL|wxEXPAND, 2);
106 sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
107 sizer_3->Add(new wxStaticText(this, -1, _T("Opacity (%)")), 1, wxALL|wxEXPAND, 2);
108 sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
110 //By default the STL Iso value is visible.
111 _stlIntSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("Internal STL Surface visible") );
112 _stlIntSurfaceVisible->SetValue( true );
113 _stlExtSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("External STL Surface visible") );
114 _stlExtSurfaceVisible->SetValue( true );
115 _stlSurfaceValue = new wxSlider( this, ID_SLIDER_STL_THRESH, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
116 _stlSurfaceValue->SetLabel( _T("STL Surface Value") );
117 _stlSurfaceValue->SetRange(0, 100);
118 //hard coded value 'cause thie is still not reachable: (int)_3DWorldSTL->GetSTLThreshold()
119 _stlSurfaceValue->SetValue( 45 ); //100*.45 remember to multiply by 100
123 wxStaticBoxSizer* sizer_4 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("STL Surface values")), wxVERTICAL);
124 sizer_4->Add(_stlIntSurfaceVisible, 1, wxALL|wxEXPAND, 2);
125 sizer_4->Add(_stlExtSurfaceVisible, 1, wxALL|wxEXPAND, 2);
126 sizer_4->Add(new wxStaticText(this, -1, _T("STL Isovalue")), 1, wxALL|wxEXPAND, 2);
127 sizer_4->Add(_stlSurfaceValue, 1, wxALL|wxEXPAND, 2);
129 _stlIntSurfaceVisible->Disable();
130 _stlExtSurfaceVisible->Disable();
131 _stlSurfaceValue->Disable();
133 _chkInvertSliceOrder = new wxCheckBox(this, ID_CHECKBOX_INVERT_SLICE_ORDER, _T("Invert slice order"));
135 wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
136 sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
138 // sizer_2->Add(_axis_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
139 sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
140 sizer_2->Add(_vessels_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
141 sizer_2->Add(_chkInvertSliceOrder, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
143 wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
144 sizer_1->Add(_3DWorldSTL, 1, wxEXPAND, 0);
145 sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
153 //----------------------------------------------------------------------------
154 wxSurfaceSTLWidget::~wxSurfaceSTLWidget( )
156 _3DWorldSTL->Delete();
159 //----------------------------------------------------------------------------
160 /*void wxSurfaceSTLWidget::ShowMARACASDataDebug( vtkImageData *ima )
162 _3DWorldSTL->ShowMARACASData2Debug( ima );
167 ima->GetScalarRange( minmax );
172 _isoValue->SetRange((int)min, (int)max);
173 _isoValue->SetValue( (int)(max/2) );
176 //----------------------------------------------------------------------------
177 void wxSurfaceSTLWidget::ShowMARACASData( marInterface* mar )
182 // _width = _mar->_experiment->getDynData( )->getVolume( )->getWidth( );
183 // _height = _mar->_experiment->getDynData( )->getVolume( )->getHeight( );
184 // _depth = _mar->_experiment->getDynData( )->getVolume( )->getDepth( );
187 double min, max; //backward compatibility
190 //_3DWorldSTL->_mar = mar;
191 // _3DWorldSTL->ShowMARACASData( mar );
192 _3DWorldSTL->ShowMARACASDataAndAxe( mar );
196 _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
198 _isoValue->SetRange((int)min, (int)max);
199 _isoValue->SetValue( (int)(max/4) );
201 _opacity->SetValue( 50 );
202 _chkInvertSliceOrder->SetValue( _mar->_parameters->getBoolParam( marParameters::e_invest_slice_order ) );
205 //----------------------------------------------------------------------------
206 void wxSurfaceSTLWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
209 data.SetChooseFull( true );
210 for( int i = 0; i < 16; i++ )
212 wxColour colour( i * 16, i * 16, i * 16 );
213 data.SetCustomColour( i, colour );
216 wxColourDialog dialog ( this, &data );
217 dialog.SetTitle( _T("choose color") );
219 if( dialog.ShowModal( ) == wxID_OK )
221 wxColourData retData = dialog.GetColourData( );
222 wxColour col = retData.GetColour( );
223 //_surface_color->SetBackgroundColour( col );
225 _3DWorldSTL->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
232 //----------------------------------------------------------------------------
233 void wxSurfaceSTLWidget::OnInvertSliceOrder(wxCommandEvent& WXUNUSED(event)){
234 wxMessageDialog *msgDlg = new wxMessageDialog(this, _T("You have to restart the application!"), _T("WARNING!!"), wxOK );
237 _mar->_parameters->setBoolParam( marParameters::e_invest_slice_order, _chkInvertSliceOrder->GetValue( ) );
238 _mar->saveParameters( );
240 //----------------------------------------------------------------------------
241 void wxSurfaceSTLWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
243 _3DWorldSTL->SetSurfaceVisibility( _isoVisible->GetValue() );
245 //----------------------------------------------------------------------------
246 void wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease(wxScrollEvent& WXUNUSED(event))
249 double tmp=(double)_stlSurfaceValue->GetValue();
250 _3DWorldSTL->SetSTLThresholdRatio( tmp );
252 //----------------------------------------------------------------------------
253 void wxSurfaceSTLWidget::OnSTLSurfaceVisible(wxCommandEvent& WXUNUSED(event))
255 _3DWorldSTL->SetSTLSurfaceVisibility( _stlIntSurfaceVisible->GetValue(), _stlExtSurfaceVisible->GetValue() );
257 //----------------------------------------------------------------------------
258 void wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
261 _3DWorldSTL->SetSurfaceIsoValue( event.GetPosition() );
263 //----------------------------------------------------------------------------
264 void wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
266 _3DWorldSTL->SetSurfaceOpacity( event.GetPosition() );
269 //----------------------------------------------------------------------------
270 void wxSurfaceSTLWidget::OnVesselConstruction(wxCommandEvent& WXUNUSED(event))
273 _3DWorldSTL->ConstructVessel( );
274 _vessels_tb->EnableTool(ID_BUTTON_3D_CUTTER, true);
275 _vessels_tb->EnableTool(ID_BUTTON_EXPORT_STL, true);
277 _stlIntSurfaceVisible->Enable();
278 _stlExtSurfaceVisible->Enable();
279 _stlSurfaceValue->Enable();
280 _vessels_tb->EnableTool(ID_BUTTON_VESSELS_CONSTRUCTION, false);
281 // this->GetParent()->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, false);
283 //----------------------------------------------------------------------------
284 void wxSurfaceSTLWidget::On3DCutter(wxCommandEvent& event)
287 _3DWorldSTL->SetCuttingMode( event.IsChecked() );
290 //----------------------------------------------------------------------------
291 void wxSurfaceSTLWidget::OnExportAsSTL(wxCommandEvent& WXUNUSED(event))
294 wxString dirSTL = _mar->_parameters->getStringParam(
295 marParameters::e_installation_directory );
296 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
297 wxDirDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
298 dirSTL: wxGetHomeDir( ) );
300 if( dialog.ShowModal( ) == wxID_OK )
302 wxString tmpSTR(dialog.GetPath( ) + _T("/") + _mar->_dicom->GetPatientName() );
303 _3DWorldSTL->ExportSurfaceAsSTL( (const char*)(tmpSTR.mb_str()) );
306 //By default *always* update e_installation_directory:
307 _mar->_parameters->setStringParam( marParameters::e_installation_directory,
309 _mar->saveParameters( );