#include "HistogramDialog.h"
#include <vector>
+#include "OpenImage.xpm"
+#include "Save.xpm"
+#include "Ok.xpm"
+#include "Cancel.xpm"
+#include "Edit.xpm"
+#include "creaSystem.h"
+
+
+
// IMPLEMENT_CLASS(HistogramDialog, wxDialog)
: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));
/*
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
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);
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<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("");
+ }
+ 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<wxBitmap*> HistogramDialog::GetBitmapsList(std::vector<double> greyvect, std::vector<int> redvect, std::vector<int> greenvect, std::vector<int> 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<wxBitmap*> bitmaps;
+ for(int i = 0; i < greyvect.size();i++){
+ //bitmaps.push_back();
+ }
}
+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){
+
+ 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);
+
+ 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);
+
+ itembitmaps.push_back(item);
+
+ 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){
+ _maxgreyvalue = img->GetScalarRange()[1];
histogramW->initializeHistogram(img);
}
/**