#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) //id for events enum { ID_SAVE = 108, ID_LOAD, ID_REFRESH }; //------------------------- //Constructor //------------------------- HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type) :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")) { 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)); /* Pointers */ wxvtkmpr3Dview=NULL; wxvtkclipping3Dview=NULL; /* Histogram */ histogramW=new HistogramWidget(this, -1); /* Buttons */ 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")); //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); 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( 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)); } 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; } 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); _bitmapsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize()); _bitmapsizer->Add(edit,wxSizerFlags().Center()); return _bitmapsizer; } 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); 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){ 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<0) file.open( (const char*)(nameF.mb_str()) ); if(file.is_open()) { file << "" << std::endl; //histograms points /* file << " " << std::endl; int histogramS=histogramW->getHistogramSize(); int i=0; while(i" << std::endl; file << " " << i << "" <" << histogramW->getHistogramPoint(i) << ""<" << std::endl; i++; } file << " " << std::endl; */ //points transference Function file << " "<< std::endl; int tfPointS=histogramW->getSizeTransferenceFunction(); int i=0; int gv,in; while(igetTransferenceFunctionPoint(i,gv,in); file << " " << std::endl; file << " " << gv << "" <" << in << " "<" << std::endl; i++; } file << " "<< std::endl; //colorPoints file << " "<< std::endl; int ctfPointS=histogramW->getSizeBarColor(); i=0; int red,green,blue; while(igetDataBarColorPoint(i,gv,red,green,blue); file << " " << std::endl; file << " " << gv << "" <" << red << "" <" << green << "" <" << blue << "" <" << std::endl; i++; } file << " "<< std::endl; file << "" << std::endl; } file.close(); } void HistogramDialog::OnLoadData(wxCommandEvent& event) { wxString nameF=wxFileSelector(_T("Load Data") ); //std::string line; std::ifstream file; if(nameF.CompareTo( _T("/0") )>0) file.open( (const char*) (nameF.mb_str()) ); bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false; // JPRx int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx if(file.is_open()) { //------------- erasePointsTransferenceFunction(); eraseColorPoints(); //-------------- //std::getline(file,line); //int i=0; // JPRx while(!file.eof()) { std::string line; std::getline(file,line); //int a=line.find("histogram Data"); if( (int)(line.find("histogram Data"))!=-1) { histogramReading=true; } /* else if(line.find("histogramPoints")!=0 && histogramReading) { histogramPoints=true; } else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints) { } else if(line.find("greyValue")!=0 && histogramReading && histogramPoints) { int pos1=line.find(">"); int pos2=line.find("<",pos+1); std::string x=line.substr(pos1+1,pos2-1); gv=atoi(x.c_str()); } else if(line.find("number")!=0 && histogramReading && histogramPoints) { int pos1=line.find(">"); int pos2=line.find("<",pos+1); std::string x=line.substr(pos1+1,pos2-1); nP=atoi(x.c_str()); //add to the histogram //histogramW->addPointToTransferenceFunction(gc,in); } */ else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading) { tf=true; } else if( (int)(line.find(""))!=-1 && histogramReading && tf) { tfp=true; } else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp) { int pos1=line.find(">"); int pos2=line.find("<",pos1+1); std::string x=line.substr(pos1+1,pos2-pos1-1); gv=atoi(x.c_str()); } else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp) { int pos1=line.find(">"); int pos2=line.find("<",pos1+1); std::string x=line.substr(pos1+1,pos2-pos1-1); in=atoi(x.c_str()); histogramW->addPointToTransferenceFunction(gv,in); tfp=false; } else if( (int)(line.find("Colors"))!=-1 && histogramReading) { ctf=true; } else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf ) { ctfp=true; } else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp) { int pos1=line.find(">"); int pos2=line.find("<",pos1+1); std::string x=line.substr(pos1+1,pos2-pos1-1); gv=atoi(x.c_str()); } else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp) { 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 && histogramReading && ctf && ctfp) { 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 && histogramReading && ctf && ctfp) { 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()); histogramW->addColorPoint(gv,red,gr,bl); ctfp=false; } line.clear(); } } file.close(); histogramW->updatePlotter(); } /* On refresh btn */ void HistogramDialog::OnRefreshBtn(wxCommandEvent &event) { refreshed=true; int i=0,xi,yi,r,g,b; // -- TransferenceFunction -- int nPointsTF=getSizeTransferenceFunction(); if(nPointsTF>0) { int nTFPoints=getSizeTransferenceFunction(); i=0; while(iAddPoint( xi , yi/100.0 ); i++; } } //-- Color bar -- //clean colors int nPointsCTF=getSizeBarColor(); if(nPointsCTF>0) { _ctfun->RemoveAllPoints(); int nCTFpoints=getSizeBarColor(); i=0; while(iAddRGBPoint(xi,r/255.0,g/255.0,b/255.0 ); i++; } } //EED Borrame /* NOTE I NEED THE UPDATE */ //if it was call from the clipping ctnrl panel if(wxvtkclipping3Dview!=NULL) { wxvtkclipping3Dview->Refresh(); } else if(wxvtkmpr3Dview!=NULL) { wxvtkmpr3Dview->Refresh(); } } //----------------------- //Methods //----------------------- /* get number of points of the transference function */ int HistogramDialog::getSizeTransferenceFunction() { return histogramW->getSizeTransferenceFunction(); } /* get number of points of the barColor */ int HistogramDialog::getSizeBarColor() { return histogramW->getSizeBarColor(); } /* get a point of the transference function */ void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y) { histogramW->getTransferenceFunctionPoint(index,x,y); } /* get a color int the bqr color */ void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue) { histogramW->getDataBarColorPoint(index,x,red,green,blue); } /* get a point of the Histogram given the grey value */ int HistogramDialog::getHistogramPoint(int gValue) { return histogramW->getHistogramPoint(gValue); } //-------------------- // bar Information //--------------------- /* Get the porcentage of the positions of the min,max and actual in the bar range */ float HistogramDialog::getMaxShowedPorcentage() { return histogramW->getMaxShowedPorcentage(); } float HistogramDialog::getMinShowedPorcentage() { return histogramW->getMinShowedPorcentage(); } float HistogramDialog::getActualShowedPorcentage() { return histogramW->getActualShowedPorcentage(); } //--------------------------------------- // setting data in transferences function // and in bar color //---------------------------------------- bool HistogramDialog::addPointToTransferenceFunction(double x, double y) { return histogramW->addPointToTransferenceFunction(x,y); } bool HistogramDialog::addColorPoint(double x,int red,int green, int blue) { return histogramW->addColorPoint(x,red,green,blue); } //------------------------ //Erase data //------------------------ /* Erase all the points that are in the transference function */ void HistogramDialog::erasePointsTransferenceFunction() { histogramW->erasePointsTransferenceFunction(); } /* Erase the color points in the plotter */ void HistogramDialog::eraseColorPoints() { histogramW->eraseColorPoints(); } //------------------- // Getter and setters //------------------- void HistogramDialog::setCTF(vtkColorTransferFunction *cf) { _ctfun=cf; } void HistogramDialog:: setTF(vtkPiecewiseFunction *tf) { _tfun=tf; } bool HistogramDialog::getRefreshed() { return refreshed; } void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper) { volumeMapper=volMapper; } void HistogramDialog::setVolume(vtkVolume* vol) { newvol=vol; } void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1) { wxvtkmpr3Dview=wxvtkmpr3Dview1; } void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1) { wxvtkclipping3Dview=wxvtkclipping3Dview1; } void HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints) { histogramW->setTransferenceFunctionHasPoints(hasPoints); } void HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints) { histogramW->setTransferenceFunctionHasColor(hasColorPoints); } //-------------------- // plotter Information //--------------------- void HistogramDialog::updatePlotter() { histogramW->updatePlotter(); } /** ** Initialize the histogram */ void HistogramDialog::initializeHistogram(vtkImageData* img){ _maxgreyvalue = img->GetScalarRange()[1]; 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; }