Skip to content

Commit

Permalink
move attribute to be common to all semantic attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhhughes committed Jul 19, 2024
1 parent afa8959 commit 4dbf0a6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions include/spark_dsg/node_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ struct SemanticNodeAttributes : public NodeAttributes {
SemanticLabel semantic_label;
//! semantic feature of object
Eigen::MatrixXd semantic_feature;
//! optional label probabilities
std::map<SemanticLabel, double> semantic_class_probabilities;

protected:
std::ostream& fill_ostream(std::ostream& out) const override;
Expand Down Expand Up @@ -236,8 +238,6 @@ struct RoomNodeAttributes : public SemanticNodeAttributes {
virtual ~RoomNodeAttributes() = default;
NodeAttributes::Ptr clone() const override;

std::map<std::string, double> semantic_class_probabilities;

protected:
std::ostream& fill_ostream(std::ostream& out) const override;
void serialization_info() override;
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>spark_dsg</name>
<version>1.0.2</version>
<version>1.0.5</version>
<description>Dynamic Scene Graph (DSG) type definitions and core library code</description>

<author email="[email protected]">Nathan Hughes</author>
Expand Down
6 changes: 3 additions & 3 deletions python/bindings/src/node_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -151,9 +153,7 @@ void addBindings(pybind11::module_& module) {
});

py::class_<RoomNodeAttributes, SemanticNodeAttributes>(module, "RoomNodeAttributes")
.def(py::init<>())
.def_readwrite("semantic_class_probabilities",
&RoomNodeAttributes::semantic_class_probabilities);
.def(py::init<>());

py::class_<NearestVertexInfo>(module, "NearestVertexInfo")
.def(py::init<>())
Expand Down
43 changes: 40 additions & 3 deletions src/node_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ std::string showIterable(const T& iterable, size_t max_length = 80) {
return ss.str();
}

template <typename T>
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 <typename Scalar>
std::string quatToString(const Eigen::Quaternion<Scalar>& q) {
std::stringstream ss;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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<std::string, double> unused;
serialization::field("semantic_class_probabilities", unused);
} else {
io::warnOutdatedHeader(header);
}
}

bool RoomNodeAttributes::is_equal(const NodeAttributes& other) const {
Expand Down

0 comments on commit 4dbf0a6

Please sign in to comment.