2
* colourmap.cpp - contiuum colourmap header
3
* Copyright (C) 2010, ViewerGTKQt project
4
* Modifed by D Haley 2010
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "colourmap.h"
26
void jetColorMap(unsigned char *rgb,float value,float min,float max)
28
float max4=(max-min)/4;
32
rgb[0]=rgb[1]=rgb[2]=255;
36
rgb[0]=rgb[1]=rgb[2]=0;
43
rgb[2]=c1+(unsigned char)((255-c1)*value/max4);
45
else if (value<2*max4)
48
rgb[1]=(unsigned char)(255*(value-max4)/max4);
51
else if (value<3*max4)
53
rgb[0]=(unsigned char)(255*(value-2*max4)/max4);
60
rgb[1]=(unsigned char)(255-255*(value-3*max4)/max4);
69
void hotColorMap(unsigned char *rgb,float value,float min,float max)
71
float max3=(max-min)/3;
74
{rgb[0]=rgb[1]=rgb[2]=255;}
76
{rgb[0]=rgb[1]=rgb[2]=0;}
78
{rgb[0]=(unsigned char)(255*value/max3);rgb[1]=0;rgb[2]=0;}
80
{rgb[0]=255;rgb[1]=(unsigned char)(255*(value-max3)/max3);rgb[2]=0;}
82
{rgb[0]=255;rgb[1]=255;rgb[2]=(unsigned char)(255*(value-2*max3)/max3);}
83
else {rgb[0]=rgb[1]=rgb[2]=255;}
86
void coldColorMap(unsigned char *rgb,float value,float min,float max)
88
float max3=(max-min)/3;
91
{rgb[0]=rgb[1]=rgb[2]=255;}
93
{rgb[0]=rgb[1]=rgb[2]=0;}
95
{rgb[0]=0;rgb[1]=0;rgb[2]=(unsigned char)(255*value/max3);}
97
{rgb[0]=0;rgb[1]=(unsigned char)(255*(value-max3)/max3);rgb[2]=255;}
99
{rgb[0]=(unsigned char)(255*(value-2*max3)/max3);rgb[1]=255;rgb[2]=255;}
100
else {rgb[0]=rgb[1]=rgb[2]=255;}
103
void blueColorMap(unsigned char *rgb,float value,float min,float max)
107
{rgb[0]=rgb[1]=rgb[2]=255;}
109
{rgb[0]=rgb[1]=rgb[2]=0;}
111
{rgb[0]=0;rgb[1]=0;rgb[2]=(unsigned char)(255*value/max);}
112
else {rgb[0]=rgb[1]=0;rgb[2]=255;}
115
void positiveColorMap(unsigned char *rgb,float value,float min,float max)
122
rgb[0]=rgb[1]=rgb[2]=0;
126
rgb[0]=rgb[1]=rgb[2]=255;
130
rgb[0]=192;rgb[1]=0;rgb[2]=0;
131
rgb[0]+=(unsigned char)(63*value);
132
rgb[1]+=(unsigned char)(255*value);
134
rgb[2]+=(unsigned char)(255*2*(value-0.5));
137
void negativeColorMap(unsigned char *rgb,float value,float min,float max)
141
rgb[0]=0;rgb[1]=0;rgb[2]=0;
143
if(max>std::numeric_limits<float>::epsilon())
151
rgb[1]+=(unsigned char)(255*value);
153
rgb[2]+=(unsigned char)(255*2*(value-0.5));
157
void colorMap(unsigned char *rgb,float value,float min,float max)
160
positiveColorMap(rgb,value,0,max);
162
negativeColorMap(rgb,value,min,0);
165
hotColorMap(rgb,value,min,max);
167
coldColorMap(rgb,value,min,max);
171
void cyclicColorMap(unsigned char *rgb,float value,float min,float max)
173
float max3=(max-min)/3;
174
value-=(max-min)*(float)floor((value-min)/(max-min));
176
{rgb[0]=(unsigned char)(255-255*value/max3);rgb[1]=0;rgb[2]=255-rgb[0];}
177
else if(value<2*max3)
178
{rgb[0]=0;rgb[1]=(unsigned char)(255*(value-max3)/max3);rgb[2]=255-rgb[1];}
180
{rgb[0]=(unsigned char)(255*(value-2*max3)/max3);rgb[1]=255-rgb[0];rgb[2]=0;}
183
void randColorMap(unsigned char *rgb,float value,float min,float max)
185
srand((int)(65000*(value-min)/(max-min)));
186
rgb[0]=(unsigned char)(255*rand());
187
rgb[1]=(unsigned char)(255*rand());
188
rgb[2]=(unsigned char)(255*rand());
191
void grayColorMap(unsigned char *rgb,float value,float min,float max)
195
rgb[0]=rgb[1]=rgb[2]=(unsigned char)(255*value/max);