#include "HistogramDialog.h" #include // 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")) { _ctfun=NULL; _tfun=NULL; SetBackgroundColour(wxColour(255,255,255)); /* Pointers */ wxvtkmpr3Dview=NULL; wxvtkclipping3Dview=NULL; /* Histogram */ histogramW=new HistogramWidget(this, -1, wxPoint(0,0), wxSize(400,400),wxNO_BORDER ,imageData,type); 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 //----------------------- void HistogramDialog::OnSaveData(wxCommandEvent& event) { wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1, -1);//wxFileSelector(_T("Save Data"),wxSAVE); std::ofstream file; if(nameF.CompareTo( _T("/0") )>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(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(line.find("TransferenceFunction")!=-1 && histogramReading) { tf=true; } else if(line.find("")!=-1 && histogramReading && tf) { tfp=true; } else if(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(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(line.find("Colors")!=-1 && histogramReading) { ctf=true; } else if(line.find("greyValueRGBpoint")!=-1 && histogramReading && ctf ) { ctfp=true; } else if(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(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(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(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(); }