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