00001 #include <charm++.h>
00002 #include <math.h>
00003 #include "colorScale.h"
00004
00005
00006
00007
00008 void colorScale(double val,
00009 double min,
00010 double max,
00011 unsigned char intensity[3])
00012 {
00013
00014 max -= min;
00015 val -= min;
00016
00017
00018 double at = (val / max) * 5.0;
00019
00020
00021 intensity[0] = intensity[1] = intensity[2] = 0;
00022 double rem = at - floor(at);
00023 switch ( (int)floor(at) ) {
00024 case 0:
00025
00026 intensity[0] = (unsigned char) 255;
00027 intensity[1] = (unsigned char) (rem * 255.0);
00028 break;
00029 case 1:
00030
00031 intensity[0] = (unsigned char) (255.0 - rem * 255.0);
00032 intensity[1] = (unsigned char) 255;
00033 break;
00034 case 2:
00035
00036 intensity[1] = (unsigned char) 255;
00037 intensity[2] = (unsigned char) (rem * 255.0);
00038 break;
00039 case 3:
00040
00041 intensity[1] = (unsigned char) (255.0 - rem * 255.0);
00042 intensity[2] = (unsigned char) 255;
00043 break;
00044 case 4:
00045
00046 intensity[0] = (unsigned char) (rem * 255.0);
00047 intensity[2] = (unsigned char) 255;
00048 break;
00049 default:
00050 if ( rem <= 0.000001 ) {
00051 intensity[0] = intensity[2] = (unsigned char) 255;
00052 } else {
00053
00054
00055 intensity[0] = intensity[1] = intensity[2] = 255;
00056 }
00057 break;
00058 }
00059 }