Go to the documentation of this file.
4 #ifndef tools_sg_colormap
5 #define tools_sg_colormap
20 static const std::string& s_class() {
21 static const std::string s_v(
"tools::sg::base_colormap");
27 virtual void*
cast(
const std::string&)
const = 0;
31 mem::increment(s_class().c_str());
37 mem::increment(s_class().c_str());
47 mem::decrement(s_class().c_str());
55 if(a_index>=n)
return colorf(0.5F,0.5F,0.5F);
58 float value(
size_t a_index)
const {
60 if(a_index>=n)
return 0;
69 float d = 1.0F/(a_ncell-1);
70 for(
size_t index=0;index<a_ncell;index++) {
84 float dv = (vmax-vmin)/(_valn-1);
85 for(
size_t count=0;count<_valn;count++) {
112 virtual void*
cast(
const std::string& a_class)
const {
113 if(
void* p = cmp_cast<by_value_colormap>(
this,a_class)) {
return p;}
119 const std::string& aString){
131 const std::string& aString,
132 std::vector<float>& aValues,
133 std::vector<colorf>& aColors) {
140 std::vector<std::string> ws;
141 words(aString,
" ",
false,ws);
142 size_t wordn = ws.size();
143 size_t number = wordn/2;
147 }
else if((2*number+1)!=wordn) {
148 a_out <<
"by_value_colormap::set_by_value :"
149 <<
" An odd number (" << wordn
150 <<
" given) of words is expected in " <<
sout(aString) <<
"."
163 aValues.resize(number);
164 aColors.resize(number+1);
165 for(
size_t count=0;count<number;count++) {
166 {
const std::string& word = ws[2*count];
168 a_out <<
"by_value_colormap::set_by_value :"
169 <<
" in " <<
sout(aString)
170 <<
", " << word <<
" not a color."
176 {
const std::string& word = ws[2*count+1];
177 if(!
to(word,aValues[count])) {
178 a_out <<
"by_value_colormap::set_by_value :"
179 <<
" in " <<
sout(aString)
180 <<
", " << word <<
" not a number."
187 const std::string& word = ws[wordn-1];
189 a_out <<
"by_value_colormap::set_by_value :"
190 <<
" in " <<
sout(aString)
191 <<
", " << word <<
" not a color."
198 aValues.resize(number+1);
199 aColors.resize(number);
200 for(
size_t count=0;count<number;count++) {
201 {
const std::string& word = ws[2*count];
202 if(!
to(word,aValues[count])) {
203 a_out <<
"by_value_colormap::set_by_value :"
204 <<
" in " <<
sout(aString)
205 <<
", " << word <<
" not a number."
211 {
const std::string& word = ws[2*count+1];
213 a_out <<
"by_value_colormap::set_by_value :"
214 <<
" in " <<
sout(aString)
215 <<
", " << word <<
" not a color."
222 {
const std::string& word = ws[wordn-1];
223 if(!
to(word,aValues[number])) {
224 a_out <<
"by_value_colormap::set_by_value :"
225 <<
" in " <<
sout(aString)
226 <<
", " << word <<
" not a number."
237 const std::vector<float>& aValues,
238 const std::vector<colorf>& aColors,
259 size_t _valn = aValues.size();
260 if(!_valn) {a_col = colorf_black();
return;}
261 if(aColors.size()==(_valn+1)) {
263 if(aValue<aValues[0]) {
266 for(
int count=0;count<=int(_valn-2);count++) {
267 if( (aValues[count]<=aValue) && (aValue<aValues[count+1]) ) {
268 a_col = aColors[count+1];
272 a_col = aColors[_valn];
274 }
else if((aColors.size()+1)==_valn) {
276 for(
int count=0;count<=int(_valn-2);count++) {
277 if( (aValues[count]<=aValue) && (aValue<aValues[count+1]) ) {
278 a_col = aColors[count];
282 if(aValue<aValues[0]) {a_col = aColors[0];
return;}
283 if(aValue>=aValues[_valn-1]) {a_col = aColors[aColors.size()-1];
return;}
284 a_col = colorf_black();
286 a_col = colorf_black();
299 virtual void*
cast(
const std::string& a_class)
const {
300 if(
void* p = cmp_cast<grey_scale_colormap>(
this,a_class)) {
return p;}
320 if(a_ratio<0.0F) a_ratio = 0;
321 if(a_ratio>1.0F) a_ratio = 1;
322 a_col.
set_value(a_ratio,a_ratio,a_ratio,1);
333 virtual void*
cast(
const std::string& a_class)
const {
334 if(
void* p = cmp_cast<grey_scale_inverse_colormap>(
this,a_class)) {
return p;}
354 if(a_ratio<0.0F) a_ratio = 0;
355 if(a_ratio>1.0F) a_ratio = 1;
356 a_ratio = 1 - a_ratio;
357 a_col.
set_value(a_ratio,a_ratio,a_ratio,1);
368 virtual void*
cast(
const std::string& a_class)
const {
369 if(
void* p = cmp_cast<violet_to_red_colormap>(
this,a_class)) {
return p;}
376 set(a_min,a_max,a_ncell);
385 void set(
float a_min,
float a_max,
size_t a_ncell){
393 if(a_ratio<0.0F) a_ratio = 0;
394 if(a_ratio>1.0F) a_ratio = 1;
403 float saturation = 1;
404 float lightness = 0.5;
407 float hue = hue_mx - a_ratio * (hue_mx-hue_mn);
422 virtual void*
cast(
const std::string& a_class)
const {
423 if(
void* p = cmp_cast<const_colormap>(
this,a_class)) {
return p;}
#define TOOLS_SCLASS(a_name)