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 //-----------------------
85 //-----------------------
87 void HistogramDialog::OnSaveData(wxCommandEvent& event)
89 wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1, -1);//wxFileSelector(_T("Save Data"),wxSAVE);
91 if(nameF.CompareTo( _T("/0") )>0)
92 file.open( (const char*)(nameF.mb_str()) );
96 file << "<histogram Data>" << std::endl;
99 file << " <histogramPoints>" << std::endl;
100 int histogramS=histogramW->getHistogramSize();
104 file << " <HistogramPoint>" << std::endl;
105 file << " <greyValue>" << i << "</greyValue>" <<std::endl;
106 file << " <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
107 file << " </HistogramPoint>" << std::endl;
110 file << " </histogramPoints>" << std::endl;
112 //points transference Function
113 file << " <TransferenceFunction>"<< std::endl;
114 int tfPointS=histogramW->getSizeTransferenceFunction();
120 histogramW->getTransferenceFunctionPoint(i,gv,in);
121 file << " <Transferencepoint>" << std::endl;
122 file << " <greyValue>" << gv << "</greyValue>" <<std::endl;
123 file << " <intensity>" << in << "</intensity> "<<std::endl;
124 file << " </Transferencepoint>" << std::endl;
127 file << " </TransferenceFunction>"<< std::endl;
129 file << " <Colors>"<< std::endl;
130 int ctfPointS=histogramW->getSizeBarColor();
137 histogramW->getDataBarColorPoint(i,gv,red,green,blue);
138 file << " <greyValueRGBpoint>" << std::endl;
139 file << " <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
140 file << " <red>" << red << "</red>" <<std::endl;
141 file << " <green>" << green << "</green>" <<std::endl;
142 file << " <blue>" << blue << "</blue>" <<std::endl;
143 file << " </greyValueRGBpoint>" << std::endl;
147 file << " </Colors>"<< std::endl;
148 file << "</histogram Data>" << std::endl;
153 void HistogramDialog::OnLoadData(wxCommandEvent& event)
155 wxString nameF=wxFileSelector(_T("Load Data") );
158 if(nameF.CompareTo( _T("/0") )>0)
159 file.open( (const char*) (nameF.mb_str()) );
161 bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false; // JPRx
162 int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
166 erasePointsTransferenceFunction();
170 //std::getline(file,line);
175 std::getline(file,line);
176 //int a=line.find("histogram Data");
177 if( (int)(line.find("histogram Data"))!=-1)
179 histogramReading=true;
183 else if(line.find("histogramPoints")!=0 && histogramReading)
185 histogramPoints=true;
187 else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
191 else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
193 int pos1=line.find(">");
194 int pos2=line.find("<",pos+1);
195 std::string x=line.substr(pos1+1,pos2-1);
198 else if(line.find("number")!=0 && histogramReading && histogramPoints)
200 int pos1=line.find(">");
201 int pos2=line.find("<",pos+1);
202 std::string x=line.substr(pos1+1,pos2-1);
204 //add to the histogram
205 //histogramW->addPointToTransferenceFunction(gc,in);
208 else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
212 else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
216 else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
218 int pos1=line.find(">");
219 int pos2=line.find("<",pos1+1);
220 std::string x=line.substr(pos1+1,pos2-pos1-1);
224 else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
226 int pos1=line.find(">");
227 int pos2=line.find("<",pos1+1);
228 std::string x=line.substr(pos1+1,pos2-pos1-1);
230 histogramW->addPointToTransferenceFunction(gv,in);
234 else if( (int)(line.find("Colors"))!=-1 && histogramReading)
239 else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
244 else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
246 int pos1=line.find(">");
247 int pos2=line.find("<",pos1+1);
248 std::string x=line.substr(pos1+1,pos2-pos1-1);
252 else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
254 int pos1=line.find(">");
255 int pos2=line.find("<",pos1+1);
256 std::string x=line.substr(pos1+1,pos2-pos1-1);
260 else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
262 int pos1=line.find(">");
263 int pos2=line.find("<",pos1+1);
264 std::string x=line.substr(pos1+1,pos2-pos1-1);
267 else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
269 int pos1=line.find(">");
270 int pos2=line.find("<",pos1+1);
271 std::string x=line.substr(pos1+1,pos2-pos1-1);
273 histogramW->addColorPoint(gv,red,gr,bl);
281 histogramW->updatePlotter();
287 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
293 // -- TransferenceFunction --
294 int nPointsTF=getSizeTransferenceFunction();
299 int nTFPoints=getSizeTransferenceFunction();
303 getTransferenceFunctionPoint(i,xi,yi);
304 _tfun->AddPoint( xi , yi/100.0 );
310 int nPointsCTF=getSizeBarColor();
313 _ctfun->RemoveAllPoints();
315 int nCTFpoints=getSizeBarColor();
319 getDataBarColorPoint(i,xi,r,g,b);
320 _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
328 NOTE I NEED THE UPDATE
330 //if it was call from the clipping ctnrl panel
331 if(wxvtkclipping3Dview!=NULL)
333 wxvtkclipping3Dview->Refresh();
336 else if(wxvtkmpr3Dview!=NULL)
338 wxvtkmpr3Dview->Refresh();
344 //-----------------------
346 //-----------------------
349 get number of points of the transference function
351 int HistogramDialog::getSizeTransferenceFunction()
353 return histogramW->getSizeTransferenceFunction();
357 get number of points of the barColor
359 int HistogramDialog::getSizeBarColor()
361 return histogramW->getSizeBarColor();
364 get a point of the transference function
366 void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
368 histogramW->getTransferenceFunctionPoint(index,x,y);
371 get a color int the bqr color
373 void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
375 histogramW->getDataBarColorPoint(index,x,red,green,blue);
378 get a point of the Histogram
381 int HistogramDialog::getHistogramPoint(int gValue)
383 return histogramW->getHistogramPoint(gValue);
386 //--------------------
388 //---------------------
390 Get the porcentage of the positions of
391 the min,max and actual in the bar range
393 float HistogramDialog::getMaxShowedPorcentage()
395 return histogramW->getMaxShowedPorcentage();
397 float HistogramDialog::getMinShowedPorcentage()
399 return histogramW->getMinShowedPorcentage();
401 float HistogramDialog::getActualShowedPorcentage()
403 return histogramW->getActualShowedPorcentage();
405 //---------------------------------------
406 // setting data in transferences function
408 //----------------------------------------
409 bool HistogramDialog::addPointToTransferenceFunction(double x, double y)
411 return histogramW->addPointToTransferenceFunction(x,y);
413 bool HistogramDialog::addColorPoint(double x,int red,int green, int blue)
415 return histogramW->addColorPoint(x,red,green,blue);
417 //------------------------
419 //------------------------
422 Erase all the points that are in the transference function
424 void HistogramDialog::erasePointsTransferenceFunction()
426 histogramW->erasePointsTransferenceFunction();
429 Erase the color points in the plotter
431 void HistogramDialog::eraseColorPoints()
433 histogramW->eraseColorPoints();
436 //-------------------
437 // Getter and setters
438 //-------------------
440 void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
445 void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
450 bool HistogramDialog::getRefreshed()
455 void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
457 volumeMapper=volMapper;
459 void HistogramDialog::setVolume(vtkVolume* vol)
463 void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
465 wxvtkmpr3Dview=wxvtkmpr3Dview1;
467 void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
469 wxvtkclipping3Dview=wxvtkclipping3Dview1;
473 void HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
475 histogramW->setTransferenceFunctionHasPoints(hasPoints);
477 void HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
479 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
482 //--------------------
483 // plotter Information
484 //---------------------
485 void HistogramDialog::updatePlotter()
487 histogramW->updatePlotter();