|
5 | 5 | #ifndef DSR_NODE_COLORS_H |
6 | 6 | #define DSR_NODE_COLORS_H |
7 | 7 |
|
| 8 | +#include <cstdint> |
8 | 9 | #include <map> |
9 | 10 | #include <string> |
| 11 | +#include <vector> |
10 | 12 |
|
| 13 | +/* |
| 14 | + * Node colours, keyed by node type. |
| 15 | + * |
| 16 | + * Grouped into semantic FAMILIES so a graph reads at a glance: blues are the robot platform, |
| 17 | + * cyans/teals are sensors, greens are cognition/navigation, browns are structure and furniture, |
| 18 | + * pinks/magentas are a detected person. You should be able to spot "that is a sensor" without |
| 19 | + * reading the label. |
| 20 | + * |
| 21 | + * Two rules to preserve when editing: |
| 22 | + * |
| 23 | + * 1. `agent` MUST stay a neutral grey. It is the "this agent has not reported its health yet" |
| 24 | + * state; rc::AgentStatePublisher overwrites it live with green/orange/red (see |
| 25 | + * common/agent_state_publisher/agent_status.h in active_inference). Giving `agent` a real |
| 26 | + * colour here would make a silent or dead agent look meaningful. |
| 27 | + * 2. Avoid plain "green" / "orange" / "red" for ordinary node types, so those three keep reading |
| 28 | + * as agent health rather than as a node category. |
| 29 | + * |
| 30 | + * Every value must be a CSS3 colour name (list at the bottom of this file). QColor yields BLACK for |
| 31 | + * anything it cannot parse; GraphNode::set_color now rejects and logs such values rather than |
| 32 | + * painting the node black, but keep them valid anyway. |
| 33 | + * |
| 34 | + * A type NOT listed here no longer collapses onto one flat default — see stable_fallback_color(). |
| 35 | + */ |
11 | 36 | static const std::map<std::string, std::string> node_colors = { |
12 | | - { "root", "red"}, |
| 37 | +// -- Structure / world ------------------------------------------------------------------------ |
| 38 | + { "root", "red"}, // the single graph root; long-standing, kept |
13 | 39 | { "transform", "SteelBlue"}, |
14 | | - { "room", "Gray"}, |
15 | | - { "differentialrobot", "GoldenRod"}, |
16 | | - { "omnirobot", "Gray"}, |
17 | | - { "robot", "Gray"}, |
18 | | - { "path_to_target", "Gray"}, |
19 | | - { "intention", "Gray"}, |
20 | | - { "rgbd", "Gray"}, |
21 | | - { "pan_tilt", "Gray"}, |
22 | | - { "battery", "Gray"}, |
23 | | - { "pose", "Gray"}, |
24 | | - { "laser", "GreenYellow"}, |
25 | | - { "camera", "Gray"}, |
26 | | - { "imu", "LightSalmon"}, |
27 | | - { "slam_device", "Gray"}, |
28 | | - { "object", "Gray"}, |
29 | | - { "affordance_space", "Gray"}, |
30 | | - { "person", "Gray"}, |
31 | | - { "personal_space", "Gray"}, |
| 40 | + { "mind", "MediumPurple"}, // parent of the agent nodes |
| 41 | + { "room", "Tan"}, |
| 42 | + { "wall", "CadetBlue"}, |
| 43 | + { "floor", "BurlyWood"}, |
32 | 44 | { "plane", "Khaki"}, |
33 | | - { "box", "Gray"}, |
34 | | - { "cylinder", "Gray"}, |
35 | | - { "ball", "Gray"}, |
| 45 | + { "grid", "Wheat"}, |
36 | 46 | { "mesh", "LightBlue"}, |
37 | | - { "face", "Gray"}, |
38 | | - { "body", "Gray"}, |
39 | | - { "chest", "Gray"}, |
40 | | - { "nose", "Gray"}, |
41 | | - { "left_eye", "Gray"}, |
42 | | - { "right_eye", "Gray"}, |
43 | | - { "left_ear", "Gray"}, |
44 | | - { "right_ear", "Gray"}, |
45 | | - { "left_arm", "Gray"}, |
46 | | - { "right_arm", "Gray"}, |
47 | | - { "left_shoulder", "Gray"}, |
48 | | - { "right_shoulder", "Gray"}, |
49 | | - { "left_elbow", "Gray"}, |
50 | | - { "right_elbow", "Gray"}, |
51 | | - { "left_wrist", "Gray"}, |
52 | | - { "right_wrist", "Gray"}, |
53 | | - { "left_hand", "Gray"}, |
54 | | - { "right_hand", "Gray"}, |
55 | | - { "left_hip", "Gray"}, |
56 | | - { "right_hip", "Gray"}, |
57 | | - { "left_leg", "Gray"}, |
58 | | - { "right_leg", "Gray"}, |
59 | | - { "left_knee", "Gray"}, |
60 | | - { "right_knee", "Gray"}, |
61 | | - { "mug", "Gray"}, |
62 | | - { "cup", "Gray"}, |
63 | | - { "noodles", "Gray"}, |
64 | | - { "table", "Gray"}, |
65 | | - { "chair", "Gray"}, |
66 | | - { "shelve", "Gray"}, |
67 | | - { "dish", "Gray"}, |
68 | | - { "spoon", "Gray"}, |
69 | | - { "testtype", "Gray"}, |
70 | | - { "glass", "Gray"}, |
71 | | - { "plant", "Gray"}, |
72 | | - { "microwave", "Gray"}, |
73 | | - { "oven", "Gray"}, |
74 | | - { "vase", "Gray"}, |
75 | | - { "refrigerator", "Gray"}, |
76 | 47 |
|
77 | | -//melex-rodao types |
78 | | - { "road", "Gray"}, |
79 | | - { "building", "Gray"}, |
80 | | - { "vehicle", "Gray"}, |
81 | | - { "gps", "Gray"}, |
82 | | - { "grid", "Gray"}, |
| 48 | +// -- Robot platform --------------------------------------------------------------------------- |
| 49 | + { "robot", "RoyalBlue"}, |
| 50 | + { "omnirobot", "CornflowerBlue"}, |
| 51 | + { "differentialrobot", "GoldenRod"}, |
| 52 | + { "body", "LightSteelBlue"}, |
| 53 | + { "pan_tilt", "PowderBlue"}, |
| 54 | + { "battery", "YellowGreen"}, |
83 | 55 |
|
84 | | - { "wall", "SteelBlue"}, |
85 | | - { "floor", "BurlyWood"}, |
| 56 | +// -- Sensors ---------------------------------------------------------------------------------- |
| 57 | + { "rgbd", "MediumTurquoise"}, |
| 58 | + { "camera", "Turquoise"}, |
| 59 | + { "laser", "GreenYellow"}, |
| 60 | + { "imu", "LightSalmon"}, |
| 61 | + { "slam_device", "DarkCyan"}, |
| 62 | + { "gps", "DeepSkyBlue"}, |
| 63 | + |
| 64 | +// -- Cognition / navigation ------------------------------------------------------------------- |
| 65 | + { "path_to_target", "SpringGreen"}, |
| 66 | + { "intention", "MediumSpringGreen"}, |
| 67 | + { "pose", "Aquamarine"}, |
86 | 68 | { "affordance", "DarkOrange"}, |
| 69 | + { "affordance_space", "Coral"}, |
| 70 | + { "object", "DarkSeaGreen"}, |
| 71 | + |
| 72 | +// -- Geometric primitives --------------------------------------------------------------------- |
| 73 | + { "box", "SlateBlue"}, |
| 74 | + { "cylinder", "MediumSlateBlue"}, |
| 75 | + { "ball", "DarkSlateBlue"}, |
| 76 | + |
| 77 | +// -- Furniture / household objects -------------------------------------------------------------- |
| 78 | + { "table", "Peru"}, |
| 79 | + { "chair", "Sienna"}, |
| 80 | + { "shelve", "Chocolate"}, |
| 81 | + { "microwave", "DarkOliveGreen"}, |
| 82 | + { "oven", "IndianRed"}, |
| 83 | + { "refrigerator", "PaleTurquoise"}, |
| 84 | + { "vase", "MediumSeaGreen"}, |
| 85 | + { "plant", "ForestGreen"}, |
| 86 | + { "mug", "Plum"}, |
| 87 | + { "cup", "Violet"}, |
| 88 | + { "glass", "PaleGreen"}, |
| 89 | + { "dish", "Moccasin"}, |
| 90 | + { "spoon", "PaleGoldenRod"}, |
| 91 | + { "noodles", "NavajoWhite"}, |
| 92 | + { "testtype", "Gold"}, |
87 | 93 |
|
88 | | -//Agent |
| 94 | +// -- Person & skeleton -------------------------------------------------------------------------- |
| 95 | +// One pink/magenta family so a detected person reads as a single cluster. Left/right pairs share a |
| 96 | +// colour ON PURPOSE (the symmetry is the point), and joints are separated from limbs: 22 near |
| 97 | +// identical pinks would carry less information than two clearly different ones. |
| 98 | + { "person", "HotPink"}, |
| 99 | + { "personal_space", "Pink"}, |
| 100 | + { "face", "LightPink"}, |
| 101 | + { "nose", "PaleVioletRed"}, |
| 102 | + { "left_eye", "Orchid"}, |
| 103 | + { "right_eye", "Orchid"}, |
| 104 | + { "left_ear", "Orchid"}, |
| 105 | + { "right_ear", "Orchid"}, |
| 106 | + { "chest", "DeepPink"}, |
| 107 | + // joints |
| 108 | + { "left_shoulder", "MediumOrchid"}, |
| 109 | + { "right_shoulder", "MediumOrchid"}, |
| 110 | + { "left_elbow", "MediumOrchid"}, |
| 111 | + { "right_elbow", "MediumOrchid"}, |
| 112 | + { "left_wrist", "MediumOrchid"}, |
| 113 | + { "right_wrist", "MediumOrchid"}, |
| 114 | + { "left_hip", "MediumOrchid"}, |
| 115 | + { "right_hip", "MediumOrchid"}, |
| 116 | + { "left_knee", "MediumOrchid"}, |
| 117 | + { "right_knee", "MediumOrchid"}, |
| 118 | + // limbs / extremities |
| 119 | + { "left_arm", "MediumVioletRed"}, |
| 120 | + { "right_arm", "MediumVioletRed"}, |
| 121 | + { "left_hand", "MediumVioletRed"}, |
| 122 | + { "right_hand", "MediumVioletRed"}, |
| 123 | + { "left_leg", "MediumVioletRed"}, |
| 124 | + { "right_leg", "MediumVioletRed"}, |
| 125 | + |
| 126 | +// -- melex-rodao types --------------------------------------------------------------------------- |
| 127 | + { "road", "DarkKhaki"}, |
| 128 | + { "building", "SaddleBrown"}, |
| 129 | + { "vehicle", "DarkSalmon"}, |
| 130 | + |
| 131 | +// -- Agent --------------------------------------------------------------------------------------- |
| 132 | +// KEEP NEUTRAL GREY - see rule 1 above. This is the "health not reported yet" colour; the live |
| 133 | +// value is written over it by rc::AgentStatePublisher. |
89 | 134 | { "agent", "Gray"} |
90 | 135 | }; |
91 | 136 |
|
| 137 | +/* |
| 138 | + * Colour for a type with no entry above. |
| 139 | + * |
| 140 | + * Unlisted types used to collapse onto a single flat default, so a graph full of new types was a |
| 141 | + * wall of identical nodes carrying no information. Instead, hash the type name into a curated |
| 142 | + * palette: distinct, readable, never grey, never the three agent-health colours. |
| 143 | + * |
| 144 | + * The hash is FNV-1a spelled out here rather than std::hash, because the colour must be THE SAME in |
| 145 | + * every agent's viewer and across rebuilds - std::hash offers no such guarantee. The same type name |
| 146 | + * always yields the same colour, and a newly introduced type gets a distinct one for free. |
| 147 | + */ |
| 148 | +inline std::string stable_fallback_color(const std::string &type) |
| 149 | +{ |
| 150 | + static const std::vector<std::string> palette = { |
| 151 | + "DodgerBlue", "MediumAquamarine", "SandyBrown", "MediumOrchid", |
| 152 | + "LightSeaGreen", "Chocolate", "CadetBlue", "DarkKhaki", |
| 153 | + "PaleVioletRed", "OliveDrab", "SlateBlue", "MediumPurple", |
| 154 | + "DarkTurquoise", "IndianRed", "Thistle", "YellowGreen", |
| 155 | + }; |
| 156 | + std::uint32_t h = 2166136261u; // FNV-1a offset basis |
| 157 | + for (const unsigned char c : type) |
| 158 | + { |
| 159 | + h ^= c; |
| 160 | + h *= 16777619u; // FNV-1a prime |
| 161 | + } |
| 162 | + return palette[h % palette.size()]; |
| 163 | +} |
| 164 | + |
92 | 165 | #endif //DSR_NODE_COLORS_H |
93 | 166 |
|
94 | 167 | // VALID COLOR NAMES https://www.w3.org/TR/2018/REC-css-color-3-20180619/ |
|
0 commit comments