Skip to content

Commit 910f775

Browse files
committed
--allow for accessing semantic data vector
1 parent d836e6f commit 910f775

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

src/esp/bindings/SceneBindings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void initSceneBindings(py::module& m) {
5454
.def_property("type", &SceneNode::getType, &SceneNode::setType)
5555
.def_property("semantic_id", &SceneNode::getSemanticId,
5656
&SceneNode::setSemanticId)
57+
.def_property(
58+
"object_semantic_id", &SceneNode::getBaseObjectId,
59+
&SceneNode::setBaseObjectId,
60+
R"(This node's owning object's ID, for instance-based semantics)")
61+
.def_property(
62+
"drawable_semantic_id", &SceneNode::getDrawableId,
63+
&SceneNode::setDrawableId,
64+
R"(This node's drawable's ID, for instance-based semantics)")
5765
.def(
5866
"create_child", [](SceneNode& self) { return &self.createChild(); },
5967
R"(Creates a child node, and sets its parent to the current node.)")

src/esp/scene/SceneNode.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// This source code is licensed under the MIT license found in the
33
// LICENSE file in the root directory of this source tree.
44

5-
#include "SceneNode.h"
5+
#include <Corrade/Utility/Assert.h>
6+
67
#include "SceneGraph.h"
8+
#include "SceneNode.h"
79
#include "esp/core/Check.h"
810
#include "esp/geo/Geo.h"
911
#include "esp/sensor/Sensor.h"
@@ -239,6 +241,14 @@ const Mn::Range3D& SceneNode::getAbsoluteAABB() const {
239241
}
240242
}
241243

244+
void SceneNode::setSemanticIDVector(const std::vector<int>& _semanticIDs) {
245+
if (semanticIDs_.size() < _semanticIDs.size()) {
246+
semanticIDs_.resize(_semanticIDs.size());
247+
}
248+
std::copy(std::begin(_semanticIDs), std::end(_semanticIDs),
249+
std::begin(semanticIDs_));
250+
}
251+
242252
void setSemanticIdForSubtree(SceneNode* node, int semanticId) {
243253
if (node->getSemanticId() == semanticId) {
244254
// We assume the entire subtree's semanticId matches the root's, so we can
@@ -253,5 +263,17 @@ void setSemanticIdForSubtree(SceneNode* node, int semanticId) {
253263
preOrderTraversalWithCallback(*node, cb);
254264
}
255265

266+
void setSemanticInfoForSubtree(SceneNode* node,
267+
const std::vector<int>& _semanticIDs) {
268+
if (node->getSemanticIDVector() == _semanticIDs) {
269+
// We assume the entire subtree's semantic/instance ID vector matches the
270+
// root's, so we can early out here.
271+
return;
272+
}
273+
274+
auto cb = [&](SceneNode& node) { node.setSemanticIDVector(_semanticIDs); };
275+
preOrderTraversalWithCallback(*node, cb);
276+
}
277+
256278
} // namespace scene
257279
} // namespace esp

src/esp/scene/SceneNode.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,24 @@ class SceneNode : public MagnumObject,
165165
semanticId;
166166
}
167167

168+
//! Gets node's owning objectID, for panoptic rendering.
169+
virtual int getBaseObjectId() const {
170+
return semanticIDs_[static_cast<int>(SceneNodeSemanticDataIDX::OBJECT_ID)];
171+
}
172+
168173
//! Sets node's owning objectID, for panoptic rendering.
169-
virtual void setBaseObjectId(int objectId) {
174+
void setBaseObjectId(int objectId) {
170175
semanticIDs_[static_cast<int>(SceneNodeSemanticDataIDX::OBJECT_ID)] =
171176
objectId;
172177
}
178+
//! Gets node's corresponding drawable's id, for panoptic rendering.
179+
virtual int getDrawableId() const {
180+
return semanticIDs_[static_cast<int>(
181+
SceneNodeSemanticDataIDX::DRAWABLE_ID)];
182+
}
173183

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

@@ -191,6 +201,17 @@ class SceneNode : public MagnumObject,
191201
* scene node.
192202
*/
193203
const std::vector<int>& getSemanticIDVector() const { return semanticIDs_; }
204+
205+
/**
206+
* @brief Set the value for the various semantic IDs to be rendered by this
207+
* scene node. As values are added, we want to make sure we support shorter,
208+
* older vectors.
209+
* @param _semanticIDs The vector of semantic sensor IDs this scene node will
210+
* use for rendering. This vector might not be the same size as the current
211+
* vector.
212+
*/
213+
void setSemanticIDVector(const std::vector<int>& _semanticIDs);
214+
194215
Magnum::Vector3 absoluteTranslation() const;
195216

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

432+
/**
433+
* @brief Set the semantic and instance IDs of a scene graph subtree.
434+
*
435+
* @param node Root node of the subtree.
436+
* @param semanticIDs Vector of semantic and instance ids to set
437+
*/
438+
void setSemanticInfoForSubtree(SceneNode* node,
439+
const std::vector<int>& _semanticIDs);
440+
411441
CORRADE_ENUMSET_OPERATORS(SceneNodeTags)
412442
} // namespace scene
413443
} // namespace esp

0 commit comments

Comments
 (0)