From 0006c401e6399555e1cfa83989a3343ccce51813 Mon Sep 17 00:00:00 2001 From: Juan Prieto Date: Mon, 20 Jul 2009 10:06:10 +0000 Subject: [PATCH] *** empty log message *** --- .../widgets/pPlotter/HistogramDialog.cxx | 94 +++++++++++++++++++ .../widgets/pPlotter/HistogramDialog.h | 24 ++++- .../widgets/pPlotter/HistogramWidget.h | 6 +- ...wxMaracasMultipleVolumeRendererManager.cxx | 16 +++- .../wxMaracasMultipleVolumeRendererManager.h | 6 +- ...MaracasMultipleVolumeRendererManagerData.h | 7 ++ .../wxMaracasMultipleVolumeRendererPanel.cxx | 55 +++++++---- .../wxMaracasMultipleVolumeRendererPanel.h | 8 +- .../wxMaracasMultipleVolumeRendererView.cxx | 11 ++- .../wxMaracasMultipleVolumeRendererView.h | 7 +- 10 files changed, 204 insertions(+), 30 deletions(-) diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx index 681263e..a60429e 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx @@ -80,6 +80,70 @@ HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* i SetBestSize(wxSize(600,600)); } +HistogramDialog::HistogramDialog(wxWindow *parent,wxString title) +:wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")){ + _ctfun=NULL; + _tfun=NULL; + + SetBackgroundColour(wxColour(255,255,255)); + /* + Pointers + */ + wxvtkmpr3Dview=NULL; + wxvtkclipping3Dview=NULL; + + /* + Histogram + */ + + histogramW=new HistogramWidget(this, -1); + + refreshed=false; + + /* + Buttons + */ + okBtn = new wxButton(this,wxID_OK ,_T("OK")); + cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel")); + + saveDataBtn = new wxButton(this,ID_SAVE,_T("Save")); + loadDataBtn = new wxButton(this,ID_LOAD,_T("Load")); + refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh")); + + Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData ); + Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData ); + Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn ); + + //------------------- + //GUI + //------------------- + + //Upper Box + wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL ); + //Including components for plotter control + upper_box->Add( histogramW, 4, wxGROW); + + + //bottom Sizer + wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL ); + bottomBox->Add( okBtn, wxSizerFlags().Center()); + bottomBox->AddSpacer(40); + bottomBox->Add( saveDataBtn,wxSizerFlags().Center() ); + bottomBox->AddSpacer(40); + bottomBox->Add( loadDataBtn,wxSizerFlags().Center() ); + bottomBox->AddSpacer(40); + bottomBox->Add( refreshBtn,wxSizerFlags().Center() ); + bottomBox->AddSpacer(40); + bottomBox->Add( cancelBtn,wxSizerFlags().Center() ); + //Sizer + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add(upper_box,1,wxEXPAND); + sizer->Add(bottomBox,0,wxCENTER); + SetAutoLayout( TRUE ); + SetSizer( sizer ); + SetBestSize(wxSize(600,600)); +} + //----------------------- //Handling events //----------------------- @@ -488,3 +552,33 @@ void HistogramDialog::OnRefreshBtn(wxCommandEvent &event) } +/** +** Initialize the histogram +*/ + void HistogramDialog::initializeHistogram(vtkImageData* img){ + histogramW->initializeHistogram(img); + } +/** +** Returns two vectors, the grey level of the point and its value, the value is between [0,1] +**/ + void HistogramDialog::GetValuesPointsFunction(std::vector& greylevel,std::vector& value){ + + histogramW->GetValuesPointsFunction(greylevel, value); + } + +/** +** Returns two vectors, the grey level of the point and its value, the red, green +** and blue value is between [0,1] +**/ +void HistogramDialog::GetValuesColorPointsFunction(std::vector& greylevel, + std::vector& red, + std::vector& green, + std::vector& blue) +{ + histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue); +} + +void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){ + _tfun = _opac; + _ctfun = _color; +} \ No newline at end of file diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h index a23cd3b..d1881f6 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h @@ -34,6 +34,10 @@ public: Constructor */ HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type); + /* + Constructor + */ + HistogramDialog(wxWindow *parent,wxString title); /* Methods */ @@ -124,7 +128,25 @@ public: void OnSaveData(wxCommandEvent& event); void OnLoadData(wxCommandEvent& event); void OnRefreshBtn(wxCommandEvent& event); - + + /** + ** Initialize the histogram + */ + void initializeHistogram(vtkImageData* img); + /** + ** Returns two vectors, the grey level of the point and its value, the value is between [0,1] + **/ + void GetValuesPointsFunction(std::vector& greylevel,std::vector& value); + + /** + ** Returns two vectors, the grey level of the point and its value, the red, green + ** and blue value is between [0,1] + **/ + void GetValuesColorPointsFunction(std::vector& greylevel, + std::vector& red, + std::vector& green, + std::vector& blue); + void SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color); private: /* Histogram Widget diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h index 3947d32..28c5184 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h @@ -41,7 +41,7 @@ public: HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type); HistogramWidget( wxWindow *parent, wxWindowID id); - void initializeHistogram(vtkImageData* img); + ~HistogramWidget(); /* @@ -136,6 +136,10 @@ public: int getHistogramSize(); void setType(int type); + /** + ** Initialize the histogram + */ + void initializeHistogram(vtkImageData* img); /** ** Returns two vectors, the grey level of the point and its value, the value is between [0,1] **/ diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.cxx index 980ac8d..c95a8bc 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasMultipleVolumeRendererManager.cxx,v $ Language: C++ - Date: $Date: 2009/07/10 13:18:24 $ - Version: $Revision: 1.2 $ + Date: $Date: 2009/07/20 10:06:12 $ + Version: $Revision: 1.3 $ Copyright: (c) 2002, 2003 License: @@ -102,7 +102,8 @@ vtkImageData* wxMaracasMultipleVolumeRendererManager::getImageData(std::string f vtkMetaImageReader* reader = vtkMetaImageReader::New(); reader->SetFileName(filename.c_str()); reader->Update(); - vtkImageData* img = reader->GetOutput(); + vtkImageData* img = reader->GetOutput(); + vtkImageCast* cast = vtkImageCast::New(); cast->SetInput(img); cast->SetOutputScalarTypeToUnsignedShort(); @@ -110,6 +111,7 @@ vtkImageData* wxMaracasMultipleVolumeRendererManager::getImageData(std::string f //reader->Delete(); //img->Delete(); return cast->GetOutput(); + //return img; } return NULL; } @@ -158,3 +160,11 @@ void wxMaracasMultipleVolumeRendererManager::deleteActor(int propid) throw (char } } + +vtkPiecewiseFunction* wxMaracasMultipleVolumeRendererManager::GetTransferFunction(int volumeid){ + return getViewData(volumeid)->GetTransferFunction(); +} +vtkColorTransferFunction* wxMaracasMultipleVolumeRendererManager::GetColorFunction(int volumeid){ + + return getViewData(volumeid)->GetColorFunction(); +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.h index cb55609..0e64ccd 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManager.h @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasMultipleVolumeRendererManager.h,v $ Language: C++ - Date: $Date: 2009/07/08 15:14:03 $ - Version: $Revision: 1.2 $ + Date: $Date: 2009/07/20 10:06:12 $ + Version: $Revision: 1.3 $ Copyright: (c) 2002, 2003 License: @@ -82,6 +82,8 @@ public: **/ void deleteActor(int volumeid)throw (char *); + vtkPiecewiseFunction* GetTransferFunction(int volumeid); + vtkColorTransferFunction* GetColorFunction(int volumeid); private: std::vector prop3Dvect; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.h index b117450..b1ad57e 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.h @@ -59,6 +59,13 @@ public: ** Volume Opacity **/ void setVolumeOpacity(std::vector greylevel,std::vector value); + + vtkPiecewiseFunction* GetTransferFunction(){ + return _tfun; + } + vtkColorTransferFunction* GetColorFunction(){ + return _ctfun; + } protected: /** diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.cxx index 3327a85..6337f76 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.cxx @@ -3,6 +3,7 @@ #include #include "wxMaracasMultipleVolumeRendererView.h" #include "Color.xpm" +//#include /** ** Implementation of viewProp3D **/ @@ -18,6 +19,7 @@ wxMaracasMultipleVolumeRendererPanel::wxMaracasMultipleVolumeRendererPanel(wxWin wxMaracasMultipleVolumeRendererPanel::~wxMaracasMultipleVolumeRendererPanel(){ //wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false); wxMaracasMultipleVolumeRendererView::getInstance()->deleteVolume(_propid); + delete mwxwidget; } void wxMaracasMultipleVolumeRendererPanel::createControls(vtkImageData* img){ @@ -31,9 +33,7 @@ void wxMaracasMultipleVolumeRendererPanel::createControls(vtkImageData* img){ Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onCheckBoxChange); checkbox->SetValue(true); - sizerirmprop->Add(checkbox,wxFIXED_MINSIZE); - - //this->addControl(checkbox); + sizerirmprop->Add(checkbox,wxFIXED_MINSIZE); wxBitmap bitmap(Color_xpm); _colorchoose = new wxBitmapButton(this, -1, bitmap,wxDefaultPosition,wxSize(30,30)); @@ -46,22 +46,39 @@ void wxMaracasMultipleVolumeRendererPanel::createControls(vtkImageData* img){ - _frame = new wxFrame(this, 10, _T("Configure Transfer Functions")); + //_frame = new wxFrame(this, 10, _T("Configure Transfer Functions")); - wxButton* button1 = new wxButton(_frame,20,_T("OK")); + /*wxButton* button1 = new wxButton(_frame,20,_T("OK")); Connect(button1->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onOK); wxButton* button2 = new wxButton(_frame,30,_T("Cancel") ); Connect(button2->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onCancel); wxButton* button3 = new wxButton(_frame,40,_T("Update")); - Connect(button3->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onUpdate); - + Connect(button3->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onUpdate); */ - mwxwidget = new HistogramWidget(_frame, -1); + mwxwidget = new HistogramDialog(this, _T("Color Transfer Function")); mwxwidget->initializeHistogram(img); - mwxwidget->Refresh(); - wxBoxSizer* boxSizer0 = new wxBoxSizer(wxHORIZONTAL); + mwxwidget->erasePointsTransferenceFunction(); + double range[2]; + img->GetScalarRange(range); + double max = range[1]; + + /* + adding the poinst of the transference function + */ + //X + mwxwidget->addPointToTransferenceFunction(max * 0/2,0.0); + mwxwidget->addPointToTransferenceFunction(max * 1/2,100.0); + mwxwidget->addPointToTransferenceFunction(max * 2/2,100.0); + + mwxwidget->addColorPoint(max*0/4,(int)(0.0*255),(int)(0.0*255),(int)(0.0*255)); + mwxwidget->addColorPoint(max*1/4,(int)(1.0*255),(int)(0.0*255),(int)(0.0*255)); + mwxwidget->addColorPoint(max*2/4,(int)(0.0*255),(int)(0.0*255),(int)(1.0*255)); + mwxwidget->addColorPoint(max*3/4,(int)(0.0*255),(int)(1.0*255),(int)(0.0*255)); + mwxwidget->addColorPoint(max*4/4,(int)(0.0*255),(int)(0.0*255),(int)(0.2*255)); + + /*wxBoxSizer* boxSizer0 = new wxBoxSizer(wxHORIZONTAL); boxSizer0->Add(mwxwidget, 4, wxGROW); wxBoxSizer* boxSizer = new wxBoxSizer(wxHORIZONTAL); @@ -82,15 +99,17 @@ void wxMaracasMultipleVolumeRendererPanel::createControls(vtkImageData* img){ _frame->SetSizer(boxsizer2); _frame->Refresh(); - _frame->Update(); - + _frame->Update();*/ + mwxwidget->SetFunctions(wxMaracasMultipleVolumeRendererView::getInstance()->GetTransferFunction(getPropId()), + wxMaracasMultipleVolumeRendererView::getInstance()->GetColorFunction(getPropId())); + mwxwidget->Refresh(); } void wxMaracasMultipleVolumeRendererPanel::onOK(wxCommandEvent& event){ updateVolume(); - _frame->Show(false); + //_frame->Show(false); } void wxMaracasMultipleVolumeRendererPanel::onCancel(wxCommandEvent& event){ - _frame->Show(false); + //_frame->Show(false); } void wxMaracasMultipleVolumeRendererPanel::onUpdate(wxCommandEvent& event){ updateVolume(); @@ -112,8 +131,12 @@ void wxMaracasMultipleVolumeRendererPanel::updateVolume(){ wxMaracasMultipleVolumeRendererView::getInstance()->SetValuesPointsFunction(this->_propid, greylevel, values); } -void wxMaracasMultipleVolumeRendererPanel::onColorChange(wxCommandEvent& event){ - _frame->Show(true); +void wxMaracasMultipleVolumeRendererPanel::onColorChange(wxCommandEvent& event){ + + if(mwxwidget->ShowModal()==wxID_OK){ + updateVolume(); + mwxwidget->Show(false); + } } void wxMaracasMultipleVolumeRendererPanel::onCheckBoxChange(wxCommandEvent& event){ wxMaracasMultipleVolumeRendererView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue()); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.h index 4e56b5c..13d2405 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererPanel.h @@ -2,7 +2,7 @@ #define wxMaracasMultipleVolumeRendererPanel_H_ #include -#include "HistogramWidget.h" +#include "HistogramDialog.h" class wxMaracasMultipleVolumeRendererPanel : public wxPanel{ @@ -25,8 +25,10 @@ private: int _propid; - HistogramWidget* mwxwidget; - wxFrame* _frame; + bool first; + + HistogramDialog* mwxwidget; + //wxFrame* _frame; }; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.cxx index 539648a..ec3512b 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasMultipleVolumeRendererView.cxx,v $ Language: C++ - Date: $Date: 2009/07/08 14:22:14 $ - Version: $Revision: 1.1 $ + Date: $Date: 2009/07/20 10:06:12 $ + Version: $Revision: 1.2 $ Copyright: (c) 2002, 2003 License: @@ -111,6 +111,7 @@ void wxMaracasMultipleVolumeRendererView::addVolume(vtkImageData* img, std::stri if(id!=-1){ wxMaracasMultipleVolumeRendererPanel* controlpan = new wxMaracasMultipleVolumeRendererPanel(this, id,img); addVolumeViewPanel(controlpan, dataname); + controlpan->updateVolume(); } }catch(char* str){ std::cout << "Exception : " << str << '\n'; @@ -141,6 +142,12 @@ void wxMaracasMultipleVolumeRendererView::SetValuesPointsFunction(int volid, std volmanager->setVolumeOpacity(volid, greylevel, values); } +vtkPiecewiseFunction* wxMaracasMultipleVolumeRendererView::GetTransferFunction(int volumeid){ + return volmanager->GetTransferFunction(volumeid); +} +vtkColorTransferFunction* wxMaracasMultipleVolumeRendererView::GetColorFunction(int volumeid){ + return volmanager->GetColorFunction(volumeid); +} /** ** **/ diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.h index 3272b0d..c23b676 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererView.h @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasMultipleVolumeRendererView.h,v $ Language: C++ - Date: $Date: 2009/07/08 14:22:14 $ - Version: $Revision: 1.1 $ + Date: $Date: 2009/07/20 10:06:12 $ + Version: $Revision: 1.2 $ Copyright: (c) 2002, 2003 License: @@ -62,6 +62,9 @@ public: void addVolumeViewPanel(wxMaracasMultipleVolumeRendererPanel* irmview, std::string dataname); + vtkPiecewiseFunction* GetTransferFunction(int volumeid); + vtkColorTransferFunction* GetColorFunction(int volumeid); + private: static wxMaracasMultipleVolumeRendererView* instance; -- 2.46.2