]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.cxx
9ac95faeead4fcf76362c622572b933396a1d762
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramDialogComboBoxItem.cxx
1 #include "HistogramDialogComboBoxItem.h"
2 #include <vector>
3
4 //-------------------------
5 //Constructor
6 //-------------------------
7 HistogramDialogComboBoxItem::HistogramDialogComboBoxItem()
8 {
9
10         _bar_width = 30;
11         _bar_height = 20;
12         
13
14         colorBar_Bitmap = new wxBitmap(_bar_width,      _bar_height);
15
16 }
17 HistogramDialogComboBoxItem::HistogramDialogComboBoxItem( int bar_width,int bar_height)
18 {
19
20         _bar_width = bar_width;
21         _bar_height = bar_height;
22
23         //_maxgreyvalue = maxgreyvalue;
24
25         colorBar_Bitmap = new wxBitmap(_bar_width,      _bar_height);
26
27 }
28 HistogramDialogComboBoxItem::~HistogramDialogComboBoxItem(){
29         
30         
31 }
32 void HistogramDialogComboBoxItem::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect){
33
34         _greyvect=greyvect;
35         _redvect=redvect;
36         _greenvect=greenvect;
37         _bluevect=bluevect;
38
39         wxMemoryDC temp_dc;
40         temp_dc.SelectObject( *colorBar_Bitmap );               
41         temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
42         temp_dc.SetPen(wxPen( colourParent,1,wxSOLID  ));
43         
44         temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);
45         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
46         temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);   
47
48         double initial_r, initial_g, initial_b; 
49         double next_r, next_g, next_b;
50         double initialgreyv=0, nextgreyv=0;
51         
52         for (int i =0; i < _redvect.size(); i++){
53                 initialgreyv = nextgreyv;
54                 initial_r = _redvect[i]*255.0;          
55                 initial_g = _greenvect[i]*255.0;                
56                 initial_b = _bluevect[i]*255.0;         
57
58                 if(i < _redvect.size()-1){
59                         nextgreyv = _greyvect[i+1];
60                         next_r = _redvect[i+1]*255.0;
61                         next_g = _greenvect[i+1]*255.0;
62                         next_b = _bluevect[i+1]*255.0;            
63                 }else{
64                         nextgreyv = 1;  
65                         next_r = initial_r;
66                         next_g = initial_g;
67                         next_b = initial_b;
68                 }
69
70                 int ini_pixelX=_bar_width*initialgreyv;
71                 int end_pixelX=_bar_width*nextgreyv;            
72
73                 double m_scope_r = (double)(next_r-initial_r)/(end_pixelX-ini_pixelX);
74                 double m_scope_g = (double)(next_g-initial_g)/(end_pixelX-ini_pixelX);
75                 double m_scope_b = (double)(next_b-initial_b)/(end_pixelX-ini_pixelX);
76
77                 next_r = initial_r;
78                 next_g = initial_g;
79                 next_b = initial_b;
80
81                 for (int Xi =ini_pixelX; Xi<= end_pixelX; Xi++)                                         
82                 {
83                         temp_dc.SetBrush(wxBrush( wxColour(next_r, next_g, next_b),wxSOLID  ));
84                         temp_dc.SetPen(wxPen( wxColour(next_r, next_g, next_b),1,wxSOLID  ));
85                 
86                         temp_dc.DrawLine(Xi, 0, Xi, _bar_height);               
87
88                         next_r = (int)(m_scope_r + next_r);
89                         next_g = (int)(m_scope_g + next_g);
90                         next_b = (int)(m_scope_b + next_b);                                                     
91                 }
92         }
93 }
94
95 wxBitmap HistogramDialogComboBoxItem::GetBitmap(){
96         
97         return *colorBar_Bitmap;
98 }
99 void HistogramDialogComboBoxItem::SetTransferFunction(std::vector<double> greyvect, std::vector<double> value){
100     _greyvecttransfunct = greyvect;
101         _value=value;
102 }