Skip to content

Commit

Permalink
--allow for accessing semantic data vector
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Feb 15, 2024
1 parent d836e6f commit 910f775
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/esp/bindings/SceneBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ void initSceneBindings(py::module& m) {
.def_property("type", &SceneNode::getType, &SceneNode::setType)
.def_property("semantic_id", &SceneNode::getSemanticId,
&SceneNode::setSemanticId)
.def_property(
"object_semantic_id", &SceneNode::getBaseObjectId,
&SceneNode::setBaseObjectId,
R"(This node's owning object's ID, for instance-based semantics)")
.def_property(
"drawable_semantic_id", &SceneNode::getDrawableId,
&SceneNode::setDrawableId,
R"(This node's drawable's ID, for instance-based semantics)")
.def(
"create_child", [](SceneNode& self) { return &self.createChild(); },
R"(Creates a child node, and sets its parent to the current node.)")
Expand Down
24 changes: 23 additions & 1 deletion src/esp/scene/SceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include "SceneNode.h"
#include <Corrade/Utility/Assert.h>

#include "SceneGraph.h"
#include "SceneNode.h"
#include "esp/core/Check.h"
#include "esp/geo/Geo.h"
#include "esp/sensor/Sensor.h"
Expand Down Expand Up @@ -239,6 +241,14 @@ const Mn::Range3D& SceneNode::getAbsoluteAABB() const {
}
}

void SceneNode::setSemanticIDVector(const std::vector<int>& _semanticIDs) {
if (semanticIDs_.size() < _semanticIDs.size()) {
semanticIDs_.resize(_semanticIDs.size());
}
std::copy(std::begin(_semanticIDs), std::end(_semanticIDs),
std::begin(semanticIDs_));
}

void setSemanticIdForSubtree(SceneNode* node, int semanticId) {
if (node->getSemanticId() == semanticId) {
// We assume the entire subtree's semanticId matches the root's, so we can
Expand All @@ -253,5 +263,17 @@ void setSemanticIdForSubtree(SceneNode* node, int semanticId) {
preOrderTraversalWithCallback(*node, cb);
}

void setSemanticInfoForSubtree(SceneNode* node,
const std::vector<int>& _semanticIDs) {
if (node->getSemanticIDVector() == _semanticIDs) {
// We assume the entire subtree's semantic/instance ID vector matches the
// root's, so we can early out here.
return;
}

auto cb = [&](SceneNode& node) { node.setSemanticIDVector(_semanticIDs); };
preOrderTraversalWithCallback(*node, cb);
}

} // namespace scene
} // namespace esp
36 changes: 33 additions & 3 deletions src/esp/scene/SceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,24 @@ class SceneNode : public MagnumObject,
semanticId;
}

//! Gets node's owning objectID, for panoptic rendering.
virtual int getBaseObjectId() const {
return semanticIDs_[static_cast<int>(SceneNodeSemanticDataIDX::OBJECT_ID)];
}

//! Sets node's owning objectID, for panoptic rendering.
virtual void setBaseObjectId(int objectId) {
void setBaseObjectId(int objectId) {
semanticIDs_[static_cast<int>(SceneNodeSemanticDataIDX::OBJECT_ID)] =
objectId;
}
//! Gets node's corresponding drawable's id, for panoptic rendering.
virtual int getDrawableId() const {
return semanticIDs_[static_cast<int>(
SceneNodeSemanticDataIDX::DRAWABLE_ID)];
}

//! Sets node's corresponding drawable's id, for panoptic rendering.
virtual void setDrawableId(int drawableId) {
void setDrawableId(int drawableId) {
semanticIDs_[static_cast<int>(SceneNodeSemanticDataIDX::DRAWABLE_ID)] =
drawableId;
}
Expand All @@ -182,7 +192,7 @@ class SceneNode : public MagnumObject,
* @param idToGetIDX The index of the ID to get
* @return the semantic value corresponding to the given index
*/
virtual int getShaderObjectID(int idToGetIDX) const {
int getShaderObjectID(int idToGetIDX) const {
return semanticIDs_[idToGetIDX];
}

Expand All @@ -191,6 +201,17 @@ class SceneNode : public MagnumObject,
* scene node.
*/
const std::vector<int>& getSemanticIDVector() const { return semanticIDs_; }

/**
* @brief Set the value for the various semantic IDs to be rendered by this
* scene node. As values are added, we want to make sure we support shorter,
* older vectors.
* @param _semanticIDs The vector of semantic sensor IDs this scene node will
* use for rendering. This vector might not be the same size as the current
* vector.
*/
void setSemanticIDVector(const std::vector<int>& _semanticIDs);

Magnum::Vector3 absoluteTranslation() const;

Magnum::Vector3 absoluteTranslation();
Expand Down Expand Up @@ -408,6 +429,15 @@ void preOrderFeatureTraversalWithCallback(SceneNode& node, Callable&& cb) {
*/
void setSemanticIdForSubtree(SceneNode* node, int semanticId);

/**
* @brief Set the semantic and instance IDs of a scene graph subtree.
*
* @param node Root node of the subtree.
* @param semanticIDs Vector of semantic and instance ids to set
*/
void setSemanticInfoForSubtree(SceneNode* node,
const std::vector<int>& _semanticIDs);

CORRADE_ENUMSET_OPERATORS(SceneNodeTags)
} // namespace scene
} // namespace esp
Expand Down

0 comments on commit 910f775

Please sign in to comment.