Below is a full example using the native components.
struct MyTransfer :
{
MyTransfer(const MyTransfer& other)
bool startPointLeaf(const PointDataTree::LeafNodeType& leaf)
{
mHandle = std::make_unique<AttributeHandle<Vec3f>>(leaf.constAttributeArray("P"));
mFilter = std::make_unique<GroupFilter>("mygroup", leaf.attributeSet());
return true;
}
void rasterizePoint(const Coord& ijk, const Index id, const CoordBBox& bounds)
{
if (!mFilter->valid(&id)) return;
Vec3d P = ijk.asVec3d() + Vec3d(this->mHandle->get(id));
P = this->transformSourceToTarget(P);
const auto* mask = this->mask();
for (auto& coord : bounds) {
const Index voxel = FloatTree::LeafNodeType::coordToOffset(coord);
if (!mask->isOn(voxel)) continue;
Vec3d dist = coord.asVec3d() - P;
this->buffer()[voxel] += dist.
length();
}
}
bool endPointLeaf(const PointDataTree::LeafNodeType&) { return true; }
bool finalize(const Coord&, size_t) { return false; }
private:
std::unique_ptr<AttributeHandle<Vec3f>> mHandle {nullptr};
std::unique_ptr<GroupFilter> mFilter {nullptr};
};
T length() const
Length of the vector.
Definition Vec3.h:201
Vec3< int32_t > Vec3i
Definition Vec3.h:662
Grid< PointDataTree > PointDataGrid
Point data grid.
Definition PointDataGrid.h:195
Definition PointDataGrid.h:170
Grid< FloatTree > FloatGrid
Definition openvdb.h:75
The VolumeTransfer module provides methods to automatically setup and access destination buffers for ...
Definition PointTransfer.h:297