From 4dbf0a6ed328c054b1e1b76c469b32d684fe8661 Mon Sep 17 00:00:00 2001 From: Nathan Hughes Date: Fri, 19 Jul 2024 16:40:53 +0000 Subject: [PATCH] move attribute to be common to all semantic attributes --- CMakeLists.txt | 2 +- include/spark_dsg/node_attributes.h | 4 +-- package.xml | 2 +- python/bindings/src/node_attributes.cpp | 6 ++-- src/node_attributes.cpp | 43 +++++++++++++++++++++++-- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 076da19..d313241 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.14) -project(spark_dsg VERSION 1.0.4) +project(spark_dsg VERSION 1.0.5) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/include/spark_dsg/node_attributes.h b/include/spark_dsg/node_attributes.h index 701d2d1..046310f 100644 --- a/include/spark_dsg/node_attributes.h +++ b/include/spark_dsg/node_attributes.h @@ -178,6 +178,8 @@ struct SemanticNodeAttributes : public NodeAttributes { SemanticLabel semantic_label; //! semantic feature of object Eigen::MatrixXd semantic_feature; + //! optional label probabilities + std::map semantic_class_probabilities; protected: std::ostream& fill_ostream(std::ostream& out) const override; @@ -236,8 +238,6 @@ struct RoomNodeAttributes : public SemanticNodeAttributes { virtual ~RoomNodeAttributes() = default; NodeAttributes::Ptr clone() const override; - std::map semantic_class_probabilities; - protected: std::ostream& fill_ostream(std::ostream& out) const override; void serialization_info() override; diff --git a/package.xml b/package.xml index 0127432..bedb74f 100644 --- a/package.xml +++ b/package.xml @@ -1,7 +1,7 @@ spark_dsg - 1.0.2 + 1.0.5 Dynamic Scene Graph (DSG) type definitions and core library code Nathan Hughes diff --git a/python/bindings/src/node_attributes.cpp b/python/bindings/src/node_attributes.cpp index 16d3ec1..5158bf9 100644 --- a/python/bindings/src/node_attributes.cpp +++ b/python/bindings/src/node_attributes.cpp @@ -134,6 +134,8 @@ void addBindings(pybind11::module_& module) { .def_readwrite("bounding_box", &SemanticNodeAttributes::bounding_box) .def_readwrite("semantic_label", &SemanticNodeAttributes::semantic_label) .def_readwrite("semantic_feature", &SemanticNodeAttributes::semantic_feature) + .def_readwrite("semantic_class_probabilities", + &RoomNodeAttributes::semantic_class_probabilities) .def_readonly_static("NO_SEMANTIC_LABEL", &SemanticNodeAttributes::NO_SEMANTIC_LABEL); @@ -151,9 +153,7 @@ void addBindings(pybind11::module_& module) { }); py::class_(module, "RoomNodeAttributes") - .def(py::init<>()) - .def_readwrite("semantic_class_probabilities", - &RoomNodeAttributes::semantic_class_probabilities); + .def(py::init<>()); py::class_(module, "NearestVertexInfo") .def(py::init<>()) diff --git a/src/node_attributes.cpp b/src/node_attributes.cpp index 17963b5..3a8d8b4 100644 --- a/src/node_attributes.cpp +++ b/src/node_attributes.cpp @@ -65,6 +65,29 @@ std::string showIterable(const T& iterable, size_t max_length = 80) { return ss.str(); } +template +std::string showMap(const T& iterable, size_t max_length = 80) { + std::stringstream ss; + ss << "{"; + auto iter = iterable.begin(); + while (iter != iterable.end()) { + ss << iter->first << ": " << iter->second; + + ++iter; + if (iter != iterable.end()) { + ss << ", "; + } + + if (max_length && ss.str().size() >= max_length) { + ss << "..."; + break; + } + } + ss << "}"; + + return ss.str(); +} + template std::string quatToString(const Eigen::Quaternion& q) { std::stringstream ss; @@ -175,7 +198,8 @@ std::ostream& SemanticNodeAttributes::fill_ostream(std::ostream& out) const { << " - bounding box: " << bounding_box << "\n" << " - label: " << std::to_string(semantic_label) << "\n" << " - feature: [" << semantic_feature.rows() << " x " << semantic_feature.cols() - << "]"; + << "]" + << " - likelihoods: " << showMap(semantic_class_probabilities); return out; } @@ -186,6 +210,12 @@ void SemanticNodeAttributes::serialization_info() { serialization::field("bounding_box", bounding_box); serialization::field("semantic_label", semantic_label); serialization::field("semantic_feature", semantic_feature); + const auto& header = io::GlobalInfo::loadedHeader(); + if (header.version < io::Version(1, 0, 5)) { + io::warnOutdatedHeader(header); + } else { + serialization::field("semantic_class_probabilities", semantic_class_probabilities); + } } bool SemanticNodeAttributes::is_equal(const NodeAttributes& other) const { @@ -201,7 +231,8 @@ bool SemanticNodeAttributes::is_equal(const NodeAttributes& other) const { return name == derived->name && color == derived->color && bounding_box == derived->bounding_box && semantic_label == derived->semantic_label && - semantic_feature == derived->semantic_feature; + semantic_feature == derived->semantic_feature && + semantic_class_probabilities == derived->semantic_class_probabilities; } ObjectNodeAttributes::ObjectNodeAttributes() @@ -263,7 +294,13 @@ std::ostream& RoomNodeAttributes::fill_ostream(std::ostream& out) const { void RoomNodeAttributes::serialization_info() { SemanticNodeAttributes::serialization_info(); - serialization::field("semantic_class_probabilities", semantic_class_probabilities); + const auto& header = io::GlobalInfo::loadedHeader(); + if (header.version < io::Version(1, 0, 5)) { + std::map unused; + serialization::field("semantic_class_probabilities", unused); + } else { + io::warnOutdatedHeader(header); + } } bool RoomNodeAttributes::is_equal(const NodeAttributes& other) const {