#include "Save.xpm"
#include "Ok.xpm"
#include "Cancel.xpm"
-#include "Edit.xpm"
+#include "Delete.xpm"
+
#include "creaSystem.h"
//-------------------------
//Constructor
//-------------------------
-HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type)
+HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,bool extracontrols)
:wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox"))
{
- initializeHistogramDialog();
+ initializeHistogramDialog(extracontrols);
initializeHistogram(imageData);
}
-HistogramDialog::HistogramDialog(wxWindow *parent,wxString title)
+HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,bool extracontrols)
:wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")){
- initializeHistogramDialog();
+
+ initializeHistogramDialog(extracontrols);
+}
+HistogramDialog::~HistogramDialog(){
+
}
-void HistogramDialog::initializeHistogramDialog(){
+void HistogramDialog::initializeHistogramDialog(bool extracontrols){
+ _currentcolorselectedbitmap = -1;
_ctfun=NULL;
_tfun=NULL;
- _maxgreyvalue=0;
+ _panextracontrols=NULL;
+ _maxgreyvalue = 1;
SetBackgroundColour(wxColour(255,255,255));
/*
//Upper Box
wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
//Including components for plotter control
+
upper_box->Add( histogramW, 4, wxGROW);
- upper_box->Add( getControls(),wxSizerFlags().Center() );
+ upper_box->Add( getControls(extracontrols),wxSizerFlags().Center() );
//bottom Sizer
wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
SetSizer( sizer );
SetBestSize(wxSize(600,600));
}
+wxPanel* HistogramDialog::getPanExtraControls(){
+ wxBoxSizer* sizer0 = new wxBoxSizer(wxVERTICAL);
+ _panextracontrols = new wxPanel(this);
-wxSizer* HistogramDialog::getControls(){
-
- wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
-
- 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());
-
-
-
- return sizer;
-
+ _panextracontrols->SetSizer(sizer0);
+ _panextracontrols->SetAutoLayout(true);
+ return _panextracontrols;
}
+/**
+** Set to true in the constructor
+**/
+void HistogramDialog::setInfoPanExtraControls(std::vector<HistogramDialogComboBoxItem*> comboitems){
+ _comboitems = comboitems;
+ if(_panextracontrols!=NULL){
+ _panextracontrols->Show(false);
+ for(int i=0; i < comboitems.size();i++){
-wxSizer* HistogramDialog::getBitmapCombo(){
- _bitmapsizer = new wxBoxSizer(wxHORIZONTAL);
-
- _bitmapcombo = getBitmapComboElements();
+ wxBitmap bitmap = comboitems[i]->GetBitmap();
+
+
+ _panextracontrols->GetSizer()->Add(getBitmapButtonDelete(bitmap),wxSizerFlags().Center());
+ _panextracontrols->GetSizer()->AddSpacer(5);
+
+ }
+
+ wxButton* button = new wxButton(_panextracontrols,wxID_ANY);
+ button->SetToolTip("Add the current color to the list of predefined");
+ button->SetLabel(wxString(_T("Add")));
+ Connect(button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditColorsCombo);
+ _panextracontrols->GetSizer()->Add(button);
+ _panextracontrols->Layout();
+ _panextracontrols->Refresh();
+ _panextracontrols->Show(true);
+ this->Layout();
+ this->Refresh();
- 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);
+ }
+}
+wxSizer* HistogramDialog::getBitmapButtonDelete(wxBitmap bitmap){
+ //wxCheckBox* checkbox = new wxCheckBox(_panextracontrols,wxID_ANY,_T(""));
+ wxBitmap bitmap0(Delete_xpm);
+ wxBitmapButton* deletebutton = new wxBitmapButton(_panextracontrols,wxID_ANY,bitmap0,wxDefaultPosition,wxSize(20,20));
+ deletebutton->SetToolTip("Delete the color from the list");
+ Connect(deletebutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnDeleteColor);
+ _deletebuttonsvector.push_back(deletebutton);
- _bitmapsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
- _bitmapsizer->Add(edit,wxSizerFlags().Center());
-
- return _bitmapsizer;
+ //wxBitmap bitmap0(OpenImage_xpm);
+ wxBitmapButton* button = new wxBitmapButton(_panextracontrols,wxID_ANY,bitmap,wxDefaultPosition,wxSize(30,30));
+ button->SetToolTip("Load the current color configuration.");
+ bitmapbuttonsvect.push_back(button);
+ Connect(button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditColorsCombo);
+ /*char c[10];
+ wxString s;
+ s.Printf(_T("%d"),i);*/
+ //button->SetBitmapLabel(comboitems[i]->GetBitmap());
+ // wxStaticBitmap* button = new wxStaticBitmap(_panextracontrols,i,comboitems[i]->GetBitmap(),wxDefaultPosition,wxSize(30,30));
+ wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
+ sizer->Add(button,wxSizerFlags().Center());
+ sizer->AddSpacer(5);
+ sizer->Add(deletebutton,wxSizerFlags().Center());
+ return sizer;
}
-
-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();
+void HistogramDialog::OnDeleteColor(wxCommandEvent& event){
+ for(int i = 0; i < _deletebuttonsvector.size();i++){
+ if(event.GetId()==_deletebuttonsvector[i]->GetId()){
+ _currentcolorselectedbitmap = -1;
+ //this->eraseColorPoints();
+ //this->erasePointsTransferenceFunction();
+ HistogramDialogComboBoxItem* temp;
+ temp = _comboitems[i];
+ _deletebuttonsvector[i]->Hide();
+ bitmapbuttonsvect[i]->Hide();
+ delete temp;
+ //Remove buttons
+ _panextracontrols->GetSizer()->Remove(i*2);
+ //Remove Space
+ _panextracontrols->GetSizer()->Remove(i*2);
+ for(int k = i; k < _comboitems.size()-1;k++){
+ _comboitems[k] = _comboitems[k+1];
+ _deletebuttonsvector[k] = _deletebuttonsvector[k+1];
+ bitmapbuttonsvect[k] = bitmapbuttonsvect[k+1];
+ }
+ _comboitems.pop_back();
+ _deletebuttonsvector.pop_back();
+ bitmapbuttonsvect.pop_back();
+ }
}
- this->Layout();
+ _panextracontrols->Layout();
}
-
-wxBitmapComboBox* HistogramDialog::getBitmapComboElements(){
- std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
- currentpath.append(FILENAME);
-
- std::vector<int> redvect,greenvect,bluevect;
- std::vector<double> greyvect;
-
-
- std::vector<HistogramDialogComboBoxItem*> 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("");
+void HistogramDialog::OnEditColorsCombo(wxCommandEvent& event){
+ bool loadconfig = false;
+ UpdateCurrentComboElement();
+ for(int i = 0; i < bitmapbuttonsvect.size();i++){
+ if(event.GetId()==bitmapbuttonsvect[i]->GetId()){
+ if(i<_comboitems.size()){
+ _currentcolorselectedbitmap = i;
+ loadconfig = true;
+ HistogramDialogComboBoxItem* currentconfig = _comboitems[i];
+ std::vector<double> greyvect = currentconfig->getGreyVector();
+ std::vector<double> _redvect = currentconfig->getRedVector();
+ std::vector<double> _greenvect = currentconfig->getGreenVector();
+ std::vector<double> _bluevect= currentconfig->getBlueVector();
+ this->eraseColorPoints();
+ this->erasePointsTransferenceFunction();
+ for(int i = 0; i < currentconfig->getGreyVector().size();i++){
+ double greyv = currentconfig->getGreyVector()[i];
+ double red = currentconfig->getRedVector()[i];
+ double green = currentconfig->getGreenVector()[i];
+ double blue = currentconfig->getBlueVector()[i];
+
+ this->addColorPoint(greyv*_maxgreyvalue, red*255.0, green*255.0, blue*255.0);
+ }
+ for(int i = 0; i < currentconfig->getGreyVectorTransfer().size();i++){
+ double greyv = currentconfig->getGreyVectorTransfer()[i];
+ double value = currentconfig->getValueVector()[i];
+ std::cout<<"void HistogramDialog::OnEditColorsCombo(wxCommandEvent& event){"<<greyv<<" "<<value<<std::endl;
+ this->addPointToTransferenceFunction(greyv*_maxgreyvalue, value*100);
+ }
+ }
+ }
}
- wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
-
- Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialog::OnBitmapComboItemSelected);
-
-
- for(int i = 0; i < bitmapsitems.size(); i++){
- bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
+ if(!loadconfig){
+ AddNewBitmapButton();
}
-
- return bitmapcombo;
+ _panextracontrols->Layout();
+ this->Layout();
+ this->Refresh();
}
-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);
- }
- }
-
+void HistogramDialog::UpdateCurrentComboElement(){
+ if(_currentcolorselectedbitmap >= 0 && _currentcolorselectedbitmap < _comboitems.size()){
+ setCurrentColorConfigurationIntoButton();
}
}
-std::vector<wxBitmap*> HistogramDialog::GetBitmapsList(std::vector<double> greyvect, std::vector<int> redvect, std::vector<int> greenvect, std::vector<int> bluevect){
-
- std::vector<wxBitmap*> bitmaps;
- for(int i = 0; i < greyvect.size();i++){
- //bitmaps.push_back();
+void HistogramDialog::AddNewBitmapButton(){
+ this->eraseColorPoints();
+ this->erasePointsTransferenceFunction();
+ HistogramDialogComboBoxItem* boxitem = new HistogramDialogComboBoxItem();
+ wxBitmap bitmap = boxitem->GetBitmap();
+ wxSizer* sizer = getBitmapButtonDelete(bitmap);
+ _panextracontrols->GetSizer()->Insert(_comboitems.size()*2,sizer,wxSizerFlags().Center());
+ _panextracontrols->GetSizer()->InsertSpacer(_comboitems.size()*2+1,5);
+ _comboitems.push_back(boxitem);
+ _currentcolorselectedbitmap = _comboitems.size()-1;
+}
+void HistogramDialog::setCurrentColorConfigurationIntoButton(){
+
+ std::vector<double> greylevel;
+ std::vector<double> red;
+ std::vector<double> green;
+ std::vector<double> blue;
+ std::vector<double> red0;
+ std::vector<double> green0;
+ std::vector<double> blue0;
+ GetValuesColorPointsFunction(greylevel,red,green,blue);
+
+ for(int i = 0;i< greylevel.size();i++){
+ greylevel[i] = greylevel[i]/_maxgreyvalue;
+ /*std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){red"<<red[i]<<std::endl;
+ std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){green"<<green[i]<<std::endl;
+ std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){blue"<<blue[i]<<std::endl;*/
+ red0.push_back(red[i]);
+ green0.push_back(green[i]);
+ blue0.push_back(blue[i]);
+ /*std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){red"<<red0[i]<<std::endl;
+ std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){green"<<green0[i]<<std::endl;
+ std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){blue"<<blue0[i]<<std::endl;*/
+ }
+
+ std::vector<double> greylevel1;
+ std::vector<double> value;
+ this->GetValuesPointsFunction(greylevel1,value);
+
+ for(int i = 0;i< greylevel1.size();i++){
+ greylevel1[i] = greylevel1[i]/_maxgreyvalue;
+ value[i] = value[i];
+ std::cout<<"void HistogramDialog::setCurrentColorConfigurationIntoButton(){"<<greylevel1[i]<<std::endl;
+ std::cout<<"void HistogramDialog::setCurrentColorConfigurationIntoButton(){"<<value[i]<<std::endl;
+ }
+ if(_currentcolorselectedbitmap >= 0 && _currentcolorselectedbitmap < _comboitems.size()){
+ _comboitems[_currentcolorselectedbitmap]->SetColors(greylevel,red0,green0,blue0);
+ _comboitems[_currentcolorselectedbitmap]->SetTransferFunction(greylevel1,value);
+ bitmapbuttonsvect[_currentcolorselectedbitmap]->SetBitmapLabel(_comboitems[_currentcolorselectedbitmap]->GetBitmap());
}
}
-void HistogramDialog::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename, std::vector<double>& greyvect, std::vector<int>& redvect, std::vector<int>& greenvect, std::vector<int>& bluevect){
+wxSizer* HistogramDialog::getControls(bool extracontrols){
+
+ wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
- std::ifstream file;
- file.open( (const char*) (filename.c_str()) );
- double gv=-1;
- int in=-1,red=-1,gr=-1,bl=-1;
-
- std::cout<<filename<<std::endl;
- itembitmaps.clear();
- if(file.is_open())
- {
- bool add = false;
- HistogramDialogComboBoxItem* item=NULL;
- while(!file.eof())
- {
- std::string line;
- std::getline(file,line);
+ 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);
- if( (int)(line.find("<Colors>")!=-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("</Colors>"))!=-1 ){
+
- item->SetColors(greyvect,redvect,greenvect,bluevect);
+ 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);
- itembitmaps.push_back(item);
+ if(extracontrols){
+ sizer->Add(getPanExtraControls(),wxSizerFlags().Center());
+ }
+ //sizer->Add(getBitmapCombo(),wxSizerFlags().Center());
+
+
+
+ return sizer;
- greyvect.clear();
- redvect.clear();
- greenvect.clear();
- bluevect.clear();
- }
-
- line.clear();
- }
- file.close();
- std::cout<<itembitmaps.size()<<std::endl;
- }
-
}
+
//-----------------------
//Handling events
//-----------------------
/**
** Initialize the histogram
*/
- void HistogramDialog::initializeHistogram(vtkImageData* img){
+ void HistogramDialog::initializeHistogram(vtkImageData* img){
_maxgreyvalue = img->GetScalarRange()[1];
histogramW->initializeHistogram(img);
}