Skip to content

Commit

Permalink
Minor fixes around yield and compact node (#333)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
msz-rai authored Sep 27, 2024
1 parent bd194c7 commit c7ea149
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/graph/NodesCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CompactByFieldPointsNode : IPointsNodeSingleInput
void enqueueExecImpl() override;

// Node requirements
std::vector<rgl_field_t> getRequiredFieldList() const override { return {IS_HIT_I32, IS_GROUND_I32}; }
std::vector<rgl_field_t> getRequiredFieldList() const override { return {fieldToCompactBy}; }

// Point cloud description
bool isDense() const override { return true; }
Expand Down Expand Up @@ -399,8 +399,15 @@ struct YieldPointsNode : IPointsNodeSingleInput
// Node requirements
std::vector<rgl_field_t> 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<Field<XYZ_VEC3_F32>::type>::Ptr getXYZCache() { return xyzHostCache; }

Expand Down
9 changes: 9 additions & 0 deletions src/graph/YieldPointsNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

void YieldPointsNode::setParameters(const std::vector<rgl_field_t>& 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?
}
Expand All @@ -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);
}

0 comments on commit c7ea149

Please sign in to comment.