Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@

namespace hydra::visualizer {

enum class NamedColors {
BLACK,
WHITE,
RED,
GREEN,
BLUE,
YELLOW,
ORANGE,
PURPLE,
CYAN,
MAGENTA,
PINK,
GRAY,
};

spark_dsg::Color colorFromName(NamedColors color);

std_msgs::msg::ColorRGBA makeColorMsg(const spark_dsg::Color& color,
std::optional<double> alpha = std::nullopt);

Expand Down
10 changes: 8 additions & 2 deletions hydra_visualizer/include/hydra_visualizer/layer_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ struct LayerConfig {
double scale = 0.03; //[ 0.001, 1.0]
//! @brief intralayer edge alpha
double alpha = 1.0; //[ 0.0, 1.0]
//! @brief show intralayer edge in color
//! @brief Color to use for edge
NamedColors color = NamedColors::BLACK;
//! @brief show intralayer edge using node colors
bool use_color = true;
//! @brief draw interlayer edges
bool draw_interlayer = true;
Expand All @@ -84,7 +86,7 @@ struct LayerConfig {
double interlayer_scale = 0.03; // [0.001, 1.0]
//! @brief interlayer edge alpha
double interlayer_alpha = 1.0; // [0.0, 1.0]
//! @brief show interlayer edge in color
//! @brief show interlayer edge using node colors
bool interlayer_use_color = true;
//! @brief Number of edges to skip when drawing interlayer edges
size_t interlayer_insertion_skip = 0; // [0, 1000]
Expand All @@ -108,6 +110,8 @@ struct LayerConfig {
bool add_jitter = false;
//! @brief amount of jitter to add
double jitter_scale = 0.2; //[ 0.05, 5.0]
//! @brief Color to use for text
NamedColors color = NamedColors::BLACK;
} text;

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

bool shouldVisualize(const spark_dsg::SceneGraphNode& node) const;
spark_dsg::Color text_color() const;
spark_dsg::Color edge_color() const;

const LayerConfig config;

Expand Down
31 changes: 31 additions & 0 deletions hydra_visualizer/src/color/colormap_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@ std::function<Color(size_t)> lookupColormap(DiscretePalette cmap) {

} // namespace

spark_dsg::Color colorFromName(NamedColors color) {
switch (color) {
case NamedColors::BLACK:
return spark_dsg::Color::black();
case NamedColors::WHITE:
return spark_dsg::Color::white();
case NamedColors::RED:
return spark_dsg::Color::red();
case NamedColors::GREEN:
return spark_dsg::Color::green();
case NamedColors::BLUE:
return spark_dsg::Color::blue();
case NamedColors::YELLOW:
return spark_dsg::Color::yellow();
case NamedColors::ORANGE:
return spark_dsg::Color::orange();
case NamedColors::PURPLE:
return spark_dsg::Color::purple();
case NamedColors::CYAN:
return spark_dsg::Color::cyan();
case NamedColors::MAGENTA:
return spark_dsg::Color::magenta();
case NamedColors::PINK:
return spark_dsg::Color::pink();
case NamedColors::GRAY:
return spark_dsg::Color::gray();
default:
return spark_dsg::Color::black();
}
}

std_msgs::msg::ColorRGBA makeColorMsg(const Color& color, std::optional<double> alpha) {
std_msgs::msg::ColorRGBA msg;
msg.r = static_cast<double>(color.r) / 255.0;
Expand Down
8 changes: 4 additions & 4 deletions hydra_visualizer/src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ MarkerArray makeLayerNodeTextMarkers(const std_msgs::msg::Header& header,

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

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

const auto c_source =
info.config.edges.use_color ? info.node_color(source_node) : Color();
info.config.edges.use_color ? info.node_color(source_node) : info.edge_color();
const auto c_target =
info.config.edges.use_color ? info.node_color(target_node) : Color();
info.config.edges.use_color ? info.node_color(target_node) : info.edge_color();
marker.colors.push_back(makeColorMsg(c_source, info.config.edges.alpha));
marker.colors.push_back(makeColorMsg(c_target, info.config.edges.alpha));
}
Expand Down Expand Up @@ -605,7 +605,7 @@ Marker makeLayerTextMarker(const std_msgs::msg::Header& header,
marker.id = 0;
marker.action = Marker::ADD;
marker.scale.z = info.config.text.scale;
marker.color = makeColorMsg(Color());
marker.color = makeColorMsg(info.text_color());

std::optional<uint64_t> best_stamp;
Eigen::Vector3d pos = Eigen::Vector3d::Zero();
Expand Down
41 changes: 41 additions & 0 deletions hydra_visualizer/src/layer_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "hydra_visualizer/layer_info.h"

#include <config_utilities/config.h>
#include <config_utilities/types/enum.h>
#include <spark_dsg/node_attributes.h>

namespace hydra::visualizer {
Expand Down Expand Up @@ -71,6 +72,22 @@ void declare_config(LayerConfig::Edges& config) {
field(config.draw, "draw");
field(config.scale, "scale");
field(config.alpha, "alpha");
enum_field(config.color,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: you could define a config utilities enum type conversion, then no duplicates would be needed.

"color",
{
{NamedColors::BLACK, "black"},
{NamedColors::WHITE, "white"},
{NamedColors::RED, "red"},
{NamedColors::GREEN, "green"},
{NamedColors::BLUE, "blue"},
{NamedColors::YELLOW, "yellow"},
{NamedColors::ORANGE, "orange"},
{NamedColors::PURPLE, "purple"},
{NamedColors::CYAN, "cyan"},
{NamedColors::MAGENTA, "magenta"},
{NamedColors::PINK, "pink"},
{NamedColors::GRAY, "gray"},
});
field(config.use_color, "use_color");
field(config.draw_interlayer, "draw_interlayer");
field(config.interlayer_use_source, "interlayer_use_source");
Expand All @@ -91,6 +108,22 @@ void declare_config(LayerConfig::Text& config) {
field(config.scale, "scale");
field(config.add_jitter, "add_jitter");
field(config.jitter_scale, "jitter_scale");
enum_field(config.color,
"color",
{
{NamedColors::BLACK, "black"},
{NamedColors::WHITE, "white"},
{NamedColors::RED, "red"},
{NamedColors::GREEN, "green"},
{NamedColors::BLUE, "blue"},
{NamedColors::YELLOW, "yellow"},
{NamedColors::ORANGE, "orange"},
{NamedColors::PURPLE, "purple"},
{NamedColors::CYAN, "cyan"},
{NamedColors::MAGENTA, "magenta"},
{NamedColors::PINK, "pink"},
{NamedColors::GRAY, "gray"},
});
}

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

Color LayerInfo::text_color() const {
return colorFromName(config.text.color);
}

Color LayerInfo::edge_color() const {
return colorFromName(config.edges.color);
}

bool LayerInfo::shouldVisualize(const spark_dsg::SceneGraphNode& node) const {
if (!config.visualize) {
return false;
Expand Down
Loading