]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBoxItem.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramDialogComboBoxItem.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "HistogramDialogComboBoxItem.h"
27 #include <vector>
28
29 //-------------------------
30 //Constructor
31 //-------------------------
32 HistogramDialogComboBoxItem::HistogramDialogComboBoxItem()
33 {
34
35         _bar_width = 30;
36         _bar_height = 20;
37         
38
39         colorBar_Bitmap = new wxBitmap(_bar_width,      _bar_height);
40
41 }
42 HistogramDialogComboBoxItem::HistogramDialogComboBoxItem( int bar_width,int bar_height)
43 {
44
45         _bar_width = bar_width;
46         _bar_height = bar_height;
47
48         //_maxgreyvalue = maxgreyvalue;
49
50         colorBar_Bitmap = new wxBitmap(_bar_width,      _bar_height);
51
52 }
53 HistogramDialogComboBoxItem::~HistogramDialogComboBoxItem(){
54         
55         
56 }
57 void HistogramDialogComboBoxItem::SetColors(std::vector<double> greyvect, std::vector<double> redvect, std::vector<double> greenvect, std::vector<double> bluevect){
58
59         _greyvect=greyvect;
60         _redvect=redvect;
61         _greenvect=greenvect;
62         _bluevect=bluevect;
63
64         wxMemoryDC temp_dc;
65         temp_dc.SelectObject( *colorBar_Bitmap );               
66         temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
67         temp_dc.SetPen(wxPen( colourParent,1,wxSOLID  ));
68         
69         temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);
70         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
71         temp_dc.DrawRectangle(0, 0, _bar_width, _bar_height);   
72
73         double initial_r, initial_g, initial_b; 
74         double next_r, next_g, next_b;
75         double initialgreyv=0, nextgreyv=0;
76         
77         for (int i =0; i < _redvect.size(); i++){
78                 initialgreyv = nextgreyv;
79                 initial_r = _redvect[i]*255.0;          
80                 initial_g = _greenvect[i]*255.0;                
81                 initial_b = _bluevect[i]*255.0;         
82
83                 if(i < _redvect.size()-1){
84                         nextgreyv = _greyvect[i+1];
85                         next_r = _redvect[i+1]*255.0;
86                         next_g = _greenvect[i+1]*255.0;
87                         next_b = _bluevect[i+1]*255.0;            
88                 }else{
89                         nextgreyv = 1;  
90                         next_r = initial_r;
91                         next_g = initial_g;
92                         next_b = initial_b;
93                 }
94
95                 int ini_pixelX=_bar_width*initialgreyv;
96                 int end_pixelX=_bar_width*nextgreyv;            
97
98                 double m_scope_r = (double)(next_r-initial_r)/(end_pixelX-ini_pixelX);
99                 double m_scope_g = (double)(next_g-initial_g)/(end_pixelX-ini_pixelX);
100                 double m_scope_b = (double)(next_b-initial_b)/(end_pixelX-ini_pixelX);
101
102                 next_r = initial_r;
103                 next_g = initial_g;
104                 next_b = initial_b;
105
106                 for (int Xi =ini_pixelX; Xi<= end_pixelX; Xi++)                                         
107                 {
108                         temp_dc.SetBrush(wxBrush( wxColour(next_r, next_g, next_b),wxSOLID  ));
109                         temp_dc.SetPen(wxPen( wxColour(next_r, next_g, next_b),1,wxSOLID  ));
110                 
111                         temp_dc.DrawLine(Xi, 0, Xi, _bar_height);               
112
113                         next_r = (int)(m_scope_r + next_r);
114                         next_g = (int)(m_scope_g + next_g);
115                         next_b = (int)(m_scope_b + next_b);                                                     
116                 }
117         }
118 }
119
120 wxBitmap HistogramDialogComboBoxItem::GetBitmap(){
121         
122         return *colorBar_Bitmap;
123 }
124 void HistogramDialogComboBoxItem::SetTransferFunction(std::vector<double> greyvect, std::vector<double> value){
125     _greyvecttransfunct = greyvect;
126         _value=value;
127 }