Skip to content

Commit 9c65168

Browse files
Feature/more colors (#44)
* add text color selection * also add edge color selection to visualizer
1 parent 13a3fb0 commit 9c65168

File tree

5 files changed

+101
-6
lines changed

5 files changed

+101
-6
lines changed

hydra_visualizer/include/hydra_visualizer/color/colormap_utilities.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040

4141
namespace hydra::visualizer {
4242

43+
enum class NamedColors {
44+
BLACK,
45+
WHITE,
46+
RED,
47+
GREEN,
48+
BLUE,
49+
YELLOW,
50+
ORANGE,
51+
PURPLE,
52+
CYAN,
53+
MAGENTA,
54+
PINK,
55+
GRAY,
56+
};
57+
58+
spark_dsg::Color colorFromName(NamedColors color);
59+
4360
std_msgs::msg::ColorRGBA makeColorMsg(const spark_dsg::Color& color,
4461
std::optional<double> alpha = std::nullopt);
4562

hydra_visualizer/include/hydra_visualizer/layer_info.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ struct LayerConfig {
7474
double scale = 0.03; //[ 0.001, 1.0]
7575
//! @brief intralayer edge alpha
7676
double alpha = 1.0; //[ 0.0, 1.0]
77-
//! @brief show intralayer edge in color
77+
//! @brief Color to use for edge
78+
NamedColors color = NamedColors::BLACK;
79+
//! @brief show intralayer edge using node colors
7880
bool use_color = true;
7981
//! @brief draw interlayer edges
8082
bool draw_interlayer = true;
@@ -84,7 +86,7 @@ struct LayerConfig {
8486
double interlayer_scale = 0.03; // [0.001, 1.0]
8587
//! @brief interlayer edge alpha
8688
double interlayer_alpha = 1.0; // [0.0, 1.0]
87-
//! @brief show interlayer edge in color
89+
//! @brief show interlayer edge using node colors
8890
bool interlayer_use_color = true;
8991
//! @brief Number of edges to skip when drawing interlayer edges
9092
size_t interlayer_insertion_skip = 0; // [0, 1000]
@@ -108,6 +110,8 @@ struct LayerConfig {
108110
bool add_jitter = false;
109111
//! @brief amount of jitter to add
110112
double jitter_scale = 0.2; //[ 0.05, 5.0]
113+
//! @brief Color to use for text
114+
NamedColors color = NamedColors::BLACK;
111115
} text;
112116

113117
struct BoundingBoxes {
@@ -158,6 +162,8 @@ class LayerInfo {
158162
LayerInfo& graph(const spark_dsg::DynamicSceneGraph& graph, spark_dsg::LayerId layer);
159163

160164
bool shouldVisualize(const spark_dsg::SceneGraphNode& node) const;
165+
spark_dsg::Color text_color() const;
166+
spark_dsg::Color edge_color() const;
161167

162168
const LayerConfig config;
163169

hydra_visualizer/src/color/colormap_utilities.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,37 @@ std::function<Color(size_t)> lookupColormap(DiscretePalette cmap) {
7373

7474
} // namespace
7575

76+
spark_dsg::Color colorFromName(NamedColors color) {
77+
switch (color) {
78+
case NamedColors::BLACK:
79+
return spark_dsg::Color::black();
80+
case NamedColors::WHITE:
81+
return spark_dsg::Color::white();
82+
case NamedColors::RED:
83+
return spark_dsg::Color::red();
84+
case NamedColors::GREEN:
85+
return spark_dsg::Color::green();
86+
case NamedColors::BLUE:
87+
return spark_dsg::Color::blue();
88+
case NamedColors::YELLOW:
89+
return spark_dsg::Color::yellow();
90+
case NamedColors::ORANGE:
91+
return spark_dsg::Color::orange();
92+
case NamedColors::PURPLE:
93+
return spark_dsg::Color::purple();
94+
case NamedColors::CYAN:
95+
return spark_dsg::Color::cyan();
96+
case NamedColors::MAGENTA:
97+
return spark_dsg::Color::magenta();
98+
case NamedColors::PINK:
99+
return spark_dsg::Color::pink();
100+
case NamedColors::GRAY:
101+
return spark_dsg::Color::gray();
102+
default:
103+
return spark_dsg::Color::black();
104+
}
105+
}
106+
76107
std_msgs::msg::ColorRGBA makeColorMsg(const Color& color, std::optional<double> alpha) {
77108
std_msgs::msg::ColorRGBA msg;
78109
msg.r = static_cast<double>(color.r) / 255.0;

hydra_visualizer/src/drawing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ MarkerArray makeLayerNodeTextMarkers(const std_msgs::msg::Header& header,
436436

437437
marker.text = name.empty() ? NodeSymbol(node->id).str() : name;
438438
marker.scale.z = info.config.text.scale;
439-
marker.color = makeColorMsg(Color());
439+
marker.color = makeColorMsg(info.text_color());
440440

441441
fillPoseWithIdentity(marker.pose);
442442
tf2::convert(node->attributes().position, marker.pose.position);
@@ -527,9 +527,9 @@ Marker makeLayerEdgeMarkers(const std_msgs::msg::Header& header,
527527
marker.points.push_back(target);
528528

529529
const auto c_source =
530-
info.config.edges.use_color ? info.node_color(source_node) : Color();
530+
info.config.edges.use_color ? info.node_color(source_node) : info.edge_color();
531531
const auto c_target =
532-
info.config.edges.use_color ? info.node_color(target_node) : Color();
532+
info.config.edges.use_color ? info.node_color(target_node) : info.edge_color();
533533
marker.colors.push_back(makeColorMsg(c_source, info.config.edges.alpha));
534534
marker.colors.push_back(makeColorMsg(c_target, info.config.edges.alpha));
535535
}
@@ -605,7 +605,7 @@ Marker makeLayerTextMarker(const std_msgs::msg::Header& header,
605605
marker.id = 0;
606606
marker.action = Marker::ADD;
607607
marker.scale.z = info.config.text.scale;
608-
marker.color = makeColorMsg(Color());
608+
marker.color = makeColorMsg(info.text_color());
609609

610610
std::optional<uint64_t> best_stamp;
611611
Eigen::Vector3d pos = Eigen::Vector3d::Zero();

hydra_visualizer/src/layer_info.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "hydra_visualizer/layer_info.h"
3636

3737
#include <config_utilities/config.h>
38+
#include <config_utilities/types/enum.h>
3839
#include <spark_dsg/node_attributes.h>
3940

4041
namespace hydra::visualizer {
@@ -71,6 +72,22 @@ void declare_config(LayerConfig::Edges& config) {
7172
field(config.draw, "draw");
7273
field(config.scale, "scale");
7374
field(config.alpha, "alpha");
75+
enum_field(config.color,
76+
"color",
77+
{
78+
{NamedColors::BLACK, "black"},
79+
{NamedColors::WHITE, "white"},
80+
{NamedColors::RED, "red"},
81+
{NamedColors::GREEN, "green"},
82+
{NamedColors::BLUE, "blue"},
83+
{NamedColors::YELLOW, "yellow"},
84+
{NamedColors::ORANGE, "orange"},
85+
{NamedColors::PURPLE, "purple"},
86+
{NamedColors::CYAN, "cyan"},
87+
{NamedColors::MAGENTA, "magenta"},
88+
{NamedColors::PINK, "pink"},
89+
{NamedColors::GRAY, "gray"},
90+
});
7491
field(config.use_color, "use_color");
7592
field(config.draw_interlayer, "draw_interlayer");
7693
field(config.interlayer_use_source, "interlayer_use_source");
@@ -91,6 +108,22 @@ void declare_config(LayerConfig::Text& config) {
91108
field(config.scale, "scale");
92109
field(config.add_jitter, "add_jitter");
93110
field(config.jitter_scale, "jitter_scale");
111+
enum_field(config.color,
112+
"color",
113+
{
114+
{NamedColors::BLACK, "black"},
115+
{NamedColors::WHITE, "white"},
116+
{NamedColors::RED, "red"},
117+
{NamedColors::GREEN, "green"},
118+
{NamedColors::BLUE, "blue"},
119+
{NamedColors::YELLOW, "yellow"},
120+
{NamedColors::ORANGE, "orange"},
121+
{NamedColors::PURPLE, "purple"},
122+
{NamedColors::CYAN, "cyan"},
123+
{NamedColors::MAGENTA, "magenta"},
124+
{NamedColors::PINK, "pink"},
125+
{NamedColors::GRAY, "gray"},
126+
});
94127
}
95128

96129
void declare_config(LayerConfig::BoundingBoxes& config) {
@@ -162,6 +195,14 @@ LayerInfo& LayerInfo::graph(const DynamicSceneGraph& graph, LayerId layer) {
162195
return *this;
163196
}
164197

198+
Color LayerInfo::text_color() const {
199+
return colorFromName(config.text.color);
200+
}
201+
202+
Color LayerInfo::edge_color() const {
203+
return colorFromName(config.edges.color);
204+
}
205+
165206
bool LayerInfo::shouldVisualize(const spark_dsg::SceneGraphNode& node) const {
166207
if (!config.visualize) {
167208
return false;

0 commit comments

Comments
 (0)