wxSurfaceSTLWidget.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: wxSurfaceSTLWidget.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2009/05/14 13:54:57 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011   
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 #include "wxSurfaceSTLWidget.h"
00019 #include <matrix.h>
00020 
00021 #include <wx/dialog.h>
00022 #include <wx/colordlg.h>
00023 
00024 #ifndef __WXMSW__
00025 #   include "../res/bitmaps/extract.xpm"
00026 #   include "../res/bitmaps/del_axis.xpm"
00027 #   include "../res/bitmaps/vessels.xpm"
00028 #   include "../res/bitmaps/cutter.xpm"
00029 #   include "../res/bitmaps/stl.xpm"
00030 #endif
00031 
00032 //----------------------------------------------------------------------------
00033 BEGIN_EVENT_TABLE( wxSurfaceSTLWidget, wxPanel )
00034 
00035     EVT_TOOL(ID_BUTTON_VESSELS_CONSTRUCTION, wxSurfaceSTLWidget::OnVesselConstruction )
00036     EVT_TOOL(ID_BUTTON_3D_CUTTER, wxSurfaceSTLWidget::On3DCutter )
00037     EVT_TOOL(ID_BUTTON_EXPORT_STL, wxSurfaceSTLWidget::OnExportAsSTL )
00038 
00039     EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR, wxSurfaceSTLWidget::OnChooseSurfaceColor )
00040     EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE, wxSurfaceSTLWidget::OnIsoVisible )
00041     EVT_CHECKBOX(ID_CHECKBOX_STL_VISIBLE, wxSurfaceSTLWidget::OnSTLSurfaceVisible )
00042 
00043     EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease)
00044 
00045     EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease)
00046     EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_STL_THRESH, wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease)
00047 
00048     EVT_CHECKBOX(ID_CHECKBOX_INVERT_SLICE_ORDER, wxSurfaceSTLWidget::OnInvertSliceOrder )
00049 
00050 END_EVENT_TABLE( );
00051 
00052 //----------------------------------------------------------------------------
00053 wxSurfaceSTLWidget::wxSurfaceSTLWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
00054     const wxString& name) : wxPanel( parent, id, pos, size, style, name )
00055 {
00056     _mar = NULL;
00057 
00058     _3DWorldSTL = new vtk3DSurfaceSTLWidget( this, ID_WORLD3D );
00059 
00060     // Set up axis toolbar
00061     wxBitmap axisToolBarBitmaps[ 2 ];
00062     axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
00063     axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase );
00064 
00065 
00066     //By default the Iso value is visible.
00067     _isoVisible = new wxCheckBox( this, ID_CHECKBOX_ISOVISIBLE, _T("Iso visible") );
00068     _isoVisible->SetValue( true );
00069     _isoValue = new wxSlider( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00070     _opacity = new wxSlider( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00071     _isoValue->SetLabel( _T("IsoValue") );
00072     _opacity->SetLabel( _T("Surface opacity") );
00073 
00074     //I can't get to brighten the button when mouse over:
00075     //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
00076     //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
00077     
00078     // Set up vessels toolbar
00079     wxBitmap vesselsToolBarBitmaps[ 3 ];
00080     vesselsToolBarBitmaps[ 0 ] = wxBITMAP( vesselstoolbar_extract );
00081     vesselsToolBarBitmaps[ 1 ] = wxBITMAP( vesselstoolbar_cutter );
00082     vesselsToolBarBitmaps[ 2 ] = wxBITMAP( vesselstoolbar_stl );
00083 
00084          _vessels_tb = new wxToolBar( this, -1);
00085     _vessels_tb->SetMargins( 4, 4 );
00086     _vessels_tb->SetToolBitmapSize( wxSize( vesselsToolBarBitmaps[ 0 ].GetWidth( ), vesselsToolBarBitmaps[ 0 ].GetHeight( ) ) );
00087     _vessels_tb->AddTool(ID_BUTTON_VESSELS_CONSTRUCTION, _T("Construct Surface"), vesselsToolBarBitmaps[ 0 ],  _T("Construct Surface"));
00088     _vessels_tb->AddSeparator( );
00089     //_vessels_tb->AddTool(ID_BUTTON_3D_CUTTER, vesselsToolBarBitmaps[ 1 ], "Delete axis", "short help string");
00090     _vessels_tb->AddCheckTool(ID_BUTTON_3D_CUTTER, _T("Delete axis"), vesselsToolBarBitmaps[ 1 ], wxNullBitmap, _T("Delete axis") ); //, "short help string"
00091     _vessels_tb->AddSeparator( );
00092     _vessels_tb->AddTool(ID_BUTTON_EXPORT_STL, _T("Export as STL"), vesselsToolBarBitmaps[ 2 ], _T("Export as STL"));
00093     _vessels_tb->Realize( );
00094     _vessels_tb->SetRows( 1 ); 
00095 
00096 
00097     //Set Properties:
00098     _isoValue->SetSize(wxSize(64, 16));
00099     //End set properties
00100     
00101     //Do the layout:
00102     wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("Iso Surface values")), wxVERTICAL);
00103     //Some borders are needed on wxGTK otherwise static text and slider labels collides.
00104     sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
00105     sizer_3->Add(new wxStaticText(this, -1, _T("Isovalue")), 1, wxALL|wxEXPAND, 2);
00106     sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
00107     sizer_3->Add(new wxStaticText(this, -1, _T("Opacity (%)")), 1, wxALL|wxEXPAND, 2);
00108     sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
00109 
00110     //By default the STL Iso value is visible.
00111     _stlIntSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("Internal STL Surface visible") );
00112     _stlIntSurfaceVisible->SetValue( true );
00113     _stlExtSurfaceVisible = new wxCheckBox( this, ID_CHECKBOX_STL_VISIBLE, _T("External STL Surface visible") );
00114     _stlExtSurfaceVisible->SetValue( true );
00115     _stlSurfaceValue = new wxSlider( this, ID_SLIDER_STL_THRESH, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00116     _stlSurfaceValue->SetLabel( _T("STL Surface Value") );
00117     _stlSurfaceValue->SetRange(0, 100);
00118     //hard coded value 'cause thie is still not reachable: (int)_3DWorldSTL->GetSTLThreshold()
00119     _stlSurfaceValue->SetValue( 45 ); //100*.45 remember to multiply by 100
00120 
00121 
00122     //Do the layout:
00123     wxStaticBoxSizer* sizer_4 = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("STL Surface values")), wxVERTICAL);
00124     sizer_4->Add(_stlIntSurfaceVisible, 1, wxALL|wxEXPAND, 2);
00125     sizer_4->Add(_stlExtSurfaceVisible, 1, wxALL|wxEXPAND, 2);
00126     sizer_4->Add(new wxStaticText(this, -1, _T("STL Isovalue")), 1, wxALL|wxEXPAND, 2);
00127     sizer_4->Add(_stlSurfaceValue, 1, wxALL|wxEXPAND, 2);
00128     
00129     _stlIntSurfaceVisible->Disable();
00130     _stlExtSurfaceVisible->Disable();
00131     _stlSurfaceValue->Disable();
00132 
00133     _chkInvertSliceOrder = new wxCheckBox(this, ID_CHECKBOX_INVERT_SLICE_ORDER, _T("Invert slice order")); 
00134 
00135     wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
00136     sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
00137 // EED Borrame
00138 //    sizer_2->Add(_axis_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
00139     sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
00140     sizer_2->Add(_vessels_tb, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
00141     sizer_2->Add(_chkInvertSliceOrder, 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
00142 
00143     wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
00144     sizer_1->Add(_3DWorldSTL, 1, wxEXPAND, 0);
00145     sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
00146 
00147     SetAutoLayout(true);
00148     SetSizer(sizer_1);
00149     Layout();
00150 
00151 }
00152 
00153 //----------------------------------------------------------------------------
00154 wxSurfaceSTLWidget::~wxSurfaceSTLWidget( )
00155 {
00156         _3DWorldSTL->Delete();
00157 }
00158 
00159 //----------------------------------------------------------------------------
00160 /*void wxSurfaceSTLWidget::ShowMARACASDataDebug( vtkImageData *ima )
00161 {
00162     _3DWorldSTL->ShowMARACASData2Debug( ima );
00163        
00164     //GUI stuff:
00165         float minmax[2];
00166         float min,max;
00167         ima->GetScalarRange( minmax );
00168         min = minmax[0];
00169     max = minmax[1];
00170     
00171     
00172      _isoValue->SetRange((int)min, (int)max);
00173      _isoValue->SetValue( (int)(max/2) );
00174 
00175 }*/
00176 //----------------------------------------------------------------------------
00177 void wxSurfaceSTLWidget::ShowMARACASData( marInterface* mar )
00178 {
00179 wxBusyCursor wait;
00180 
00181 
00182 //    _width  = _mar->_experiment->getDynData( )->getVolume( )->getWidth( );
00183 //    _height = _mar->_experiment->getDynData( )->getVolume( )->getHeight( );
00184 //    _depth  = _mar->_experiment->getDynData( )->getVolume( )->getDepth( );
00185     
00186 
00187     double min, max; //backward compatibility
00188 
00189     _mar = mar;
00190     //_3DWorldSTL->_mar = mar;
00191 //    _3DWorldSTL->ShowMARACASData( mar );
00192     _3DWorldSTL->ShowMARACASDataAndAxe( mar );
00193 
00194         
00195     //GUI stuff:
00196     _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
00197 
00198     _isoValue->SetRange((int)min, (int)max);
00199     _isoValue->SetValue( (int)(max/4) );
00200      
00201     _opacity->SetValue( 50 );
00202         _chkInvertSliceOrder->SetValue( _mar->_parameters->getBoolParam( marParameters::e_invest_slice_order ) );
00203 
00204 }
00205 //----------------------------------------------------------------------------
00206 void wxSurfaceSTLWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
00207 {
00208     wxColourData data;
00209     data.SetChooseFull( true );
00210     for( int i = 0; i < 16; i++ )
00211     {
00212         wxColour colour( i * 16, i * 16, i * 16 );
00213         data.SetCustomColour( i, colour );
00214     } // rof
00215 
00216     wxColourDialog dialog ( this, &data );
00217     dialog.SetTitle( _T("choose color") );
00218 
00219     if( dialog.ShowModal( ) == wxID_OK )
00220     {
00221         wxColourData retData = dialog.GetColourData( );
00222         wxColour col = retData.GetColour( );
00223       //_surface_color->SetBackgroundColour( col );
00224 
00225       _3DWorldSTL->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
00226 
00227     } // fi
00228  
00229 }
00230 
00231 
00232 //----------------------------------------------------------------------------
00233 void wxSurfaceSTLWidget::OnInvertSliceOrder(wxCommandEvent& WXUNUSED(event)){
00234   wxMessageDialog *msgDlg = new wxMessageDialog(this, _T("You have to restart the application!"), _T("WARNING!!"), wxOK );  
00235   msgDlg->ShowModal();
00236   delete msgDlg;
00237   _mar->_parameters->setBoolParam( marParameters::e_invest_slice_order, _chkInvertSliceOrder->GetValue( ) );
00238   _mar->saveParameters( );
00239 }
00240 //----------------------------------------------------------------------------
00241 void wxSurfaceSTLWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
00242 {
00243   _3DWorldSTL->SetSurfaceVisibility( _isoVisible->GetValue() );
00244 }
00245 //----------------------------------------------------------------------------
00246 void wxSurfaceSTLWidget::OnSliderSTLSurfaceValueThumbrelease(wxScrollEvent& WXUNUSED(event))
00247 {
00248   wxBusyCursor wait;
00249   double tmp=(double)_stlSurfaceValue->GetValue();
00250   _3DWorldSTL->SetSTLThresholdRatio( tmp );
00251 }
00252 //----------------------------------------------------------------------------
00253 void wxSurfaceSTLWidget::OnSTLSurfaceVisible(wxCommandEvent& WXUNUSED(event))
00254 {
00255   _3DWorldSTL->SetSTLSurfaceVisibility( _stlIntSurfaceVisible->GetValue(), _stlExtSurfaceVisible->GetValue() );
00256 }
00257 //----------------------------------------------------------------------------
00258 void wxSurfaceSTLWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
00259 {
00260   wxBusyCursor wait;
00261   _3DWorldSTL->SetSurfaceIsoValue( event.GetPosition() );
00262 }
00263 //----------------------------------------------------------------------------
00264 void wxSurfaceSTLWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
00265 {
00266   _3DWorldSTL->SetSurfaceOpacity( event.GetPosition() );
00267 }
00268 
00269 //----------------------------------------------------------------------------
00270 void wxSurfaceSTLWidget::OnVesselConstruction(wxCommandEvent& WXUNUSED(event))
00271 {
00272         wxBusyCursor wait;
00273   _3DWorldSTL->ConstructVessel( );
00274   _vessels_tb->EnableTool(ID_BUTTON_3D_CUTTER, true);
00275   _vessels_tb->EnableTool(ID_BUTTON_EXPORT_STL, true);
00276 
00277   _stlIntSurfaceVisible->Enable();
00278   _stlExtSurfaceVisible->Enable();
00279   _stlSurfaceValue->Enable();
00280   _vessels_tb->EnableTool(ID_BUTTON_VESSELS_CONSTRUCTION, false);
00281 //  this->GetParent()->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, false);
00282 }
00283 //----------------------------------------------------------------------------
00284 void wxSurfaceSTLWidget::On3DCutter(wxCommandEvent& event)
00285 {
00286         wxBusyCursor wait;
00287   _3DWorldSTL->SetCuttingMode( event.IsChecked() );
00288 }
00289 
00290 //----------------------------------------------------------------------------
00291 void wxSurfaceSTLWidget::OnExportAsSTL(wxCommandEvent& WXUNUSED(event))
00292 {
00293         wxBusyCursor wait;
00294   wxString dirSTL = _mar->_parameters->getStringParam( 
00295     marParameters::e_installation_directory ); 
00296   dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
00297   wxDirDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
00298   dirSTL: wxGetHomeDir( ) );
00299 
00300   if( dialog.ShowModal( ) == wxID_OK ) 
00301   {
00302      wxString tmpSTR(dialog.GetPath( ) +  _T("/") + _mar->_dicom->GetPatientName() );
00303       _3DWorldSTL->ExportSurfaceAsSTL( (const char*)(tmpSTR.mb_str())  );
00304   }
00305 
00306   //By default *always* update e_installation_directory:
00307   _mar->_parameters->setStringParam( marParameters::e_installation_directory,
00308     dialog.GetPath( ) ); 
00309   _mar->saveParameters( );
00310 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1