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;
43 colorBar_Bitmap = NULL;
46 this->SetSizer(getBitmapCombo());
50 printf("EED HistogramDialogComboBox\n");
52 std::string currentpath = crea::System::GetExecutablePath();
55 currentpath.append("../share/creaMaracasVisu/data/");
56 printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this directory\n");
57 currentpath = "/home/davila/dataHistogram";
60 crea::System::createDirectory(currentpath.c_str());
64 HistogramDialogComboBox::~HistogramDialogComboBox()
68 void HistogramDialogComboBox::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect)
72 _greenvect = greenvect;
76 wxSizer* HistogramDialogComboBox::getBitmapCombo()
78 //_bitmapsizer = new wxBoxSizer(wxVERTICAL);
79 _bitmapsizer = new wxBoxSizer(wxVERTICAL);
81 wxBoxSizer* comboeditsizer = new wxBoxSizer(wxHORIZONTAL);
82 _bitmapcombo = getBitmapComboElements();
84 wxBitmap bitmap1(Edit_xpm);
85 wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
86 Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
88 comboeditsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
89 comboeditsizer->Add(edit,wxSizerFlags().Center());
91 _bitmapsizer->Add(comboeditsizer,wxSizerFlags().FixedMinSize().Center());
92 _bitmapsizer->AddSpacer(5);
93 _bitmapsizer->Add(getSlidersWlCo(),wxSizerFlags().Expand().Center());
98 wxSizer* HistogramDialogComboBox::getSlidersWlCo()
100 wxBoxSizer* sizersliders = new wxBoxSizer(wxVERTICAL);
102 _slidercolor = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
103 _sliderwindowlevel = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
105 sizersliders->Add(_slidercolor,wxSizerFlags().Expand().Center());
106 sizersliders->Add(_sliderwindowlevel,wxSizerFlags().Expand().Center());
108 Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
109 Connect(_sliderwindowlevel->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnWindowLevelChanged);
114 double HistogramDialogComboBox::GetWindowLevel()
117 if(_sliderwindowlevel != NULL)
118 val= _sliderwindowlevel->GetValue();
122 double HistogramDialogComboBox::GetColorLevel()
125 if(_slidercolor != NULL)
126 val = _slidercolor->GetValue();
130 void HistogramDialogComboBox::OnColorLevelChanged(wxCommandEvent& event)
132 _slidercolor->GetValue();
133 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
134 ProcessEvent(newevent);
137 void HistogramDialogComboBox::OnWindowLevelChanged(wxCommandEvent& event)
139 _sliderwindowlevel->GetValue();
140 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
141 ProcessEvent(newevent);
144 void HistogramDialogComboBox::setImageData(vtkImageData* img)
146 _maxgreyvalue = img->GetScalarRange()[1];
151 void HistogramDialogComboBox::setSlidersValue()
154 if(_slidercolor!=NULL){
155 _slidercolor->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
156 _slidercolor->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
158 if(_sliderwindowlevel!=NULL){
159 _sliderwindowlevel->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
160 _sliderwindowlevel->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
165 void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event)
169 bool createaddandremovecontrols = true;
170 HistogramDialog* dialog = new HistogramDialog(this,_T("Color Configuration"),createaddandremovecontrols);
171 dialog->initializeHistogram(_img);
172 dialog->setInfoPanExtraControls(_bitmapsitems);
174 if(dialog->ShowModal()==wxID_OK)
176 dialog->UpdateCurrentComboElement();
177 _bitmapsitems = dialog->getComboBoxItems();
179 //std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); // JPR
180 std::string dllLastName;
181 std::string currentpath;
183 dllLastName = "bbcreaMaracasVisu";
184 currentpath = crea::System::GetDllAppPath(dllLastName);
187 currentpath = crea::System::GetExecutablePath();
188 currentpath.append("../share/creaMaracasVisu/data/");
190 currentpath.append(FILENAME);
192 std::vector<double> redvect,greenvect,bluevect;
193 std::vector<double> greyvect;
195 saveCurrentConfiguration(_bitmapsitems, currentpath);
196 wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
197 for(int i = 0; i < _bitmapsitems.size();i++){
198 delete _bitmapsitems[i];
200 _bitmapsitems.clear();
201 _bitmapcombo = getBitmapComboElements();
202 if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
204 tempbitmapcombo->Destroy();
212 void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename)
215 file.open( (const char*) (filename.c_str()) );
216 double gv=-1,red=-1,gr=-1,bl=-1;
221 file << "<ComboBoxData>" << std::endl;
222 for(int i = 0; i < itembitmaps.size();i++)
224 HistogramDialogComboBoxItem* item = itembitmaps[i];
225 std::vector<double> vecttransfer = item->getGreyVectorTransfer();
226 std::vector<double> value = item->getValueVector();
228 file << " <ComboBoxItem>"<< std::endl;
229 for(int j = 0; j < vecttransfer.size();j++)
232 file << " <TransferenceFunction>"<< std::endl;
234 file << " <Transferencepoint>" << std::endl;
235 file << " <greyValue>" << vecttransfer[j] << "</greyValue>" <<std::endl;
236 file << " <intensity>" << value[j] << "</intensity> "<<std::endl;
237 file << " </Transferencepoint>" << std::endl;
238 if(j==vecttransfer.size()-1){
239 file << " </TransferenceFunction>"<< std::endl;
242 std::vector<double> greyv = item->getGreyVector();
243 std::vector<double> red = item->getRedVector();
244 std::vector<double> green = item->getGreenVector();
245 std::vector<double> blue = item->getBlueVector();
246 for(int j = 0; j < greyv.size();j++)
249 file << " <Colors>" << std::endl;
251 file << " <greyValueRGBpoint>" << std::endl;
252 file << " <RGBgreyValue>" << greyv[j] << "</RGBgreyValue>" <<std::endl;
253 file << " <red>" << red[j] << "</red>" <<std::endl;
254 file << " <green>" << green[j] << "</green>" <<std::endl;
255 file << " <blue>" << blue[j] << "</blue>" <<std::endl;
256 file << " </greyValueRGBpoint>" << std::endl;
257 if(j==greyv.size()-1){
258 file << " </Colors>" << std::endl;
261 file << " </ComboBoxItem>"<< std::endl;
263 file << "</ComboBoxData>" << std::endl;
268 wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
270 std::string currentpath = "";
272 currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
275 currentpath = crea::System::GetExecutablePath();
276 currentpath.append("../share/CreaMaracasVisu/data/");
278 printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this file ******************\n");
279 currentpath = "/home/davila/dataHistogram";
282 currentpath.append(FILENAME);
284 std::cout<<"current file name " <<currentpath<<std::endl;
286 std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
287 OnLoadComboBoxData(bitmapsitems, currentpath);
288 _bitmapsitems = bitmapsitems;
290 choices = new wxString[bitmapsitems.size()];
291 for(int i = 0; i < bitmapsitems.size();i++)
295 wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
296 bitmapcombo->SetSize(65,30);
298 Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
300 for(int i = 0; i < bitmapsitems.size(); i++)
302 bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
307 void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
309 if(_bitmapcombo!=NULL)
311 _currentitem = event.GetInt();
312 if(_bitmapsitems.size()>_currentitem)
314 HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[_currentitem];
315 _greyvect = currentconfig->getGreyVector();
316 _redvect = currentconfig->getRedVector();
317 _greenvect = currentconfig->getGreenVector();
318 _bluevect= currentconfig->getBlueVector();
319 _greyvecttransfer = currentconfig->getGreyVectorTransfer();
320 _value = currentconfig->getValueVector();
321 wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
322 ProcessEvent(newevent);
327 void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
329 std::vector<double> redvect, greenvect, bluevect;
330 std::vector<double> greyvect, greyvecttransfunct, value;
336 greyvecttransfunct.clear();
340 file.open( (const char*) (filename.c_str()) );
341 double gv=-1,gvtransfer=-1,intensity=-1,red=-1,gr=-1,bl=-1;
344 //std::cout<<filename<<std::endl;
349 HistogramDialogComboBoxItem* item=NULL;
353 std::getline(file,line);
354 //std::cout<<line<<std::endl;
355 if( (int)(line.find("<ComboBoxItem>")!=-1))
357 item = new HistogramDialogComboBoxItem();
358 }else if((int)(line.find("<greyValue>"))!=-1) {
359 int pos1=line.find(">");
360 int pos2=line.find("<",pos1+1);
361 std::string x=line.substr(pos1+1,pos2-pos1-1);
362 gvtransfer=atof(x.c_str());
363 greyvecttransfunct.push_back(gvtransfer);
364 }else if((int)(line.find("<intensity>"))!=-1) {
365 int pos1=line.find(">");
366 int pos2=line.find("<",pos1+1);
367 std::string x=line.substr(pos1+1,pos2-pos1-1);
368 intensity=atof(x.c_str());
369 value.push_back(intensity);
371 else if( (int)(line.find("<RGBgreyValue>"))!=-1)
373 int pos1=line.find(">");
374 int pos2=line.find("<",pos1+1);
375 std::string x=line.substr(pos1+1,pos2-pos1-1);
377 greyvect.push_back(gv);
379 else if( (int)(line.find("<red>"))!=-1)
381 int pos1=line.find(">");
382 int pos2=line.find("<",pos1+1);
383 std::string x=line.substr(pos1+1,pos2-pos1-1);
385 redvect.push_back(red);
387 else if( (int)(line.find("<green>"))!=-1)
389 int pos1=line.find(">");
390 int pos2=line.find("<",pos1+1);
391 std::string x=line.substr(pos1+1,pos2-pos1-1);
393 greenvect.push_back(gr);
395 else if( (int)(line.find("<blue>"))!=-1 )
397 int pos1=line.find(">");
398 int pos2=line.find("<",pos1+1);
399 std::string x=line.substr(pos1+1,pos2-pos1-1);
401 bluevect.push_back(bl);
403 }else if( (int)(line.find("</ComboBoxItem>"))!=-1 ) {
405 item->SetColors(greyvect,redvect,greenvect,bluevect);
406 item->SetTransferFunction(greyvecttransfunct,value);
407 /*for(int i = 0; i < greyvecttransfunct.size();i++){
408 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvecttransfunct[i]<<std::endl;
409 std::cout<<value[i]<<std::endl;
411 for(int i = 0; i < greyvect.size();i++){
412 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvect[i]<<std::endl;
413 std::cout<<redvect[i]<<std::endl;
414 std::cout<<greenvect[i]<<std::endl;
415 std::cout<<bluevect[i]<<std::endl;
418 itembitmaps.push_back(item);
420 greyvecttransfunct.clear();
430 //std::cout<<itembitmaps.size()<<std::endl;
435 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
437 void HistogramDialogComboBox::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
439 for(int i = 0; i < _greyvecttransfer.size();i++) {
440 greylevel.push_back(_greyvecttransfer[i]*_maxgreyvalue);
441 value.push_back(_value[i]);
446 ** Returns two vectors, the grey level of the point and its value, the red, green
447 ** and blue value is between [0,1]
449 void HistogramDialogComboBox::GetValuesColorPointsFunction(std::vector<double>& greylevel,
450 std::vector<double>& red,
451 std::vector<double>& green,
452 std::vector<double>& blue)
454 for(int i = 0; i < _greyvect.size();i++) {
455 greylevel.push_back(_greyvect[i]*_maxgreyvalue);
456 red.push_back(_redvect[i]);
457 green.push_back(_greenvect[i]);
458 blue.push_back(_bluevect[i]);