Skip to content

Commit

Permalink
Build grid for NanoVDB volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
szellmann committed Dec 9, 2024
1 parent 71b8bb3 commit b0d8996
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scene/volume/spatial_field/NanoVDBField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void NanoVDBField::commit()

vfield.voxelSpaceTransform = mat4x3(mat3::identity(),float3{0.f,0.f,0.f});

buildGrid();

vfield.gridAccel = m_gridAccel.visionarayAccel();

dispatch();
}

Expand All @@ -68,4 +72,39 @@ aabb NanoVDBField::bounds() const
{(float)upper[0], (float)upper[1], (float)upper[2]}};
}

void NanoVDBField::buildGrid()
{
#if defined(WITH_CUDA) || defined(WITH_HIP)
return;
#endif
int3 gridDims{64, 64, 64};
box3f worldBounds = {bounds().min,bounds().max};
m_gridAccel.init(gridDims, worldBounds);

dco::GridAccel &vaccel = m_gridAccel.visionarayAccel();
auto acc = vfield.asNanoVDB.grid->getAccessor();

float3 mcSize = (worldBounds.max-worldBounds.min) / float3(gridDims);

for (unsigned mcz=0; mcz<gridDims.z; ++mcz) {
for (unsigned mcy=0; mcy<gridDims.y; ++mcy) {
for (unsigned mcx=0; mcx<gridDims.x; ++mcx) {
const vec3i mcID(mcx,mcy,mcz);
box3f mcBounds{worldBounds.min+mcSize*float3(mcx,mcy,mcz),
worldBounds.min+mcSize*float3(mcx+1,mcy+1,mcz+1)};

nanovdb::CoordBBox bbox(
{(int)mcBounds.min.x,(int)mcBounds.min.y,(int)mcBounds.min.z},
{(int)mcBounds.max.x+1,(int)mcBounds.max.y+1,(int)mcBounds.max.z+1});

for (nanovdb::CoordBBox::Iterator iter = bbox.begin(); iter; ++iter) {
float value = acc.getValue(*iter);
updateMC(mcID,gridDims,value,vaccel.valueRanges);
updateMCStepSize(mcID,gridDims,0.5f,vaccel.stepSizes); // TODO!?
}
}
}
}
}

} // namespace visionaray
2 changes: 2 additions & 0 deletions scene/volume/spatial_field/NanoVDBField.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct NanoVDBField : public SpatialField
bool isValid() const override;

aabb bounds() const override;

void buildGrid() override;
private:

helium::IntrusivePtr<Array1D> m_gridData;
Expand Down

0 comments on commit b0d8996

Please sign in to comment.