From: Juan Prieto Date: Fri, 7 Aug 2009 14:56:27 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: EED.02Oct2009~7 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=67508e2c541ebe1a7ab4f3a401fcb8bb53984fc8;p=creaMaracasVisu.git *** empty log message *** --- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.cxx new file mode 100644 index 0000000..6c8dcd3 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.cxx @@ -0,0 +1,340 @@ +#include "HistogramDialogComboBox.h" +#include + +#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 greyvect, std::vector redvect, std::vector greenvect, std::vector 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 redvect,greenvect,bluevect; + std::vector 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& 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 << "" << std::endl; + for(int i = 0; i < itembitmaps.size();i++){ + HistogramDialogComboBoxItem* item = itembitmaps[i]; + std::vector vecttransfer = item->getGreyVectorTransfer(); + std::vector value = item->getValueVector(); + + file << " "<< std::endl; + for(int j = 0; j < vecttransfer.size();j++){ + if(j==0){ + file << " "<< std::endl; + } + file << " " << std::endl; + file << " " << vecttransfer[j] << "" <" << value[j] << " "<" << std::endl; + if(j==vecttransfer.size()-1){ + file << " "<< std::endl; + } + } + std::vector greyv = item->getGreyVector(); + std::vector red = item->getRedVector(); + std::vector green = item->getGreenVector(); + std::vector blue = item->getBlueVector(); + for(int j = 0; j < greyv.size();j++) + { + if(j==0){ + file << " " << std::endl; + } + file << " " << std::endl; + file << " " << greyv[j] << "" <" << red[j] << "" <" << green[j] << "" <" << blue[j] << "" <" << std::endl; + if(j==greyv.size()-1){ + file << " " << std::endl; + } + } + + file << " "<< std::endl; + + } + file << "" << std::endl; + + } + file.close(); + +} + +wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements(){ + std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); + currentpath.append(FILENAME); + + std::vector 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& itembitmaps, std::string filename) +{ + std::vector redvect, greenvect, bluevect; + std::vector 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<")!=-1)) + { + item = new HistogramDialogComboBoxItem(); + }else if((int)(line.find(""))!=-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(""))!=-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(""))!=-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(""))!=-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(""))!=-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(""))!=-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(""))!=-1 ){ + + item->SetColors(greyvect,redvect,greenvect,bluevect); + item->SetTransferFunction(greyvecttransfunct,value); + for(int i = 0; i < greyvecttransfunct.size();i++){ + std::cout<<"HistogramDialogComboBox::OnLoadComboBoxData("<& greylevel,std::vector& 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& greylevel, + std::vector& red, + std::vector& green, + std::vector& 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 diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.h new file mode 100644 index 0000000..578fdf5 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.h @@ -0,0 +1,95 @@ + +#ifndef __HistogramDialogComboBox__ +#define __HistogramDialogComboBox__ + + +// ---------------------------------------------------------------------------- +// wx headers inclusion. +// For compilers that support precompilation, includes . +// ---------------------------------------------------------------------------- + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include +#include + +#include "HistogramDialogComboBoxItem.h" +#include +#include +#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 greyvect, std::vector redvect, std::vector greenvect, std::vector bluevect); + wxBitmap GetBitmap(); + + std::vector getGreyVector(){return _greyvect;} + std::vector getRedVector(){return _redvect;} + std::vector getGreenVector(){return _greenvect;} + std::vector 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& greylevel,std::vector& 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& greylevel, + std::vector& red, + std::vector& green, + std::vector& blue); + +private: + + std::vector _greyvect; + std::vector _redvect; + std::vector _greenvect; + std::vector _bluevect; + std::vector _greyvecttransfer; + std::vector _value; + vtkImageData* _img; + int _maxgreyvalue; + int _currentitem; + + /* + * Represents the color of the backGround. Default color is the parent color. + */ + + wxBitmapComboBox* _bitmapcombo; + std::vector _bitmapsitems; + wxBitmap* colorBar_Bitmap; + wxSizer* _bitmapsizer; + + wxSizer* getBitmapCombo(); + wxBitmapComboBox* getBitmapComboElements(); + void OnLoadComboBoxData(std::vector& itembitmaps,std::string filename); + void saveCurrentConfiguration(std::vector& itembitmaps,std::string filename); + +}; + +#endif + + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.cxx new file mode 100644 index 0000000..9ac95fa --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.cxx @@ -0,0 +1,102 @@ +#include "HistogramDialogComboBoxItem.h" +#include + +//------------------------- +//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 greyvect, std::vector redvect, std::vector greenvect, std::vector 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 greyvect, std::vector value){ + _greyvecttransfunct = greyvect; + _value=value; +} \ No newline at end of file diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.h new file mode 100644 index 0000000..06ff848 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.h @@ -0,0 +1,65 @@ + +#ifndef __HistogramDialogComboBoxItem__ +#define __HistogramDialogComboBoxItem__ + + +// ---------------------------------------------------------------------------- +// wx headers inclusion. +// For compilers that support precompilation, includes . +// ---------------------------------------------------------------------------- + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include +#include + +class HistogramDialogComboBoxItem +{ +public: + /* + Constructor + */ + HistogramDialogComboBoxItem(); + HistogramDialogComboBoxItem(int bar_width,int bar_height); + ~HistogramDialogComboBoxItem(); + + void SetColors(std::vector greyvect, std::vector redvect, std::vector greenvect, std::vector bluevect); + void SetTransferFunction(std::vector greyvect, std::vector value); + wxBitmap GetBitmap(); + + std::vector getGreyVector(){return _greyvect;} + std::vector getRedVector(){return _redvect;} + std::vector getGreenVector(){return _greenvect;} + std::vector getBlueVector(){return _bluevect;} + + std::vector getGreyVectorTransfer(){return _greyvecttransfunct;} + std::vector getValueVector(){return _value;} +private: + + + std::vector _greyvect; + std::vector _redvect; + std::vector _greenvect; + std::vector _bluevect; + + std::vector _greyvecttransfunct; + std::vector _value; + + /* + * Represents the color of the backGround. Default color is the parent color. + */ + wxColour colourParent; + + int _bar_width; + int _bar_height; + + wxBitmap* colorBar_Bitmap; + +}; + +#endif + + +