]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialog.cxx
Support #1768 CREATIS Licence insertion
[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         wxString nameF=wxFileSelector(_T("Save Data"), _T(" "),_T(""),_T(""),_T("*.*"),wxSAVE, NULL, -1,  -1);//wxFileSelector(_T("Save Data"),wxSAVE);
363         std::ofstream file;
364         if(nameF.CompareTo( _T("/0") )>0)
365                 file.open( (const char*)(nameF.mb_str()) );
366
367         if(file.is_open())
368         {
369                 file << "<histogram Data>" << std::endl;
370                 //histograms points
371                 /*
372                 file << "       <histogramPoints>" << std::endl;
373                 int histogramS=histogramW->getHistogramSize();
374                 int i=0;        
375                 while(i<histogramS)
376                 {
377                         file << "               <HistogramPoint>" << std::endl;
378                         file << "                       <greyValue>" << i << "</greyValue>" <<std::endl;
379                         file << "                       <number>" << histogramW->getHistogramPoint(i) << "</number>"<<std::endl;
380                         file << "               </HistogramPoint>" << std::endl;
381                         i++;
382                 }
383                 file << "       </histogramPoints>" << std::endl;
384                 */
385                 //points transference Function
386                 file << " <TransferenceFunction>"<< std::endl;
387                 int tfPointS=histogramW->getSizeTransferenceFunction();
388                 int i=0;
389                 int gv,in;
390                 while(i<tfPointS)
391                 {
392                         
393                         histogramW->getTransferenceFunctionPoint(i,gv,in);
394                         file << "               <Transferencepoint>" << std::endl;
395                         file << "                       <greyValue>" << gv << "</greyValue>" <<std::endl;
396                         file << "                       <intensity>" << in << "</intensity> "<<std::endl;
397                         file << "               </Transferencepoint>" << std::endl;
398                         i++;
399                 }
400                 file << "       </TransferenceFunction>"<< std::endl;
401                 //colorPoints
402                 file << "       <Colors>"<< std::endl;
403                 int ctfPointS=histogramW->getSizeBarColor();
404
405                 i=0;
406                 int red,green,blue;
407                 while(i<ctfPointS)
408                 {
409                         
410                         histogramW->getDataBarColorPoint(i,gv,red,green,blue);
411                         file << "               <greyValueRGBpoint>" << std::endl;
412                         file << "                       <RGBgreyValue>" << gv << "</RGBgreyValue>" <<std::endl;
413                         file << "                       <red>" << red << "</red>" <<std::endl;
414                         file << "                       <green>" << green << "</green>" <<std::endl;
415                         file << "                       <blue>" << blue << "</blue>" <<std::endl;
416                         file << "               </greyValueRGBpoint>" << std::endl;
417                         i++;
418                 }
419
420                 file << "       </Colors>"<< std::endl;
421                 file << "</histogram Data>" << std::endl;
422         }
423         file.close();
424 }
425
426 void HistogramDialog::OnLoadData(wxCommandEvent& event)
427 {
428         wxString nameF=wxFileSelector(_T("Load Data") );
429         //std::string line;
430         std::ifstream file;
431         if(nameF.CompareTo( _T("/0") )>0)
432                 file.open(  (const char*) (nameF.mb_str()) );
433         
434         bool histogramReading=false,/*histogramPoints=false,histogramPoint=false,*/tf=false,ctf=false,tfp=false,ctfp=false;  // JPRx
435         int gv=-1,in=-1,red=-1,gr=-1,bl=-1/*,nPoints=-1*/; // JPRx
436         if(file.is_open())
437         {
438                 //-------------
439                 erasePointsTransferenceFunction();
440                 eraseColorPoints();
441                 //--------------
442         
443                 //std::getline(file,line);
444                 //int i=0;  // JPRx
445                 while(!file.eof())
446                 {
447                         std::string line;
448                         std::getline(file,line);
449                         //int a=line.find("histogram Data");
450                         if( (int)(line.find("histogram Data"))!=-1)
451                         {
452                                 histogramReading=true;
453                         
454                         }
455                         /*
456                         else if(line.find("histogramPoints")!=0 && histogramReading)
457                         {
458                                 histogramPoints=true;
459                         }
460                         else if(line.find("histogramPoint")!=0 && histogramReading && histogramPoints)
461                         {
462
463                         }
464                         else if(line.find("greyValue")!=0 && histogramReading && histogramPoints)
465                         {
466                                 int pos1=line.find(">");
467                                 int pos2=line.find("<",pos+1);
468                                 std::string x=line.substr(pos1+1,pos2-1);
469                                 gv=atoi(x.c_str());
470                         }
471                         else if(line.find("number")!=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                                 nP=atoi(x.c_str());
477                                 //add to the histogram
478                                 //histogramW->addPointToTransferenceFunction(gc,in);
479                         }
480                         */
481                         else if( (int)(line.find("TransferenceFunction"))!=-1 && histogramReading)
482                         {
483                                 tf=true;
484                         }
485                         else if( (int)(line.find("<Transferencepoint>"))!=-1 && histogramReading && tf)
486                         {
487                                 tfp=true;
488                         }
489                         else if( (int)(line.find("greyValue"))!=-1 && histogramReading && tf && tfp)
490                         {
491                                 int pos1=line.find(">");
492                                 int pos2=line.find("<",pos1+1);
493                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
494                                 gv=atoi(x.c_str());
495                                 
496                         }
497                         else if( (int)(line.find("intensity"))!=-1 && histogramReading && tf && tfp)
498                         {
499                                 int pos1=line.find(">");
500                                 int pos2=line.find("<",pos1+1);
501                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
502                                 in=atoi(x.c_str());
503                                 histogramW->addPointToTransferenceFunction(gv,in);
504                                 tfp=false;
505                                 
506                         }
507                         else if( (int)(line.find("Colors"))!=-1 && histogramReading)
508                         {
509                                 ctf=true;
510                         }
511                         
512                         else if( (int)(line.find("greyValueRGBpoint"))!=-1 && histogramReading && ctf )
513                         {
514                                 ctfp=true;
515                                 
516                         }
517                         else if( (int)(line.find("RGBgreyValue"))!=-1 && histogramReading && ctf && ctfp)
518                         {
519                                 int pos1=line.find(">");
520                                 int pos2=line.find("<",pos1+1);
521                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
522                                 gv=atoi(x.c_str());
523                                 
524                         }
525                         else if( (int)(line.find("red"))!=-1 && histogramReading && ctf && ctfp)
526                         {
527                                 int pos1=line.find(">");
528                                 int pos2=line.find("<",pos1+1);
529                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
530                                 red=atoi(x.c_str());
531                                 
532                         }
533                         else if( (int)(line.find("green"))!=-1 && histogramReading && ctf && ctfp)
534                         {
535                                 int pos1=line.find(">");
536                                 int pos2=line.find("<",pos1+1);
537                                 std::string x=line.substr(pos1+1,pos2-pos1-1);
538                                 gr=atoi(x.c_str());
539                         }
540                         else if( (int)(line.find("blue"))!=-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                                 bl=atoi(x.c_str());
546                                 histogramW->addColorPoint(gv,red,gr,bl);
547                                 ctfp=false;
548                         }
549                         line.clear();
550              }
551      }
552         
553         file.close();
554         histogramW->updatePlotter();
555 }
556 /*
557  On refresh btn
558 */
559
560 void HistogramDialog::OnRefreshBtn(wxCommandEvent &event)
561 {
562         refreshed=true;
563                         
564                         int i=0,xi,yi,r,g,b;
565                         
566                         // -- TransferenceFunction --
567                         int nPointsTF=getSizeTransferenceFunction();
568
569                         if(nPointsTF>0)
570                         {
571
572                                 int nTFPoints=getSizeTransferenceFunction();
573                                 i=0;
574                                 while(i<nTFPoints)
575                                 {
576                                         getTransferenceFunctionPoint(i,xi,yi);
577                                         _tfun->AddPoint( xi , yi/100.0 );
578                                         i++;
579                                 }
580                         }
581                         //-- Color bar --
582                         //clean colors
583                         int nPointsCTF=getSizeBarColor();
584                         if(nPointsCTF>0)
585                         {                       
586                                 _ctfun->RemoveAllPoints();
587                                 
588                                 int nCTFpoints=getSizeBarColor();
589                                 i=0;    
590                                 while(i<nCTFpoints)
591                                 {
592                                         getDataBarColorPoint(i,xi,r,g,b);
593                                         _ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
594                                         i++;
595                                 }
596                         }
597
598 //EED Borrame
599
600         /*
601          NOTE I NEED THE UPDATE
602         */
603         //if it was call from the clipping ctnrl panel
604         //if(wxvtkclipping3Dview!=NULL)
605         //{
606         //      wxvtkclipping3Dview->Refresh();
607
608         //}
609         //else if(wxvtkmpr3Dview!=NULL)
610         //{
611         //      wxvtkmpr3Dview->Refresh();
612
613         //}
614 }
615
616
617 //-----------------------
618 //Methods
619 //-----------------------
620
621 /*
622                 get number of points of the transference function
623         */
624         int HistogramDialog::getSizeTransferenceFunction()
625         {
626                 return histogramW->getSizeTransferenceFunction();
627                 
628         }
629         /*
630                 get number of points of the barColor
631         */
632         int HistogramDialog::getSizeBarColor()
633         {
634                 return histogramW->getSizeBarColor();
635         }
636         /*
637                 get a point of the transference function
638         */
639         void HistogramDialog::getTransferenceFunctionPoint(int index,int& x,int& y)
640         {
641                 histogramW->getTransferenceFunctionPoint(index,x,y);
642         }
643         /*
644                 get a  color int the bqr color
645         */
646         void HistogramDialog::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
647         {
648                 histogramW->getDataBarColorPoint(index,x,red,green,blue);
649         }
650         /*
651                 get a point of the Histogram
652                 given the grey value
653         */
654         int HistogramDialog::getHistogramPoint(int gValue)
655         {
656                 return histogramW->getHistogramPoint(gValue);
657         }
658
659         //--------------------
660         // bar Information
661         //---------------------
662         /*
663          Get the porcentage of the positions of 
664          the min,max and actual in the bar range
665         */
666         float HistogramDialog::getMaxShowedPorcentage()
667         {
668                 return histogramW->getMaxShowedPorcentage();
669         }
670         float HistogramDialog::getMinShowedPorcentage()
671         {
672                 return histogramW->getMinShowedPorcentage();
673         }
674         float HistogramDialog::getActualShowedPorcentage()
675         {
676                 return histogramW->getActualShowedPorcentage();
677         }
678         //---------------------------------------
679         // setting data in transferences function
680         // and in bar color
681         //----------------------------------------
682         bool  HistogramDialog::addPointToTransferenceFunction(double x, double y)
683         {
684                 return histogramW->addPointToTransferenceFunction(x,y);
685         }
686         bool  HistogramDialog::addColorPoint(double x,int red,int green, int blue)
687         {
688                 return histogramW->addColorPoint(x,red,green,blue);
689         }
690         //------------------------
691         //Erase data
692         //------------------------
693         
694         /*
695          Erase all the points that are in the transference function
696         */
697         void HistogramDialog::erasePointsTransferenceFunction()
698         {
699                 histogramW->erasePointsTransferenceFunction();
700         }
701         /*
702         Erase the  color points in the plotter
703         */
704         void HistogramDialog::eraseColorPoints()
705         {
706                 histogramW->eraseColorPoints();
707         }
708
709         //-------------------
710         // Getter and setters
711         //-------------------
712
713         void HistogramDialog::setCTF(vtkColorTransferFunction *cf)
714         {
715                 _ctfun=cf;
716         
717         }
718         void HistogramDialog:: setTF(vtkPiecewiseFunction *tf)
719         {
720                 _tfun=tf;
721         }
722
723         bool HistogramDialog::getRefreshed()
724         {
725                 return refreshed;
726         }
727         
728         void HistogramDialog::setVolumeMapper(vtkVolumeRayCastMapper* volMapper)
729         {
730                 volumeMapper=volMapper;
731         }
732         void HistogramDialog::setVolume(vtkVolume* vol)
733         {
734                 newvol=vol;     
735         }
736         //void HistogramDialog::setMPR3Dview(wxVtkMPR3DView *wxvtkmpr3Dview1)
737         //{
738         //      wxvtkmpr3Dview=wxvtkmpr3Dview1;
739         //}
740         //void HistogramDialog::setClipping3DView(wxVtkClipping3DView *wxvtkclipping3Dview1)
741         //{
742         //      wxvtkclipping3Dview=wxvtkclipping3Dview1;
743         //}
744
745
746         void  HistogramDialog::setTransferenceFunctionHasPoints(bool hasPoints)
747         {
748                 histogramW->setTransferenceFunctionHasPoints(hasPoints);
749         }
750         void  HistogramDialog::setTransferenceFunctionHasColor(bool hasColorPoints)
751         {
752                 histogramW->setTransferenceFunctionHasColor(hasColorPoints);
753         }
754
755         //--------------------
756         // plotter Information
757         //---------------------
758         void  HistogramDialog::updatePlotter()
759         {
760                 histogramW->updatePlotter();
761         }
762
763
764 /**
765 **      Initialize the histogram 
766 */
767         void HistogramDialog::initializeHistogram(vtkImageData* img){   
768                 _maxgreyvalue = img->GetScalarRange()[1];
769                 histogramW->initializeHistogram(img);
770         }
771 /**
772 **      Returns two vectors, the grey level of the point and its value, the value is between [0,1]
773 **/
774         void HistogramDialog::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
775
776                 histogramW->GetValuesPointsFunction(greylevel, value);
777         }
778
779 /**
780 **      Returns two vectors, the grey level of the point and its value, the red, green
781 **      and blue value is between [0,1]
782 **/
783 void HistogramDialog::GetValuesColorPointsFunction(std::vector<double>& greylevel,
784                                                                 std::vector<double>& red,
785                                                                 std::vector<double>& green,
786                                                                 std::vector<double>& blue)
787 {
788         histogramW->GetValuesColorPointsFunction(greylevel, red, green, blue);
789 }
790
791 void HistogramDialog::SetFunctions(vtkPiecewiseFunction* _opac, vtkColorTransferFunction* _color){
792         _tfun = _opac;
793         _ctfun = _color;        
794 }