]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx
1a2c14093f0a03835514879350d6e7ee66f5a2af
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramDialog.cxx
1 #include "HistogramDialog.h"
2 #include <vector>
3
4 #include "OpenImage.xpm"
5 #include "Save.xpm"
6 #include "Ok.xpm"
7 #include "Cancel.xpm"
8 #include "Delete.xpm"
9
10 #include "creaSystem.h"
11
12
13
14 // IMPLEMENT_CLASS(HistogramDialog, wxDialog)
15
16
17 //id for events
18 enum {
19     ID_SAVE  = 108,
20         ID_LOAD,
21         ID_REFRESH
22 };
23
24 //-------------------------
25 //Constructor
26 //-------------------------
27 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,vtkImageData* imageData,bool extracontrols)
28 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE   ,_T("dialogBox"))
29 {
30
31         initializeHistogramDialog(extracontrols);
32         initializeHistogram(imageData);
33
34 }
35
36 HistogramDialog::HistogramDialog(wxWindow *parent,wxString title,bool extracontrols)
37 :wxDialog(parent,-1,title,wxDefaultPosition,wxDefaultSize,wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE   ,_T("dialogBox")){
38         
39         initializeHistogramDialog(extracontrols);
40 }
41 HistogramDialog::~HistogramDialog(){    
42
43 }
44
45 void HistogramDialog::initializeHistogramDialog(bool extracontrols){
46         _currentcolorselectedbitmap = -1;
47     _ctfun=NULL;
48         _tfun=NULL;
49         _panextracontrols=NULL;
50         _maxgreyvalue = 1;
51
52         SetBackgroundColour(wxColour(255,255,255));
53         /*
54         Pointers
55         */
56         //wxvtkmpr3Dview=NULL;
57         //wxvtkclipping3Dview=NULL;
58         
59         /*
60          Histogram
61         */
62         
63         histogramW=new HistogramWidget(this, -1);
64         
65         /*
66         Buttons
67         */
68         wxBitmap bitmap0(Ok_xpm);
69         okBtn = new wxBitmapButton(this, wxID_OK, bitmap0,wxDefaultPosition,wxDefaultSize);             
70         
71         wxBitmap bitmap1(Cancel_xpm);
72         cancelBtn = new wxBitmapButton(this, wxID_CANCEL, bitmap1,wxDefaultPosition,wxDefaultSize);     
73         
74         //saveDataBtn = new wxButton(this,ID_SAVE,_T("Save"));
75         //loadDataBtn = new wxButton(this,ID_LOAD,_T("Load"));
76         //refreshBtn = new wxButton(this,ID_REFRESH,_T("Refresh"));
77         
78         //Connect(saveDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnSaveData     );
79         //Connect(loadDataBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnLoadData     );
80         //Connect(refreshBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &HistogramDialog::OnRefreshBtn    );
81         
82         //-------------------
83         //GUI
84         //-------------------
85         
86         //Upper Box
87         wxBoxSizer * upper_box = new wxBoxSizer( wxHORIZONTAL );
88         //Including components for plotter control
89         
90         upper_box->Add( histogramW, 4, wxGROW);
91         upper_box->Add( getControls(extracontrols),wxSizerFlags().Center() );   
92
93         //bottom Sizer
94         wxBoxSizer *bottomBox = new wxBoxSizer( wxHORIZONTAL );
95         bottomBox->Add( okBtn, wxSizerFlags().Center());
96         bottomBox->AddSpacer(40);
97         //bottomBox->Add( saveDataBtn,wxSizerFlags().Center() );
98         //bottomBox->AddSpacer(40);
99         //bottomBox->Add( loadDataBtn,wxSizerFlags().Center() );
100         //bottomBox->AddSpacer(40);
101         //bottomBox->Add( refreshBtn,wxSizerFlags().Center() );
102         //bottomBox->AddSpacer(40);
103         bottomBox->Add( cancelBtn,wxSizerFlags().Center() );
104         
105         //Sizer
106         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
107         sizer->Add(upper_box,1,wxEXPAND);       
108     sizer->Add(bottomBox,0,wxCENTER);
109         SetAutoLayout( TRUE );
110         SetSizer( sizer );
111         SetBestSize(wxSize(600,600));
112 }
113 wxPanel* HistogramDialog::getPanExtraControls(){
114         wxBoxSizer* sizer0 = new wxBoxSizer(wxVERTICAL);
115     _panextracontrols = new wxPanel(this);      
116
117         _panextracontrols->SetSizer(sizer0);
118         _panextracontrols->SetAutoLayout(true);
119
120     return _panextracontrols;
121 }
122 /**
123 ** Set to true in the constructor
124 **/
125 void HistogramDialog::setInfoPanExtraControls(std::vector<HistogramDialogComboBoxItem*> comboitems){
126         _comboitems = comboitems;
127         if(_panextracontrols!=NULL){
128                 _panextracontrols->Show(false);
129                 for(int i=0; i < comboitems.size();i++){
130
131                         wxBitmap bitmap = comboitems[i]->GetBitmap();
132                         
133                         
134                         _panextracontrols->GetSizer()->Add(getBitmapButtonDelete(bitmap),wxSizerFlags().Center());                      
135                         _panextracontrols->GetSizer()->AddSpacer(5);
136             
137                 }       
138                 
139                 wxButton* button = new wxButton(_panextracontrols,wxID_ANY);                    
140                 button->SetToolTip(wxString("Add the current color to the list of predefined",wxConvUTF8));
141                 button->SetLabel(wxString(_T("Add")));
142                 Connect(button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditColorsCombo);                             
143                 _panextracontrols->GetSizer()->Add(button);                                             
144                 _panextracontrols->Layout();            
145                 _panextracontrols->Refresh();
146                 _panextracontrols->Show(true);
147                 this->Layout();
148                 this->Refresh();
149
150         }
151 }
152 wxSizer* HistogramDialog::getBitmapButtonDelete(wxBitmap bitmap){
153         //wxCheckBox* checkbox = new wxCheckBox(_panextracontrols,wxID_ANY,_T(""));
154         wxBitmap bitmap0(Delete_xpm);
155         wxBitmapButton* deletebutton = new wxBitmapButton(_panextracontrols,wxID_ANY,bitmap0,wxDefaultPosition,wxSize(20,20));
156         deletebutton->SetToolTip(wxString("Delete the color from the list",wxConvUTF8));
157         Connect(deletebutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnDeleteColor);
158          _deletebuttonsvector.push_back(deletebutton);
159         
160         //wxBitmap bitmap0(OpenImage_xpm);
161         wxBitmapButton* button = new wxBitmapButton(_panextracontrols,wxID_ANY,bitmap,wxDefaultPosition,wxSize(30,30));                 
162         button->SetToolTip(wxString("Load the current color configuration.",wxConvUTF8));
163         bitmapbuttonsvect.push_back(button);                    
164         Connect(button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnEditColorsCombo);
165         /*char c[10];
166         wxString s;
167         s.Printf(_T("%d"),i);*/
168         
169         //button->SetBitmapLabel(comboitems[i]->GetBitmap());
170         // wxStaticBitmap* button = new wxStaticBitmap(_panextracontrols,i,comboitems[i]->GetBitmap(),wxDefaultPosition,wxSize(30,30));                 
171         wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
172         sizer->Add(button,wxSizerFlags().Center());
173         sizer->AddSpacer(5);
174         sizer->Add(deletebutton,wxSizerFlags().Center());
175         return sizer;
176 }
177 void HistogramDialog::OnDeleteColor(wxCommandEvent& event){
178     for(int i = 0; i < _deletebuttonsvector.size();i++){
179                 if(event.GetId()==_deletebuttonsvector[i]->GetId()){
180                         _currentcolorselectedbitmap = -1;
181                         //this->eraseColorPoints();
182                         //this->erasePointsTransferenceFunction();
183                         HistogramDialogComboBoxItem* temp;
184                         temp = _comboitems[i];
185                         _deletebuttonsvector[i]->Hide();
186                         bitmapbuttonsvect[i]->Hide();
187                         delete temp;
188                         //Remove buttons
189                         _panextracontrols->GetSizer()->Remove(i*2);
190                         //Remove Space
191                         _panextracontrols->GetSizer()->Remove(i*2);
192                         for(int k = i; k < _comboitems.size()-1;k++){
193                 _comboitems[k] = _comboitems[k+1];
194                                 _deletebuttonsvector[k] = _deletebuttonsvector[k+1];
195                                 bitmapbuttonsvect[k] = bitmapbuttonsvect[k+1];
196                         }                       
197                         _comboitems.pop_back(); 
198                         _deletebuttonsvector.pop_back();
199                         bitmapbuttonsvect.pop_back();
200                 }
201         }
202     _panextracontrols->Layout();
203 }
204 void HistogramDialog::OnEditColorsCombo(wxCommandEvent& event){
205         bool loadconfig = false;
206         UpdateCurrentComboElement();
207         for(int i = 0; i < bitmapbuttonsvect.size();i++){
208                 if(event.GetId()==bitmapbuttonsvect[i]->GetId()){
209                         if(i<_comboitems.size()){
210                                 _currentcolorselectedbitmap = i;
211                                 loadconfig = true;
212                                 HistogramDialogComboBoxItem* currentconfig = _comboitems[i];
213                                 std::vector<double> greyvect = currentconfig->getGreyVector();
214                                 std::vector<double> _redvect = currentconfig->getRedVector();
215                                 std::vector<double> _greenvect = currentconfig->getGreenVector();
216                                 std::vector<double> _bluevect= currentconfig->getBlueVector();
217                                 this->eraseColorPoints();
218                                 this->erasePointsTransferenceFunction();
219                                 for(int i = 0; i < currentconfig->getGreyVector().size();i++){
220                                         double greyv = currentconfig->getGreyVector()[i];
221                                         double red = currentconfig->getRedVector()[i];
222                                         double green = currentconfig->getGreenVector()[i];
223                                         double blue = currentconfig->getBlueVector()[i];
224
225                                         this->addColorPoint(greyv*_maxgreyvalue, red*255.0, green*255.0, blue*255.0);
226                                 }
227                                 for(int i = 0; i < currentconfig->getGreyVectorTransfer().size();i++){
228                                         double greyv = currentconfig->getGreyVectorTransfer()[i];       
229                                         double value = currentconfig->getValueVector()[i];
230                                         std::cout<<"void HistogramDialog::OnEditColorsCombo(wxCommandEvent& event){"<<greyv<<" "<<value<<std::endl;
231                                         this->addPointToTransferenceFunction(greyv*_maxgreyvalue, value*100);
232                                 }
233                         }
234                 }
235         }
236         if(!loadconfig){                
237                 AddNewBitmapButton();           
238         }
239         
240         _panextracontrols->Layout();
241         this->Layout();
242         this->Refresh();
243 }
244 void HistogramDialog::UpdateCurrentComboElement(){
245         if(_currentcolorselectedbitmap >= 0 && _currentcolorselectedbitmap < _comboitems.size()){
246                 setCurrentColorConfigurationIntoButton();
247         }
248 }
249 void HistogramDialog::AddNewBitmapButton(){     
250         this->eraseColorPoints();
251         this->erasePointsTransferenceFunction();
252         HistogramDialogComboBoxItem* boxitem = new HistogramDialogComboBoxItem();       
253         wxBitmap bitmap = boxitem->GetBitmap();
254         wxSizer* sizer = getBitmapButtonDelete(bitmap);
255     _panextracontrols->GetSizer()->Insert(_comboitems.size()*2,sizer,wxSizerFlags().Center());                  
256         _panextracontrols->GetSizer()->InsertSpacer(_comboitems.size()*2+1,5);
257         _comboitems.push_back(boxitem);         
258         _currentcolorselectedbitmap = _comboitems.size()-1;
259 }
260 void HistogramDialog::setCurrentColorConfigurationIntoButton(){
261                 
262                 std::vector<double> greylevel;
263                 std::vector<double> red;
264                 std::vector<double> green;
265                 std::vector<double> blue;
266                 std::vector<double> red0;
267                 std::vector<double> green0;
268                 std::vector<double> blue0;
269                 GetValuesColorPointsFunction(greylevel,red,green,blue);
270
271                 for(int i = 0;i< greylevel.size();i++){
272                         greylevel[i] = greylevel[i]/_maxgreyvalue;
273                         /*std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){red"<<red[i]<<std::endl;
274                         std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){green"<<green[i]<<std::endl;
275                         std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){blue"<<blue[i]<<std::endl;*/
276                         red0.push_back(red[i]);
277                         green0.push_back(green[i]);
278                         blue0.push_back(blue[i]);                       
279                         /*std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){red"<<red0[i]<<std::endl;
280                         std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){green"<<green0[i]<<std::endl;
281                         std::cout<<"HistogramDialog::setCurrentColorConfigurationIntoButton(){blue"<<blue0[i]<<std::endl;*/
282                 }
283                 
284                 std::vector<double> greylevel1;
285                 std::vector<double> value;              
286                 this->GetValuesPointsFunction(greylevel1,value);                
287
288                 for(int i = 0;i< greylevel1.size();i++){
289                         greylevel1[i] = greylevel1[i]/_maxgreyvalue;
290                         value[i] = value[i];
291                         std::cout<<"void HistogramDialog::setCurrentColorConfigurationIntoButton(){"<<greylevel1[i]<<std::endl;
292                         std::cout<<"void HistogramDialog::setCurrentColorConfigurationIntoButton(){"<<value[i]<<std::endl;
293                 }
294         if(_currentcolorselectedbitmap >= 0 && _currentcolorselectedbitmap < _comboitems.size()){
295                 _comboitems[_currentcolorselectedbitmap]->SetColors(greylevel,red0,green0,blue0);
296                 _comboitems[_currentcolorselectedbitmap]->SetTransferFunction(greylevel1,value);        
297                 bitmapbuttonsvect[_currentcolorselectedbitmap]->SetBitmapLabel(_comboitems[_currentcolorselectedbitmap]->GetBitmap());
298         }
299 }
300
301 wxSizer* HistogramDialog::getControls(bool extracontrols){              
302                 
303         wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
304         
305         wxBitmap bitmap0(OpenImage_xpm);
306         wxBitmapButton* opendata = new wxBitmapButton(this, -1, bitmap0,wxDefaultPosition,wxSize(30,30));       
307         Connect(opendata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnLoadData);                  
308         sizer->Add(opendata,wxSizerFlags().Center());   
309         sizer->AddSpacer(5);
310
311         
312
313         wxBitmap bitmap1(Save_xpm);
314         wxBitmapButton* savedata = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));       
315         Connect(savedata->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialog::OnSaveData);                  
316         sizer->Add(savedata,wxSizerFlags().Center());
317         sizer->AddSpacer(5);
318
319         if(extracontrols){
320                 sizer->Add(getPanExtraControls(),wxSizerFlags().Center());
321         }
322     //sizer->Add(getBitmapCombo(),wxSizerFlags().Center());
323         
324         
325         
326         return sizer;
327
328
329 }
330
331 //-----------------------
332 //Handling events
333 //-----------------------
334
335 void HistogramDialog::OnSaveData(wxCommandEvent& event)
336 {
337         wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1,  -1);//wxFileSelector(_T("Save Data"),wxSAVE);
338         std::ofstream file;
339         if(nameF.CompareTo( _T("/0") )>0)
340                 file.open( (const char*)(nameF.mb_str()) );
341
342         if(file.is_open())
343         {
344                 file << "<histogram Data>" << std::endl;
345                 //histograms points
346                 /*
347                 file << "       <histogramPoints>" << std::endl;
348                 int histogramS=histogramW->getHistogramSize();
349                 int i=0;        
350                 while(i<histogramS)
351                 {
352                         file << "               <HistogramPoint>" << std::endl;
353                         file << "                       <greyValue>" << i << "</greyValue>" <<std::endl;
354                         file << "                       <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
355                         file << "               </HistogramPoint>" << std::endl;
356                         i++;
357                 }
358                 file << "       </histogramPoints>" << std::endl;
359                 */
360                 //points transference Function
361                 file << " <TransferenceFunction>"<< std::endl;
362                 int tfPointS=histogramW->getSizeTransferenceFunction();
363                 int i=0;
364                 int gv,in;
365                 while(i<tfPointS)
366                 {
367                         
368                         histogramW->getTransferenceFunctionPoint(i,gv,in);
369                         file << "               <Transferencepoint>" << std::endl;
370                         file << "                       <greyValue>" << gv << "</greyValue>" <<std::endl;
371                         file << "                       <intensity>" << in << "</intensity> "<<std::endl;
372                         file << "               </Transferencepoint>" << std::endl;
373                         i++;
374                 }
375                 file << "       </TransferenceFunction>"<< std::endl;
376                 //colorPoints
377                 file << "       <Colors>"<< std::endl;
378                 int ctfPointS=histogramW->getSizeBarColor();
379
380                 i=0;
381                 int red,green,blue;
382                 while(i<ctfPointS)
383                 {
384                         
385                         histogramW->getDataBarColorPoint(i,gv,red,green,blue);
386                         file << "               <greyValueRGBpoint>" << std::endl;
387                         file << "                       <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
388                         file << "                       <red>" << red << "</red>" <<std::endl;
389                         file << "                       <green>" << green << "</green>" <<std::endl;
390                         file << "                       <blue>" << blue << "</blue>" <<std::endl;
391                         file << "               </greyValueRGBpoint>" << std::endl;
392                         i++;
393                 }
394
395                 file << "       </Colors>"<< std::endl;
396                 file << "</histogram Data>" << std::endl;
397         }
398         file.close();
399 }
400
401 void HistogramDialog::OnLoadData(wxCommandEvent& event)
402 {
403         wxString nameF=wxFileSelector(_T("Load Data") );
404         //std::string line;
405         std::ifstream file;
406         if(nameF.CompareTo( _T("/0") )>0)
407                 file.open(  (const char*) (nameF.mb_str()) );
408         
409         bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false;  // JPRx
410         int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
411         if(file.is_open())
412         {
413                 //-------------
414                 erasePointsTransferenceFunction();
415                 eraseColorPoints();
416                 //--------------
417         
418                 //std::getline(file,line);
419                 //int i=0;  // JPRx
420                 while(!file.eof())
421                 {
422                         std::string line;
423                         std::getline(file,line);
424                         //int a=line.find("histogram Data");
425                         if( (int)(line.find("histogram Data"))!=-1)
426                         {
427                                 histogramReading=true;
428                         
429                         }
430                         /*
431                         else if(line.find("histogramPoints")!=0 && histogramReading)
432                         {
433                                 histogramPoints=true;
434                         }
435                         else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
436                         {
437
438                         }
439                         else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
440                         {
441                                 int pos1=line.find(">");
442                                 int pos2=line.find("<",pos+1);
443                                 std::string x=line.substr(pos1+1,pos2-1);
444                                 gv=atoi(x.c_str());
445                         }
446                         else if(line.find("number")!=0 && histogramReading && histogramPoints)
447                         {
448                                 int pos1=line.find(">");
449                                 int pos2=line.find("<",pos+1);
450                                 std::string x=line.substr(pos1+1,pos2-1);
451                                 nP=atoi(x.c_str());
452                                 //add to the histogram
453                                 //histogramW->addPointToTransferenceFunction(gc,in);
454                         }
455                         */
456                         else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
457                         {
458                                 tf=true;
459                         }
460                         else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
461                         {
462                                 tfp=true;
463                         }
464                         else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
465                         {
466                                 int pos1=line.find(">");
467                                 int pos2=line.find("<",pos1+1);
468                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
469                                 gv=atoi(x.c_str());
470                                 
471                         }
472                         else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
473                         {
474                                 int pos1=line.find(">");
475                                 int pos2=line.find("<",pos1+1);
476                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
477                                 in=atoi(x.c_str());
478                                 histogramW->addPointToTransferenceFunction(gv,in);
479                                 tfp=false;
480                                 
481                         }
482                         else if( (int)(line.find("Colors"))!=-1 && histogramReading)
483                         {
484                                 ctf=true;
485                         }
486                         
487                         else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
488                         {
489                                 ctfp=true;
490                                 
491                         }
492                         else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
493                         {
494                                 int pos1=line.find(">");
495                                 int pos2=line.find("<",pos1+1);
496                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
497                                 gv=atoi(x.c_str());
498                                 
499                         }
500                         else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
501                         {
502                                 int pos1=line.find(">");
503                                 int pos2=line.find("<",pos1+1);
504                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
505                                 red=atoi(x.c_str());
506                                 
507                         }
508                         else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
509                         {
510                                 int pos1=line.find(">");
511                                 int pos2=line.find("<",pos1+1);
512                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
513                                 gr=atoi(x.c_str());
514                         }
515                         else if( (int)(line.find("blue"))!=-1 && histogramReading && ctf && ctfp)
516                         {
517                                 int pos1=line.find(">");
518                                 int pos2=line.find("<",pos1+1);
519                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
520                                 bl=atoi(x.c_str());
521                                 histogramW->addColorPoint(gv,red,gr,bl);
522                                 ctfp=false;
523                         }
524                         line.clear();
525              }
526      }
527         
528         file.close();
529         histogramW->updatePlotter();
530 }
531 /*
532  On refresh btn
533 */
534
535 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
536 {
537         refreshed=true;
538                         
539                         int i=0,xi,yi,r,g,b;
540                         
541                         // -- TransferenceFunction --
542                         int nPointsTF=getSizeTransferenceFunction();
543
544                         if(nPointsTF>0)
545                         {
546
547                                 int nTFPoints=getSizeTransferenceFunction();
548                                 i=0;
549                                 while(i<nTFPoints)
550                                 {
551                                         getTransferenceFunctionPoint(i,xi,yi);
552                                         _tfun->AddPoint( xi , yi/100.0 );
553                                         i++;
554                                 }
555                         }
556                         //-- Color bar --
557                         //clean colors
558                         int nPointsCTF=getSizeBarColor();
559                         if(nPointsCTF>0)
560                         {                       
561                                 _ctfun->RemoveAllPoints();
562                                 
563                                 int nCTFpoints=getSizeBarColor();
564                                 i=0;    
565                                 while(i<nCTFpoints)
566                                 {
567                                         getDataBarColorPoint(i,xi,r,g,b);
568                                         _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
569                                         i++;
570                                 }
571                         }
572
573 //EED Borrame
574
575         /*
576          NOTE I NEED THE UPDATE
577         */
578         //if it was call from the clipping ctnrl panel
579         //if(wxvtkclipping3Dview!=NULL)
580         //{
581         //      wxvtkclipping3Dview->Refresh();
582
583         //}
584         //else if(wxvtkmpr3Dview!=NULL)
585         //{
586         //      wxvtkmpr3Dview->Refresh();
587
588         //}
589 }
590
591
592 //-----------------------
593 //Methods
594 //-----------------------
595
596 /*
597                 get number of points of the transference function
598         */
599         int HistogramDialog::getSizeTransferenceFunction()
600         {
601                 return histogramW->getSizeTransferenceFunction();
602                 
603         }
604         /*
605                 get number of points of the barColor
606         */
607         int HistogramDialog::getSizeBarColor()
608         {
609                 return histogramW->getSizeBarColor();
610         }
611         /*
612                 get a point of the transference function
613         */
614         void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
615         {
616                 histogramW->getTransferenceFunctionPoint(index,x,y);
617         }
618         /*
619                 get a  color int the bqr color
620         */
621         void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
622         {
623                 histogramW->getDataBarColorPoint(index,x,red,green,blue);
624         }
625         /*
626                 get a point of the Histogram
627                 given the grey value
628         */
629         int HistogramDialog::getHistogramPoint(int gValue)
630         {
631                 return histogramW->getHistogramPoint(gValue);
632         }
633
634         //--------------------
635         // bar Information
636         //---------------------
637         /*
638          Get the porcentage of the positions of 
639          the min,max and actual in the bar range
640         */
641         float HistogramDialog::getMaxShowedPorcentage()
642         {
643                 return histogramW->getMaxShowedPorcentage();
644         }
645         float HistogramDialog::getMinShowedPorcentage()
646         {
647                 return histogramW->getMinShowedPorcentage();
648         }
649         float HistogramDialog::getActualShowedPorcentage()
650         {
651                 return histogramW->getActualShowedPorcentage();
652         }
653         //---------------------------------------
654         // setting data in transferences function
655         // and in bar color
656         //----------------------------------------
657         bool  HistogramDialog::addPointToTransferenceFunction(double x, double y)
658         {
659                 return histogramW->addPointToTransferenceFunction(x,y);
660         }
661         bool  HistogramDialog::addColorPoint(double x,int red,int green, int blue)
662         {
663                 return histogramW->addColorPoint(x,red,green,blue);
664         }
665         //------------------------
666         //Erase data
667         //------------------------
668         
669         /*
670          Erase all the points that are in the transference function
671         */
672         void HistogramDialog::erasePointsTransferenceFunction()
673         {
674                 histogramW->erasePointsTransferenceFunction();
675         }
676         /*
677         Erase the  color points in the plotter
678         */
679         void HistogramDialog::eraseColorPoints()
680         {
681                 histogramW->eraseColorPoints();
682         }
683
684         //-------------------
685         // Getter and setters
686         //-------------------
687
688         void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
689         {
690                 _ctfun=cf;
691         
692         }
693         void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
694         {
695                 _tfun=tf;
696         }
697
698         bool HistogramDialog::getRefreshed()
699         {
700                 return refreshed;
701         }
702         
703         void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
704         {
705                 volumeMapper=volMapper;
706         }
707         void HistogramDialog::setVolume(vtkVolume* vol)
708         {
709                 newvol=vol;     
710         }
711         //void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
712         //{
713         //      wxvtkmpr3Dview=wxvtkmpr3Dview1;
714         //}
715         //void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
716         //{
717         //      wxvtkclipping3Dview=wxvtkclipping3Dview1;
718         //}
719
720
721         void  HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
722         {
723                 histogramW->setTransferenceFunctionHasPoints(hasPoints);
724         }
725         void  HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
726         {
727                 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
728         }
729
730         //--------------------
731         // plotter Information
732         //---------------------
733         void  HistogramDialog::updatePlotter()
734         {
735                 histogramW->updatePlotter();
736         }
737
738
739 /**
740 **      Initialize the histogram 
741 */
742         void HistogramDialog::initializeHistogram(vtkImageData* img){   
743                 _maxgreyvalue = img->GetScalarRange()[1];
744                 histogramW->initializeHistogram(img);
745         }
746 /**
747 **      Returns two vectors, the grey level of the point and its value, the value is between [0,1]
748 **/
749         void HistogramDialog::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
750
751                 histogramW->GetValuesPointsFunction(greylevel, value);
752         }
753
754 /**
755 **      Returns two vectors, the grey level of the point and its value, the red, green
756 **      and blue value is between [0,1]
757 **/
758 void HistogramDialog::GetValuesColorPointsFunction(std::vector<double>& greylevel,
759                                                                 std::vector<double>& red,
760                                                                 std::vector<double>& green,
761                                                                 std::vector<double>& blue)
762 {
763         histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue);
764 }
765
766 void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){
767         _tfun = _opac;
768         _ctfun = _color;        
769 }