wxSurfaceWidget.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: wxSurfaceWidget.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 "../res/bitmaps/extract.xpm"
00019 #include "../res/bitmaps/del_axis.xpm"
00020 #include "../res/bitmaps/plans.xpm"
00021 #include "wxSurfaceWidget.h"
00022 #include "../marDictionary.h"
00023 #include "../wxMaracas_ManualTree_MPRDlg.h"
00024 
00025 
00026 #include <matrix.h>
00027 
00028 #include <wx/dialog.h>
00029 #include <wx/colordlg.h>
00030 
00031 // PS -> #ifndef __WXMSW__
00032 // PS -> #   include "../res/bitmaps/extract.xpm"
00033 // PS -> #   include "../res/bitmaps/del_axis.xpm"
00034 // PS -> #endif
00035 
00036 //----------------------------------------------------------------------------
00037 BEGIN_EVENT_TABLE( wxSurfaceWidget, wxPanel )
00038 
00039     EVT_BUTTON(ID_BUTTON_NEW_AXIS               , wxSurfaceWidget::OnExtractAxis                        )
00040     EVT_BUTTON(ID_BUTTON_DELETE_AXIS    , wxSurfaceWidget::OnDeleteAxis                         )
00041     EVT_BUTTON(ID_BUTTON_QUANTIFICATION , wxSurfaceWidget::OnQuantification                     )
00042     EVT_BUTTON(ID_BUTTON_MANUAL_AXIS    , wxSurfaceWidget::OnManualAxis                         )
00043 
00044 
00045     EVT_BUTTON(ID_BUTTON_CHOOSE_COLOR   , wxSurfaceWidget::OnChooseSurfaceColor         )
00046     EVT_CHECKBOX(ID_CHECKBOX_ISOVISIBLE , wxSurfaceWidget::OnIsoVisible                         )
00047 
00048     EVT_COMMAND_SCROLL(ID_SLIDER_OPACITY, wxSurfaceWidget::OnSliderOpacityScrollThumbrelease)
00049     EVT_COMMAND_SCROLL_THUMBRELEASE(ID_SLIDER_ISOVAL, wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease)
00050 END_EVENT_TABLE( );
00051 
00052 //----------------------------------------------------------------------------
00053 wxSurfaceWidget::wxSurfaceWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, 
00054                                                                  const wxSize& size, long style, const wxString& name) 
00055                                                                  : wxPanel( parent, id, pos, size, style, name )
00056 {
00057 printf("EED wxSurfaceWidget::wxSurfaceWidget  1 \n" );
00058 
00059         marDictionary marDict;
00060         char tmp[256];
00061 
00062         _id_toolbar_plans=-1;
00063         _mar = NULL;
00064 
00065         _3DWorld = new vtk3DSurfaceWidget( this, ID_WORLD3D );
00066         _3DWorld->SetInterfaceVtkPanelWidgets(this);
00067 
00068     // Set up axis toolbar
00069     wxBitmap axisToolBarBitmaps[ 3 ];
00070     axisToolBarBitmaps[ 0 ] = wxBITMAP( axistoolbar_extract );
00071     axisToolBarBitmaps[ 1 ] = wxBITMAP( axistoolbar_erase   );
00072     axisToolBarBitmaps[ 2 ] = wxBITMAP( toolbar_plans       );
00073 
00074 
00075    _bt_new_axis                 = new wxBitmapButton( this, ID_BUTTON_NEW_AXIS          , axisToolBarBitmaps[ 0 ] );
00076    _bt_delete_axis              = new wxBitmapButton( this, ID_BUTTON_DELETE_AXIS       , axisToolBarBitmaps[ 1 ] );
00077    _bt_call_quantification      = new wxBitmapButton( this, ID_BUTTON_QUANTIFICATION, axisToolBarBitmaps[ 2 ],wxDefaultPosition,wxSize(70,70));
00078 
00079         _bt_manual_axis         = new wxButton(this, ID_BUTTON_MANUAL_AXIS, _T("Manual Axis")); 
00080 //      _bt_manual_axis->SetSize(80,40);
00081 
00082 
00083 
00084 
00085 
00086     //By default the Iso value is visible.
00087     _isoVisible = new wxCheckBox ( this, ID_CHECKBOX_ISOVISIBLE, wxString(marDict.GetString(15), wxConvUTF8) );  //"Iso visible"
00088     _isoValue   = new wxSlider   ( this, ID_SLIDER_ISOVAL, 0, 0, 10000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00089     _opacity    = new wxSlider   ( this, ID_SLIDER_OPACITY, 0, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00090     _isoVisible->SetValue( true );
00091     _isoValue->SetLabel( wxString(marDict.GetString(25), wxConvUTF8) ); // "IsoValue"
00092     _opacity->SetLabel( wxString(marDict.GetString(0), wxConvUTF8) ); //"Surface opacity"
00093 
00094 
00095     //I can't get to brighten the button when mouse over:
00096     //_surface_color = new wxButton(this, ID_BUTTON_CHOOSE_COLOR, "", wxPoint(0,0), wxSize(150,50), wxRAISED_BORDER);
00097     //_surface_color->SetBackgroundColour( wxColour(250, 235, 214));
00098 
00099 
00100     //Set Properties:
00101     _isoValue->SetSize(wxSize(64, 16));
00102     //End set properties
00103 
00104     //Do the layout:
00105     wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(new wxStaticBox(this, -1,wxString(marDict.GetString(10), wxConvUTF8)  ), wxVERTICAL);//"Iso Surface values"
00106     //Some borders are needed on wxGTK otherwise static text and slider labels collides.
00107     sizer_3->Add(_isoVisible, 1, wxALL|wxEXPAND, 2);
00108     sizer_3->Add(new wxStaticText(this, -1, wxString(marDict.GetString(20), wxConvUTF8)), 1, wxALL|wxEXPAND, 2); // "Opacity (%)"
00109     sizer_3->Add(_opacity, 1, wxALL|wxEXPAND, 2);
00110     sizer_3->Add(new wxStaticText(this, -1,wxString(marDict.GetString(25), wxConvUTF8) ), 1, wxALL|wxEXPAND, 2); // "Isovalue"
00111     sizer_3->Add(_isoValue, 1, wxALL|wxEXPAND, 2);
00112 
00113     //Do the layout:
00114         strcpy( tmp , marDict.GetString(30) ); 
00115         _st_cero        = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE );     // "0"
00116 
00117         strcpy( tmp , marDict.GetString(35) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(40) );
00118         _st_text        = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE);      // "Select\n artery" 
00119 
00120         strcpy( tmp , marDict.GetString(45) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(50) );
00121         _st_one = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE );             // "1 \n Axis Extraction" 
00122 
00123         strcpy( tmp , marDict.GetString(55) ); strcat( tmp , "\n" ); strcat( tmp , marDict.GetString(60) );
00124         _st_two = new wxStaticText(this,-1 , wxString(tmp, wxConvUTF8),wxPoint(0,0),wxDefaultSize,wxALIGN_CENTRE);              // " 2 \n Quantification"
00125 
00126 
00127 //      wxFont font(12,wxDEFAULT ,wxNORMAL,wxBOLD);
00128 //      st_blank->SetFont(font);
00129 //      st_next1->SetFont(font);
00130 //      st_next2->SetFont(font);
00131 //      _st_one->SetFont(font);
00132 //      _st_two->SetFont(font);
00133 //      _st_cero->SetFont(font);
00134  
00135         _st_one->Disable();
00136         _bt_new_axis->Disable();
00137         _bt_delete_axis->Disable();
00138         _st_two->Disable();
00139         _bt_call_quantification->Disable();
00140 
00141 
00142 
00143         wxFlexGridSizer *axis_sizer = new wxFlexGridSizer(3,5,5,5);
00144         axis_sizer->Add(_st_cero                                ,0,wxALIGN_CENTER_HORIZONTAL);
00145         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTER_HORIZONTAL);
00146         axis_sizer->Add(_st_one                                 ,0,wxALIGN_CENTER_HORIZONTAL);
00147         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTER_HORIZONTAL);
00148         axis_sizer->Add(_st_two                                 ,0,wxALIGN_CENTER_HORIZONTAL);
00149 
00150         axis_sizer->Add(_st_text                                ,0,wxALIGN_CENTRE_VERTICAL);
00151         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))     ,0,wxALIGN_CENTRE_VERTICAL);
00152         axis_sizer->Add(_bt_new_axis                    ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
00153         axis_sizer->Add(new wxStaticText(this,-1 , _T("  "))                            ,0,wxALIGN_CENTRE_VERTICAL);
00154         axis_sizer->Add(_bt_call_quantification ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
00155 
00156         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTRE_VERTICAL);
00157         axis_sizer->Add(new wxStaticText(this,-1 , _T(" "))                             ,0,wxALIGN_CENTRE_VERTICAL);
00158         axis_sizer->Add(_bt_delete_axis                 ,0,wxALIGN_CENTRE_VERTICAL|wxALIGN_CENTER_HORIZONTAL);
00159     wxBoxSizer *sizer_2 = new wxBoxSizer(wxVERTICAL);
00160     sizer_2->Add(sizer_3        , 1, wxEXPAND, 0);
00161     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
00162     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
00163     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
00164     sizer_2->Add(new wxStaticText(this,-1 , _T(" "))    );
00165     sizer_2->Add(axis_sizer     , 1, wxEXPAND|wxALL|wxALIGN_LEFT, 0);
00166     sizer_2->Add(_bt_manual_axis);
00167 
00168 
00169     wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
00170     sizer_1->Add(_3DWorld, 1, wxEXPAND, 0);
00171     sizer_1->Add(sizer_2, 0, wxALL|wxALIGN_RIGHT, 5);
00172 
00173     SetSizer(sizer_1);
00174     SetAutoLayout(true);
00175     Layout();
00176 
00177 
00178 
00179 }
00180 
00181 //----------------------------------------------------------------------------
00182 wxSurfaceWidget::~wxSurfaceWidget( )
00183 {
00184         _3DWorld->Delete();
00185 }
00186 
00187 //----------------------------------------------------------------------------
00188 void wxSurfaceWidget::ShowMARACASData( marInterface* mar )
00189 {
00190   wxBusyCursor wait;
00191 
00192    double min, max; //backward compatibility
00193   _mar = mar;
00194   _3DWorld->ShowMARACASData( mar );
00195   _3DWorld->ConfigureVTK( );
00196   _3DWorld->InitCameraReset( );
00197 
00198   //GUI stuff:
00199   _mar->_experiment->getDynData( )->getVolume( )->getMinMax( min, max );
00200 
00201   _isoValue->SetRange((int)min, (int)max);
00202   _isoValue->SetValue( (int)(max/4) );
00203 
00204   _opacity->SetValue( 50 );
00205 
00206 //EED 31 Mai 2007
00207 //  _3DWorld->Render();
00208 
00209 }
00210 //----------------------------------------------------------------------------
00211 void wxSurfaceWidget::OnChooseSurfaceColor(wxCommandEvent& WXUNUSED(event))
00212 {
00213     wxColourData data;
00214     data.SetChooseFull( true );
00215     for( int i = 0; i < 16; i++ )
00216     {
00217         wxColour colour( i * 16, i * 16, i * 16 );
00218         data.SetCustomColour( i, colour );
00219     } // rof
00220 
00221     wxColourDialog dialog ( this, &data );
00222     dialog.SetTitle( _T("choose color") );
00223 
00224     if( dialog.ShowModal( ) == wxID_OK )
00225     {
00226         wxColourData retData = dialog.GetColourData( );
00227         wxColour col = retData.GetColour( );
00228       //_surface_color->SetBackgroundColour( col );
00229 
00230       _3DWorld->SetSurfaceColor(col.Red(), col.Green(), col.Blue() );
00231 
00232     } // fi
00233 
00234 }
00235 //----------------------------------------------------------------------------
00236 void wxSurfaceWidget::OnIsoVisible(wxCommandEvent& WXUNUSED(event))
00237 {
00238   _3DWorld->SetSurfaceVisibility( _isoVisible->GetValue() );
00239 }
00240 //----------------------------------------------------------------------------
00241 void wxSurfaceWidget::OnSliderIsovalueScrollThumbrelease(wxScrollEvent& event)
00242 {
00243   wxBusyCursor wait;
00244   _3DWorld->SetSurfaceIsoValue( event.GetPosition() );
00245 }
00246 //----------------------------------------------------------------------------
00247 void wxSurfaceWidget::OnSliderOpacityScrollThumbrelease(wxScrollEvent& event)
00248 {
00249   _3DWorld->SetSurfaceOpacity( event.GetPosition() );
00250 }
00251 //----------------------------------------------------------------------------
00252 void wxSurfaceWidget::OnExtractAxis(wxCommandEvent& event)
00253 {
00254   if(_3DWorld->GetInitialSphere() )
00255   {
00256 // EED Borrame
00257 long int startTimeAE = clock();;
00258 
00259 
00260    wxBusyCursor wait;
00261 
00262         gtm::TVector< double > xc( 3 );
00263         double data[3];
00264         int extent[ 6 ];
00265         double spc[ 3 ];
00266 // PS ->        vtkPolyData* allData; //PS
00267 
00268         vtkImageData *imageData=_mar->_experiment->getDynData( )->getVolume( )->castVtk();
00269     imageData->GetExtent( extent );
00270     imageData->GetSpacing( spc );
00271     _3DWorld->GetSphereCenter( data );
00272 
00273 
00274 //EED 20 Sep 2006
00275 //      _mar->_experiment->setStartPoint( (int)data[0] - extent[0], (int)data[1] - extent[2], (int)data[2] - extent[4]);
00276         double x,y,z;
00277         x= (data[0] - extent[0]) / spc[0];
00278         y= (data[1] - extent[2]) / spc[1];
00279         z= (data[2] - extent[4]) / spc[2];
00280         _mar->_experiment->setStartPoint( (int)x, (int)y, (int)z);
00281 
00282         _mar->_experiment->extractVascularTree( );
00283 
00284         _mar->_experiment->setAxis( 0 );
00285 
00286         AddAxisActors();
00287 // PS ->         allData = temp->Draw( ); //PS
00288 // PS ->      _3DWorld->SetAxis( allData );//PS
00289 
00290     //Disabling tool
00291 
00292 //EED    _axis_tb->EnableTool(ID_BUTTON_NEW_AXIS, false);
00293 //EED    _axis_tb->EnableTool(ID_BUTTON_DELETE_AXIS, true);
00294 
00295         _bt_new_axis->Disable();
00296     _st_two->Enable();
00297         _bt_delete_axis->Enable();
00298         _bt_call_quantification->Enable();
00299 
00300         event.Skip();
00301         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
00302         ProcessEvent( ev );
00303 
00304 /*
00305 //EED Borrame
00306 FILE *ff;
00307 ff = fopen("c:/temp/MaracasStadistics.txt","a+");
00308 long int endtime = clock();
00309 double sg = (double)(endtime-startTimeAE) / (double)CLK_TCK;
00310 fprintf(ff,"EED %p wxSurfaceWidget::OnExtractAxis > AE_t = %f \n",this,sg);
00311 fclose(ff);
00312 */
00313 
00314   }
00315   else
00316   {
00317         wxMessageBox( _T("Set an initial point.\n \n (Double click over the interest artery.)"),
00318                                           _T("DxMM : MARACAS"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
00319   }
00320 
00321 }
00322 //----------------------------------------------------------------------------
00323 void wxSurfaceWidget::AddAxisActors(){
00324         // Axes ...
00325         marAxis         *maraxis                = _mar->_experiment->getAxis( );
00326         vtkPolyData *vtkpolydata        = maraxis->Draw();
00327         vtkPoints       *vtkpoints              = vtkpolydata->GetPoints();
00328         int                     size                    = vtkpoints->GetNumberOfPoints();
00329 
00330 // EED 22 sep 2006
00331 // EED 07 dic 2006
00332         double voxelSize = _mar->_parameters->getVoxelSize();
00333         double pp[3];
00334         int i;
00335         for (i=0;i<size;i++)
00336         {
00337                 vtkpoints->GetPoint(i,pp);
00338                 pp[0]=pp[0] * voxelSize;
00339                 pp[1]=pp[1] * voxelSize;
00340                 pp[2]=pp[2] * voxelSize;
00341         }
00342 
00343 
00344         if (maraxis!=NULL) _3DWorld->SetAxis( vtkpolydata );
00345         // Other Actors..
00346         // ..
00347 }
00348 //----------------------------------------------------------------------------
00349 void wxSurfaceWidget::Clean3D(){
00350   _3DWorld->RemoveAxis( );
00351 }
00352 //----------------------------------------------------------------------------
00353 void wxSurfaceWidget::RefreshAxis() {   
00354         _3DWorld->Render(); 
00355 }
00356 //----------------------------------------------------------------------------
00357 void wxSurfaceWidget::OnDeleteAxis(wxCommandEvent& event)
00358 {
00359         wxBusyCursor wait;
00360         Clean3D();
00361         _mar->_experiment->DeleteAxis( 0 );
00362 
00363     //Disabling tool
00364     //wxToolBar::EnableTool This function should only be called after Realize.
00365 
00366         _bt_new_axis->Enable();
00367         _bt_delete_axis->Disable();
00368         _bt_call_quantification->Disable();
00369         _st_one->Enable();
00370         _st_two->Disable();
00371 
00372         event.Skip();
00373         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_DELETE_AXIS);
00374         ProcessEvent(  ev );
00375 
00376 }
00377 //----------------------------------------------------------------------------
00378 void wxSurfaceWidget::CallBackOnLeftDClick( wxMouseEvent& event ){
00379         _3DWorld->SetInitialPoint();
00380         if ( _3DWorld->GetInitialSphere() ){  
00381                 marAxis *maraxis = _mar->_experiment->getAxis( );
00382 
00383                 if (maraxis==NULL) {
00384                         _st_one->Enable();
00385                         _bt_new_axis->Enable();
00386                 } else {
00387                         _st_one->Disable();
00388                         _bt_new_axis->Disable();
00389                 }
00390 
00391         }
00392 
00393 
00394         if ( !_3DWorld->GetInitialSphere() ) {
00395                         _st_one->Disable();
00396                         _bt_new_axis->Disable();
00397         }
00398 
00399 }
00400 //----------------------------------------------------------------------------
00401 void wxSurfaceWidget::OnQuantification(wxCommandEvent& event){
00402         if (_id_toolbar_plans!=-1){
00403            wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,_id_toolbar_plans);
00404            ProcessEvent(  ev );
00405         }
00406 }
00407 //----------------------------------------------------------------------------
00408 void wxSurfaceWidget::SetId_toolbar_plans(int id_toolbar_plans ){
00409         _id_toolbar_plans=id_toolbar_plans;
00410 }
00411 //----------------------------------------------------------------------------
00412 int wxSurfaceWidget::GetIsovalue(){
00413         return _isoValue->GetValue();
00414 }
00415 //----------------------------------------------------------------------------
00416 int wxSurfaceWidget::GetOpacity(){
00417         return _opacity->GetValue();
00418 }
00419 //----------------------------------------------------------------------------
00420 vtk3DSurfaceWidget *wxSurfaceWidget::GetVtk3DSurfaceWidget(){
00421         return _3DWorld;
00422 }
00423 //----------------------------------------------------------------------------
00424 void wxSurfaceWidget::OnManualAxis(wxCommandEvent& event)
00425 {
00426         wxBusyCursor wait;
00427         if ( _bt_delete_axis->IsEnabled() )
00428         {
00429                 OnDeleteAxis(event);
00430         }
00431 
00432         vtkImageData *imagedata =  _mar->_experiment->getDynData( )->getVolume( )->castVtk();   
00433         wxMaracas_ManualTree_MPRDlg  *maracasManualTreeMPRDlg = new wxMaracas_ManualTree_MPRDlg( this , new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
00434         marAxis *maraxis = new marAxis( _mar->_experiment->getParameters() );
00435         maracasManualTreeMPRDlg->SetMarAxis( maraxis );
00436         maracasManualTreeMPRDlg->ConfigureVTK();
00437         if (maracasManualTreeMPRDlg->ShowModal()==wxID_OK)
00438         {
00439                 if (maracasManualTreeMPRDlg->ExportPoints()==true){
00440                         _mar->_experiment->appendAxis(maraxis);
00441                         _bt_new_axis->Disable();
00442                         _st_two->Enable();
00443                         _bt_delete_axis->Enable();
00444                         _bt_call_quantification->Enable();
00445                         AddAxisActors();
00446                         event.Skip();
00447                         wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,ID_BUTTON_NEW_AXIS);
00448                         ProcessEvent(  ev );
00449                 } else {
00450                         delete maraxis;
00451                 }
00452         }
00453         maracasManualTreeMPRDlg->Destroy();
00454 
00455 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1