PhoenixPNG
1.2.5
Set of tools to ease use of png file
Toggle main menu visibility
Loading...
Searching...
No Matches
PColorMap.cpp
Go to the documentation of this file.
1
/***************************************
2
Auteur : Pierre Aubert
3
Mail : pierre.aubert@lapp.in2p3.fr
4
Licence : CeCILL-C
5
****************************************/
6
7
#include <stdlib.h>
8
#include "
PColorMap.h
"
9
11
15
PColorValue
createColorValue
(
float
value,
const
PString & color){
16
size_t
nbChannel(color.size());
17
color_t
red(0), green(0), blue(0), alpha(0);
18
if
(nbChannel >= 2lu){
19
PString redHex(color.substr(0lu, 2lu));
20
red = (
color_t
)strtol(redHex.c_str(), NULL, 16);
21
}
22
if
(nbChannel >= 4lu){
23
PString greenHex(color.substr(2lu, 2lu));
24
green = (
color_t
)strtol(greenHex.c_str(), NULL, 16);
25
}
26
if
(nbChannel >= 6lu){
27
PString blueHex(color.substr(4lu, 2lu));
28
blue = (
color_t
)strtol(blueHex.c_str(), NULL, 16);
29
}
30
if
(nbChannel >= 8lu){
31
PString alphaHex(color.substr(6lu, 2lu));
32
alpha = (
color_t
)strtol(alphaHex.c_str(), NULL, 16);
33
}
34
return
createColorValue
(value, red, green, blue, alpha);
35
}
36
38
45
PColorValue
createColorValue
(
float
value,
color_t
red,
color_t
green,
color_t
blue,
color_t
alpha){
46
PColorValue
colorValue;
47
colorValue.
value
= value;
48
colorValue.
r
= red;
49
colorValue.
g
= green;
50
colorValue.
b
= blue;
51
colorValue.
a
= alpha;
52
return
colorValue;
53
}
54
56
62
void
getColorValue
(
color_t
& red,
color_t
& green,
color_t
& blue,
color_t
& alpha,
const
PColorValue
& color){
63
red = color.
r
;
64
green = color.
g
;
65
blue = color.
b
;
66
alpha = color.
a
;
67
}
68
70
75
void
phoenix_interpolateColor
(
PColorValue
& output,
const
PColorValue
& colorMin,
const
PColorValue
& colorMax,
float
value){
76
float
ratio((value - colorMin.
value
)/(colorMax.
value
- colorMin.
value
));
77
78
output.
r
= colorMax.
r
*ratio + colorMin.
r
*(1.0f - ratio);
79
output.
g
= colorMax.
g
*ratio + colorMin.
g
*(1.0f - ratio);
80
output.
b
= colorMax.
b
*ratio + colorMin.
b
*(1.0f - ratio);
81
output.
a
= colorMax.
a
*ratio + colorMin.
a
*(1.0f - ratio);
82
}
83
85
90
PColorValue
phoenix_interpolateColor
(
const
PColorValue
& colorMin,
const
PColorValue
& colorMax,
float
value){
91
PColorValue
out;
92
phoenix_interpolateColor
(out, colorMin, colorMax, value);
93
return
out;
94
}
95
97
PColorMap::PColorMap
(){
98
initialisationPColorMap
();
99
}
100
102
104
PColorMap::PColorMap
(
const
PColorMap
& other){
105
copyPColorMap
(other);
106
}
107
109
PColorMap::~PColorMap
(){
110
111
}
112
114
117
PColorMap
&
PColorMap::operator =
(
const
PColorMap
& other){
118
copyPColorMap
(other);
119
return
*
this
;
120
}
121
123
126
void
PColorMap::addColor
(
float
value,
const
PString & color){
127
PColorValue
colorValue =
createColorValue
(value, color);
128
p_mapColor
[value] = colorValue;
129
}
130
132
138
void
PColorMap::addColor
(
float
value,
color_t
red,
color_t
green,
color_t
blue,
color_t
alpha){
139
PColorValue
colorValue =
createColorValue
(value, red, green, blue, alpha);
140
p_mapColor
[value] = colorValue;
141
}
142
144
149
void
PColorMap::interpolate
(
color_t
& red,
color_t
& green,
color_t
& blue,
float
value)
const
{
150
PColorValue
out;
151
interpolate
(out, value);
152
red = out.
r
;
153
green = out.
g
;
154
blue = out.
b
;
155
}
156
158
164
void
PColorMap::interpolate
(
color_t
& red,
color_t
& green,
color_t
& blue,
color_t
& alpha,
float
value)
const
{
165
PColorValue
out;
166
interpolate
(out, value);
167
red = out.
r
;
168
green = out.
g
;
169
blue = out.
b
;
170
alpha = out.
a
;
171
}
172
174
177
void
PColorMap::interpolate
(
PColorValue
& output,
float
value)
const
{
178
if
(
p_mapColor
.size() == 0lu){
return
;}
//No color
179
PMapColorValue::const_iterator itMin(
p_mapColor
.begin());
180
if
(value <= itMin->second.value){
//If the value is smaller than the first colored one
181
output = itMin->second;
//We copy this value
182
return
;
183
}
184
PMapColorValue::const_reverse_iterator rit(
p_mapColor
.rbegin());
185
if
(value >= rit->second.value){
//If the value is greater than the last colored one
186
output = rit->second;
//We copy this value
187
return
;
188
}
189
PMapColorValue::const_iterator itMax(itMin);
190
++itMax;
191
while
(itMax !=
p_mapColor
.end()){
192
if
(value >= itMin->second.value && value < itMax->second.value){
193
phoenix_interpolateColor
(output, itMin->second, itMax->second, value);
194
break
;
195
}
196
++itMax;
197
++itMin;
198
}
199
}
200
202
204
void
PColorMap::copyPColorMap
(
const
PColorMap
& other){
205
p_mapColor
= other.
p_mapColor
;
206
}
207
209
void
PColorMap::initialisationPColorMap
(){
210
211
}
212
213
214
215
216
getColorValue
void getColorValue(color_t &red, color_t &green, color_t &blue, color_t &alpha, const PColorValue &color)
Get the rgba values from PColorValue.
Definition
PColorMap.cpp:62
phoenix_interpolateColor
void phoenix_interpolateColor(PColorValue &output, const PColorValue &colorMin, const PColorValue &colorMax, float value)
Interpolate a color with a value by respect to min an max color.
Definition
PColorMap.cpp:75
createColorValue
PColorValue createColorValue(float value, const PString &color)
Create a PColorValue.
Definition
PColorMap.cpp:15
PColorMap.h
color_t
unsigned char color_t
Type des of a color.
Definition
PColorMap.h:14
phoenix_interpolateColor
void phoenix_interpolateColor(PColorValue &output, const PColorValue &colorMin, const PColorValue &colorMax, float value)
Interpolate a color with a value by respect to min an max color.
Definition
PColorMap.cpp:75
createColorValue
PColorValue createColorValue(float value, const PString &color)
Create a PColorValue.
Definition
PColorMap.cpp:15
PColorMap::p_mapColor
PMapColorValue p_mapColor
Vector of the value.
Definition
PColorMap.h:58
PColorMap::addColor
void addColor(float value, const PString &color)
Add a color in the PColorMap.
Definition
PColorMap.cpp:126
PColorMap::PColorMap
PColorMap()
Default constructor of PColorMap.
Definition
PColorMap.cpp:97
PColorMap::copyPColorMap
void copyPColorMap(const PColorMap &other)
Copy function of PColorMap.
Definition
PColorMap.cpp:204
PColorMap::operator=
PColorMap & operator=(const PColorMap &other)
Definition of equal operator of PColorMap.
Definition
PColorMap.cpp:117
PColorMap::initialisationPColorMap
void initialisationPColorMap()
Initialisation function of the class PColorMap.
Definition
PColorMap.cpp:209
PColorMap::interpolate
void interpolate(color_t &red, color_t &green, color_t &blue, float value) const
Interpolate color by respect to the given value.
Definition
PColorMap.cpp:149
PColorMap::~PColorMap
virtual ~PColorMap()
Destructor of PColorMap.
Definition
PColorMap.cpp:109
PColorValue
Color related to a value.
Definition
PColorMap.h:17
PColorValue::r
color_t r
Red channel.
Definition
PColorMap.h:21
PColorValue::g
color_t g
Green channel.
Definition
PColorMap.h:23
PColorValue::value
float value
Value of the color.
Definition
PColorMap.h:19
PColorValue::a
color_t a
Alpha channel.
Definition
PColorMap.h:27
PColorValue::b
color_t b
Blue channel.
Definition
PColorMap.h:25
src
PColorMap.cpp
Generated by
1.17.0