1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "HistogramDialogComboBox.h"
31 #include "creaSystem.h"
32 #include "HistogramDialog.h"
33 //-------------------------
35 //-------------------------
36 HistogramDialogComboBox::HistogramDialogComboBox(wxWindow* parent)
42 _sliderwindowlevel = NULL;
44 colorBar_Bitmap = NULL;
46 InitCurrentPathColorsFuntion();
47 this->SetSizer(getBitmapCombo());
54 HistogramDialogComboBox::~HistogramDialogComboBox()
58 void HistogramDialogComboBox::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect)
62 _greenvect = greenvect;
66 wxSizer* HistogramDialogComboBox::getBitmapCombo()
68 //_bitmapsizer = new wxBoxSizer(wxVERTICAL);
69 _bitmapsizer = new wxBoxSizer(wxVERTICAL);
71 wxBoxSizer* comboeditsizer = new wxBoxSizer(wxHORIZONTAL);
72 _bitmapcombo = getBitmapComboElements();
73 BitmapComboItemSelect(0);
74 wxBitmap bitmap1(Edit_xpm);
75 wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
76 Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
77 _ckboxActive= new wxCheckBox( this,
81 //wxSize(sizeX,sizeY),
83 wxCHK_2STATE | wxALIGN_RIGHT);
84 _ckboxActive->SetValue(false);
86 Connect( _ckboxActive->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (void (wxPanel::*)(wxScrollEvent&)) &HistogramDialogComboBox::OnChkBoxActive);
88 comboeditsizer->Add(_ckboxActive,wxSizerFlags().Center().FixedMinSize());
89 comboeditsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
90 comboeditsizer->Add(edit,wxSizerFlags().Center());
91 _bitmapsizer->Add(comboeditsizer,wxSizerFlags().FixedMinSize().Center());
92 _bitmapsizer->AddSpacer(5);
93 _bitmapsizer->Add(getSlidersWlCo(),wxSizerFlags().Expand().Center());
97 wxSizer* HistogramDialogComboBox::getSlidersWlCo()
99 wxBoxSizer* sizersliders = new wxBoxSizer(wxVERTICAL);
100 _slidercolor = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
101 _sliderwindowlevel = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
102 sizersliders->Add(_slidercolor,wxSizerFlags().Expand().Center());
103 sizersliders->Add(_sliderwindowlevel,wxSizerFlags().Expand().Center());
104 Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
105 Connect(_sliderwindowlevel->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnWindowLevelChanged);
109 double HistogramDialogComboBox::GetWindowLevel()
112 if(_sliderwindowlevel != NULL)
114 val= _sliderwindowlevel->GetValue();
119 double HistogramDialogComboBox::GetColorLevel()
122 if(_slidercolor != NULL)
124 val = _slidercolor->GetValue();
130 bool HistogramDialogComboBox::GetActive()
133 if (_ckboxActive!=NULL)
135 result = _ckboxActive->GetValue();
141 void HistogramDialogComboBox::OnChkBoxActive(wxCommandEvent& event)
143 wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
144 ProcessEvent(newevent);
148 void HistogramDialogComboBox::OnColorLevelChanged(wxCommandEvent& event)
150 _slidercolor->GetValue();
151 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
152 ProcessEvent(newevent);
155 void HistogramDialogComboBox::OnWindowLevelChanged(wxCommandEvent& event)
157 _sliderwindowlevel->GetValue();
158 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
159 ProcessEvent(newevent);
162 void HistogramDialogComboBox::setImageData(vtkImageData* img)
164 _maxgreyvalue = img->GetScalarRange()[1];
169 void HistogramDialogComboBox::setSlidersValue()
172 if(_slidercolor!=NULL){
173 _slidercolor->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
174 _slidercolor->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
176 if(_sliderwindowlevel!=NULL){
177 _sliderwindowlevel->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
178 _sliderwindowlevel->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
183 void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event)
187 bool createaddandremovecontrols = true;
188 HistogramDialog* dialog = new HistogramDialog(this,_T("Color Configuration"),createaddandremovecontrols);
189 dialog->initializeHistogram(_img);
190 dialog->setInfoPanExtraControls(_bitmapsitems);
192 if(dialog->ShowModal()==wxID_OK)
194 dialog->UpdateCurrentComboElement();
195 _bitmapsitems = dialog->getComboBoxItems();
197 std::vector<double> redvect,greenvect,bluevect;
198 std::vector<double> greyvect;
200 saveCurrentConfiguration(_bitmapsitems, GetFileNameOfColorsFunction() );
201 wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
202 for(int i = 0; i < _bitmapsitems.size();i++)
204 delete _bitmapsitems[i];
206 _bitmapsitems.clear();
207 _bitmapcombo = getBitmapComboElements();
210 // if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo))
212 // tempbitmapcombo->Destroy();
214 // printf ("EED ERROR HistogramDialogComboBox::OnEditBitmapCombo. Can't replace bitmapcombo \n");
224 void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename)
227 file.open( (const char*) (filename.c_str()) );
228 double gv=-1,red=-1,gr=-1,bl=-1;
233 file << "<ComboBoxData>" << std::endl;
234 for(int i = 0; i < itembitmaps.size();i++)
236 HistogramDialogComboBoxItem* item = itembitmaps[i];
237 std::vector<double> vecttransfer = item->getGreyVectorTransfer();
238 std::vector<double> value = item->getValueVector();
240 file << " <ComboBoxItem>"<< std::endl;
241 for(int j = 0; j < vecttransfer.size();j++)
244 file << " <TransferenceFunction>"<< std::endl;
246 file << " <Transferencepoint>" << std::endl;
247 file << " <greyValue>" << vecttransfer[j] << "</greyValue>" <<std::endl;
248 file << " <intensity>" << value[j] << "</intensity> "<<std::endl;
249 file << " </Transferencepoint>" << std::endl;
250 if(j==vecttransfer.size()-1){
251 file << " </TransferenceFunction>"<< std::endl;
254 std::vector<double> greyv = item->getGreyVector();
255 std::vector<double> red = item->getRedVector();
256 std::vector<double> green = item->getGreenVector();
257 std::vector<double> blue = item->getBlueVector();
258 for(int j = 0; j < greyv.size();j++)
261 file << " <Colors>" << std::endl;
263 file << " <greyValueRGBpoint>" << std::endl;
264 file << " <RGBgreyValue>" << greyv[j] << "</RGBgreyValue>" <<std::endl;
265 file << " <red>" << red[j] << "</red>" <<std::endl;
266 file << " <green>" << green[j] << "</green>" <<std::endl;
267 file << " <blue>" << blue[j] << "</blue>" <<std::endl;
268 file << " </greyValueRGBpoint>" << std::endl;
269 if(j==greyv.size()-1){
270 file << " </Colors>" << std::endl;
273 file << " </ComboBoxItem>"<< std::endl;
275 file << "</ComboBoxData>" << std::endl;
280 void HistogramDialogComboBox::InitCurrentPathColorsFuntion()
282 _currentpathColorsFuntion = "";
284 _currentpathColorsFuntion = crea::System::GetDllAppPath("bbcreaMaracasVisu");
287 _currentpathColorsFuntion = crea::System::GetExecutablePath();
288 _currentpathColorsFuntion.append("/../share/creaMaracasVisu/data/");
290 crea::System::createDirectory(_currentpathColorsFuntion.c_str());
295 std::string HistogramDialogComboBox::GetFileNameOfColorsFunction()
297 std::string filename;
298 filename = _currentpathColorsFuntion;
299 filename.append(COLORSFUNCTIONFILENAME);
304 wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
306 std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
307 OnLoadComboBoxData(bitmapsitems, GetFileNameOfColorsFunction() );
308 _bitmapsitems = bitmapsitems;
310 choices = new wxString[bitmapsitems.size()];
311 for(int i = 0; i < bitmapsitems.size();i++)
313 choices[i] = _T("Color Function");
316 wxBitmapComboBox* bitmapcombo;
317 //EED wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
318 if (_bitmapcombo!=NULL)
320 _bitmapcombo->Clear();
321 bitmapcombo=_bitmapcombo;
323 bitmapcombo = new wxBitmapComboBox(this, -1, _T(""));
325 // wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""));
326 bitmapcombo->SetSize(165,30);
328 Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
330 for(int i = 0; i < bitmapsitems.size(); i++)
332 bitmapcombo->Append(_T("ColorFunction"), bitmapsitems[i]->GetBitmap() );
333 // bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
335 BitmapComboItemSelect(0);
340 void HistogramDialogComboBox::BitmapComboItemSelect(int value)
342 HistogramDialogComboBoxItem* currentconfig;
343 if(_bitmapcombo!=NULL)
345 _currentitem = value;
346 _bitmapcombo->Select(value);
347 if(_bitmapsitems.size()>_currentitem)
349 currentconfig = _bitmapsitems[_currentitem];
350 _greyvect = currentconfig->getGreyVector();
351 _redvect = currentconfig->getRedVector();
352 _greenvect = currentconfig->getGreenVector();
353 _bluevect = currentconfig->getBlueVector();
354 _greyvecttransfer = currentconfig->getGreyVectorTransfer();
355 _value = currentconfig->getValueVector();
356 wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
357 ProcessEvent(newevent);
363 void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
365 BitmapComboItemSelect( event.GetInt() );
368 void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
370 std::vector<double> redvect, greenvect, bluevect;
371 std::vector<double> greyvect, greyvecttransfunct, value;
377 greyvecttransfunct.clear();
381 file.open( (const char*) (filename.c_str()) );
382 double gv=-1,gvtransfer=-1,intensity=-1,red=-1,gr=-1,bl=-1;
385 //std::cout<<filename<<std::endl;
391 HistogramDialogComboBoxItem* item=NULL;
395 std::getline(file,line);
396 //std::cout<<line<<std::endl;
397 if( (int)(line.find("<ComboBoxItem>")!=-1))
399 item = new HistogramDialogComboBoxItem();
400 }else if((int)(line.find("<greyValue>"))!=-1) {
401 int pos1=line.find(">");
402 int pos2=line.find("<",pos1+1);
403 std::string x=line.substr(pos1+1,pos2-pos1-1);
404 gvtransfer=atof(x.c_str());
405 greyvecttransfunct.push_back(gvtransfer);
406 }else if((int)(line.find("<intensity>"))!=-1) {
407 int pos1=line.find(">");
408 int pos2=line.find("<",pos1+1);
409 std::string x=line.substr(pos1+1,pos2-pos1-1);
410 intensity=atof(x.c_str());
411 value.push_back(intensity);
413 else if( (int)(line.find("<RGBgreyValue>"))!=-1)
415 int pos1=line.find(">");
416 int pos2=line.find("<",pos1+1);
417 std::string x=line.substr(pos1+1,pos2-pos1-1);
419 greyvect.push_back(gv);
421 else if( (int)(line.find("<red>"))!=-1)
423 int pos1=line.find(">");
424 int pos2=line.find("<",pos1+1);
425 std::string x=line.substr(pos1+1,pos2-pos1-1);
427 redvect.push_back(red);
429 else if( (int)(line.find("<green>"))!=-1)
431 int pos1=line.find(">");
432 int pos2=line.find("<",pos1+1);
433 std::string x=line.substr(pos1+1,pos2-pos1-1);
435 greenvect.push_back(gr);
437 else if( (int)(line.find("<blue>"))!=-1 )
439 int pos1=line.find(">");
440 int pos2=line.find("<",pos1+1);
441 std::string x=line.substr(pos1+1,pos2-pos1-1);
443 bluevect.push_back(bl);
445 }else if( (int)(line.find("</ComboBoxItem>"))!=-1 ) {
447 item->SetColors(greyvect,redvect,greenvect,bluevect);
448 item->SetTransferFunction(greyvecttransfunct,value);
449 /*for(int i = 0; i < greyvecttransfunct.size();i++){
450 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvecttransfunct[i]<<std::endl;
451 std::cout<<value[i]<<std::endl;
453 for(int i = 0; i < greyvect.size();i++){
454 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvect[i]<<std::endl;
455 std::cout<<redvect[i]<<std::endl;
456 std::cout<<greenvect[i]<<std::endl;
457 std::cout<<bluevect[i]<<std::endl;
460 itembitmaps.push_back(item);
462 greyvecttransfunct.clear();
472 //std::cout<<itembitmaps.size()<<std::endl;
477 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
479 void HistogramDialogComboBox::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
481 for(int i = 0; i < _greyvecttransfer.size();i++) {
482 greylevel.push_back(_greyvecttransfer[i]*_maxgreyvalue);
483 value.push_back(_value[i]);
488 ** Returns two vectors, the grey level of the point and its value, the red, green
489 ** and blue value is between [0,1]
491 void HistogramDialogComboBox::GetValuesColorPointsFunction(std::vector<double>& greylevel,
492 std::vector<double>& red,
493 std::vector<double>& green,
494 std::vector<double>& blue)
496 for(int i = 0; i < _greyvect.size();i++) {
497 greylevel.push_back(_greyvect[i]*_maxgreyvalue);
498 red.push_back(_redvect[i]);
499 green.push_back(_greenvect[i]);
500 blue.push_back(_bluevect[i]);