From 1f7a3dc82e27e218ecf69e19be2f36c02456ea2d Mon Sep 17 00:00:00 2001 From: Juan Prieto Date: Tue, 4 Aug 2009 15:35:04 +0000 Subject: [PATCH] *** empty log message *** --- .../widgets/pPlotter/HistogramDialog.cxx | 291 +++++++++++++----- .../widgets/pPlotter/HistogramDialog.h | 34 +- .../widgets/pPlotter/HistogramWidget.cxx | 21 +- .../widgets/pPlotter/HistogramWidget.h | 4 +- .../wxWindows/widgets/pPlotter/mathplot.cxx | 2 +- 5 files changed, 267 insertions(+), 85 deletions(-) diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx index a60429e..d4b9809 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx @@ -1,6 +1,15 @@ #include "HistogramDialog.h" #include +#include "OpenImage.xpm" +#include "Save.xpm" +#include "Ok.xpm" +#include "Cancel.xpm" +#include "Edit.xpm" +#include "creaSystem.h" + + + // IMPLEMENT_CLASS(HistogramDialog, wxDialog) @@ -18,8 +27,20 @@ HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* i :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")) { - _ctfun=NULL; + initializeHistogramDialog(); + initializeHistogram(imageData); + +} + +HistogramDialog::HistogramDialog(wxWindow *parent,wxString title) +:wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")){ + initializeHistogramDialog(); +} + +void HistogramDialog::initializeHistogramDialog(){ + _ctfun=NULL; _tfun=NULL; + _maxgreyvalue=0; SetBackgroundColour(wxColour(255,255,255)); /* @@ -32,23 +53,24 @@ HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* i Histogram */ - histogramW=new HistogramWidget(this, -1, wxPoint(0,0), wxSize(400,400),wxNO_BORDER ,imageData,type); + histogramW=new HistogramWidget(this, -1); - refreshed=false; - /* Buttons */ - okBtn = new wxButton(this,wxID_OK ,_T("OK")); - cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel")); + wxBitmap bitmap0(Ok_xpm); + okBtn = new wxBitmapButton(this, wxID_OK, bitmap0,wxDefaultPosition,wxDefaultSize); + + wxBitmap bitmap1(Cancel_xpm); + cancelBtn = new wxBitmapButton(this, wxID_CANCEL, bitmap1,wxDefaultPosition,wxDefaultSize); - saveDataBtn = new wxButton(this,ID_SAVE,_T("Save")); - loadDataBtn = new wxButton(this,ID_LOAD,_T("Load")); - refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh")); + //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 ); + //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 @@ -58,19 +80,20 @@ HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* i wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL ); //Including components for plotter control upper_box->Add( histogramW, 4, wxGROW); - + upper_box->Add( getControls(),wxSizerFlags().Center() ); //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( 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); @@ -80,70 +103,193 @@ 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; +wxSizer* HistogramDialog::getControls(){ + + wxSizer* sizer = new wxBoxSizer(wxVERTICAL); - /* - Histogram - */ + wxBitmap bitmap0(OpenImage_xpm); + wxBitmapButton* opendata = new wxBitmapButton(this, -1, bitmap0,wxDefaultPosition,wxSize(30,30)); + Connect(opendata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnLoadData); + sizer->Add(opendata,wxSizerFlags().Center()); + sizer->AddSpacer(5); + + wxBitmap bitmap1(Save_xpm); + wxBitmapButton* savedata = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30)); + Connect(savedata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnSaveData); + sizer->Add(savedata,wxSizerFlags().Center()); + sizer->AddSpacer(5); + + sizer->Add(getBitmapCombo(),wxSizerFlags().Center()); - 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")); + return sizer; + + +} + +wxSizer* HistogramDialog::getBitmapCombo(){ + _bitmapsizer = new wxBoxSizer(wxHORIZONTAL); + + _bitmapcombo = getBitmapComboElements(); + + wxBitmap bitmap1(Edit_xpm); + wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30)); + Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditBitmapCombo); - 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 ); + _bitmapsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize()); + _bitmapsizer->Add(edit,wxSizerFlags().Center()); + + return _bitmapsizer; - //------------------- - //GUI - //------------------- +} + +void HistogramDialog::OnEditBitmapCombo(wxCommandEvent& event){ + + wxBitmapComboBox* tempbitmapcombo = _bitmapcombo; + + for(int i = 0; i < _bitmapsitems.size();i++){ + delete _bitmapsitems[i]; + } + _bitmapsitems.clear(); + + _bitmapcombo = getBitmapComboElements(); + if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){ + + + tempbitmapcombo->Destroy(); + } + this->Layout(); +} + +wxBitmapComboBox* HistogramDialog::getBitmapComboElements(){ + std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); + currentpath.append(FILENAME); + + std::vector redvect,greenvect,bluevect; + std::vector greyvect; + + + std::vector bitmapsitems; + OnLoadComboBoxData(bitmapsitems, currentpath,greyvect, redvect,greenvect,bluevect); + _bitmapsitems = bitmapsitems; + wxString* choices; + choices = new wxString[bitmapsitems.size()]; + for(int i = 0; i < bitmapsitems.size();i++){ + choices[i] = _T(""); + } + wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices); + + Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialog::OnBitmapComboItemSelected); - //Upper Box - wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL ); - //Including components for plotter control - upper_box->Add( histogramW, 4, wxGROW); + + for(int i = 0; i < bitmapsitems.size(); i++){ + bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap()); + } + + return bitmapcombo; +} +void HistogramDialog::OnBitmapComboItemSelected(wxCommandEvent& event){ + if(_bitmapcombo!=NULL){ + int selecteditem = event.GetInt(); + if(_bitmapsitems.size()>selecteditem){ + HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[selecteditem]; + this->eraseColorPoints(); + for(int i = 0; i < currentconfig->getGreyVector().size();i++){ + int greyv = currentconfig->getGreyVector()[i]*_maxgreyvalue; + int red = currentconfig->getRedVector()[i]; + int green = currentconfig->getGreenVector()[i]; + int blue = currentconfig->getBlueVector()[i]; + + this->addColorPoint(greyv, red, green, blue); + } + } + + } +} +std::vector HistogramDialog::GetBitmapsList(std::vector greyvect, std::vector redvect, std::vector greenvect, std::vector bluevect){ - //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)); + std::vector bitmaps; + for(int i = 0; i < greyvect.size();i++){ + //bitmaps.push_back(); + } } +void HistogramDialog::OnLoadComboBoxData(std::vector& itembitmaps, std::string filename, std::vector& greyvect, std::vector& redvect, std::vector& greenvect, std::vector& bluevect){ + + std::ifstream file; + file.open( (const char*) (filename.c_str()) ); + double gv=-1; + int in=-1,red=-1,gr=-1,bl=-1; + + std::cout<")!=-1)) + { + item = new HistogramDialogComboBoxItem(); + }else if( (int)(line.find("RGBgreyValue"))!=-1) + { + int pos1=line.find(">"); + int pos2=line.find("<",pos1+1); + std::string x=line.substr(pos1+1,pos2-pos1-1); + gv=atof(x.c_str()); + + } + else if( (int)(line.find("red"))!=-1) + { + int pos1=line.find(">"); + int pos2=line.find("<",pos1+1); + std::string x=line.substr(pos1+1,pos2-pos1-1); + red=atoi(x.c_str()); + + } + else if( (int)(line.find("green"))!=-1) + { + int pos1=line.find(">"); + int pos2=line.find("<",pos1+1); + std::string x=line.substr(pos1+1,pos2-pos1-1); + gr=atoi(x.c_str()); + } + else if( (int)(line.find("blue"))!=-1 ) + { + int pos1=line.find(">"); + int pos2=line.find("<",pos1+1); + std::string x=line.substr(pos1+1,pos2-pos1-1); + bl=atoi(x.c_str()); + greyvect.push_back(gv); + redvect.push_back(red); + greenvect.push_back(gr); + bluevect.push_back(bl); + }else if( (int)(line.find(""))!=-1 ){ + + item->SetColors(greyvect,redvect,greenvect,bluevect); + + itembitmaps.push_back(item); + + greyvect.clear(); + redvect.clear(); + greenvect.clear(); + bluevect.clear(); + + } + + line.clear(); + } + file.close(); + std::cout<GetScalarRange()[1]; histogramW->initializeHistogram(img); } /** diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h index d1881f6..011314d 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.h @@ -26,6 +26,12 @@ #include #include #include "../wxMPRWidget.h" +#include "HistogramDialogComboBoxItem.h" + +#include + + +#define FILENAME "/Data/colorsfunction.txt" class HistogramDialog:public wxDialog { @@ -128,6 +134,7 @@ public: void OnSaveData(wxCommandEvent& event); void OnLoadData(wxCommandEvent& event); void OnRefreshBtn(wxCommandEvent& event); + void OnEditBitmapCombo(wxCommandEvent& event); /** ** Initialize the histogram @@ -147,20 +154,27 @@ public: std::vector& green, std::vector& blue); void SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color); + + void OnBitmapComboItemSelected(wxCommandEvent& event); private: /* Histogram Widget */ HistogramWidget* histogramW; - +/** +** +**/ + double _maxgreyvalue; /* ok Button */ - wxButton *okBtn; + //wxButton *okBtn; + wxBitmapButton *okBtn; /* cancel Button */ - wxButton *cancelBtn; + //wxButton *cancelBtn; + wxBitmapButton *cancelBtn; /* save Button */ @@ -174,7 +188,7 @@ private: */ wxButton *refreshBtn; - + wxSizer* _bitmapsizer; // the user had pressed refresh bool refreshed; @@ -187,11 +201,19 @@ private: //things to refresh wxVtkMPR3DView *wxvtkmpr3Dview; wxVtkClipping3DView *wxvtkclipping3Dview; - - + + wxBitmapComboBox* _bitmapcombo; + std::vector _bitmapsitems; + wxSizer* getControls(); + wxSizer* getBitmapCombo(); + wxBitmapComboBox* getBitmapComboElements(); + void OnLoadComboBoxData(std::vector& itembitmaps, std::string filename,std::vector& greyvect, std::vector& redvect, std::vector& greenvect, std::vector& bluevect); + std::vector GetBitmapsList(std::vector greyvect, std::vector redvect, std::vector greenvect, std::vector bluevect); // DECLARE_CLASS(HistogramDialog); // any class wishing to process wxWindows events must use this macro //DECLARE_EVENT_TABLE() + + void initializeHistogramDialog(); }; #endif diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx index 1badcef..51a30e7 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx @@ -8,6 +8,7 @@ #include "HistogramWidget.h" #include "vtkImageCast.h" #include + // ---------------------------------------------------------------------------- // WX headers inclusion. // For compilers that support precompilation, includes . @@ -15,8 +16,9 @@ #ifndef WX_PRECOMP #include - #endif + #endif +#include //---------------------------------------------------------------------------- // Class implementation //---------------------------------------------------------------------------- @@ -41,15 +43,16 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint } */ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type): - wxPanel(parent,id,pos,size) + wxPanel(parent,id,wxDefaultPosition,wxDefaultSize) { SetBackgroundColour(wxColour(255,255,255)); //histogram histogram= new pHistogram(imageData); + //plotter plotter=new pPlotter(this, 400,350); - + //is a plotter of histograms plotter->setType(2); //setting the popMenu @@ -59,8 +62,11 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint idHistogram=-1; transferenceFunctionHasColor=true; transferenceFunctionHasPoints=true; - this->type=type;; + this->type=type; + this->SetAutoLayout(true); + this->Refresh(); + //drawing drawHistogram(); drawTransferenceFunction(); @@ -74,9 +80,10 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint SetBackgroundColour(wxColour(255,255,255)); histogram = NULL; + //plotter plotter=new pPlotter(this, 400,350); - + //is a plotter of histograms plotter->setType(2); //setting the popMenu @@ -87,10 +94,14 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint transferenceFunctionHasColor=true; transferenceFunctionHasPoints=true; this->type=type;; + this->SetAutoLayout(true); + this->Refresh(); } + + void HistogramWidget::initializeHistogram(vtkImageData* img){ if(histogram ==NULL){ histogram= new pHistogram(img); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h index 28c5184..e04bbb1 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h @@ -155,6 +155,7 @@ public: std::vector& blue); + private: pHistogram* histogram; @@ -169,11 +170,12 @@ private: */ bool transferenceFunctionHasPoints; bool transferenceFunctionHasColor; + wxPanel* getControls(); /* * type=1 with transference function for moving * type=2 without transference function for moving */ - int type; + int type; DECLARE_CLASS(HistogramWidget); //---------------------------------------------------------------------------- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx index fc7203f..5a34b17 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx @@ -394,7 +394,7 @@ EVT_MENU( mpID_LOCKASPECT,mpWindow::OnLockAspect) END_EVENT_TABLE() mpWindow::mpWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag ) -: wxScrolledWindow( parent, id, pos, size, flag, wxT("wxPlotter") ) +: wxScrolledWindow( parent, id, wxDefaultPosition, wxDefaultSize, flag, wxT("wxPlotter") ) { m_scaleX = m_scaleY = 1.0; m_posX = m_posY = 0; -- 2.46.2