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