wxVtkClipping3DViewCntrlPanel.cxx

Go to the documentation of this file.
00001 
00002 #include "wxVtkClipping3DViewCntrlPanel.h"
00003 #include "wx/colordlg.h"
00004 #include "vtkTriangleFilter.h"
00005 #include "vtkPolyDataConnectivityFilter.h"
00006 #include "vtkClosePolyData.h"
00007 #include "vtkSTLWriter.h"
00008 #include "HistogramDialog.h"
00009 #include "marDicomBase.h"
00010 
00011 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
00012 : wxPanel(parent, -1)
00013 {
00014         wxPanel *panel  = this;
00015         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
00016 
00017 //EEDx2.6
00018 //      wxStaticText    *text1                  = new wxStaticText(panel, -1,_T("          "));
00019 //      wxStaticText    *text2                  = new wxStaticText(panel, -1,_T("  "));
00020 
00021                                         _surfA                  = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
00022                                         _surfB                  = new wxRadioButton(panel,-1,_T("B"));
00023                                         _surfC                  = new wxRadioButton(panel,-1,_T("C"));
00024                                         _surfD                  = new wxRadioButton(panel,-1,_T("D"));
00025 
00026 
00027         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00028         //wxCheckBox            *ckVolum                = new wxCheckBox(panel,-1,_T("Vol"));
00029         wxCheckBox              *ckBoxSurface   = new wxCheckBox(panel,-1,_T("Surface Box"));
00030         
00031         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00032         //wxCheckBox            *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
00033 
00034                                         _color                  = new wxButton(panel,-1,_T(""));
00035                                         _visible                = new wxCheckBox(panel,-1,_T("Vis"));
00036                                         _opacity                = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL | wxSL_LABELS);
00037 
00038         wxStaticText    *isoValueTitle  = new wxStaticText(panel,-1,_T("isoValue"));
00039                                         _isoValue               = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS);
00040 
00041 
00042                                         _wireFrameRep   = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
00043                                         _surfaceRep             = new wxRadioButton(panel,-1,_T("Surface"));
00044 
00045 
00046         double range[2];
00047         vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
00048         vtkimagedata->GetScalarRange( range );
00049         _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
00050         _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
00051 
00052 
00053         _isoValue->SetTickFreq(25,0);
00054 
00055         _isoValueSpin   = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
00056         _isoValueSpin->SetRange(1,8);
00057         _isoValueSpin->SetValue(5);
00058         Connect(_isoValueSpin->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin ); 
00059 
00060         wxButton *btnSTL                                = new wxButton(panel,-1,_T("Create STL File"));
00061         wxButton *btnSaveRaw                    = new wxButton(panel,-1,_T("Save Raw Volume"));
00062 
00063         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00064         //wxButton *btnVolumeFunctions  = new wxButton(panel,-1,_T("Read Volume Functions"));
00065 
00066 
00067         Connect(btnSTL->GetId()                         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL    ); 
00068         Connect(btnSaveRaw->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume    ); 
00069         
00070         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00071         //Connect(btnVolumeFunctions->GetId()   , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions  ); 
00072 
00073 
00074         wxButton *btnMeshVTKLoad        = new wxButton(panel,-1,_T("Load Mesh"));
00075         Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad      ); 
00076 
00077 
00078 /*
00079         int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
00080         int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
00081         int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
00082         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,"X");
00083                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00084         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,"Y");
00085                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00086         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,"Z");
00087                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
00088 */
00089 
00090 //      ckVolum->Enable(false);
00091         ckBoxSurface->SetValue(false);
00092         
00093         
00094         //ckBoxVolume->SetValue(false);
00095 
00096 
00097         _color->SetSize(40,20);
00098         _opacity->SetSize(370,20);
00099 //      ckBoxX->SetValue(true);
00100 //      ckBoxY->SetValue(true);
00101 //      ckBoxZ->SetValue(true);
00102         _surfA->SetValue(true);
00103         _wireFrameRep->SetValue(false);
00104         _surfaceRep->SetValue(true);
00105         _visible->SetValue(false);
00106 //      _positionX->SetSize(400,20);
00107 //      _positionY->SetSize(400,20);
00108 //      _positionZ->SetSize(400,20);
00109 
00110         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00111         //Connect(ckVolum->GetId()              , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume                             );
00112         //Connect(ckBoxVolume->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume                  );
00113 
00114         Connect(_surfA->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
00115         Connect(_surfB->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
00116         Connect(_surfC->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
00117         Connect(_surfD->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
00118         Connect(ckBoxSurface->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface                 );
00119 
00120         Connect(_wireFrameRep->GetId()  , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
00121         Connect(_surfaceRep->GetId()    , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
00122 
00123         Connect(_color->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor                                             );
00124         Connect(_visible->GetId()               , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface                    );
00125         Connect(_opacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity                                   );
00126 
00127 //EED 27Dic2007
00128 //      Connect(_isoValue->GetId()              , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                  );
00129         Connect(_isoValue->GetId()              , wxEVT_SCROLL_THUMBRELEASE               , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                          );
00130 
00131 /*
00132         Connect(ckBoxX->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
00133         Connect(_positionX->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
00134         Connect(ckBoxY->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
00135         Connect(_positionY->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
00136         Connect(ckBoxZ->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
00137         Connect(_positionZ->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
00138 */
00139 
00140         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
00141         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
00142         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
00143         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
00144         wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
00145         //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
00146         //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
00147         //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
00148 
00149         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume        
00150         //sizerH0->Add( ckVolum                                                                 , 1, wxALL|wxEXPAND, 0);
00151         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
00152         //sizerH0->Add( ckBoxVolume                                                             , 1, wxALL|wxEXPAND, 0);
00153         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
00154         //sizerH0->Add( btnVolumeFunctions                                              , 1, wxALL|wxEXPAND, 0);
00155         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
00156         sizerH0->Add( btnMeshVTKLoad                                                    , 1, wxALL|wxEXPAND, 0);
00157 
00158 
00159         sizerH1->Add( _surfA                                                                    , 1, wxALL|wxEXPAND, 0);
00160         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
00161         sizerH1->Add( _surfB                                                                    , 1, wxALL|wxEXPAND, 0);
00162         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
00163         sizerH1->Add( _surfC                                                                    , 1, wxALL|wxEXPAND, 0);
00164         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
00165         sizerH1->Add( _surfD                                                                    , 1, wxALL|wxEXPAND, 0);
00166         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
00167         sizerH1->Add( ckBoxSurface                                                              , 1, wxALL|wxEXPAND, 0);
00168         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
00169         sizerH1->Add( btnSTL                                                                    , 1, wxALL|wxEXPAND, 0);
00170         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
00171         sizerH1->Add( btnSaveRaw                                                                , 1, wxALL|wxEXPAND, 0);
00172 
00173 
00174 //      sizerH2->Add( new wxStaticText(panel, -1,_T("          ")                       , 1, wxALL|wxEXPAND, 0);
00175         sizerH2->Add( _color                            , 1, wxALL|wxEXPAND, 0);
00176         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
00177         sizerH2->Add( _visible                          , 1, wxALL|wxEXPAND, 0);
00178         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
00179 
00180         
00181         sizerH2->Add( _wireFrameRep                             , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
00182         sizerH2->Add( new wxStaticText(panel, -1,_T("   "))                                     , 1, wxALL|wxEXPAND, 0);
00183         sizerH2->Add( _surfaceRep                               , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
00184         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
00185         
00186         sizerH2->Add( _opacity                          , 1, wxALL|wxEXPAND, 0);
00187 
00188 
00189         sizerH3->Add( isoValueTitle                     , 1, wxALL|wxEXPAND, 0);
00190         sizerH3->Add( _isoValueSpin                     , 1, wxALL|wxEXPAND, 0);
00191         sizerH3->Add( _isoValue                         , 1, wxALL|wxEXPAND, 0);
00192 
00193 /*
00194         sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
00195         sizerH4->Add( text2                     , 1, wxALL|wxEXPAND, 0);
00196         sizerH4->Add( _positionX                , 1, wxALL|wxEXPAND, 0);
00197 
00198         sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
00199         sizerH5->Add( text2                     , 1, wxALL|wxEXPAND, 0);
00200         sizerH5->Add( _positionY                , 1, wxALL|wxEXPAND, 0);
00201 
00202         sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
00203         sizerH6->Add( text2                     , 1, wxALL|wxEXPAND, 0);
00204         sizerH6->Add( _positionZ                , 1, wxALL|wxEXPAND, 0);
00205 */
00206         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
00207         sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
00208         sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
00209         sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
00210 //      sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
00211 //      sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
00212 //      sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
00213 
00214         panel->SetSize(300,60);
00215         panel->SetAutoLayout(true);
00216         panel->SetSizer(sizer);
00217         panel->Layout();
00218 
00219         panel->SetEventHandler((wxEvtHandler*)this);
00220 
00221 }
00222 //-------------------------------------------------------------------
00223 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
00224 {
00225 }
00226 //-------------------------------------------------------------------
00227 void wxVtkClipping3DViewCntrlPanel::Refresh()
00228 {
00229 //      wxPanel::Refresh();
00230 /*
00231         _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
00232         _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
00233         _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
00234 */
00235 }
00236 //-------------------------------------------------------------------
00237 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
00238 {
00239         int idTissue=-1;
00240         if (_surfA->GetValue()==true)
00241         {
00242                 idTissue=0;
00243         }
00244         if (_surfB->GetValue()==true)
00245         {
00246                 idTissue=1;
00247         }
00248         if (_surfC->GetValue()==true)
00249         {
00250                 idTissue=2;
00251         }
00252         if (_surfD->GetValue()==true)
00253         {
00254                 idTissue=3;
00255         }
00256 
00257         return idTissue;
00258 }
00259 /*
00260 //-------------------------------------------------------------------
00261 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
00262 {
00263         _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
00264         _wxvtkclipping3Dview->Refresh();
00265 }
00266 //-------------------------------------------------------------------
00267 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
00268 {
00269         _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
00270         _wxvtkclipping3Dview->Refresh();
00271 }
00272 //-------------------------------------------------------------------
00273 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
00274 {
00275         _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
00276         _wxvtkclipping3Dview->Refresh();
00277 }
00278 */
00279 
00280 //-------------------------------------------------------------------
00281 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
00282 {
00283         int idTissue=GetIdTissue();
00284         if (idTissue!=-1)
00285         {
00286                 // Color
00287                 vtkActor *tmpActor;
00288                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
00289                 double rgb[3];
00290                 tmpActor->GetProperty()->GetColor( rgb );
00291                 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
00292                 _color->SetBackgroundColour(colour);
00293 
00294                 // Visible
00295                 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
00296 
00297                 // Opacity
00298                 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
00299 
00300                 // Representation Type  WireFrame / Surface
00301                 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
00302                 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
00303 
00304                 // isoValue
00305                 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
00306                 _isoValue->SetValue(isoValue);
00307         }
00308 }
00309 
00310 
00311 //-------------------------------------------------------------------
00312 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
00313 {
00314         int idTissue=GetIdTissue();
00315         if (idTissue!=-1)
00316         {
00317                 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
00318 
00319                 _wxvtkclipping3Dview->Refresh();
00320 
00321                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00322                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00323 
00324         }
00325 }
00326 
00327 //-------------------------------------------------------------------
00328 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
00329 {
00330         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
00331         _wxvtkclipping3Dview->Refresh();
00332 
00333         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00334         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00335 }
00336 //-------------------------------------------------------------------
00337 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
00338 {
00339         _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
00340         _wxvtkclipping3Dview->Refresh();
00341 }
00342 //-------------------------------------------------------------------
00343 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
00344 {
00345         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
00346         _wxvtkclipping3Dview->Refresh();
00347 }
00348 //-------------------------------------------------------------------
00349 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
00350 {
00351         int idTissue=GetIdTissue();
00352         if (idTissue!=-1)
00353         {
00354 // EED 17 Janvier 2007
00355                 wxColourDialog dlgColour(this);
00356 //              dlgColour.ShowModal();
00357                 if( dlgColour.ShowModal( ) == wxID_OK ) 
00358                 {
00359                         vtkActor *tmpActor;
00360                         tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
00361                         float r=dlgColour.GetColourData().GetColour().Red()/255;
00362                         float g=dlgColour.GetColourData().GetColour().Green()/255;
00363                         float b=dlgColour.GetColourData().GetColour().Blue()/255;
00364                         tmpActor->GetProperty()->SetColor( r , g , b );
00365                         _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
00366 
00367                         _wxvtkclipping3Dview->Refresh();
00368 
00369                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00370                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00371                 }
00372         }
00373 }
00374 //-------------------------------------------------------------------
00375 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
00376 {
00377         int idTissue=GetIdTissue();
00378         if (idTissue!=-1)
00379         {
00380                 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
00381 
00382                 _wxvtkclipping3Dview->Refresh();
00383 
00384                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00385                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00386         }
00387 }
00388 //-------------------------------------------------------------------
00389 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
00390 {
00391         int idTissue=GetIdTissue();
00392         if (idTissue!=-1)
00393         {
00394                 vtkActor *tmpActor;
00395                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
00396                 float opacity=_opacity->GetValue();
00397                 tmpActor->GetProperty()->SetOpacity( opacity/100 );
00398 
00399                 _wxvtkclipping3Dview->Refresh();
00400 
00401                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00402                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00403         }
00404 }
00405 
00406 //----------------------------------------------------------------------------
00407 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
00408 {
00409         int value = _isoValue->GetValue();
00410         int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
00411         int min=value - delta/2;
00412         int max=value + delta/2;
00413         if (min<0)
00414         {
00415                 min=0;
00416                 max=delta;
00417         }
00418         _isoValue->SetRange(min,max);
00419 }
00420 
00421 
00422 //------------------------------------------------------------------------
00423 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
00424 {
00425         wxBusyCursor wait;
00426 
00427         int idTissue=GetIdTissue();
00428         if (idTissue!=-1)
00429         {
00430                 int isoValue=_isoValue->GetValue();
00431                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
00432 //              wxString tmpStr;
00433 //              tmpStr.Printf("%d",isoValue);
00434         
00435                 _wxvtkclipping3Dview->Refresh();
00436 
00437                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00438                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00439         }
00440 
00441 }
00442 //-------------------------------------------------------------------
00443 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
00444 {
00445 
00446         int idTissue=GetIdTissue();
00447         if (idTissue==-1)
00448         {
00449                 idTissue=0;
00450         }
00451 
00452 
00453         wxString dirSTL = wxGetHomeDir( ) ;
00454         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
00455 
00456         if( dialog.ShowModal( ) == wxID_OK ) 
00457         {
00458            
00459         
00460                 // ------------------------------------------------------------------------
00461                 //  1.  GENERATE STL FILES
00462                 // ------------------------------------------------------------------------
00463 //              const char* fileprefix = "c:\\Creatis\\";
00464                 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
00465                 std::string filename;
00466 
00467                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
00468 
00469         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
00470 
00471 
00472                 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
00473                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
00474         pdcf->SetInput( filtro->GetOutput() );
00475         vtkClosePolyData *cpd = vtkClosePolyData::New();
00476         cpd->SetInput( pdcf->GetOutput() );
00477 
00478                 // 1.2 se escribe a disco el archivo stl de la superficie interna
00479         cpd->Update();
00480         vtkSTLWriter *writer = vtkSTLWriter::New();
00481         writer->SetInput( cpd->GetOutput() );
00482                 filename =prefix;
00483         writer->SetFileName(filename.c_str());
00484         writer->SetFileTypeToASCII();
00485         writer->Write();
00486         writer->Delete();
00487 
00488    
00489         filtro->Delete();
00490         cpd->Delete();
00491         pdcf->Delete();
00492         }
00493 
00494 }
00495 
00496 //EED 30 Janvier 2007
00497 //-------------------------------------------------------------------
00498 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
00499 {
00500         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
00501         if (dialog.ShowModal() == wxID_OK)
00502         {
00503                 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
00504                 std::string filename  = (const char*) (dialog.GetFilename().mb_str() );
00505                 float rescalaSlope           =  1;
00506                 float rescalaIntercept       =  0;
00507                 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
00508                 vtkImageData *vtkimagedata       = vtkmprbasedata->GetImageData();
00509                 int dim[3];
00510                 vtkimagedata->GetDimensions(dim);
00511                 int voi[6];
00512                 voi[0]=0;
00513                 voi[1]=dim[0];
00514                 voi[2]=0;
00515                 voi[3]=dim[1];
00516                 voi[4]=0;
00517                 voi[5]=dim[2];
00518 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
00519                 marRAW2Files marraw2;
00520                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
00521         }
00522 }
00523 
00524 //EED 22 Fevrier 2007
00525 //-------------------------------------------------------------------
00526 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
00527 {
00528         
00529         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
00530         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
00531         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
00532         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
00533         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
00534         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
00535         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
00536         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
00537         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
00538         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
00539 
00540         //use for update in the refresh
00541         /*
00542         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
00543         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
00544         */
00545 
00546         /*
00547         MMLR BORRAME 
00548         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
00549         if (dialog.ShowModal() == wxID_OK)
00550         {
00551                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
00552                 
00553         
00554         }
00555         */
00556 
00557         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
00558         // 
00559         // put in a method
00560         //
00561         int tfSize=gtf->size();
00562                 if(tfSize>0)
00563                 {
00564                         int i=0;
00565                         hDlg->erasePointsTransferenceFunction();
00566                         while(i<tfSize)
00567                         {
00568                                 double g=(*gtf)[i];
00569                                 double in=(*itf)[i];
00570                                 hDlg->addPointToTransferenceFunction(g,in*100);
00571                                 i++;
00572                         }
00573                         
00574                 }
00575 
00576         int ctfSize=rctf->size();
00577         if(ctfSize>0)
00578         {
00579                 int i=0;
00580                         while(i<ctfSize)
00581                         {
00582                                 double gr=(*greyctf)[i];
00583                                 double r=(*rctf)[i];
00584                                 double g=(*gctf)[i];
00585                                 double b=(*bctf)[i];
00586                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
00587                                 i++;
00588                         }
00589         }
00590         //setting variables if the user wants to do refresh
00591         hDlg->setCTF(ctfun);
00592         hDlg->setTF(tfun);
00593         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
00594         /*
00595         hDlg->setVolume(newvol);
00596         hDlg->setVolumeMapper(volumeMapper);
00597         */
00598         //
00599         // when the user had changed the transference Function
00600         //
00601         if(hDlg->ShowModal()== wxID_OK )
00602         {       
00603                         // -- vtkPiecewiseFunction --
00604                         tfun->RemoveAllPoints();
00605                         gtf->clear();
00606                         itf->clear();
00607                 
00608                         int nTFPoints=hDlg->getSizeTransferenceFunction();
00609                         int i=0;
00610                         while(i<nTFPoints)
00611                         {
00612                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
00613                                 tfun->AddPoint( xi , yi/100.0 );
00614                                 gtf->push_back(xi);
00615                                 itf->push_back(yi/100.0);
00616                                 i++;
00617                         }       
00618                         // -- vtkColorTransferFunction  --
00619                         ctfun->RemoveAllPoints ();
00620                         //clean colors
00621                         rctf->clear();
00622                         gctf->clear();
00623                         bctf->clear();
00624                         greyctf->clear();
00625 
00626                         int nCTFpoints=hDlg->getSizeBarColor();
00627                         i=0;    
00628                         while(i<nCTFpoints)
00629                         {
00630                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
00631                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
00632                                 rctf->push_back(r/255.0);
00633                                 gctf->push_back(g/255.0);
00634                                 bctf->push_back(b/255.0);
00635                                 greyctf->push_back(xi);
00636                                 i++;
00637                         }
00638                         //---------------------------------
00639                         // Refreshing and sending the event
00640                         //---------------------------------
00641                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
00642                         _wxvtkclipping3Dview->Refresh();
00643                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00644                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00645                         
00646                         /*
00647                         volumeMapper->Update();
00648                         newvol->Update();
00649                         */
00650         } else  {
00651                 if(hDlg->getRefreshed())
00652                 {
00653                         int i=0,size;
00654                         //--Transference Function----
00655                         tfun->RemoveAllPoints();
00656                         i=0;
00657                         size=gtf->size();
00658                         for(i=0;i<size;i++)
00659                         {
00660                                 double grey1=(*gtf)[i];
00661                                 double  in2=(*itf)[i];
00662                                 tfun->AddPoint( grey1 , in2 );
00663                         }
00664                         
00665                         // -- vtkColorTransferFunction  --
00666                         ctfun->RemoveAllPoints ();
00667                         
00668                         i=0;
00669                         size=greyctf->size();           
00670                         for(i=0;i<size;i++)
00671                         {
00672                                 double grey2=(*greyctf)[i];
00673                                 double red =(*rctf)[i];
00674                                 double green =(*gctf)[i];
00675                                 double blue = (*bctf)[i];
00676                                 ctfun->AddRGBPoint(grey2,red,green,blue);
00677                         }
00678                 
00679                         //---------------------------------
00680                         // Refreshing and sending the event
00681                         //---------------------------------
00682                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
00683                         _wxvtkclipping3Dview->Refresh();
00684                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00685                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00686                         
00687                         /*
00688                         volumeMapper->Update();
00689                         newvol->Update();
00690                         */
00691                  }
00692                  
00693         }
00694         //destroy the dialog
00695         hDlg->Destroy();
00696 }
00697 
00698 //EED 23 Mai 2007
00699 //-------------------------------------------------------------------
00700 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
00701 {
00702         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
00703         if (dialog.ShowModal() == wxID_OK)
00704         {
00705                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
00706                 _wxvtkclipping3Dview->Refresh();
00707                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
00708                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00709         }
00710 }
00711 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1