|
| 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 <visualization_msgs/msg/marker.hpp> |
| 11 | +#include <visualization_msgs/msg/marker_array.hpp> |
| 12 | + |
| 13 | +namespace hydra { |
| 14 | + |
| 15 | +static const auto registration_ = |
| 16 | + config::RegistrationWithConfig<UpdateRoomsFunctor::Sink, |
| 17 | + GtRoomPublisher, |
| 18 | + GtRoomPublisher::Config>("GtRoomPublisher"); |
| 19 | + |
| 20 | +void declare_config(GtRoomPublisher::Config& config) { |
| 21 | + using namespace config; |
| 22 | + name("GtRoomPublisher::Config"); |
| 23 | + field(config.ns, "ns"); |
| 24 | + field(config.colormap, "colormap"); |
| 25 | +} |
| 26 | + |
| 27 | +using visualization_msgs::msg::Marker; |
| 28 | +using visualization_msgs::msg::MarkerArray; |
| 29 | + |
| 30 | +GtRoomPublisher::GtRoomPublisher(const Config& config) |
| 31 | + : config(config), nh_(ianvs::NodeHandle::this_node(config.ns)) { |
| 32 | + room_publisher_ = nh_.create_publisher<MarkerArray>("gt_room_boundaries", 1); |
| 33 | +} |
| 34 | + |
| 35 | +std::string GtRoomPublisher::printInfo() const { return config::toString(config); } |
| 36 | + |
| 37 | +void GtRoomPublisher::call(uint64_t, const RoomFinder& rf) const { |
| 38 | + LOG(WARNING) << "GT Room sink called"; |
| 39 | + MarkerArray ma; |
| 40 | + auto& m = ma.markers.emplace_back(); |
| 41 | + m.action = m.DELETEALL; |
| 42 | + int idx = 0; |
| 43 | + int room_idx = 0; |
| 44 | + |
| 45 | + auto colormap = visualizer::DiscreteColormap(config.colormap); |
| 46 | + |
| 47 | + for (auto room : rf.room_extents.room_bounding_boxes) { |
| 48 | + for (auto box : room) { |
| 49 | + auto& m = ma.markers.emplace_back(); |
| 50 | + m.header.frame_id = "map"; |
| 51 | + m.ns = "gt_rooms"; |
| 52 | + m.id = idx++; |
| 53 | + m.action = m.ADD; |
| 54 | + m.type = m.CUBE; |
| 55 | + m.pose.orientation.w = 1; |
| 56 | + m.pose.position.x = box.world_P_center.x(); |
| 57 | + m.pose.position.y = box.world_P_center.y(); |
| 58 | + m.pose.position.z = box.world_P_center.z(); |
| 59 | + m.scale.x = box.dimensions.x(); |
| 60 | + m.scale.y = box.dimensions.y(); |
| 61 | + m.scale.z = box.dimensions.z(); |
| 62 | + m.color = visualizer::makeColorMsg(colormap.getColor(room_idx), 0.5); |
| 63 | + } |
| 64 | + ++room_idx; |
| 65 | + } |
| 66 | + |
| 67 | + room_publisher_->publish(ma); |
| 68 | +} |
| 69 | + |
| 70 | +} // namespace hydra |
0 commit comments