|
| 1 | +#include "hydra_ros/backend/gt_room_publisher.h" |
| 2 | + |
| 3 | +#include <config_utilities/config.h> |
| 4 | +#include <config_utilities/factory.h> |
| 5 | +#include <config_utilities/parsing/context.h> |
| 6 | +#include <config_utilities/printing.h> |
| 7 | +#include <config_utilities/validation.h> |
| 8 | +#include <glog/logging.h> |
| 9 | + |
| 10 | +#include <memory> |
| 11 | + |
| 12 | +#include <visualization_msgs/msg/marker.hpp> |
| 13 | +#include <visualization_msgs/msg/marker_array.hpp> |
| 14 | + |
| 15 | +namespace hydra { |
| 16 | + |
| 17 | +void declare_config(GtRoomPublisher::Config& config) { |
| 18 | + using namespace config; |
| 19 | + name("GtRoomPublisher::Config"); |
| 20 | + field(config.ns, "ns"); |
| 21 | +} |
| 22 | + |
| 23 | +GtRoomPublisher::GtRoomPublisher(const Config& config) |
| 24 | + : config(config), nh_(ianvs::NodeHandle::this_node(config.ns)) { |
| 25 | + room_publisher_ = |
| 26 | + nh_.create_publisher<visualization_msgs::msg::MarkerArray>("topic_name", 1); |
| 27 | +} |
| 28 | + |
| 29 | +std::string GtRoomPublisher::printInfo() const { return config::toString(config); } |
| 30 | + |
| 31 | +void GtRoomPublisher::call(uint64_t, const RoomFinder& rf) const { |
| 32 | + LOG(WARNING) << "GT Room sink called"; |
| 33 | + visualization_msgs::msg::MarkerArray ma; |
| 34 | + visualization_msgs::msg::Marker m; |
| 35 | + m.action = m.DELETEALL; |
| 36 | + ma.markers.push_back(m); |
| 37 | + int idx = 0; |
| 38 | + int room_idx = 0; |
| 39 | + |
| 40 | + const std::vector<double> reds{0, .2, .4, .6, .8, 1}; |
| 41 | + const std::vector<double> greens{1, .8, .6, .4, .2}; |
| 42 | + const std::vector<double> blues{.4, .2, 0, 1}; |
| 43 | + |
| 44 | + for (auto room : rf.room_extents_.room_bounding_boxes) { |
| 45 | + for (auto box : room) { |
| 46 | + visualization_msgs::msg::Marker m; |
| 47 | + m.header.frame_id = "map"; |
| 48 | + m.ns = "gt_rooms"; |
| 49 | + m.id = idx++; |
| 50 | + m.action = m.ADD; |
| 51 | + m.type = m.CUBE; |
| 52 | + m.pose.orientation.w = 1; |
| 53 | + m.pose.position.x = box.world_P_center.x(); |
| 54 | + m.pose.position.y = box.world_P_center.y(); |
| 55 | + m.pose.position.z = box.world_P_center.z(); |
| 56 | + m.scale.x = box.dimensions.x(); |
| 57 | + m.scale.y = box.dimensions.y(); |
| 58 | + m.scale.z = box.dimensions.z(); |
| 59 | + m.color.a = 0.5; |
| 60 | + m.color.r = reds.at(room_idx % reds.size()); |
| 61 | + m.color.g = greens.at(room_idx % greens.size()); |
| 62 | + m.color.b = blues.at(room_idx % blues.size()); |
| 63 | + ma.markers.push_back(m); |
| 64 | + } |
| 65 | + ++room_idx; |
| 66 | + } |
| 67 | + |
| 68 | + room_publisher_->publish(ma); |
| 69 | +} |
| 70 | + |
| 71 | +} // namespace hydra |
0 commit comments