Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
321 commits
Select commit Hold shift + click to select a range
0651e12
reverted use of createLevelSetDilatedMesh
kmuseth Jan 28, 2026
a49e070
removed FilesLoop
kmuseth Jan 28, 2026
08ecd14
added missing include
kmuseth Jan 28, 2026
733ca17
Add meeting notes Jan 14 2026.
apradhana Jan 28, 2026
5a1d810
snapshot
kmuseth Jan 28, 2026
9bc561d
added -files action
kmuseth Jan 29, 2026
2d0d8d8
snapshot
kmuseth Jan 29, 2026
6042fe0
snapshot
kmuseth Jan 29, 2026
008fcfd
snapshot
kmuseth Jan 29, 2026
18ea0dc
snapshot
kmuseth Jan 30, 2026
af6d21e
Merge pull request #2152 from danrbailey/fix_point_index_io_bug
danrbailey Jan 30, 2026
d563f21
added Spinner to vdb_tool
kmuseth Jan 31, 2026
7bda52e
snapshot
kmuseth Jan 31, 2026
b8a7017
Merge remote-tracking branch 'origin' into improve_vdb_tool_2
kmuseth Jan 31, 2026
6c72d4b
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Jan 31, 2026
c3a13f7
snapshot
kmuseth Feb 2, 2026
7331cbb
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Feb 2, 2026
6dba711
snapshot
kmuseth Feb 2, 2026
c4b1fdf
snapshot
kmuseth Feb 3, 2026
acd69bd
major simlifications to soup2ls
kmuseth Feb 3, 2026
16289e6
cleanup and optimization wrt mesh update
kmuseth Feb 4, 2026
457923e
snapshot
kmuseth Feb 4, 2026
affe5ee
major cleanup and fixed estimateVoxelSize
kmuseth Feb 4, 2026
ed67752
fixed bug related to use of -debug
kmuseth Feb 5, 2026
4b150d2
improved previous fix
kmuseth Feb 5, 2026
43de2e3
snapshot
kmuseth Feb 6, 2026
c7930b0
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Feb 6, 2026
42ea51f
removed whitespace
kmuseth Feb 6, 2026
b922803
added Geometry::isPlanar
kmuseth Feb 6, 2026
5d1d089
placeholder for PolySoupToLevelSet.h
kmuseth Feb 6, 2026
489397f
finished implementation of tools/PolySoupToLevelSet.h
kmuseth Feb 6, 2026
b5ef5d7
imrpoved polySoupToLevelSet with functor for D(dx)
kmuseth Feb 6, 2026
acd3675
improved documentation
kmuseth Feb 7, 2026
7e4a4e4
snapshot
kmuseth Feb 7, 2026
b743393
snapshot
kmuseth Feb 7, 2026
afe9ab7
snapshot
kmuseth Feb 9, 2026
5594b15
output is not directed to cerr in order not to conflict with piplining
kmuseth Feb 9, 2026
6a7716f
removed whitespace
kmuseth Feb 10, 2026
470d617
snapshot
kmuseth Feb 10, 2026
1945a45
snapshot
kmuseth Feb 10, 2026
6f99494
Add TSC Meeting Notes 2026-02-22.md.
apradhana Feb 11, 2026
7bda688
added unit test for the new -files loop
kmuseth Feb 12, 2026
b570fb0
added ProgressT to PolySoupToLevelSet
kmuseth Feb 12, 2026
49727f6
Use ASWF images for docs
danrbailey Feb 13, 2026
73af5d2
Merge pull request #2167 from danrbailey/docs_ci
danrbailey Feb 13, 2026
2e09066
major rewrite of PolySoupToLevelSet.h
kmuseth Feb 14, 2026
20e9d75
This commit adds Python bindings for OpenVDB's polySoupToLevelSet too…
rohan-sawhney Feb 14, 2026
70ca7b2
remove unused variable from test
rohan-sawhney Feb 14, 2026
f60a647
minor fix to PolySoupToLevelSet.h
kmuseth Feb 14, 2026
2437d35
improved doxygen documentation
kmuseth Feb 14, 2026
443221f
improved documentation
kmuseth Feb 16, 2026
f6294c5
snapshot
kmuseth Feb 19, 2026
7657e2b
added cutoff option to -ls2fog action
kmuseth Feb 20, 2026
43e570e
move python shrink wrap example to app folder inside openvdb/python
rohan-sawhney Feb 20, 2026
a0fefc4
Merge pull request #9 from rohan-sawhney/improve_vdb_tool_2
kmuseth Feb 20, 2026
1615df3
added vol2mesh and fog2mesh actions
kmuseth Feb 21, 2026
546b86a
consolidated actions into volumeToMesh
kmuseth Feb 21, 2026
0d4cf92
added placeholder for -slice action
kmuseth Feb 23, 2026
9007165
snapshot
kmuseth Feb 24, 2026
78752e1
snapshot
kmuseth Feb 24, 2026
3446183
finished implementation of -slice action
kmuseth Feb 24, 2026
11835c0
updated change files
kmuseth Feb 24, 2026
7adde81
snapshot
kmuseth Feb 24, 2026
475ef36
Fixed a unit test failure on non 64bit architectures
Idclip Feb 24, 2026
476db06
fix nanobind install
swahtz Feb 25, 2026
d72d0de
signature fixes
swahtz Feb 25, 2026
272e2d4
Add isGpuAvailable function to check for CUDA-capable GPU availability
swahtz Feb 26, 2026
494a6e5
release test executables
swahtz Feb 26, 2026
0daa226
python path on windows fix
swahtz Feb 26, 2026
72455de
windows python: fix for required dll directories
swahtz Feb 26, 2026
de4cecf
windows paths
swahtz Feb 26, 2026
02652dd
test fixes
swahtz Feb 26, 2026
437875f
Merge pull request #2171 from Idclip/unit_test_fix
Idclip Feb 26, 2026
b740c83
added ascii option to -write
kmuseth Feb 26, 2026
6ebf82a
fixed typos
kmuseth Feb 28, 2026
01b792f
cleaned up -slice implementation
kmuseth Mar 1, 2026
5eb31b2
cleanup
kmuseth Mar 2, 2026
c22ff41
cleanup
kmuseth Mar 2, 2026
31188ad
added force option to -slice action
kmuseth Mar 2, 2026
6e3851a
snapshot
kmuseth Mar 2, 2026
c5cb54e
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Mar 2, 2026
2f28ad5
snapshot
kmuseth Mar 3, 2026
9d86849
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Mar 3, 2026
c51f7a6
fixed typo
kmuseth Mar 3, 2026
3bf14ef
NanoVDB `PointsToGrid::countNodes`: Use segmented radix sort for high…
swahtz Mar 4, 2026
5c26f15
placeholder for imgToMpeg
kmuseth Mar 4, 2026
2bb7fcd
improved imgToMpeg
kmuseth Mar 4, 2026
59b4503
snapshot
kmuseth Mar 4, 2026
bfd4414
updated cmake with VDB_TOOL_USE_MPEG
kmuseth Mar 4, 2026
555c7a2
improved -movie action
kmuseth Mar 5, 2026
399cba8
correct aspect ratio in -slice
kmuseth Mar 6, 2026
47ce0c8
snapshot
kmuseth Mar 7, 2026
c64832b
added replaceExt
kmuseth Mar 7, 2026
ad5ae9f
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Mar 7, 2026
d601927
snapshot
kmuseth Mar 7, 2026
40132c3
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Mar 7, 2026
3e84d94
improved error handling in vdb_tool
kmuseth Mar 8, 2026
1235134
added action -errorOnWarning
kmuseth Mar 9, 2026
9737554
snapshot
kmuseth Mar 9, 2026
95866ef
added exclude option to -files
kmuseth Mar 9, 2026
9e7452f
added -log action with file option
kmuseth Mar 10, 2026
7c64387
snapshot
kmuseth Mar 10, 2026
43c571f
snapshot
kmuseth Mar 10, 2026
c8b526d
snapshot
kmuseth Mar 10, 2026
821ac83
-files path= is not optional
kmuseth Mar 10, 2026
2b38319
snapshot
kmuseth Mar 11, 2026
2a1adec
snapshot
kmuseth Mar 11, 2026
814ce30
Texlive was upgraded from 2025 to 2026, use whichever version is inst…
danrbailey Mar 11, 2026
747f970
Merge pull request #2176 from danrbailey/doxygen_fix
danrbailey Mar 11, 2026
0110bf6
Merge pull request #2149 from swahtz/enable_nanovdb_pytests
swahtz Mar 11, 2026
e3b3268
snapshot
kmuseth Mar 12, 2026
25556b7
improved Tool::config and README.md
kmuseth Mar 12, 2026
4c9aab6
fixed failed unit test
kmuseth Mar 13, 2026
2470dce
now -files supports multiple path and anonymous path
kmuseth Mar 13, 2026
76f924b
added min_size and max_size options to -files action
kmuseth Mar 13, 2026
0690431
failed attempt that removing mesh <-> VDB round trips
kmuseth Mar 13, 2026
6588c44
snapshot
kmuseth Mar 16, 2026
2bd9070
Fix OPENVDB_TESTS
danrbailey Mar 20, 2026
d69862a
Suppress warning - "WARNING: testGridNaming.vdb2 has more than one gr…
danrbailey Mar 20, 2026
5b3312d
fixed typos in README.md
kmuseth Mar 21, 2026
8ba6d31
NanoVDB:
jmlait Mar 27, 2026
29fdff0
Merge pull request #2181 from danrbailey/fix_openvdb_tests
danrbailey Mar 27, 2026
5a79aa3
Merge pull request #2182 from danrbailey/suppress_unittest_warning
danrbailey Mar 27, 2026
69b859b
Merge pull request #2163 from apradhana/TSC-Jan142026
danrbailey Mar 27, 2026
7d6832d
Update CONTRIBUTING.md to include new policy about closing PRs that d…
danrbailey Mar 27, 2026
061597b
Remove trailing whitespace.
jmlait Mar 28, 2026
d1954e8
cleanup
kmuseth Mar 30, 2026
1ad76da
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth Mar 30, 2026
b3dcbfd
fixed a few typos
kmuseth Mar 31, 2026
9033991
NanoVDB: add CPU port of VoxelBlockManager and supporting utilities (…
sifakis Apr 1, 2026
563fe83
Merge pull request #2188 from danrbailey/stale_pr_policy
danrbailey Apr 6, 2026
94c9d49
Meeting Notes
danrbailey Apr 9, 2026
de2beee
Added copy of VCL (version2) v2.02.03 at dc6cb6cea60bb983314c33386f5f…
Idclip Apr 14, 2026
11fe358
Removed compiled parts of VCL used for examples and runtime instructi…
Idclip Apr 14, 2026
609a19f
Pass texlive repository argument explicitly to match tlnet version
danrbailey Apr 21, 2026
3fe1482
Merge pull request #2194 from danrbailey/fix_texlive_download
danrbailey Apr 21, 2026
d61220e
Use a specific texlive mirror to try and improve stability
danrbailey Apr 22, 2026
d11b61f
Merge pull request #2195 from danrbailey/texlive_mirror
danrbailey Apr 22, 2026
62846aa
new experimental offset and tools::distanceFieldToSDF
kmuseth Apr 29, 2026
85a5d3b
Fix pending change spelling
jmlait Apr 29, 2026
2a40e47
Merge pull request #2191 from danrbailey/notes_0804
danrbailey Apr 29, 2026
1f57a10
Add the static to the cnanovdb_readaccessor_init to match the other
jmlait Apr 30, 2026
2549b79
added ex_raytrace_iso_surface
kmuseth Apr 30, 2026
e94f62b
When syncing accidentally reset the magic number test to the old
jmlait May 4, 2026
ac952ca
added points2sdf
kmuseth May 4, 2026
054a43c
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth May 4, 2026
11a90ef
BROKEN commit
kmuseth May 4, 2026
a275d6a
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth May 4, 2026
49e3749
ray-tracing of nanovdb::Grids<ValueOnIndex> with unsigned distance fi…
kmuseth May 4, 2026
a5f721e
major cleanup of ex_raytrace_iso_surface
kmuseth May 5, 2026
5bde6dc
Switch from tbb/blocked_range.h to tbb/task_arena.h to pull in TBB ve…
danrbailey May 6, 2026
94f6d6e
documentation
kmuseth May 6, 2026
68baf93
snapshot
kmuseth May 6, 2026
18332dc
snapshot
kmuseth May 6, 2026
e6543f6
Merge pull request #2200 from danrbailey/tbb2023
danrbailey May 6, 2026
2163471
Add support for reading file version 221 (FLOAT_FRUSTUM_BBOX)
danrbailey Apr 11, 2026
e287f84
Merge pull request #2193 from danrbailey/io_float_frustum_bbox
danrbailey May 6, 2026
eaf7824
added mode option to -soup2ls and soup2offset
kmuseth May 7, 2026
931a489
snapshot
kmuseth May 7, 2026
8269e25
fixed bug in -soup2offset
kmuseth May 10, 2026
6909648
added action alias -shrinkwrap for -soup2ls
kmuseth May 11, 2026
6a30a43
snapshot
kmuseth May 11, 2026
765400c
snapshot
kmuseth May 11, 2026
6ae3b06
Merge pull request #2187 from sideeffects/send_upstream_fixcannovdbsize
jmlait May 13, 2026
2e326ec
documentation
kmuseth May 13, 2026
b4aed3a
Massively improved Doxygen documentation for Geometry.h, Util.h and …
kmuseth May 13, 2026
5d82714
more documentation
kmuseth May 13, 2026
8a8be3a
improved documentation in Tools.h
kmuseth May 13, 2026
88bc745
improved vdb_tool/examples files
kmuseth May 13, 2026
4492fc8
improved unit-test coverage of vdb_tool
kmuseth May 13, 2026
3e51b42
improved unit-test coverage of Util.h
kmuseth May 13, 2026
544190c
Added VCL SIMD header wrapper for aliasing between simd, tuple and sc…
Idclip Jul 8, 2023
d3d7fcf
Initial manual vectorization/matching of SphericalTransfer scheme i.e…
Idclip Apr 3, 2026
30b537d
Added weekly CI for VCL=ON (OFF by default)
Idclip Apr 8, 2026
ac2e13d
Minor fixes for AVX512F/AVX512+
Idclip Apr 12, 2026
4ec2411
Removed Tuple < and > operators - added explicit overloads for cwiseL…
Idclip May 4, 2026
58bc64a
Re-introduce Vec relational ops as deprecated (but note that these de…
Idclip May 13, 2026
77b2b5d
Added component wise operators to Tuple, including comparison operato…
Idclip May 4, 2026
ae01ce7
Converted Rasterize over to new operators away from explicit methods
Idclip May 4, 2026
30666fd
Added pendingchanges
Idclip May 14, 2026
1043e16
Update to Tree Iterator to work with Mask Grids
danrbailey Feb 17, 2026
29af0b2
Add unit test for mask leaf iterator
danrbailey May 14, 2026
9787995
Add pending notes
danrbailey May 14, 2026
6e20818
added action -sdf2udf/abs
kmuseth May 14, 2026
1fe6702
PR feedback - typos, tests and fixes
Idclip May 15, 2026
da3cf29
Merge pull request #2202 from danrbailey/mask_iterator
danrbailey May 15, 2026
7d506bd
Merge pull request #2190 from Idclip/vcl_simd
Idclip May 16, 2026
2977ff6
snapshot
kmuseth May 18, 2026
fe4e9da
snapshot
kmuseth May 18, 2026
c388cc9
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth May 18, 2026
d071917
Fixed a mistake in a AX unit test causing bad IR generation
Idclip May 18, 2026
088527a
Fixed a few strict CXX build issues on clang macos
Idclip May 18, 2026
fc93727
Added an assert to check that function group symbols are unique
Idclip May 18, 2026
85438f9
Add MeshToGrid: CUDA triangle mesh to NanoVDB UDF/IndexGrid converter…
sifakis May 21, 2026
7817e18
added actions -forAllValues, -forOnValues and -forOffValues
kmuseth May 21, 2026
fb04324
Merge remote-tracking branch 'upstream/master' into improve_vdb_tool_2
kmuseth May 21, 2026
600fbad
added OpenUSD read support
kmuseth May 22, 2026
8573ed6
snapshot
kmuseth May 22, 2026
7070cc1
fixed bug in -slice and added more unit-tests
kmuseth May 22, 2026
fefda65
Add persistent CUDA ray tracing path for iso-surface example
rohan-sawhney May 25, 2026
6738c4d
forgot to add FastExpr.h
kmuseth May 26, 2026
2ecd8f3
Suppress some doxygen warings in AST.h
Idclip May 28, 2026
1f0d204
improved documentation
kmuseth May 29, 2026
0b37233
Merge pull request #2205 from Idclip/ax_unit_test_fixes
Idclip May 29, 2026
8416906
added comments explaining persistent threads logic
rohan-sawhney May 29, 2026
7030e77
Merge pull request #10 from rohan-sawhney/improve_vdb_tool_2
kmuseth May 29, 2026
003e18d
added action -calc and made several improvements to Calculator class
kmuseth May 30, 2026
f6bb3ab
Merge remote-tracking branch 'origin/improve_vdb_tool_2' into improve…
kmuseth May 30, 2026
dffaed7
option pre-fix named kernel is now optional for the actions -calc/for…
kmuseth May 31, 2026
54e4078
massive improvements to Calculator and Parser
kmuseth Jun 1, 2026
044cc5f
-forValues now support multiple grids
kmuseth Jun 2, 2026
d0078f9
fixed some typos
kmuseth Jun 2, 2026
4b07d97
fixed some typos
kmuseth Jun 2, 2026
430ede2
cleanup
kmuseth Jun 3, 2026
bb25954
improved uuid and added quiet option to -for loops
kmuseth Jun 3, 2026
d058703
imrpoved printout format of the -print action
kmuseth Jun 5, 2026
2f05ecd
Fix an issue with blosc zlib on Windows static lib (use zlib that Ope…
danrbailey Jun 11, 2026
4b6afe9
Synchnronization with Houdini 22.
jmlait Jun 11, 2026
6206bd0
Add pending changes.
jmlait Jun 11, 2026
9ac662c
Fix the missing NODE_MASK_COMPRESSION tests in Archive.cc, restoring
jmlait Jun 11, 2026
8d49a50
Must use getFormatVersion as readGridCompression is static.
jmlait Jun 11, 2026
c21e8b1
Pending change for 221 fix.
jmlait Jun 12, 2026
ba6ec74
Merge pull request #2235 from sideeffects/sendupstream_221support
jmlait Jun 17, 2026
c313acf
Merge pull request #2233 from sideeffects/sendupstream_h22sync
jmlait Jun 17, 2026
238e586
Add changes
danrbailey Jun 18, 2026
6a20fea
Merge pull request #2234 from AcademySoftwareFoundation/feature/fix_w…
danrbailey Jun 18, 2026
be4f270
Merge pull request #2222 from Idclip/ax_ast_doxy
danrbailey Jun 18, 2026
505ca1d
improved format and information for the -print action
kmuseth Jun 18, 2026
f7f69d4
make 6 major improvements to the -log action
kmuseth Jun 18, 2026
a734ef6
adopted <filesystem> and improved Geometry::triangulate
kmuseth Jun 19, 2026
7848ce8
added read support for gltf and glb geometry files used by Blender an…
kmuseth Jun 21, 2026
ef90fa3
cleanup
kmuseth Jun 21, 2026
e35666e
snapshot
kmuseth Jun 21, 2026
e9e0904
now -if works with infix expressions
kmuseth Jun 21, 2026
d3c437c
documentation
kmuseth Jun 22, 2026
7829dfb
added -switch and -case actions
kmuseth Jun 22, 2026
9ce9ce9
snapshot
kmuseth Jun 23, 2026
568b07c
improvements to =print
kmuseth Jun 23, 2026
bd9ab12
documentation
kmuseth Jun 23, 2026
b1c703c
improved openvdb_cmd.txt
kmuseth Jun 23, 2026
e75939d
snapshot
kmuseth Jun 23, 2026
358f6da
Bugfix for GridHandle::read(). (#2237)
areidmeyer Jun 24, 2026
54b1e49
improved -help action
kmuseth Jun 24, 2026
470c99c
Merge remote-tracking branch 'upstream/master' into improve_vdb_tool_2
kmuseth Jun 24, 2026
40e5c1a
removed trailing whitespaces
kmuseth Jun 24, 2026
76f071c
removed trailing whitespaces
kmuseth Jun 24, 2026
9f0a4cb
fixed some compiler warnings
kmuseth Jun 26, 2026
e80571a
fixed more compiler warnings
kmuseth Jun 26, 2026
cdf3a40
address build issues on Windows
kmuseth Jun 27, 2026
249a30c
Merge branch 'master' into improve_vdb_tool_2
kmuseth Jun 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion nanovdb/nanovdb/NanoVDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -4719,7 +4719,7 @@ using OnIndexGrid = Grid<OnIndexTree>;
* @endcode
*/

/// @brief Use this function, which depends a pointer to GridData, to call
/// @brief Use this function, which depends on a pointer to GridData, to call
/// other functions that depend on a NanoGrid of a known ValueType.
/// @details This function allows for generic programming by converting GridData
/// to a NanoGrid of the type encoded in GridData::mGridType.
Expand Down Expand Up @@ -5762,6 +5762,26 @@ class ChannelAccessor : public DefaultReadAccessor<IndexT>

}; // ChannelAccessor

/// @brief Generic Accessor type that maps to either a ReadAccessor or ChannelAccessor
/// @tparam BuildT Build type, e.g. float or ValueOnIndex
/// @tparam ValueT Value type, e.g. float or Vec3f
template <typename BuildT, typename ValueT>
using AccType = typename util::conditional<BuildTraits<BuildT>::is_index,
ChannelAccessor<ValueT, BuildT>, DefaultReadAccessor<BuildT>>::type;

/// @brief Generic template functions that return an Accessor to either an index grid or a regular grid
template <typename GridT, typename ValueT>
inline __hostdev__ auto getAccessor(const GridT &grid, ValueT *sideCar = nullptr)
{
using BuildT = typename GridT::BuildType;
if constexpr(BuildTraits<BuildT>::is_index) {
return sideCar ? ChannelAccessor<ValueT, BuildT>(grid, sideCar) : ChannelAccessor<ValueT, BuildT>(grid);
} else {
static_assert(util::is_same<ValueT, typename GridT::ValueType>::value, "wrong ValueT for regular GridT");
return DefaultReadAccessor<BuildT>(grid);
}
}

#if 0
// This MiniGridHandle class is only included as a stand-alone example. Note that aligned_alloc is a C++17 feature!
// Normally we recommend using GridHandle defined in util/GridHandle.h but this minimal implementation could be an
Expand Down
1 change: 1 addition & 0 deletions nanovdb/nanovdb/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ nanovdb_example(NAME "ex_bump_pool_buffer")
nanovdb_example(NAME "ex_collide_level_set")
nanovdb_example(NAME "ex_raytrace_fog_volume")
nanovdb_example(NAME "ex_raytrace_level_set")
nanovdb_example(NAME "ex_raytrace_iso_surface")
nanovdb_example(NAME "ex_dilate_nanovdb_cuda" OPENVDB)
nanovdb_example(NAME "ex_merge_nanovdb_cuda" OPENVDB)
nanovdb_example(NAME "ex_refine_nanovdb_cuda" OPENVDB)
Expand Down
187 changes: 187 additions & 0 deletions nanovdb/nanovdb/examples/ex_raytrace_iso_surface/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: Apache-2.0

#pragma once

#define _USE_MATH_DEFINES
#include <cmath>
#include <chrono>
#include <fstream>
#include <nanovdb/NanoVDB.h>
#include "ComputePrimitives.h"

struct RenderOp;
template<typename GridT>
__global__ void renderIsoSurfacePersistentKernel(RenderOp renderOp, float* image, const GridT* grid, int numPixels, int* nextPixel);

struct RenderOp
{
using Vec3T = nanovdb::math::Vec3<float>;
using RayT = nanovdb::math::Ray<float>;
int mWidth, mHeight;
float mDx, mIso, mWBBoxDimZ;
Vec3T mWBBoxCenter;

template<typename BufferT>
RenderOp(nanovdb::GridHandle<BufferT>& handle, int width, int height)
{
mWidth = width;
mHeight = height;
const auto *metaData = handle.gridMetaData();
mDx = float(metaData->voxelSize()[0]);
mIso = mDx;
mWBBoxDimZ = (float)metaData->worldBBox().dim()[2] * 2;
mWBBoxCenter = Vec3T(metaData->worldBBox().min() + metaData->worldBBox().dim() * 0.5f);
}

template<typename GridT>
inline float renderImage(bool useCuda, float* image, const GridT* grid)
{
using ClockT = std::chrono::high_resolution_clock;
auto t0 = ClockT::now();

computeForEach(
useCuda, mWidth * mHeight, 512, __FILE__, __LINE__, [this, image, grid] __hostdev__(int start, int end) {
(*this)(start, end, image, grid);
});
computeSync(useCuda, __FILE__, __LINE__);

auto t1 = ClockT::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count() / 1000.f;
return duration;
}

template <typename GridT>
inline __hostdev__ void operator()(int start, int end, float* image, const GridT* grid) const
{
static_assert(nanovdb::util::is_same<typename GridT::BuildType, float, nanovdb::ValueOnIndex, nanovdb::ValueIndex>::value, "only works for float and OnIndex grids");
auto acc = nanovdb::getAccessor<GridT, float>(*grid);
for (int i = start; i < end; ++i) {
this->renderPixel(i, image, grid, acc);
}
}

template <typename GridT, typename AccT>
inline __hostdev__ void renderPixel(int i, float* image, const GridT* grid, AccT& acc) const
{
float t0, v;
nanovdb::Coord ijk;
RayT iRay = this->getIndexRay(i, grid);
if (nanovdb::math::isoCrossing(iRay, acc, ijk, v, t0, mIso)) {// intersect...
this->composite(image, i, (t0 * mDx) / (mWBBoxDimZ * 2), 1.0f);
} else {
this->composite(image, i, 0.0f, 0.0f);// write background value.
}
}

template<typename GridT>
inline float renderImagePersistent(float* image, const GridT* grid, int* nextPixel) const
{
int device = 0;
NANOVDB_CUDA_CHECK_ERROR(cudaGetDevice(&device), __FILE__, __LINE__);

cudaDeviceProp properties;
NANOVDB_CUDA_CHECK_ERROR(cudaGetDeviceProperties(&properties, device), __FILE__, __LINE__);

constexpr int blockSize = 256;
// Launch a small, fixed pool of blocks that persists on the GPU and
// pulls pixel work from a global counter instead of launching one
// logical thread per pixel up front.
int blockCount = properties.multiProcessorCount * 4;
if (blockCount < 1) blockCount = 1;

// Reset the work queue before each timed render. The kernel advances
// this counter by one warp of pixels at a time.
NANOVDB_CUDA_CHECK_ERROR(cudaMemset(nextPixel, 0, sizeof(int)), __FILE__, __LINE__);

using ClockT = std::chrono::high_resolution_clock;
auto t0 = ClockT::now();

const int numPixels = mWidth * mHeight;
renderIsoSurfacePersistentKernel<GridT><<<blockCount, blockSize>>>(*this, image, grid, numPixels, nextPixel);
NANOVDB_CUDA_CHECK_ERROR(cudaGetLastError(), __FILE__, __LINE__);
NANOVDB_CUDA_CHECK_ERROR(cudaDeviceSynchronize(), __FILE__, __LINE__);

auto t1 = ClockT::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count() / 1000.f;
return duration;
}

template <typename GridT>
inline __hostdev__ RayT getIndexRay(int i, const GridT *grid) const
{
// perspective camera along Z-axis...
const uint32_t x = i % mWidth, y = i / mWidth;
const float fov = 45.f;
const float u = (float(x) + 0.5f) / mWidth;
const float v = (float(y) + 0.5f) / mHeight;
const float aspect = mWidth / float(mHeight);
const float Px = (2.f * u - 1.f) * tanf(fov / 2 * 3.14159265358979323846f / 180.f) * aspect;
const float Py = (2.f * v - 1.f) * tanf(fov / 2 * 3.14159265358979323846f / 180.f);
const Vec3T origin = mWBBoxCenter + Vec3T(0, 0, mWBBoxDimZ);
Vec3T dir(Px, Py, -1.f);
dir.normalize();
RayT wRay(origin, dir);
return wRay.worldToIndexF(*grid);// transform the ray to the grid's index-space.
}

inline __hostdev__ void composite(float* outImage, int offset, float value, float alpha) const
{
const uint32_t x = offset % mWidth, y = offset / mWidth;

// checkerboard background...
const int mask = 1 << 7;
const float bg = ((x & mask) ^ (y & mask)) ? 1.0f : 0.5f;
outImage[offset] = alpha * value + (1.0f - alpha) * bg;
}

inline void saveImage(const std::string& filename, const float* image) const
{
const auto isLittleEndian = []() -> bool {
static int x = 1;
static bool result = reinterpret_cast<uint8_t*>(&x)[0] == 1;
return result;
};

float scale = 1.0f;
if (isLittleEndian()) scale = -scale;

std::fstream fs(filename, std::ios::out | std::ios::binary);
if (!fs.is_open()) throw std::runtime_error("Unable to open file: " + filename);

fs << "Pf\n"
<< mWidth << "\n"
<< mHeight << "\n"
<< scale << "\n";

for (int i = 0; i < mWidth * mHeight; ++i) {
float r = image[i];
fs.write((char*)&r, sizeof(float));
}
}
};

template<typename GridT>
__global__ void renderIsoSurfacePersistentKernel(RenderOp renderOp, float* image, const GridT* grid, int numPixels, int* nextPixel)
{
static_assert(nanovdb::util::is_same<typename GridT::BuildType, float, nanovdb::ValueOnIndex, nanovdb::ValueIndex>::value, "only works for float and OnIndex grids");
auto acc = nanovdb::getAccessor<GridT, float>(*grid);
const unsigned int lane = threadIdx.x & 31u;

// Keep the fixed set of launched threads busy until all pixels have been assigned.
while (true) {
int base = 0;
// Each warp asks the shared counter for the next batch of 32 pixels.
// Only lane 0 updates the counter; __shfl_sync copies lane 0's result
// to the other lanes in the warp.
if (lane == 0) base = atomicAdd(nextPixel, 32);
base = __shfl_sync(0xFFFFFFFFu, base, 0);

// Each lane renders one pixel from the batch: lane 0 renders base,
// lane 1 renders base + 1, and so on.
const int i = base + int(lane);
if (i >= numPixels) break;

renderOp.renderPixel(i, image, grid, acc);
}
}
51 changes: 51 additions & 0 deletions nanovdb/nanovdb/examples/ex_raytrace_iso_surface/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: Apache-2.0

#include <algorithm>
#include <iostream>
#include <nanovdb/io/IO.h>
#include <nanovdb/tools/CreatePrimitives.h>
#include <nanovdb/cuda/DeviceBuffer.h>

#if defined(NANOVDB_USE_CUDA)
using BufferT = nanovdb::cuda::DeviceBuffer;
#else
using BufferT = nanovdb::HostBuffer;
#endif

extern void runNanoVDB(nanovdb::GridHandle<BufferT>& handle, int numIterations, int width, int height, BufferT& imageBuffer, bool usePersistentThreads);

int main(int ac, char** av)
{
try {
bool usePersistentThreads = false;
const char* gridName = nullptr;
for (int i = 1; i < ac; ++i) {
if (std::strcmp(av[i], "--persistent") == 0) {
usePersistentThreads = true;
} else if (!gridName) {
gridName = av[i];
} else {
throw std::runtime_error("Usage: ex_raytrace_iso_surface [--persistent] [grid.nvdb]");
}
}
nanovdb::GridHandle<BufferT> handle;
if (gridName) {
handle = nanovdb::io::readGrid<BufferT>(gridName);
std::cout << "Loaded NanoVDB grid[" << handle.gridMetaData()->shortGridName() << "]...\n";
} else {
handle = nanovdb::tools::createLevelSetSphere<float, BufferT>(100.0f, nanovdb::Vec3d(-20, 0, 0), 1.0, 3.0, nanovdb::Vec3d(0), "sphere");
}

const int numIterations = 50;
const int width = 4096;
const int height = 4096;
BufferT imageBuffer(width * height * sizeof(float));

runNanoVDB(handle, numIterations, width, height, imageBuffer, usePersistentThreads);
}
catch (const std::exception& e) {
std::cerr << "An exception occurred: \"" << e.what() << "\"" << std::endl;
}
return 0;
}
66 changes: 66 additions & 0 deletions nanovdb/nanovdb/examples/ex_raytrace_iso_surface/nanovdb.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: Apache-2.0

#define _USE_MATH_DEFINES
#include <cmath>
#include <chrono>

#if defined(NANOVDB_USE_CUDA)
#include <nanovdb/cuda/DeviceBuffer.h>
using BufferT = nanovdb::cuda::DeviceBuffer;
#else
using BufferT = nanovdb::HostBuffer;
#endif
#include <nanovdb/GridHandle.h>
#include <nanovdb/io/IO.h>
#include <nanovdb/math/Ray.h>
#include <nanovdb/math/HDDA.h>

#include "common.h"

void runNanoVDB(nanovdb::GridHandle<BufferT>& handle, int numIterations, int width, int height, BufferT& imageBuffer, bool usePersistentThreads)
{
float *h_outImage = reinterpret_cast<float*>(imageBuffer.data());
RenderOp renderOp(handle, width, height);

auto kernel = [&](auto *h_grid){
float sum = 0;
for (int i = 0; i < numIterations; ++i, sum += renderOp.renderImage(false/*useCuda*/, h_outImage, h_grid));
std::cout << "Average of " << numIterations << " renderings (NanoVDB-Host) = " << (sum/numIterations) << " ms" << std::endl;
renderOp.saveImage("raytrace_iso_surface-nanovdb-host.pfm", (float*)imageBuffer.data());

#if defined(NANOVDB_USE_CUDA)
handle.deviceUpload();
using BuildT = typename nanovdb::util::remove_pointer_t<decltype(h_grid)>::BuildType;
auto* d_grid = handle.deviceGrid<BuildT>();
if (!d_grid) throw std::runtime_error("GridHandle does not contain a valid device grid");
imageBuffer.deviceUpload();
float* d_outImage = reinterpret_cast<float*>(imageBuffer.deviceData());
sum = 0;
if (usePersistentThreads) {
int* d_nextPixel = nullptr;
NANOVDB_CUDA_CHECK_ERROR(cudaMalloc(&d_nextPixel, sizeof(int)), __FILE__, __LINE__);
for (int i = 0; i < numIterations; ++i, sum += renderOp.renderImagePersistent(d_outImage, d_grid, d_nextPixel));
NANOVDB_CUDA_CHECK_ERROR(cudaFree(d_nextPixel), __FILE__, __LINE__);
std::cout << "Average of " << numIterations << " renderings (NanoVDB-Cuda-Persistent) = " << (sum/numIterations) << " ms " << std::endl;
imageBuffer.deviceDownload();
renderOp.saveImage("raytrace_iso_surface-nanovdb-cuda-persistent.pfm", (float*)imageBuffer.data());
} else {
for (int i = 0; i < numIterations; ++i, sum += renderOp.renderImage(true/*useCuda*/, d_outImage, d_grid));
std::cout << "Average of " << numIterations << " renderings (NanoVDB-Cuda) = " << (sum/numIterations) << " ms " << std::endl;
imageBuffer.deviceDownload();
renderOp.saveImage("raytrace_iso_surface-nanovdb-cuda.pfm", (float*)imageBuffer.data());
}
#endif
};// kernel

if (auto *h_grid = handle.grid<float>()) {
kernel(h_grid);
} else if (auto *h_grid = handle.grid<nanovdb::ValueIndex>()) {
kernel(h_grid);
} else if (auto *h_grid = handle.grid<nanovdb::ValueOnIndex>()) {
kernel(h_grid);
} else {
throw std::runtime_error("GridHandle does not contain a valid device grid");
}
}// runNanoVDB
13 changes: 6 additions & 7 deletions nanovdb/nanovdb/examples/ex_raytrace_level_set/nanovdb.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ using BufferT = nanovdb::HostBuffer;

void runNanoVDB(nanovdb::GridHandle<BufferT>& handle, int numIterations, int width, int height, BufferT& imageBuffer)
{
using GridT = nanovdb::FloatGrid;
using GridT = nanovdb::FloatGrid;
using CoordT = nanovdb::Coord;
using RealT = float;
using Vec3T = nanovdb::math::Vec3<RealT>;
using RayT = nanovdb::math::Ray<RealT>;
using RealT = float;
using Vec3T = nanovdb::math::Vec3<RealT>;
using RayT = nanovdb::math::Ray<RealT>;

auto *h_grid = handle.grid<float>();
if (!h_grid)
throw std::runtime_error("GridHandle does not contain a valid host grid");
if (!h_grid) throw std::runtime_error("GridHandle does not contain a valid host grid");

float* h_outImage = reinterpret_cast<float*>(imageBuffer.data());

Expand Down Expand Up @@ -58,7 +57,7 @@ void runNanoVDB(nanovdb::GridHandle<BufferT>& handle, int numIterations, int wid
float t0;
CoordT ijk;
float v;
if (nanovdb::math::ZeroCrossing(iRay, acc, ijk, v, t0)) {
if (nanovdb::math::zeroCrossing(iRay, acc, ijk, v, t0)) {
// write distance to surface. (we assume it is a uniform voxel)
float wT0 = t0 * float(grid->voxelSize()[0]);
compositeOp(image, i, width, height, wT0 / (wBBoxDimZ * 2), 1.0f);
Expand Down
Loading
Loading