OpenVDB Documentation

repository·master·Indexed 25 days ago

https://github.com/academysoftwarefoundation/openvdb

An open-source C++ library providing a hierarchical data structure and tools for efficient storage and manipulation of sparse volumetric data on 3D grids. Includes NanoVDB, a lightweight GPU-friendly version for rendering, the Vector Class Library (VCL) for SIMD performance on x86/x86_64, and vdb_tool, a command-line utility for volumetric transformations, mesh conversion, and per-voxel math kernels.

Tokens
15.9K
Snippets
43
Records
107
Agent score
75%

What's inside OpenVDB

  1. Overview of vdb_tool

    master

    The vdb_tool is a lightweight command-line utility for chaining high-level OpenVDB operations. It allows users to:

    • Convert polygon meshes and particles into level sets.
    • Perform volumetric transformations (e.g., dilation, erosion, Gaussian convolution).
    • Generate adaptive meshes or ray-traced images.
    • Export results as particles, meshes, or VDB files, or stream them to STDOUT for pipelining.

    Operations are defined as actions (e.g., -erode) and options (e.g., radius=2.0). Sequences of actions can be saved to and loaded from configuration files.

  2. Understand NanoVDB core concepts and limitations

    master

    NanoVDB is a standalone, static-topology implementation of the sparse volumetric VDB data structure. It is a lightweight version of OpenVDB designed for high-performance random access on both CPUs and GPUs.

    Key Characteristics

    • Static Topology: You can modify voxel values within a NanoVDB grid, but you cannot modify the tree topology (e.g., you cannot add or remove nodes/voxels once the structure is built).
    • Memory Layout: NanoVDB is pointer-less and occupies a contiguous, defragmented block of memory. This results in faster read access and better cache friendliness compared to OpenVDB.
    • Dependencies: It has virtually no external dependencies, requiring only C++11 or C99.
    • Use Cases: Ideal for GPU/CPU rendering (ray-tracing), collision detection, and applications requiring fast random access to sparse volumetric data.
  3. Select a NanoVDB implementation based on your requirements

    master

    NanoVDB provides several implementations of its core data structure and access methods depending on your target language and API:

    • C++11: Use NanoVDB.h for the standard C++ implementation.
    • C99 (OpenCL focus): Use CNanoVDB.h. This is designed for use in OpenCL kernels but relies on zero-sized arrays for _reserved padding, which may not work on all compilers (e.g., MSVC).
    • C99 (Graphics API focus): Use PNanoVDB.h. This is a more complete C99 implementation that is pointer-less, making it compatible with virtually all graphics APIs.
    • CUDA: For CUDA-specific support, refer to the cuda/ directory for headers like DeviceBuffer.h, GridHandle.cuh, and NodeManager.cuh.
  4. Build and install core OpenVDB on Windows

    master

    Follow these steps to build and install OpenVDB on Windows using CMake and vcpkg. Replace <PATH_TO_VCPKG> with your actual vcpkg installation path.

    git clone git@github.com:AcademySoftwareFoundation/openvdb.git
    cd openvdb
    mkdir build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=<PATH_TO_VCPKG>\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -A x64 ..
    cmake --build . --parallel 4 --config Release --target install
  5. Install OpenVDB dependencies on Linux

    master

    To install the core OpenVDB library on Linux, you must first install the required development dependencies using apt-get. If your distribution does not have the required versions, consider using apt pinning.

    # Linux
    apt-get install -y libboost-iostreams-dev
    apt-get install -y libtbb-dev
    apt-get install -y libblosc-dev
  6. Build vdb_tool on Linux

    master

    To build vdb_tool on Linux using CMake, navigate to the cloned directory and follow these steps. You must have OpenVDB installed. To enable NanoVDB support, pass -DOPENVDB_BUILD_NANOVDB=ON. To build unit tests, pass -DOPENVDB_BUILD_VDB_TOOL_UNITTESTS=ON.

    # Generate makefile
    mkdir build
    cd build
    cmake -DOPENVDB_CMAKE_PATH=/usr/local/lib/cmake/OpenVDB -DUSE_ALL=ON -DOPENVDB_BUILD_VDB_TOOL_UNITTESTS=ON ..
    
    # Build
    cmake --build . --parallel 2
    # OR
    make -j 2
  7. Use lazy `if(...)` for short-circuiting

    master

    The if(cond, then, else) function implements lazy evaluation. It only evaluates the branch that is taken. This is useful for guarding against mathematical errors like division by zero or square roots of negative numbers.

    Note: The switch(...) function is eager (all branches are evaluated). If you need short-circuiting logic in a switch-like structure, use nested if() calls.

  8. Understand vdb_tool terminology: Actions, Options, and Stacks

    master

    To use vdb_tool effectively, understand its core concepts:

    Actions and Options

    • Actions are high-level tools prefixed with a dash (e.g., -erode).
    • Options are arguments for actions, using the key=value format.
    • Short-hand Options: You can use the first few characters of an option name for identification. For example, -erode r=2 is equivalent to -erode radius=2.0. However, the prefix must be unique; -erode rr=2 will fail if rr doesn't match the start of any valid option.

    The Primitive Stacks

    The tool maintains two internal stacks:

    1. Geometry Stack (geo): Stores points and polygon meshes.
    2. VDB Stack (vdb): Stores VDB volumes (voxels or points).

    Primitives are referenced by their age (order on the stack), where n=0 is the most recent item and n=1 is the second most recent.

    • -mesh2ls g=1: Converts the second-to-last geometry on the stack to a level set.
    • -gauss v=0: Performs a Gaussian filter on the most recently added VDB grid.
  9. Build NanoVDB with all features and OpenVDB core

    master

    To perform an exhaustive build that includes unit tests, examples, benchmarks, CUDA support, and intrinsics alongside the OpenVDB core, use the following configuration from the root OpenVDB directory.

    foo@bar:~$ mkdir build
    foo@bar:~$ cd build
    foo@bar:~$ cmake .. -DUSE_NANOVDB=ON -DNANOVDB_BUILD_UNITTESTS=ON -DNANOVDB_BUILD_EXAMPLES=ON -DNANOVDB_BUILD_BENCHMARK=ON -DNANOVDB_USE_INTRINSICS=ON -DNANOVDB_USE_CUDA=ON -DNANOVDB_CUDA_KEEP_PTX=ON -DTBB_ROOT=/path/to/tbb -DBOOST_ROOT=/path/to/boost -DBLOSC_ROOT=/path/to/blosc -DGTEST_ROOT=/path/to/gtest -DCMAKE_INSTALL_PREFIX=/install/path
    foo@bar:~$ make -j 4 && make install