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");
28 HistogramDialogComboBox::~HistogramDialogComboBox()
32 void HistogramDialogComboBox::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect)
36 _greenvect = greenvect;
40 wxSizer* HistogramDialogComboBox::getBitmapCombo()
42 //_bitmapsizer = new wxBoxSizer(wxVERTICAL);
43 _bitmapsizer = new wxBoxSizer(wxVERTICAL);
45 wxBoxSizer* comboeditsizer = new wxBoxSizer(wxHORIZONTAL);
46 _bitmapcombo = getBitmapComboElements();
48 wxBitmap bitmap1(Edit_xpm);
49 wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
50 Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
52 comboeditsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
53 comboeditsizer->Add(edit,wxSizerFlags().Center());
55 _bitmapsizer->Add(comboeditsizer,wxSizerFlags().FixedMinSize().Center());
56 _bitmapsizer->AddSpacer(5);
57 _bitmapsizer->Add(getSlidersWlCo(),wxSizerFlags().Expand().Center());
62 wxSizer* HistogramDialogComboBox::getSlidersWlCo()
64 wxBoxSizer* sizersliders = new wxBoxSizer(wxVERTICAL);
66 _slidercolor = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
67 _sliderwindowlevel = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
69 sizersliders->Add(_slidercolor,wxSizerFlags().Expand().Center());
70 sizersliders->Add(_sliderwindowlevel,wxSizerFlags().Expand().Center());
72 Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
73 Connect(_sliderwindowlevel->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnWindowLevelChanged);
78 double HistogramDialogComboBox::GetWindowLevel()
81 if(_sliderwindowlevel != NULL)
82 val= _sliderwindowlevel->GetValue();
86 double HistogramDialogComboBox::GetColorLevel()
89 if(_slidercolor != NULL)
90 val = _slidercolor->GetValue();
94 void HistogramDialogComboBox::OnColorLevelChanged(wxCommandEvent& event)
96 _slidercolor->GetValue();
97 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
98 ProcessEvent(newevent);
101 void HistogramDialogComboBox::OnWindowLevelChanged(wxCommandEvent& event)
103 _sliderwindowlevel->GetValue();
104 wxCommandEvent newevent(wxEVT_SCROLL_THUMBTRACK,this->GetId());
105 ProcessEvent(newevent);
108 void HistogramDialogComboBox::setImageData(vtkImageData* img)
110 _maxgreyvalue = img->GetScalarRange()[1];
115 void HistogramDialogComboBox::setSlidersValue()
118 if(_slidercolor!=NULL){
119 _slidercolor->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
120 _slidercolor->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
122 if(_sliderwindowlevel!=NULL){
123 _sliderwindowlevel->SetRange(_img->GetScalarRange()[0],_img->GetScalarRange()[1]);
124 _sliderwindowlevel->SetValue((_img->GetScalarRange()[0]+_img->GetScalarRange()[1])/2);
129 void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event)
133 bool createaddandremovecontrols = true;
134 HistogramDialog* dialog = new HistogramDialog(this,_T("Color Configuration"),createaddandremovecontrols);
135 dialog->initializeHistogram(_img);
136 dialog->setInfoPanExtraControls(_bitmapsitems);
138 if(dialog->ShowModal()==wxID_OK)
140 dialog->UpdateCurrentComboElement();
141 _bitmapsitems = dialog->getComboBoxItems();
143 //std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); // JPR
144 std::string dllLastName("bbcreaMaracasVisu");
145 std::string currentpath = crea::System::GetDllAppPath(dllLastName);
146 currentpath.append(FILENAME);
148 std::vector<double> redvect,greenvect,bluevect;
149 std::vector<double> greyvect;
151 saveCurrentConfiguration(_bitmapsitems, currentpath);
152 wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
153 for(int i = 0; i < _bitmapsitems.size();i++){
154 delete _bitmapsitems[i];
156 _bitmapsitems.clear();
157 _bitmapcombo = getBitmapComboElements();
158 if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
160 tempbitmapcombo->Destroy();
168 void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename)
171 file.open( (const char*) (filename.c_str()) );
172 double gv=-1,red=-1,gr=-1,bl=-1;
177 file << "<ComboBoxData>" << std::endl;
178 for(int i = 0; i < itembitmaps.size();i++)
180 HistogramDialogComboBoxItem* item = itembitmaps[i];
181 std::vector<double> vecttransfer = item->getGreyVectorTransfer();
182 std::vector<double> value = item->getValueVector();
184 file << " <ComboBoxItem>"<< std::endl;
185 for(int j = 0; j < vecttransfer.size();j++)
188 file << " <TransferenceFunction>"<< std::endl;
190 file << " <Transferencepoint>" << std::endl;
191 file << " <greyValue>" << vecttransfer[j] << "</greyValue>" <<std::endl;
192 file << " <intensity>" << value[j] << "</intensity> "<<std::endl;
193 file << " </Transferencepoint>" << std::endl;
194 if(j==vecttransfer.size()-1){
195 file << " </TransferenceFunction>"<< std::endl;
198 std::vector<double> greyv = item->getGreyVector();
199 std::vector<double> red = item->getRedVector();
200 std::vector<double> green = item->getGreenVector();
201 std::vector<double> blue = item->getBlueVector();
202 for(int j = 0; j < greyv.size();j++)
205 file << " <Colors>" << std::endl;
207 file << " <greyValueRGBpoint>" << std::endl;
208 file << " <RGBgreyValue>" << greyv[j] << "</RGBgreyValue>" <<std::endl;
209 file << " <red>" << red[j] << "</red>" <<std::endl;
210 file << " <green>" << green[j] << "</green>" <<std::endl;
211 file << " <blue>" << blue[j] << "</blue>" <<std::endl;
212 file << " </greyValueRGBpoint>" << std::endl;
213 if(j==greyv.size()-1){
214 file << " </Colors>" << std::endl;
217 file << " </ComboBoxItem>"<< std::endl;
219 file << "</ComboBoxData>" << std::endl;
224 wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
226 std::string currentpath = "";
228 currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
230 currentpath.append(FILENAME);
232 std::cout<<"current file name " <<currentpath<<std::endl;
234 std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
235 OnLoadComboBoxData(bitmapsitems, currentpath);
236 _bitmapsitems = bitmapsitems;
238 choices = new wxString[bitmapsitems.size()];
239 for(int i = 0; i < bitmapsitems.size();i++)
243 wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
244 bitmapcombo->SetSize(65,30);
246 Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
248 for(int i = 0; i < bitmapsitems.size(); i++)
250 bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
255 void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
257 if(_bitmapcombo!=NULL)
259 _currentitem = event.GetInt();
260 if(_bitmapsitems.size()>_currentitem)
262 HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[_currentitem];
263 _greyvect = currentconfig->getGreyVector();
264 _redvect = currentconfig->getRedVector();
265 _greenvect = currentconfig->getGreenVector();
266 _bluevect= currentconfig->getBlueVector();
267 _greyvecttransfer = currentconfig->getGreyVectorTransfer();
268 _value = currentconfig->getValueVector();
269 wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
270 ProcessEvent(newevent);
275 void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
277 std::vector<double> redvect, greenvect, bluevect;
278 std::vector<double> greyvect, greyvecttransfunct, value;
284 greyvecttransfunct.clear();
288 file.open( (const char*) (filename.c_str()) );
289 double gv=-1,gvtransfer=-1,intensity=-1,red=-1,gr=-1,bl=-1;
292 //std::cout<<filename<<std::endl;
297 HistogramDialogComboBoxItem* item=NULL;
301 std::getline(file,line);
302 //std::cout<<line<<std::endl;
303 if( (int)(line.find("<ComboBoxItem>")!=-1))
305 item = new HistogramDialogComboBoxItem();
306 }else if((int)(line.find("<greyValue>"))!=-1) {
307 int pos1=line.find(">");
308 int pos2=line.find("<",pos1+1);
309 std::string x=line.substr(pos1+1,pos2-pos1-1);
310 gvtransfer=atof(x.c_str());
311 greyvecttransfunct.push_back(gvtransfer);
312 }else if((int)(line.find("<intensity>"))!=-1) {
313 int pos1=line.find(">");
314 int pos2=line.find("<",pos1+1);
315 std::string x=line.substr(pos1+1,pos2-pos1-1);
316 intensity=atof(x.c_str());
317 value.push_back(intensity);
319 else if( (int)(line.find("<RGBgreyValue>"))!=-1)
321 int pos1=line.find(">");
322 int pos2=line.find("<",pos1+1);
323 std::string x=line.substr(pos1+1,pos2-pos1-1);
325 greyvect.push_back(gv);
327 else if( (int)(line.find("<red>"))!=-1)
329 int pos1=line.find(">");
330 int pos2=line.find("<",pos1+1);
331 std::string x=line.substr(pos1+1,pos2-pos1-1);
333 redvect.push_back(red);
335 else if( (int)(line.find("<green>"))!=-1)
337 int pos1=line.find(">");
338 int pos2=line.find("<",pos1+1);
339 std::string x=line.substr(pos1+1,pos2-pos1-1);
341 greenvect.push_back(gr);
343 else if( (int)(line.find("<blue>"))!=-1 )
345 int pos1=line.find(">");
346 int pos2=line.find("<",pos1+1);
347 std::string x=line.substr(pos1+1,pos2-pos1-1);
349 bluevect.push_back(bl);
351 }else if( (int)(line.find("</ComboBoxItem>"))!=-1 ) {
353 item->SetColors(greyvect,redvect,greenvect,bluevect);
354 item->SetTransferFunction(greyvecttransfunct,value);
355 /*for(int i = 0; i < greyvecttransfunct.size();i++){
356 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvecttransfunct[i]<<std::endl;
357 std::cout<<value[i]<<std::endl;
359 for(int i = 0; i < greyvect.size();i++){
360 std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvect[i]<<std::endl;
361 std::cout<<redvect[i]<<std::endl;
362 std::cout<<greenvect[i]<<std::endl;
363 std::cout<<bluevect[i]<<std::endl;
366 itembitmaps.push_back(item);
368 greyvecttransfunct.clear();
378 //std::cout<<itembitmaps.size()<<std::endl;
383 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
385 void HistogramDialogComboBox::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
387 for(int i = 0; i < _greyvecttransfer.size();i++) {
388 greylevel.push_back(_greyvecttransfer[i]*_maxgreyvalue);
389 value.push_back(_value[i]);
394 ** Returns two vectors, the grey level of the point and its value, the red, green
395 ** and blue value is between [0,1]
397 void HistogramDialogComboBox::GetValuesColorPointsFunction(std::vector<double>& greylevel,
398 std::vector<double>& red,
399 std::vector<double>& green,
400 std::vector<double>& blue)
402 for(int i = 0; i < _greyvect.size();i++) {
403 greylevel.push_back(_greyvect[i]*_maxgreyvalue);
404 red.push_back(_redvect[i]);
405 green.push_back(_greenvect[i]);
406 blue.push_back(_bluevect[i]);