8 namespace HybridAStar {
21 ColorPoint(
float red,
float green,
float blue,
float value)
22 : r(red), g(green), b(blue), val(value) {}
24 vector<ColorPoint> color;
31 void addColorPoint(
float red,
float green,
float blue,
float value) {
32 for (
unsigned int i = 0; i < color.size(); i++) {
33 if (value < color[i].val) {
34 color.insert(color.begin() + i, ColorPoint(red, green, blue, value));
39 color.push_back(ColorPoint(red, green, blue, value));
43 void clearGradient() { color.clear(); }
46 void createDefaultHeatMapGradient() {
48 color.push_back(ColorPoint(0, 0, 1, 0.0f));
49 color.push_back(ColorPoint(0, 1, 1, 0.25f));
50 color.push_back(ColorPoint(0, 1, 0, 0.5f));
51 color.push_back(ColorPoint(1, 1, 0, 0.75f));
52 color.push_back(ColorPoint(1, 0, 0, 1.0f));
57 void getColorAtValue(
const float value,
float& red,
float& green,
float& blue) {
58 if (color.size() == 0)
61 for (
unsigned int i = 0; i < color.size(); i++) {
62 ColorPoint& currC = color[i];
64 if (value < currC.val) {
65 ColorPoint& prevC = color[ max(0, (
int)i - 1) ];
66 float valueDiff = (prevC.val - currC.val);
67 float fractBetween = (valueDiff == 0) ? 0 : (value - currC.val) / valueDiff;
68 red = (prevC.r - currC.r) * fractBetween + currC.r;
69 green = (prevC.g - currC.g) * fractBetween + currC.g;
70 blue = (prevC.b - currC.b) * fractBetween + currC.b;
76 green = color.back().g;
77 blue = color.back().b;
A color gradient class for visualizing the cost of nodes.
Definition: gradient.h:16
Definition: gradient.h:18