1 #include "HistogramDialog.h"
4 // IMPLEMENT_CLASS(HistogramDialog, wxDialog)
14 //-------------------------
16 //-------------------------
17 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,int type)
18 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox"))
24 SetBackgroundColour(wxColour(255,255,255));
29 wxvtkclipping3Dview=NULL;
35 histogramW=new HistogramWidget(this, -1, wxPoint(0,0), wxSize(400,400),wxNO_BORDER ,imageData,type);
42 okBtn = new wxButton(this,wxID_OK ,_T("OK"));
43 cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel"));
45 saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
46 loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
47 refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
49 Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData );
50 Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData );
51 Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn );
58 wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
59 //Including components for plotter control
60 upper_box->Add( histogramW, 4, wxGROW);
64 wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
65 bottomBox->Add( okBtn, wxSizerFlags().Center());
66 bottomBox->AddSpacer(40);
67 bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
68 bottomBox->AddSpacer(40);
69 bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
70 bottomBox->AddSpacer(40);
71 bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
72 bottomBox->AddSpacer(40);
73 bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
75 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
76 sizer->Add(upper_box,1,wxEXPAND);
77 sizer->Add(bottomBox,0,wxCENTER);
78 SetAutoLayout( TRUE );
80 SetBestSize(wxSize(600,600));
83 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title)
84 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ,_T("dialogBox")){
88 SetBackgroundColour(wxColour(255,255,255));
93 wxvtkclipping3Dview=NULL;
99 histogramW=new HistogramWidget(this, -1);
106 okBtn = new wxButton(this,wxID_OK ,_T("OK"));
107 cancelBtn = new wxButton(this,wxID_CANCEL,_T("Cancel"));
109 saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
110 loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
111 refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
113 Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData );
114 Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData );
115 Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn );
117 //-------------------
119 //-------------------
122 wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
123 //Including components for plotter control
124 upper_box->Add( histogramW, 4, wxGROW);
128 wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
129 bottomBox->Add( okBtn, wxSizerFlags().Center());
130 bottomBox->AddSpacer(40);
131 bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
132 bottomBox->AddSpacer(40);
133 bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
134 bottomBox->AddSpacer(40);
135 bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
136 bottomBox->AddSpacer(40);
137 bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
139 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
140 sizer->Add(upper_box,1,wxEXPAND);
141 sizer->Add(bottomBox,0,wxCENTER);
142 SetAutoLayout( TRUE );
144 SetBestSize(wxSize(600,600));
147 //-----------------------
149 //-----------------------
151 void HistogramDialog::OnSaveData(wxCommandEvent& event)
153 wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1, -1);//wxFileSelector(_T("Save Data"),wxSAVE);
155 if(nameF.CompareTo( _T("/0") )>0)
156 file.open( (const char*)(nameF.mb_str()) );
160 file << "<histogram Data>" << std::endl;
163 file << " <histogramPoints>" << std::endl;
164 int histogramS=histogramW->getHistogramSize();
168 file << " <HistogramPoint>" << std::endl;
169 file << " <greyValue>" << i << "</greyValue>" <<std::endl;
170 file << " <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
171 file << " </HistogramPoint>" << std::endl;
174 file << " </histogramPoints>" << std::endl;
176 //points transference Function
177 file << " <TransferenceFunction>"<< std::endl;
178 int tfPointS=histogramW->getSizeTransferenceFunction();
184 histogramW->getTransferenceFunctionPoint(i,gv,in);
185 file << " <Transferencepoint>" << std::endl;
186 file << " <greyValue>" << gv << "</greyValue>" <<std::endl;
187 file << " <intensity>" << in << "</intensity> "<<std::endl;
188 file << " </Transferencepoint>" << std::endl;
191 file << " </TransferenceFunction>"<< std::endl;
193 file << " <Colors>"<< std::endl;
194 int ctfPointS=histogramW->getSizeBarColor();
201 histogramW->getDataBarColorPoint(i,gv,red,green,blue);
202 file << " <greyValueRGBpoint>" << std::endl;
203 file << " <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
204 file << " <red>" << red << "</red>" <<std::endl;
205 file << " <green>" << green << "</green>" <<std::endl;
206 file << " <blue>" << blue << "</blue>" <<std::endl;
207 file << " </greyValueRGBpoint>" << std::endl;
211 file << " </Colors>"<< std::endl;
212 file << "</histogram Data>" << std::endl;
217 void HistogramDialog::OnLoadData(wxCommandEvent& event)
219 wxString nameF=wxFileSelector(_T("Load Data") );
222 if(nameF.CompareTo( _T("/0") )>0)
223 file.open( (const char*) (nameF.mb_str()) );
225 bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false; // JPRx
226 int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
230 erasePointsTransferenceFunction();
234 //std::getline(file,line);
239 std::getline(file,line);
240 //int a=line.find("histogram Data");
241 if( (int)(line.find("histogram Data"))!=-1)
243 histogramReading=true;
247 else if(line.find("histogramPoints")!=0 && histogramReading)
249 histogramPoints=true;
251 else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
255 else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
257 int pos1=line.find(">");
258 int pos2=line.find("<",pos+1);
259 std::string x=line.substr(pos1+1,pos2-1);
262 else if(line.find("number")!=0 && histogramReading && histogramPoints)
264 int pos1=line.find(">");
265 int pos2=line.find("<",pos+1);
266 std::string x=line.substr(pos1+1,pos2-1);
268 //add to the histogram
269 //histogramW->addPointToTransferenceFunction(gc,in);
272 else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
276 else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
280 else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
282 int pos1=line.find(">");
283 int pos2=line.find("<",pos1+1);
284 std::string x=line.substr(pos1+1,pos2-pos1-1);
288 else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
290 int pos1=line.find(">");
291 int pos2=line.find("<",pos1+1);
292 std::string x=line.substr(pos1+1,pos2-pos1-1);
294 histogramW->addPointToTransferenceFunction(gv,in);
298 else if( (int)(line.find("Colors"))!=-1 && histogramReading)
303 else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
308 else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
310 int pos1=line.find(">");
311 int pos2=line.find("<",pos1+1);
312 std::string x=line.substr(pos1+1,pos2-pos1-1);
316 else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
318 int pos1=line.find(">");
319 int pos2=line.find("<",pos1+1);
320 std::string x=line.substr(pos1+1,pos2-pos1-1);
324 else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
326 int pos1=line.find(">");
327 int pos2=line.find("<",pos1+1);
328 std::string x=line.substr(pos1+1,pos2-pos1-1);
331 else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
333 int pos1=line.find(">");
334 int pos2=line.find("<",pos1+1);
335 std::string x=line.substr(pos1+1,pos2-pos1-1);
337 histogramW->addColorPoint(gv,red,gr,bl);
345 histogramW->updatePlotter();
351 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
357 // -- TransferenceFunction --
358 int nPointsTF=getSizeTransferenceFunction();
363 int nTFPoints=getSizeTransferenceFunction();
367 getTransferenceFunctionPoint(i,xi,yi);
368 _tfun->AddPoint( xi , yi/100.0 );
374 int nPointsCTF=getSizeBarColor();
377 _ctfun->RemoveAllPoints();
379 int nCTFpoints=getSizeBarColor();
383 getDataBarColorPoint(i,xi,r,g,b);
384 _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
392 NOTE I NEED THE UPDATE
394 //if it was call from the clipping ctnrl panel
395 if(wxvtkclipping3Dview!=NULL)
397 wxvtkclipping3Dview->Refresh();
400 else if(wxvtkmpr3Dview!=NULL)
402 wxvtkmpr3Dview->Refresh();
408 //-----------------------
410 //-----------------------
413 get number of points of the transference function
415 int HistogramDialog::getSizeTransferenceFunction()
417 return histogramW->getSizeTransferenceFunction();
421 get number of points of the barColor
423 int HistogramDialog::getSizeBarColor()
425 return histogramW->getSizeBarColor();
428 get a point of the transference function
430 void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
432 histogramW->getTransferenceFunctionPoint(index,x,y);
435 get a color int the bqr color
437 void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
439 histogramW->getDataBarColorPoint(index,x,red,green,blue);
442 get a point of the Histogram
445 int HistogramDialog::getHistogramPoint(int gValue)
447 return histogramW->getHistogramPoint(gValue);
450 //--------------------
452 //---------------------
454 Get the porcentage of the positions of
455 the min,max and actual in the bar range
457 float HistogramDialog::getMaxShowedPorcentage()
459 return histogramW->getMaxShowedPorcentage();
461 float HistogramDialog::getMinShowedPorcentage()
463 return histogramW->getMinShowedPorcentage();
465 float HistogramDialog::getActualShowedPorcentage()
467 return histogramW->getActualShowedPorcentage();
469 //---------------------------------------
470 // setting data in transferences function
472 //----------------------------------------
473 bool HistogramDialog::addPointToTransferenceFunction(double x, double y)
475 return histogramW->addPointToTransferenceFunction(x,y);
477 bool HistogramDialog::addColorPoint(double x,int red,int green, int blue)
479 return histogramW->addColorPoint(x,red,green,blue);
481 //------------------------
483 //------------------------
486 Erase all the points that are in the transference function
488 void HistogramDialog::erasePointsTransferenceFunction()
490 histogramW->erasePointsTransferenceFunction();
493 Erase the color points in the plotter
495 void HistogramDialog::eraseColorPoints()
497 histogramW->eraseColorPoints();
500 //-------------------
501 // Getter and setters
502 //-------------------
504 void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
509 void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
514 bool HistogramDialog::getRefreshed()
519 void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
521 volumeMapper=volMapper;
523 void HistogramDialog::setVolume(vtkVolume* vol)
527 void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
529 wxvtkmpr3Dview=wxvtkmpr3Dview1;
531 void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
533 wxvtkclipping3Dview=wxvtkclipping3Dview1;
537 void HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
539 histogramW->setTransferenceFunctionHasPoints(hasPoints);
541 void HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
543 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
546 //--------------------
547 // plotter Information
548 //---------------------
549 void HistogramDialog::updatePlotter()
551 histogramW->updatePlotter();
556 ** Initialize the histogram
558 void HistogramDialog::initializeHistogram(vtkImageData* img){
559 histogramW->initializeHistogram(img);
562 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
564 void HistogramDialog::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
566 histogramW->GetValuesPointsFunction(greylevel, value);
570 ** Returns two vectors, the grey level of the point and its value, the red, green
571 ** and blue value is between [0,1]
573 void HistogramDialog::GetValuesColorPointsFunction(std::vector<double>& greylevel,
574 std::vector<double>& red,
575 std::vector<double>& green,
576 std::vector<double>& blue)
578 histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue);
581 void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){