--- /dev/null
+#include "HistogramDialogComboBox.h"
+#include <vector>
+
+#include "Edit.xpm"
+
+#include "creaSystem.h"
+#include "HistogramDialog.h"
+//-------------------------
+//Constructor
+//-------------------------
+HistogramDialogComboBox::HistogramDialogComboBox(wxWindow* parent)
+: wxPanel(parent)
+{
+
+ this->SetSizer(getBitmapCombo());
+ _img = NULL;
+ _currentitem = -1;
+ _maxgreyvalue=0;
+}
+
+HistogramDialogComboBox::~HistogramDialogComboBox(){
+
+
+}
+void HistogramDialogComboBox::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect){
+
+ _greyvect=greyvect;
+ _redvect=redvect;
+ _greenvect=greenvect;
+ _bluevect=bluevect;
+
+}
+
+
+wxSizer* HistogramDialogComboBox::getBitmapCombo(){
+ _bitmapsizer = new wxBoxSizer(wxHORIZONTAL);
+
+ _bitmapcombo = getBitmapComboElements();
+
+ wxBitmap bitmap1(Edit_xpm);
+ wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
+ Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
+
+ _bitmapsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
+ _bitmapsizer->Add(edit,wxSizerFlags().Center());
+
+ return _bitmapsizer;
+
+}
+void HistogramDialogComboBox::setImageData(vtkImageData* img){
+ _maxgreyvalue = img->GetScalarRange()[1];
+ _img = img;
+}
+void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event){
+
+ if(_img!=NULL){
+
+ bool createaddandremovecontrols = true;
+ HistogramDialog* dialog = new HistogramDialog(this,_T("Color Configuration"),createaddandremovecontrols);
+ dialog->initializeHistogram(_img);
+ dialog->setInfoPanExtraControls(_bitmapsitems);
+
+ if(dialog->ShowModal()==wxID_OK){
+
+ dialog->UpdateCurrentComboElement();
+ _bitmapsitems = dialog->getComboBoxItems();
+
+
+ std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
+ currentpath.append(FILENAME);
+
+ std::vector<double> redvect,greenvect,bluevect;
+ std::vector<double> greyvect;
+
+ saveCurrentConfiguration(_bitmapsitems, currentpath);
+ wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
+ for(int i = 0; i < _bitmapsitems.size();i++){
+ delete _bitmapsitems[i];
+ }
+ _bitmapsitems.clear();
+ _bitmapcombo = getBitmapComboElements();
+ if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
+
+ tempbitmapcombo->Destroy();
+ }
+ this->Layout();
+ }
+ dialog->Destroy();
+ }
+
+
+
+}
+void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename){
+
+ std::ofstream file;
+ file.open( (const char*) (filename.c_str()) );
+ double gv=-1,red=-1,gr=-1,bl=-1;
+ int in=-1;
+
+
+
+ if(file.is_open())
+ {
+ file << "<ComboBoxData>" << std::endl;
+ for(int i = 0; i < itembitmaps.size();i++){
+ HistogramDialogComboBoxItem* item = itembitmaps[i];
+ std::vector<double> vecttransfer = item->getGreyVectorTransfer();
+ std::vector<double> value = item->getValueVector();
+
+ file << " <ComboBoxItem>"<< std::endl;
+ for(int j = 0; j < vecttransfer.size();j++){
+ if(j==0){
+ file << " <TransferenceFunction>"<< std::endl;
+ }
+ file << " <Transferencepoint>" << std::endl;
+ file << " <greyValue>" << vecttransfer[j] << "</greyValue>" <<std::endl;
+ file << " <intensity>" << value[j] << "</intensity> "<<std::endl;
+ file << " </Transferencepoint>" << std::endl;
+ if(j==vecttransfer.size()-1){
+ file << " </TransferenceFunction>"<< std::endl;
+ }
+ }
+ std::vector<double> greyv = item->getGreyVector();
+ std::vector<double> red = item->getRedVector();
+ std::vector<double> green = item->getGreenVector();
+ std::vector<double> blue = item->getBlueVector();
+ for(int j = 0; j < greyv.size();j++)
+ {
+ if(j==0){
+ file << " <Colors>" << std::endl;
+ }
+ file << " <greyValueRGBpoint>" << std::endl;
+ file << " <RGBgreyValue>" << greyv[j] << "</RGBgreyValue>" <<std::endl;
+ file << " <red>" << red[j] << "</red>" <<std::endl;
+ file << " <green>" << green[j] << "</green>" <<std::endl;
+ file << " <blue>" << blue[j] << "</blue>" <<std::endl;
+ file << " </greyValueRGBpoint>" << std::endl;
+ if(j==greyv.size()-1){
+ file << " </Colors>" << std::endl;
+ }
+ }
+
+ file << " </ComboBoxItem>"<< std::endl;
+
+ }
+ file << "</ComboBoxData>" << std::endl;
+
+ }
+ file.close();
+
+}
+
+wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements(){
+ std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
+ currentpath.append(FILENAME);
+
+ std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
+ OnLoadComboBoxData(bitmapsitems, currentpath);
+ _bitmapsitems = bitmapsitems;
+ wxString* choices;
+ choices = new wxString[bitmapsitems.size()];
+ for(int i = 0; i < bitmapsitems.size();i++){
+ choices[i] = _T("");
+ }
+ wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
+ bitmapcombo->SetSize(65,30);
+
+ Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
+
+
+ for(int i = 0; i < bitmapsitems.size(); i++){
+ bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
+ }
+
+
+ return bitmapcombo;
+}
+void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event){
+
+ if(_bitmapcombo!=NULL){
+ _currentitem = event.GetInt();
+ if(_bitmapsitems.size()>_currentitem){
+ HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[_currentitem];
+ _greyvect = currentconfig->getGreyVector();
+ _redvect = currentconfig->getRedVector();
+ _greenvect = currentconfig->getGreenVector();
+ _bluevect= currentconfig->getBlueVector();
+
+ _greyvecttransfer = currentconfig->getGreyVectorTransfer();
+ _value = currentconfig->getValueVector();
+ wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
+ ProcessEvent(newevent);
+ }
+
+ }
+
+}
+
+void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
+{
+ std::vector<double> redvect, greenvect, bluevect;
+ std::vector<double> greyvect, greyvecttransfunct, value;
+
+ redvect.clear();
+ greenvect.clear();
+ bluevect.clear();
+ greyvect.clear();
+ greyvecttransfunct.clear();
+ value.clear();
+
+ std::ifstream file;
+ file.open( (const char*) (filename.c_str()) );
+ double gv=-1,gvtransfer=-1,intensity=-1,red=-1,gr=-1,bl=-1;
+ int in=-1;
+
+ //std::cout<<filename<<std::endl;
+ itembitmaps.clear();
+ if(file.is_open())
+ {
+ bool add = false;
+ HistogramDialogComboBoxItem* item=NULL;
+ while(!file.eof())
+ {
+ std::string line;
+ std::getline(file,line);
+ //std::cout<<line<<std::endl;
+ if( (int)(line.find("<ComboBoxItem>")!=-1))
+ {
+ item = new HistogramDialogComboBoxItem();
+ }else if((int)(line.find("<greyValue>"))!=-1){
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ gvtransfer=atof(x.c_str());
+ greyvecttransfunct.push_back(gvtransfer);
+ }else if((int)(line.find("<intensity>"))!=-1){
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ intensity=atof(x.c_str());
+ value.push_back(intensity);
+ }
+ else if( (int)(line.find("<RGBgreyValue>"))!=-1)
+ {
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ gv=atof(x.c_str());
+ greyvect.push_back(gv);
+ }
+ else if( (int)(line.find("<red>"))!=-1)
+ {
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ red=atof(x.c_str());
+ redvect.push_back(red);
+ }
+ else if( (int)(line.find("<green>"))!=-1)
+ {
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ gr=atof(x.c_str());
+ greenvect.push_back(gr);
+ }
+ else if( (int)(line.find("<blue>"))!=-1 )
+ {
+ int pos1=line.find(">");
+ int pos2=line.find("<",pos1+1);
+ std::string x=line.substr(pos1+1,pos2-pos1-1);
+ bl=atof(x.c_str());
+ bluevect.push_back(bl);
+
+ }else if( (int)(line.find("</ComboBoxItem>"))!=-1 ){
+
+ item->SetColors(greyvect,redvect,greenvect,bluevect);
+ item->SetTransferFunction(greyvecttransfunct,value);
+ for(int i = 0; i < greyvecttransfunct.size();i++){
+ std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvecttransfunct[i]<<std::endl;
+ std::cout<<value[i]<<std::endl;
+ }
+ for(int i = 0; i < greyvect.size();i++){
+ std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<<greyvect[i]<<std::endl;
+ std::cout<<redvect[i]<<std::endl;
+ std::cout<<greenvect[i]<<std::endl;
+ std::cout<<bluevect[i]<<std::endl;
+ }
+
+ itembitmaps.push_back(item);
+
+
+ greyvecttransfunct.clear();
+ value.clear();
+ greyvect.clear();
+ redvect.clear();
+ greenvect.clear();
+ bluevect.clear();
+
+ }
+
+ line.clear();
+ }
+ file.close();
+ //std::cout<<itembitmaps.size()<<std::endl;
+ }
+
+}
+
+/**
+** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
+**/
+void HistogramDialogComboBox::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
+{
+ for(int i = 0; i < _greyvecttransfer.size();i++){
+ greylevel.push_back(_greyvecttransfer[i]*_maxgreyvalue);
+ value.push_back(_value[i]);
+
+
+ }
+}
+
+/**
+** Returns two vectors, the grey level of the point and its value, the red, green
+** and blue value is between [0,1]
+**/
+void HistogramDialogComboBox::GetValuesColorPointsFunction(std::vector<double>& greylevel,
+ std::vector<double>& red,
+ std::vector<double>& green,
+ std::vector<double>& blue)
+{
+
+ for(int i = 0; i < _greyvect.size();i++){
+ greylevel.push_back(_greyvect[i]*_maxgreyvalue);
+ red.push_back(_redvect[i]);
+ green.push_back(_greenvect[i]);
+ blue.push_back(_bluevect[i]);
+ }
+}
\ No newline at end of file
--- /dev/null
+
+#ifndef __HistogramDialogComboBox__
+#define __HistogramDialogComboBox__
+
+
+// ----------------------------------------------------------------------------
+// wx headers inclusion.
+// For compilers that support precompilation, includes <wx/wx.h>.
+// ----------------------------------------------------------------------------
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#include <wx/wx.h>
+#include <vector>
+
+#include "HistogramDialogComboBoxItem.h"
+#include <fstream>
+#include <wx/bmpcbox.h>
+#include "vtkImageData.h"
+
+
+#define FILENAME "/Data/colorsfunction.txt"
+
+
+class HistogramDialogComboBox : public wxPanel
+{
+public:
+ /*
+ Constructor
+ */
+ HistogramDialogComboBox(wxWindow* parent);
+ //HistogramDialogComboBox(int bar_width,int bar_height);
+ ~HistogramDialogComboBox();
+
+ void SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect);
+ wxBitmap GetBitmap();
+
+ std::vector<double> getGreyVector(){return _greyvect;}
+ std::vector<double> getRedVector(){return _redvect;}
+ std::vector<double> getGreenVector(){return _greenvect;}
+ std::vector<double> getBlueVector(){return _bluevect;}
+
+ void OnEditBitmapCombo(wxCommandEvent& event);
+ void OnBitmapComboItemSelected(wxCommandEvent& event);
+
+ void setImageData(vtkImageData* img);
+
+ /**
+ ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
+ **/
+ void GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value);
+
+ /**
+ ** Returns two vectors, the grey level of the point and its value, the red, green
+ ** and blue value is between [0,1]
+ **/
+ void GetValuesColorPointsFunction(std::vector<double>& greylevel,
+ std::vector<double>& red,
+ std::vector<double>& green,
+ std::vector<double>& blue);
+
+private:
+
+ std::vector<double> _greyvect;
+ std::vector<double> _redvect;
+ std::vector<double> _greenvect;
+ std::vector<double> _bluevect;
+ std::vector<double> _greyvecttransfer;
+ std::vector<double> _value;
+ vtkImageData* _img;
+ int _maxgreyvalue;
+ int _currentitem;
+
+ /*
+ * Represents the color of the backGround. Default color is the parent color.
+ */
+
+ wxBitmapComboBox* _bitmapcombo;
+ std::vector<HistogramDialogComboBoxItem*> _bitmapsitems;
+ wxBitmap* colorBar_Bitmap;
+ wxSizer* _bitmapsizer;
+
+ wxSizer* getBitmapCombo();
+ wxBitmapComboBox* getBitmapComboElements();
+ void OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename);
+ void saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename);
+
+};
+
+#endif
+
+
+
--- /dev/null
+#include "HistogramDialogComboBoxItem.h"
+#include <vector>
+
+//-------------------------
+//Constructor
+//-------------------------
+HistogramDialogComboBoxItem::HistogramDialogComboBoxItem()
+{
+
+ _bar_width = 30;
+ _bar_height = 20;
+
+
+ colorBar_Bitmap = new wxBitmap(_bar_width, _bar_height);
+
+}
+HistogramDialogComboBoxItem::HistogramDialogComboBoxItem( int bar_width,int bar_height)
+{
+
+ _bar_width = bar_width;
+ _bar_height = bar_height;
+
+ //_maxgreyvalue = maxgreyvalue;
+
+ colorBar_Bitmap = new wxBitmap(_bar_width, _bar_height);
+
+}
+HistogramDialogComboBoxItem::~HistogramDialogComboBoxItem(){
+
+
+}
+void HistogramDialogComboBoxItem::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect){
+
+ _greyvect=greyvect;
+ _redvect=redvect;
+ _greenvect=greenvect;
+ _bluevect=bluevect;
+
+ wxMemoryDC temp_dc;
+ temp_dc.SelectObject( *colorBar_Bitmap );
+ temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
+ temp_dc.SetPen(wxPen( colourParent,1,wxSOLID ));
+
+ temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);
+ temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID ));
+ temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);
+
+ double initial_r, initial_g, initial_b;
+ double next_r, next_g, next_b;
+ double initialgreyv=0, nextgreyv=0;
+
+ for (int i =0; i < _redvect.size(); i++){
+ initialgreyv = nextgreyv;
+ initial_r = _redvect[i]*255.0;
+ initial_g = _greenvect[i]*255.0;
+ initial_b = _bluevect[i]*255.0;
+
+ if(i < _redvect.size()-1){
+ nextgreyv = _greyvect[i+1];
+ next_r = _redvect[i+1]*255.0;
+ next_g = _greenvect[i+1]*255.0;
+ next_b = _bluevect[i+1]*255.0;
+ }else{
+ nextgreyv = 1;
+ next_r = initial_r;
+ next_g = initial_g;
+ next_b = initial_b;
+ }
+
+ int ini_pixelX=_bar_width*initialgreyv;
+ int end_pixelX=_bar_width*nextgreyv;
+
+ double m_scope_r = (double)(next_r-initial_r)/(end_pixelX-ini_pixelX);
+ double m_scope_g = (double)(next_g-initial_g)/(end_pixelX-ini_pixelX);
+ double m_scope_b = (double)(next_b-initial_b)/(end_pixelX-ini_pixelX);
+
+ next_r = initial_r;
+ next_g = initial_g;
+ next_b = initial_b;
+
+ for (int Xi =ini_pixelX; Xi<= end_pixelX; Xi++)
+ {
+ temp_dc.SetBrush(wxBrush( wxColour(next_r, next_g, next_b),wxSOLID ));
+ temp_dc.SetPen(wxPen( wxColour(next_r, next_g, next_b),1,wxSOLID ));
+
+ temp_dc.DrawLine(Xi, 0, Xi, _bar_height);
+
+ next_r = (int)(m_scope_r + next_r);
+ next_g = (int)(m_scope_g + next_g);
+ next_b = (int)(m_scope_b + next_b);
+ }
+ }
+}
+
+wxBitmap HistogramDialogComboBoxItem::GetBitmap(){
+
+ return *colorBar_Bitmap;
+}
+void HistogramDialogComboBoxItem::SetTransferFunction(std::vector<double> greyvect, std::vector<double> value){
+ _greyvecttransfunct = greyvect;
+ _value=value;
+}
\ No newline at end of file