Skip to content

Commit d73e3b9

Browse files
committed
add object label name map to global config (#172)
Co-authored-by: Nathan Hughes <[email protected]>
1 parent 7677e5b commit d73e3b9

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

include/hydra/common/hydra_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <array>
3737
#include <atomic>
3838
#include <iostream>
39+
#include <map>
3940
#include <memory>
4041
#include <vector>
4142

@@ -44,6 +45,7 @@ namespace hydra {
4445
class HydraConfig {
4546
public:
4647
using ColorArray = std::array<uint8_t, 3>;
48+
using LabelNameMap = std::map<uint8_t, std::string>;
4749

4850
static HydraConfig& instance() {
4951
if (!instance_) {
@@ -60,6 +62,10 @@ class HydraConfig {
6062

6163
const ColorArray& getRoomColor(size_t index) const;
6264

65+
const LabelNameMap& getLabelToNameMap() const;
66+
67+
void setLabelToNameMap(const LabelNameMap& name_map);
68+
6369
private:
6470
HydraConfig();
6571

@@ -69,6 +75,7 @@ class HydraConfig {
6975
std::atomic<bool> force_shutdown_;
7076

7177
std::vector<ColorArray> colormap_;
78+
std::map<uint8_t, std::string> label_to_name_map_;
7279
};
7380

7481
std::ostream& operator<<(std::ostream& out, const HydraConfig& config);

src/common/hydra_config.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,12 @@ const HydraConfig::ColorArray& HydraConfig::getRoomColor(size_t index) const {
7474
return colormap_.at(index % colormap_.size());
7575
}
7676

77+
void HydraConfig::setLabelToNameMap(const HydraConfig::LabelNameMap& name_map) {
78+
label_to_name_map_ = name_map;
79+
}
80+
81+
const HydraConfig::LabelNameMap& HydraConfig::getLabelToNameMap() const {
82+
return label_to_name_map_;
83+
}
84+
7785
} // namespace hydra

src/frontend/mesh_segmenter.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <pcl/segmentation/extract_clusters.h>
3939
#include <spark_dsg/bounding_box_extraction.h>
4040

41+
#include "hydra/common/hydra_config.h"
42+
4143
namespace hydra {
4244

4345
using kimera::HashableColor;
@@ -356,38 +358,20 @@ void MeshSegmenter::addObjectToGraph(DynamicSceneGraph& graph,
356358
return;
357359
}
358360

359-
std::unordered_map<SemanticLabel, std::string> label_string{
360-
{0, "void"}, {1, "wall"},
361-
{2, "floor"}, {3, "chair"},
362-
{4, "door"}, {5, "table"},
363-
{6, "picture"}, {7, "cabinet"},
364-
{8, "cushion"}, {9, "window"},
365-
{10, "sofa"}, {11, "bed"},
366-
{12, "curtain"}, {13, "chest_of_drawers"},
367-
{14, "plant"}, {15, "sink"},
368-
{16, "stairs"}, {17, "ceiling"},
369-
{18, "toilet"}, {19, "stool"},
370-
{20, "towel"}, {21, "mirror"},
371-
{22, "tv_monitor"}, {23, "shower"},
372-
{24, "column"}, {25, "bathtub"},
373-
{26, "counter"}, {27, "fireplace"},
374-
{28, "lighting"}, {29, "railing"},
375-
{30, "shelving"}, {31, "blinds"},
376-
{32, "seating"}, {33, "board_panel"},
377-
{34, "furniture"}, {35, "appliances"},
378-
{36, "clothes"}, {37, "objects"},
379-
{38, "misc"}};
380-
381361
ObjectNodeAttributes::Ptr attrs = std::make_unique<ObjectNodeAttributes>();
382362
attrs->semantic_label = label;
383363
attrs->name = NodeSymbol(next_node_id_).getLabel();
384364
attrs->bounding_box = bounding_box::extract(
385365
cluster.cloud, config_.bounding_box_type, nullptr, config_.angle_step);
386-
if (label_string.count(label)) {
387-
attrs->name = label_string[label];
366+
367+
const auto& label_to_name = HydraConfig::instance().getLabelToNameMap();
368+
auto iter = label_to_name.find(label);
369+
if (iter != label_to_name.end()) {
370+
attrs->name = iter->second;
388371
} else {
389-
LOG(ERROR) << "Missing semantic label: " << std::to_string(label);
372+
VLOG(1) << "Missing semantic label from map: " << std::to_string(label);
390373
}
374+
391375
attrs->mesh_connections.insert(attrs->mesh_connections.begin(),
392376
cluster.indices.indices.begin(),
393377
cluster.indices.indices.end());

0 commit comments

Comments
 (0)