1 #include "HistogramDialogComboBox.h"
6 #include "creaSystem.h"
7 #include "HistogramDialog.h"
8 //-------------------------
10 //-------------------------
11 HistogramDialogComboBox::HistogramDialogComboBox(wxWindow* parent)
17 _sliderwindowlevel = NULL;
18 colorBar_Bitmap = NULL;
21 this->SetSizer(getBitmapCombo());
25 printf("EED HistogramDialogComboBox\n");
27 std::string currentpath = crea::System::GetExecutablePath();
30 currentpath.append("../share/creaMaracasVisu/data/");
31 printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this directory\n");
32 currentpath = "/home/davila/dataHistogram";
35 crea::System::createDirectory(currentpath.c_str());
39 HistogramDialogComboBox::~HistogramDialogComboBox()
43 void HistogramDialogComboBox::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect)
47 _greenvect = greenvect;
51 wxSizer* HistogramDialogComboBox::getBitmapCombo()
53 //_bitmapsizer = new wxBoxSizer(wxVERTICAL);
54 _bitmapsizer = new wxBoxSizer(wxVERTICAL);
56 wxBoxSizer* comboeditsizer = new wxBoxSizer(wxHORIZONTAL);
57 _bitmapcombo = getBitmapComboElements();
59 wxBitmap bitmap1(Edit_xpm);
60 wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
61 Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
63 comboeditsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
64 comboeditsizer->Add(edit,wxSizerFlags().Center());
66 _bitmapsizer->Add(comboeditsizer,wxSizerFlags().FixedMinSize().Center());
67 _bitmapsizer->AddSpacer(5);
68 _bitmapsizer->Add(getSlidersWlCo(),wxSizerFlags().Expand().Center());
73 wxSizer* HistogramDialogComboBox::getSlidersWlCo()
75 wxBoxSizer* sizersliders = new wxBoxSizer(wxVERTICAL);
77 _slidercolor = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
78 _sliderwindowlevel = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
80 sizersliders->Add(_slidercolor,wxSizerFlags().Expand().Center());
81 sizersliders->Add(_sliderwindowlevel,wxSizerFlags().Expand().Center());
83 Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
84 Connect(_sliderwindowlevel->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnWindowLevelChanged);
89 double HistogramDialogComboBox::GetWindowLevel()
92 if(_sliderwindowlevel != NULL)
93 val= _sliderwindowlevel->GetValue();
97 double HistogramDialogComboBox::GetColorLevel()
100 if(_slidercolor != NULL)
101 val = _slidercolor->GetValue();
105 void HistogramDialogComboBox::OnColorLevelChanged(wxCommandEvent& event)
107 _slidercolor->GetValue();
108 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
109 ProcessEvent(newevent);
112 void HistogramDialogComboBox::OnWindowLevelChanged(wxCommandEvent& event)
114 _sliderwindowlevel->GetValue();
115 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
116 ProcessEvent(newevent);
119 void HistogramDialogComboBox::setImageData(vtkImageData* img)
121 _maxgreyvalue = img->GetScalarRange()[1];
126 void HistogramDialogComboBox::setSlidersValue()
129 if(_slidercolor!=NULL){
130 _slidercolor->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
131 _slidercolor->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
133 if(_sliderwindowlevel!=NULL){
134 _sliderwindowlevel->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
135 _sliderwindowlevel->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
140 void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event)
144 bool createaddandremovecontrols = true;
145 HistogramDialog* dialog = new HistogramDialog(this,_T("Color Configuration"),createaddandremovecontrols);
146 dialog->initializeHistogram(_img);
147 dialog->setInfoPanExtraControls(_bitmapsitems);
149 if(dialog->ShowModal()==wxID_OK)
151 dialog->UpdateCurrentComboElement();
152 _bitmapsitems = dialog->getComboBoxItems();
154 //std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); // JPR
155 std::string dllLastName;
156 std::string currentpath;
158 dllLastName = "bbcreaMaracasVisu";
159 currentpath = crea::System::GetDllAppPath(dllLastName);
162 currentpath = crea::System::GetExecutablePath();
163 currentpath.append("../share/creaMaracasVisu/data/");
165 currentpath.append(FILENAME);
167 std::vector<double> redvect,greenvect,bluevect;
168 std::vector<double> greyvect;
170 saveCurrentConfiguration(_bitmapsitems, currentpath);
171 wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
172 for(int i = 0; i < _bitmapsitems.size();i++){
173 delete _bitmapsitems[i];
175 _bitmapsitems.clear();
176 _bitmapcombo = getBitmapComboElements();
177 if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
179 tempbitmapcombo->Destroy();
187 void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename)
190 file.open( (const char*) (filename.c_str()) );
191 double gv=-1,red=-1,gr=-1,bl=-1;
196 file << "<ComboBoxData>" << std::endl;
197 for(int i = 0; i < itembitmaps.size();i++)
199 HistogramDialogComboBoxItem* item = itembitmaps[i];
200 std::vector<double> vecttransfer = item->getGreyVectorTransfer();
201 std::vector<double> value = item->getValueVector();
203 file << " <ComboBoxItem>"<< std::endl;
204 for(int j = 0; j < vecttransfer.size();j++)
207 file << " <TransferenceFunction>"<< std::endl;
209 file << " <Transferencepoint>" << std::endl;
210 file << " <greyValue>" << vecttransfer[j] << "</greyValue>" <<std::endl;
211 file << " <intensity>" << value[j] << "</intensity> "<<std::endl;
212 file << " </Transferencepoint>" << std::endl;
213 if(j==vecttransfer.size()-1){
214 file << " </TransferenceFunction>"<< std::endl;
217 std::vector<double> greyv = item->getGreyVector();
218 std::vector<double> red = item->getRedVector();
219 std::vector<double> green = item->getGreenVector();
220 std::vector<double> blue = item->getBlueVector();
221 for(int j = 0; j < greyv.size();j++)
224 file << " <Colors>" << std::endl;
226 file << " <greyValueRGBpoint>" << std::endl;
227 file << " <RGBgreyValue>" << greyv[j] << "</RGBgreyValue>" <<std::endl;
228 file << " <red>" << red[j] << "</red>" <<std::endl;
229 file << " <green>" << green[j] << "</green>" <<std::endl;
230 file << " <blue>" << blue[j] << "</blue>" <<std::endl;
231 file << " </greyValueRGBpoint>" << std::endl;
232 if(j==greyv.size()-1){
233 file << " </Colors>" << std::endl;
236 file << " </ComboBoxItem>"<< std::endl;
238 file << "</ComboBoxData>" << std::endl;
243 wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
245 std::string currentpath = "";
247 currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
250 currentpath = crea::System::GetExecutablePath();
251 currentpath.append("../share/CreaMaracasVisu/data/");
253 printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this file ******************\n");
254 currentpath = "/home/davila/dataHistogram";
257 currentpath.append(FILENAME);
259 std::cout<<"current file name " <<currentpath<<std::endl;
261 std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
262 OnLoadComboBoxData(bitmapsitems, currentpath);
263 _bitmapsitems = bitmapsitems;
265 choices = new wxString[bitmapsitems.size()];
266 for(int i = 0; i < bitmapsitems.size();i++)
270 wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
271 bitmapcombo->SetSize(65,30);
273 Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
275 for(int i = 0; i < bitmapsitems.size(); i++)
277 bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
282 void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
284 if(_bitmapcombo!=NULL)
286 _currentitem = event.GetInt();
287 if(_bitmapsitems.size()>_currentitem)
289 HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[_currentitem];
290 _greyvect = currentconfig->getGreyVector();
291 _redvect = currentconfig->getRedVector();
292 _greenvect = currentconfig->getGreenVector();
293 _bluevect= currentconfig->getBlueVector();
294 _greyvecttransfer = currentconfig->getGreyVectorTransfer();
295 _value = currentconfig->getValueVector();
296 wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
297 ProcessEvent(newevent);
302 void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
304 std::vector<double> redvect, greenvect, bluevect;
305 std::vector<double> greyvect, greyvecttransfunct, value;
311 greyvecttransfunct.clear();
315 file.open( (const char*) (filename.c_str()) );
316 double gv=-1,gvtransfer=-1,intensity=-1,red=-1,gr=-1,bl=-1;
319 //std::cout<<filename<<std::endl;
324 HistogramDialogComboBoxItem* item=NULL;
328 std::getline(file,line);
329 //std::cout<<line<<std::endl;
330 if( (int)(line.find("<ComboBoxItem>")!=-1))
332 item = new HistogramDialogComboBoxItem();
333 }else if((int)(line.find("<greyValue>"))!=-1) {
334 int pos1=line.find(">");
335 int pos2=line.find("<",pos1+1);
336 std::string x=line.substr(pos1+1,pos2-pos1-1);
337 gvtransfer=atof(x.c_str());
338 greyvecttransfunct.push_back(gvtransfer);
339 }else if((int)(line.find("<intensity>"))!=-1) {
340 int pos1=line.find(">");
341 int pos2=line.find("<",pos1+1);
342 std::string x=line.substr(pos1+1,pos2-pos1-1);
343 intensity=atof(x.c_str());
344 value.push_back(intensity);
346 else if( (int)(line.find("<RGBgreyValue>"))!=-1)
348 int pos1=line.find(">");
349 int pos2=line.find("<",pos1+1);
350 std::string x=line.substr(pos1+1,pos2-pos1-1);
352 greyvect.push_back(gv);
354 else if( (int)(line.find("<red>"))!=-1)
356 int pos1=line.find(">");
357 int pos2=line.find("<",pos1+1);
358 std::string x=line.substr(pos1+1,pos2-pos1-1);
360 redvect.push_back(red);
362 else if( (int)(line.find("<green>"))!=-1)
364 int pos1=line.find(">");
365 int pos2=line.find("<",pos1+1);
366 std::string x=line.substr(pos1+1,pos2-pos1-1);
368 greenvect.push_back(gr);
370 else if( (int)(line.find("<blue>"))!=-1 )
372 int pos1=line.find(">");
373 int pos2=line.find("<",pos1+1);
374 std::string x=line.substr(pos1+1,pos2-pos1-1);
376 bluevect.push_back(bl);
378 }else if( (int)(line.find("</ComboBoxItem>"))!=-1 ) {
380 item->SetColors(greyvect,redvect,greenvect,bluevect);
381 item->SetTransferFunction(greyvecttransfunct,value);
382 /*for(int i = 0; i < greyvecttransfunct.size();i++){
383 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvecttransfunct[i]<<std::endl;
384 std::cout<<value[i]<<std::endl;
386 for(int i = 0; i < greyvect.size();i++){
387 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvect[i]<<std::endl;
388 std::cout<<redvect[i]<<std::endl;
389 std::cout<<greenvect[i]<<std::endl;
390 std::cout<<bluevect[i]<<std::endl;
393 itembitmaps.push_back(item);
395 greyvecttransfunct.clear();
405 //std::cout<<itembitmaps.size()<<std::endl;
410 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
412 void HistogramDialogComboBox::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
414 for(int i = 0; i < _greyvecttransfer.size();i++) {
415 greylevel.push_back(_greyvecttransfer[i]*_maxgreyvalue);
416 value.push_back(_value[i]);
421 ** Returns two vectors, the grey level of the point and its value, the red, green
422 ** and blue value is between [0,1]
424 void HistogramDialogComboBox::GetValuesColorPointsFunction(std::vector<double>& greylevel,
425 std::vector<double>& red,
426 std::vector<double>& green,
427 std::vector<double>& blue)
429 for(int i = 0; i < _greyvect.size();i++) {
430 greylevel.push_back(_greyvect[i]*_maxgreyvalue);
431 red.push_back(_redvect[i]);
432 green.push_back(_greenvect[i]);
433 blue.push_back(_bluevect[i]);