From c7ea1497e58fcdd46b813673136e645304b8b29a Mon Sep 17 00:00:00 2001 From: Mateusz Szczygielski <112629916+msz-rai@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:00:14 +0200 Subject: [PATCH] Minor fixes around yield and compact node (#333) * Fix yield node to return hasField() according to its map * Require a field that is actually used by the compact node * Fix case when hasField is called before yield node has finished executing --- src/graph/NodesCore.hpp | 11 +++++++++-- src/graph/YieldPointsNode.cpp | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/graph/NodesCore.hpp b/src/graph/NodesCore.hpp index 8e3b91fd..09b3c495 100644 --- a/src/graph/NodesCore.hpp +++ b/src/graph/NodesCore.hpp @@ -84,7 +84,7 @@ struct CompactByFieldPointsNode : IPointsNodeSingleInput void enqueueExecImpl() override; // Node requirements - std::vector getRequiredFieldList() const override { return {IS_HIT_I32, IS_GROUND_I32}; } + std::vector getRequiredFieldList() const override { return {fieldToCompactBy}; } // Point cloud description bool isDense() const override { return true; } @@ -399,8 +399,15 @@ struct YieldPointsNode : IPointsNodeSingleInput // Node requirements std::vector getRequiredFieldList() const override { return fields; } + // Point cloud description + bool hasField(rgl_field_t field) const override + { + // The `results` map cannot be relied on because the hasField() may be called before the node has finished executing. + return std::find(fields.begin(), fields.end(), field) != fields.end(); + } + // Data getters - IAnyArray::ConstPtr getFieldData(rgl_field_t field) override { return results.at(field); } + IAnyArray::ConstPtr getFieldData(rgl_field_t field) override; HostPinnedArray::type>::Ptr getXYZCache() { return xyzHostCache; } diff --git a/src/graph/YieldPointsNode.cpp b/src/graph/YieldPointsNode.cpp index b6a0b6ba..d0bcb43a 100644 --- a/src/graph/YieldPointsNode.cpp +++ b/src/graph/YieldPointsNode.cpp @@ -16,6 +16,7 @@ void YieldPointsNode::setParameters(const std::vector& fields) { + results.clear(); if (std::find(fields.begin(), fields.end(), RGL_FIELD_DYNAMIC_FORMAT) != fields.end()) { throw InvalidAPIArgument("cannot yield field 'RGL_FIELD_DYNAMIC_FORMAT'"); // TODO: Yeah, but dummies are OK? } @@ -33,3 +34,11 @@ void YieldPointsNode::enqueueExecImpl() xyzHostCache->getCount() * xyzHostCache->getSizeOf(), cudaMemcpyDefault, getStreamHandle())); } } + +IAnyArray::ConstPtr YieldPointsNode::getFieldData(rgl_field_t field) +{ + if (!results.contains(field)) { + throw std::runtime_error("Field data is not ready yet. It was requested without waiting for results."); + } + return results.at(field); +}