1 #include "HistogramDialog.h"
4 #include "OpenImage.xpm"
9 #include "creaSystem.h"
13 // IMPLEMENT_CLASS(HistogramDialog, wxDialog)
23 //-------------------------
25 //-------------------------
26 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type)
27 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox"))
30 initializeHistogramDialog();
31 initializeHistogram(imageData);
35 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title)
36 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")){
37 initializeHistogramDialog();
40 void HistogramDialog::initializeHistogramDialog(){
45 SetBackgroundColour(wxColour(255,255,255));
50 wxvtkclipping3Dview=NULL;
56 histogramW=new HistogramWidget(this, -1);
61 wxBitmap bitmap0(Ok_xpm);
62 okBtn = new wxBitmapButton(this, wxID_OK, bitmap0,wxDefaultPosition,wxDefaultSize);
64 wxBitmap bitmap1(Cancel_xpm);
65 cancelBtn = new wxBitmapButton(this, wxID_CANCEL, bitmap1,wxDefaultPosition,wxDefaultSize);
67 //saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
68 //loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
69 //refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
71 //Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData );
72 //Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData );
73 //Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn );
80 wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
81 //Including components for plotter control
82 upper_box->Add( histogramW, 4, wxGROW);
83 upper_box->Add( getControls(),wxSizerFlags().Center() );
86 wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
87 bottomBox->Add( okBtn, wxSizerFlags().Center());
88 bottomBox->AddSpacer(40);
89 //bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
90 //bottomBox->AddSpacer(40);
91 //bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
92 //bottomBox->AddSpacer(40);
93 //bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
94 //bottomBox->AddSpacer(40);
95 bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
98 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
99 sizer->Add(upper_box,1,wxEXPAND);
100 sizer->Add(bottomBox,0,wxCENTER);
101 SetAutoLayout( TRUE );
103 SetBestSize(wxSize(600,600));
106 wxSizer* HistogramDialog::getControls(){
108 wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
110 wxBitmap bitmap0(OpenImage_xpm);
111 wxBitmapButton* opendata = new wxBitmapButton(this, -1, bitmap0,wxDefaultPosition,wxSize(30,30));
112 Connect(opendata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnLoadData);
113 sizer->Add(opendata,wxSizerFlags().Center());
116 wxBitmap bitmap1(Save_xpm);
117 wxBitmapButton* savedata = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
118 Connect(savedata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnSaveData);
119 sizer->Add(savedata,wxSizerFlags().Center());
122 sizer->Add(getBitmapCombo(),wxSizerFlags().Center());
131 wxSizer* HistogramDialog::getBitmapCombo(){
132 _bitmapsizer = new wxBoxSizer(wxHORIZONTAL);
134 _bitmapcombo = getBitmapComboElements();
136 wxBitmap bitmap1(Edit_xpm);
137 wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
138 Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditBitmapCombo);
140 _bitmapsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
141 _bitmapsizer->Add(edit,wxSizerFlags().Center());
147 void HistogramDialog::OnEditBitmapCombo(wxCommandEvent& event){
149 wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
151 for(int i = 0; i < _bitmapsitems.size();i++){
152 delete _bitmapsitems[i];
154 _bitmapsitems.clear();
156 _bitmapcombo = getBitmapComboElements();
157 if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
160 tempbitmapcombo->Destroy();
165 wxBitmapComboBox* HistogramDialog::getBitmapComboElements(){
166 std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
167 currentpath.append(FILENAME);
169 std::vector<int> redvect,greenvect,bluevect;
170 std::vector<double> greyvect;
173 std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
174 OnLoadComboBoxData(bitmapsitems, currentpath,greyvect, redvect,greenvect,bluevect);
175 _bitmapsitems = bitmapsitems;
177 choices = new wxString[bitmapsitems.size()];
178 for(int i = 0; i < bitmapsitems.size();i++){
181 wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
183 Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialog::OnBitmapComboItemSelected);
186 for(int i = 0; i < bitmapsitems.size(); i++){
187 bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
193 void HistogramDialog::OnBitmapComboItemSelected(wxCommandEvent& event){
194 if(_bitmapcombo!=NULL){
195 int selecteditem = event.GetInt();
196 if(_bitmapsitems.size()>selecteditem){
197 HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[selecteditem];
198 this->eraseColorPoints();
199 for(int i = 0; i < currentconfig->getGreyVector().size();i++){
200 int greyv = currentconfig->getGreyVector()[i]*_maxgreyvalue;
201 int red = currentconfig->getRedVector()[i];
202 int green = currentconfig->getGreenVector()[i];
203 int blue = currentconfig->getBlueVector()[i];
205 this->addColorPoint(greyv, red, green, blue);
211 std::vector<wxBitmap*> HistogramDialog::GetBitmapsList(std::vector<double> greyvect, std::vector<int> redvect, std::vector<int> greenvect, std::vector<int> bluevect){
213 std::vector<wxBitmap*> bitmaps;
214 for(int i = 0; i < greyvect.size();i++){
215 //bitmaps.push_back();
218 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){
222 file.open( (const char*) (filename.c_str()) );
224 int in=-1,red=-1,gr=-1,bl=-1;
226 std::cout<<filename<<std::endl;
231 HistogramDialogComboBoxItem* item=NULL;
235 std::getline(file,line);
237 if( (int)(line.find("<Colors>")!=-1))
239 item = new HistogramDialogComboBoxItem();
240 }else if( (int)(line.find("RGBgreyValue"))!=-1)
242 int pos1=line.find(">");
243 int pos2=line.find("<",pos1+1);
244 std::string x=line.substr(pos1+1,pos2-pos1-1);
248 else if( (int)(line.find("red"))!=-1)
250 int pos1=line.find(">");
251 int pos2=line.find("<",pos1+1);
252 std::string x=line.substr(pos1+1,pos2-pos1-1);
256 else if( (int)(line.find("green"))!=-1)
258 int pos1=line.find(">");
259 int pos2=line.find("<",pos1+1);
260 std::string x=line.substr(pos1+1,pos2-pos1-1);
263 else if( (int)(line.find("blue"))!=-1 )
265 int pos1=line.find(">");
266 int pos2=line.find("<",pos1+1);
267 std::string x=line.substr(pos1+1,pos2-pos1-1);
269 greyvect.push_back(gv);
270 redvect.push_back(red);
271 greenvect.push_back(gr);
272 bluevect.push_back(bl);
273 }else if( (int)(line.find("</Colors>"))!=-1 ){
275 item->SetColors(greyvect,redvect,greenvect,bluevect);
277 itembitmaps.push_back(item);
289 std::cout<<itembitmaps.size()<<std::endl;
293 //-----------------------
295 //-----------------------
297 void HistogramDialog::OnSaveData(wxCommandEvent& event)
299 wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1, -1);//wxFileSelector(_T("Save Data"),wxSAVE);
301 if(nameF.CompareTo( _T("/0") )>0)
302 file.open( (const char*)(nameF.mb_str()) );
306 file << "<histogram Data>" << std::endl;
309 file << " <histogramPoints>" << std::endl;
310 int histogramS=histogramW->getHistogramSize();
314 file << " <HistogramPoint>" << std::endl;
315 file << " <greyValue>" << i << "</greyValue>" <<std::endl;
316 file << " <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
317 file << " </HistogramPoint>" << std::endl;
320 file << " </histogramPoints>" << std::endl;
322 //points transference Function
323 file << " <TransferenceFunction>"<< std::endl;
324 int tfPointS=histogramW->getSizeTransferenceFunction();
330 histogramW->getTransferenceFunctionPoint(i,gv,in);
331 file << " <Transferencepoint>" << std::endl;
332 file << " <greyValue>" << gv << "</greyValue>" <<std::endl;
333 file << " <intensity>" << in << "</intensity> "<<std::endl;
334 file << " </Transferencepoint>" << std::endl;
337 file << " </TransferenceFunction>"<< std::endl;
339 file << " <Colors>"<< std::endl;
340 int ctfPointS=histogramW->getSizeBarColor();
347 histogramW->getDataBarColorPoint(i,gv,red,green,blue);
348 file << " <greyValueRGBpoint>" << std::endl;
349 file << " <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
350 file << " <red>" << red << "</red>" <<std::endl;
351 file << " <green>" << green << "</green>" <<std::endl;
352 file << " <blue>" << blue << "</blue>" <<std::endl;
353 file << " </greyValueRGBpoint>" << std::endl;
357 file << " </Colors>"<< std::endl;
358 file << "</histogram Data>" << std::endl;
363 void HistogramDialog::OnLoadData(wxCommandEvent& event)
365 wxString nameF=wxFileSelector(_T("Load Data") );
368 if(nameF.CompareTo( _T("/0") )>0)
369 file.open( (const char*) (nameF.mb_str()) );
371 bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false; // JPRx
372 int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
376 erasePointsTransferenceFunction();
380 //std::getline(file,line);
385 std::getline(file,line);
386 //int a=line.find("histogram Data");
387 if( (int)(line.find("histogram Data"))!=-1)
389 histogramReading=true;
393 else if(line.find("histogramPoints")!=0 && histogramReading)
395 histogramPoints=true;
397 else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
401 else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
403 int pos1=line.find(">");
404 int pos2=line.find("<",pos+1);
405 std::string x=line.substr(pos1+1,pos2-1);
408 else if(line.find("number")!=0 && histogramReading && histogramPoints)
410 int pos1=line.find(">");
411 int pos2=line.find("<",pos+1);
412 std::string x=line.substr(pos1+1,pos2-1);
414 //add to the histogram
415 //histogramW->addPointToTransferenceFunction(gc,in);
418 else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
422 else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
426 else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
428 int pos1=line.find(">");
429 int pos2=line.find("<",pos1+1);
430 std::string x=line.substr(pos1+1,pos2-pos1-1);
434 else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
436 int pos1=line.find(">");
437 int pos2=line.find("<",pos1+1);
438 std::string x=line.substr(pos1+1,pos2-pos1-1);
440 histogramW->addPointToTransferenceFunction(gv,in);
444 else if( (int)(line.find("Colors"))!=-1 && histogramReading)
449 else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
454 else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
456 int pos1=line.find(">");
457 int pos2=line.find("<",pos1+1);
458 std::string x=line.substr(pos1+1,pos2-pos1-1);
462 else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
464 int pos1=line.find(">");
465 int pos2=line.find("<",pos1+1);
466 std::string x=line.substr(pos1+1,pos2-pos1-1);
470 else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
472 int pos1=line.find(">");
473 int pos2=line.find("<",pos1+1);
474 std::string x=line.substr(pos1+1,pos2-pos1-1);
477 else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
479 int pos1=line.find(">");
480 int pos2=line.find("<",pos1+1);
481 std::string x=line.substr(pos1+1,pos2-pos1-1);
483 histogramW->addColorPoint(gv,red,gr,bl);
491 histogramW->updatePlotter();
497 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
503 // -- TransferenceFunction --
504 int nPointsTF=getSizeTransferenceFunction();
509 int nTFPoints=getSizeTransferenceFunction();
513 getTransferenceFunctionPoint(i,xi,yi);
514 _tfun->AddPoint( xi , yi/100.0 );
520 int nPointsCTF=getSizeBarColor();
523 _ctfun->RemoveAllPoints();
525 int nCTFpoints=getSizeBarColor();
529 getDataBarColorPoint(i,xi,r,g,b);
530 _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
538 NOTE I NEED THE UPDATE
540 //if it was call from the clipping ctnrl panel
541 if(wxvtkclipping3Dview!=NULL)
543 wxvtkclipping3Dview->Refresh();
546 else if(wxvtkmpr3Dview!=NULL)
548 wxvtkmpr3Dview->Refresh();
554 //-----------------------
556 //-----------------------
559 get number of points of the transference function
561 int HistogramDialog::getSizeTransferenceFunction()
563 return histogramW->getSizeTransferenceFunction();
567 get number of points of the barColor
569 int HistogramDialog::getSizeBarColor()
571 return histogramW->getSizeBarColor();
574 get a point of the transference function
576 void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
578 histogramW->getTransferenceFunctionPoint(index,x,y);
581 get a color int the bqr color
583 void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
585 histogramW->getDataBarColorPoint(index,x,red,green,blue);
588 get a point of the Histogram
591 int HistogramDialog::getHistogramPoint(int gValue)
593 return histogramW->getHistogramPoint(gValue);
596 //--------------------
598 //---------------------
600 Get the porcentage of the positions of
601 the min,max and actual in the bar range
603 float HistogramDialog::getMaxShowedPorcentage()
605 return histogramW->getMaxShowedPorcentage();
607 float HistogramDialog::getMinShowedPorcentage()
609 return histogramW->getMinShowedPorcentage();
611 float HistogramDialog::getActualShowedPorcentage()
613 return histogramW->getActualShowedPorcentage();
615 //---------------------------------------
616 // setting data in transferences function
618 //----------------------------------------
619 bool HistogramDialog::addPointToTransferenceFunction(double x, double y)
621 return histogramW->addPointToTransferenceFunction(x,y);
623 bool HistogramDialog::addColorPoint(double x,int red,int green, int blue)
625 return histogramW->addColorPoint(x,red,green,blue);
627 //------------------------
629 //------------------------
632 Erase all the points that are in the transference function
634 void HistogramDialog::erasePointsTransferenceFunction()
636 histogramW->erasePointsTransferenceFunction();
639 Erase the color points in the plotter
641 void HistogramDialog::eraseColorPoints()
643 histogramW->eraseColorPoints();
646 //-------------------
647 // Getter and setters
648 //-------------------
650 void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
655 void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
660 bool HistogramDialog::getRefreshed()
665 void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
667 volumeMapper=volMapper;
669 void HistogramDialog::setVolume(vtkVolume* vol)
673 void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
675 wxvtkmpr3Dview=wxvtkmpr3Dview1;
677 void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
679 wxvtkclipping3Dview=wxvtkclipping3Dview1;
683 void HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
685 histogramW->setTransferenceFunctionHasPoints(hasPoints);
687 void HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
689 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
692 //--------------------
693 // plotter Information
694 //---------------------
695 void HistogramDialog::updatePlotter()
697 histogramW->updatePlotter();
702 ** Initialize the histogram
704 void HistogramDialog::initializeHistogram(vtkImageData* img){
705 _maxgreyvalue = img->GetScalarRange()[1];
706 histogramW->initializeHistogram(img);
709 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
711 void HistogramDialog::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
713 histogramW->GetValuesPointsFunction(greylevel, value);
717 ** Returns two vectors, the grey level of the point and its value, the red, green
718 ** and blue value is between [0,1]
720 void HistogramDialog::GetValuesColorPointsFunction(std::vector<double>& greylevel,
721 std::vector<double>& red,
722 std::vector<double>& green,
723 std::vector<double>& blue)
725 histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue);
728 void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){