### Install Doxygen HTML Index File Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/CMakeLists.txt Installs the main index.html file for the Doxygen documentation to the installation directory. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/html/index.html DESTINATION ${CMAKE_INSTALL_DOCDIR}/html) ``` -------------------------------- ### Install Doxygen HTML Directory Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/CMakeLists.txt Installs the entire Doxygen HTML documentation directory to the installation path, suppressing 'Installing...' messages for individual files. ```cmake install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR} MESSAGE_NEVER) ``` -------------------------------- ### Build and Install nanovdb_print Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/cmd/CMakeLists.txt Defines the nanovdb_print executable, links it against the nanovdb library, and installs it to the binary directory. ```cmake add_executable(nanovdb_print print/nanovdb_print.cc) target_link_libraries(nanovdb_print PRIVATE nanovdb) install(TARGETS nanovdb_print RUNTIME DESTINATION ${NANOVDB_INSTALL_BINDIR}) ``` -------------------------------- ### Install Optional Dependencies on Windows Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Install optional dependencies like libpng, libjpeg-turbo, openexr, and alembic using vcpkg for Windows. ```bash vcpkg install libpng:x64-windows ``` ```bash vcpkg install libjpeg-turbo:x64-windows ``` ```bash vcpkg install openexr:x64-windows ``` ```bash vcpkg install alembic:x64-windows ``` -------------------------------- ### Declare NanoVDB Example Executables Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/examples/CMakeLists.txt Declares various NanoVDB example executables using the `nanovdb_example` helper function. Some examples have specific dependencies like CUDA, OpenVDB, or cuRAND. ```cmake nanovdb_example(NAME "ex_make_custom_nanovdb") nanovdb_example(NAME "ex_make_custom_nanovdb_cuda") nanovdb_example(NAME "ex_make_funny_nanovdb") nanovdb_example(NAME "ex_make_typed_grids") nanovdb_example(NAME "ex_make_nanovdb_sphere") nanovdb_example(NAME "ex_write_nanovdb_grids") nanovdb_example(NAME "ex_openvdb_to_nanovdb" OPENVDB) nanovdb_example(NAME "ex_openvdb_to_nanovdb_accessor" OPENVDB) nanovdb_example(NAME "ex_openvdb_to_nanovdb_cuda" OPENVDB) nanovdb_example(NAME "ex_read_nanovdb_sphere") nanovdb_example(NAME "ex_read_nanovdb_sphere_accessor") nanovdb_example(NAME "ex_read_nanovdb_sphere_accessor_cuda") nanovdb_example(NAME "ex_index_grid_cuda") nanovdb_example(NAME "ex_nodemanager_cuda" OPENVDB) nanovdb_example(NAME "ex_voxels_to_grid_cuda") nanovdb_example(NAME "ex_voxels_to_grid_mgpu") nanovdb_example(NAME "ex_modify_nanovdb_thrust") nanovdb_example(NAME "ex_map_pool_buffer") 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_dilate_nanovdb_cuda" OPENVDB) nanovdb_example(NAME "ex_merge_nanovdb_cuda" OPENVDB) nanovdb_example(NAME "ex_refine_nanovdb_cuda" OPENVDB) nanovdb_example(NAME "ex_coarsen_nanovdb_cuda" OPENVDB) nanovdb_example(NAME "ex_mesh_to_grid_cuda" OPENVDB) ``` ```cmake if(CUDAToolkit_FOUND) nanovdb_example(NAME "ex_make_mgpu_nanovdb") # requires cuRAND target_link_libraries(ex_make_mgpu_nanovdb PRIVATE CUDA::curand) endif() ``` ```cmake if(NANOVDB_USE_MAGICAVOXEL) nanovdb_example(NAME "ex_vox_to_nanovdb") endif() ``` -------------------------------- ### Install VDB View Executable Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_view/CMakeLists.txt Configures the installation of the VDB View executable. The executable will be placed in the binary directory specified by the OPENVDB_INSTALL_BINDIR variable during the installation process. ```cmake install(TARGETS vdb_view RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR}) ``` -------------------------------- ### Build and Install OpenVDB Core Library Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/README.md Clones the OpenVDB repository, creates a build directory, configures the build with CMake, and compiles and installs the core library using make. ```bash git clone git@github.com:AcademySoftwareFoundation/openvdb.git cd openvdb mkdir build cd build cmake .. make -j4 && make install ``` -------------------------------- ### CMake Minimum Requirements and Project Setup Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/cmd/CMakeLists.txt Sets the minimum CMake version and defines the project name and languages. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.24) project(NanoVDBExamples LANGUAGES CXX) ``` -------------------------------- ### Build and Install nanovdb_convert Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/cmd/CMakeLists.txt Defines the nanovdb_convert executable, links it against the nanovdb library, and installs it. This target is only built if OpenVDB is enabled. ```cmake if(NOT NANOVDB_USE_OPENVDB) message(WARNING " - OpenVDB required to build nanovdb_convert. Skipping.") else() add_executable(nanovdb_convert convert/nanovdb_convert.cc) target_link_libraries(nanovdb_convert PRIVATE nanovdb) install(TARGETS nanovdb_convert RUNTIME DESTINATION ${NANOVDB_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Install Project Files Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/build.txt Install all compiled files after a successful build. This command can be used with CMake's build tool or directly if 'make' was used. ```sh cmake --build . --target install # or simply `make install` ``` -------------------------------- ### Install VCL Directory if Enabled Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb/openvdb/CMakeLists.txt Installs the VCL (VDB Compositing Library) directory if the USE_VCL option is enabled. This ensures VCL headers are available in the installation path. ```cmake if(USE_VCL) install(DIRECTORY ${CMAKE_SOURCE_DIR}/ext/vcl/openvdb DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}) endif() ``` -------------------------------- ### Install Gtest for Unit Tests on Windows Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Install the Gtest framework using vcpkg for unit testing on Windows. Specify the architecture as x64-windows. ```bash vcpkg install gtest:x64-windows ``` -------------------------------- ### Array Access Examples Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/ax/ax.txt Demonstrates accessing elements of a matrix using different indexing methods. ```OpenVDB `A[0]` ``` ```OpenVDB `A[0,0]` ``` ```OpenVDB `A[1]` ``` ```OpenVDB `A[0,1]` ``` ```OpenVDB `A[2]` ``` ```OpenVDB `A[0,2]` ``` ```OpenVDB `A[3]` ``` ```OpenVDB `A[1,0]` ``` ```OpenVDB `A[4]` ``` ```OpenVDB `A[1,1]` ``` ```OpenVDB `A[5]` ``` ```OpenVDB `A[1,2]` ``` ```OpenVDB `A[6]` ``` ```OpenVDB `A[2,0]` ``` ```OpenVDB `A[7]` ``` ```OpenVDB `A[2,1]` ``` ```OpenVDB `A[8]` ``` ```OpenVDB `A[2,2]` ``` ```OpenVDB `A[9]` ``` ```OpenVDB `A[2,1]` ``` ```OpenVDB `A[10]` ``` ```OpenVDB `A[2,2]` ``` ```OpenVDB `A[11]` ``` ```OpenVDB `A[2,3]` ``` ```OpenVDB `A[12]` ``` ```OpenVDB `A[3,0]` ``` ```OpenVDB `A[13]` ``` ```OpenVDB `A[3,1]` ``` ```OpenVDB `A[14]` ``` ```OpenVDB `A[3,2]` ``` ```OpenVDB `A[15]` ``` ```OpenVDB `A[3,3]` ``` -------------------------------- ### Python Binding Installation via PyPi Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/tsc/meetings/2022-05-17.md Users can install the OpenVDB Python bindings using `pip install openvdb`. This method relies on source distribution (`sdist`), meaning users are responsible for building the bindings themselves, as pre-compiled binaries are not provided. ```python pypi install openvdb ``` -------------------------------- ### Get vdb_tool help on all instructions Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Show help for all instructions that can be evaluated by vdb_tool, using a wildcard. ```bash vdb_tool -eval help="*" ``` -------------------------------- ### Build and Install nanovdb_validate Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/cmd/CMakeLists.txt Defines the nanovdb_validate executable, links it against the nanovdb library, and installs it to the binary directory. ```cmake add_executable(nanovdb_validate validate/nanovdb_validate.cc) target_link_libraries(nanovdb_validate PRIVATE nanovdb) install(TARGETS nanovdb_validate RUNTIME DESTINATION ${NANOVDB_INSTALL_BINDIR}) ``` -------------------------------- ### Install OpenVDB Static Library Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb/openvdb/CMakeLists.txt Installs the OpenVDB static library components to the specified directories. This is enabled when OPENVDB_CORE_STATIC is true. ```cmake if(OPENVDB_CORE_STATIC) install(TARGETS openvdb_static RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR} LIBRARY DESTINATION ${OPENVDB_INSTALL_LIBDIR} ARCHIVE DESTINATION ${OPENVDB_INSTALL_LIBDIR} ) endif() ``` -------------------------------- ### Get vdb_tool help on all actions Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Display help information for all available actions and their options in vdb_tool. ```bash vdb_tool -help ``` -------------------------------- ### Install OpenVDB Header Files Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb/openvdb/CMakeLists.txt Installs various OpenVDB header files to their respective installation directories. This includes core headers, and headers for io, math, points, tools, tree, util, thread, and simd modules. ```cmake install(FILES ${OPENVDB_LIBRARY_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/openvdb/version.h DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb) install(FILES ${OPENVDB_LIBRARY_IO_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/io) install(FILES ${OPENVDB_LIBRARY_MATH_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/math) install(FILES ${OPENVDB_LIBRARY_POINTS_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/points) install(FILES ${OPENVDB_LIBRARY_POINTS_IMPL_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/points/impl) install(FILES ${OPENVDB_LIBRARY_TOOLS_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/tools) install(FILES ${OPENVDB_LIBRARY_TOOLS_IMPL_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/tools/impl) install(FILES ${OPENVDB_LIBRARY_TREE_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/tree) install(FILES ${OPENVDB_LIBRARY_UTIL_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/util) install(FILES ${OPENVDB_LIBRARY_THREAD_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/thread) install(FILES ${OPENVDB_LIBRARY_SIMD_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb/simd) ``` -------------------------------- ### Install OpenVDB AX Headers and Libraries Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_ax/openvdb_ax/CMakeLists.txt Installs header files and targets for both static and shared builds of the OpenVDB AX module. Specifies installation destinations for different file types and build configurations. ```cmake install(FILES ax.h Exceptions.h DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb_ax/) install(FILES ${OPENVDB_AX_AST_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb_ax/ast) install(FILES ${OPENVDB_AX_CODEGEN_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb_ax/codegen) install(FILES ${OPENVDB_AX_COMPILER_INCLUDE_FILES} DESTINATION ${OPENVDB_INSTALL_INCLUDEDIR}/openvdb_ax/compiler) if(OPENVDB_AX_STATIC) install(TARGETS openvdb_ax_static RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR} LIBRARY DESTINATION ${OPENVDB_INSTALL_LIBDIR} ARCHIVE DESTINATION ${OPENVDB_INSTALL_LIBDIR} ) endif() if(OPENVDB_AX_SHARED) install(TARGETS openvdb_ax_shared RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR} LIBRARY DESTINATION ${OPENVDB_INSTALL_LIBDIR} ARCHIVE DESTINATION ${OPENVDB_INSTALL_LIBDIR} ) endif() ``` -------------------------------- ### Install OpenVDB Maya Plugin and Scripts Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_maya/openvdb_maya/CMakeLists.txt Installs the 'openvdb_maya' library to the plugins directory and MEL files to the scripts directory. ```cmake install(TARGETS openvdb_maya DESTINATION ${OPENVDB_MAYA_PLUGINS} ) install(FILES ${OPENVDB_MAYA_MODULE_MEL_FILES} DESTINATION ${OPENVDB_MAYA_SCRIPTS} ) ``` -------------------------------- ### Install OpenVDB Shared Library Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb/openvdb/CMakeLists.txt Installs the OpenVDB shared library components to the specified directories. This is enabled when OPENVDB_CORE_SHARED is true. ```cmake if(OPENVDB_CORE_SHARED) install(TARGETS openvdb_shared RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR} LIBRARY DESTINATION ${OPENVDB_INSTALL_LIBDIR} ARCHIVE DESTINATION ${OPENVDB_INSTALL_LIBDIR} ) endif() ``` -------------------------------- ### Install OpenVDB Dependencies with vcpkg Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/README.md Install necessary libraries like zlib, blosc, tbb, and boost using vcpkg. Ensure your VCPKG_DEFAULT_TRIPLET is set to x64-windows for 64-bit compatibility. ```bash vcpkg install zlib:x64-windows vcpkg install blosc:x64-windows vcpkg install tbb:x64-windows vcpkg install boost-iostreams:x64-windows vcpkg install boost-interprocess:x64-windows ``` -------------------------------- ### Install OpenVDB Dependencies with Homebrew Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/dependencies.txt Use these commands to install core libraries, build tools, and optional components for OpenVDB on systems with Homebrew package manager. ```bash #!/bin/bash # Core library brew install cmake # CMake brew install tbb # TBB brew install zlib # zlib brew install boost # Boost brew install c-blosc # blosc # AX brew install llvm # LLVM # Python brew install python # Python brew install nanobind robin-map # nanobind # Unit Tests brew install gtest # GoogleTest # vdb_view brew install glfw # GLFW # vdb_render brew install openexr # OpenEXR brew install libpng # libpng # Documentation brew install doxygen # Doxygen ``` -------------------------------- ### Production Example: Complex Math for Ray Tracing Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Union 200 level set spheres arranged in a spiral pattern and ray-trace them into an image. This example showcases complex mathematical evaluations within `vdb_tool`. ```shell vdb_tool -for n=0,200,1 -eval '{$n:137.5:*:@deg}' -eval '{$deg:d2r:@radian}' -eval '{$radian:cos:@x}' -eval '{$radian:sin:@y}' -eval '{$n:sqrt:@r}' -eval '{$r:5:+:@r_sum}' -eval '{$r_sum:0.25:pow:@pow_r}' -sphere voxel=0.1 radius='{$pow_r:0.5:*}' center='({$r:$x:*},{$r:$y:*},0)' -if '{$n:0:>}' -union -end -end -render spiral.ppm image=1024x1024 translate='(0,0,40)' ``` -------------------------------- ### OpenVDB Makefile Install Target Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/changes.txt An 'install_lib' build target has been added to the Makefile. ```makefile install_lib ``` -------------------------------- ### Define NanoVDB Math Header Files Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/CMakeLists.txt Lists the header files for NanoVDB's math utilities that will be installed. ```cmake set(NANOVDB_INCLUDE_MATH_FILES math/CSampleFromVoxels.h math/DitherLUT.h math/HDDA.h math/Math.h math/Ray.h math/SampleFromVoxels.h math/Stencils.h ) ``` -------------------------------- ### Hello, World! for OpenVDB Points Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/examplecode.txt A basic example of creating a point cloud, writing it to a VDB file, and reading it back. It demonstrates initializing OpenVDB, creating point data, computing voxel size, creating a `PointDataGrid`, and iterating over points. ```cpp #include #include #include #include #include int main() { // Initialize grid types and point attributes types. openvdb::initialize(); // Create a vector with four point positions. std::vector positions; positions.push_back(openvdb::Vec3R(0, 1, 0)); positions.push_back(openvdb::Vec3R(1.5, 3.5, 1)); positions.push_back(openvdb::Vec3R(-1, 6, -2)); positions.push_back(openvdb::Vec3R(1.1, 1.25, 0.06)); // The VDB Point-Partioner is used when bucketing points and requires a // specific interface. For convenience, we use the PointAttributeVector // wrapper around an stl vector wrapper here, however it is also possible to // write one for a custom data structure in order to match the interface // required. openvdb::points::PointAttributeVector positionsWrapper(positions); // This method computes a voxel-size to match the number of // points / voxel requested. Although it won't be exact, it typically offers // a good balance of memory against performance. int pointsPerVoxel = 8; float voxelSize = openvdb::points::computeVoxelSize(positionsWrapper, pointsPerVoxel); // Print the voxel-size to cout std::cout << "VoxelSize=" << voxelSize << std::endl; // Create a transform using this voxel-size. openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(voxelSize); // Create a PointDataGrid containing these four points and using the // transform given. This function has two template parameters, (1) the codec // to use for storing the position, (2) the grid we want to create // (ie a PointDataGrid). // We use no compression here for the positions. openvdb::points::PointDataGrid::Ptr grid = openvdb::points::createPointDataGrid(positions, *transform); // Set the name of the grid grid->setName("Points"); // Create a VDB file object and write out the grid. openvdb::io::File("mypoints.vdb").write({grid}); // Create a new VDB file object for reading. openvdb::io::File newFile("mypoints.vdb"); // Open the file. This reads the file header, but not any grids. newFile.open(); // Read the grid by name. openvdb::GridBase::Ptr baseGrid = newFile.readGrid("Points"); newFile.close(); // From the example above, "Points" is known to be a PointDataGrid, // so cast the generic grid pointer to a PointDataGrid pointer. grid = openvdb::gridPtrCast(baseGrid); openvdb::Index64 count = openvdb::points::pointCount(grid->tree()); std::cout << "PointCount=" << count << std::endl; // Iterate over all the leaf nodes in the grid. for (auto leafIter = grid->tree().cbeginLeaf(); leafIter; ++leafIter) { // Verify the leaf origin. std::cout << "Leaf" << leafIter->origin() << std::endl; // Extract the position attribute from the leaf by name (P is position). const openvdb::points::AttributeArray& array = leafIter->constAttributeArray("P"); // Create a read-only AttributeHandle. Position always uses Vec3f. openvdb::points::AttributeHandle positionHandle(array); // Iterate over the point indices in the leaf. ``` -------------------------------- ### Configure VDB View CMake Project Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_view/CMakeLists.txt Sets up the CMake build environment for the VDB View application. Ensure you have CMake version 3.24 or higher installed. This script finds necessary packages like OpenGL and GLEW (on Windows) and includes a custom module for GLFW setup. ```cmake cmake_minimum_required(VERSION 3.24) project(VDBView LANGUAGES CXX) include(GNUInstallDirs) find_package(OpenGL REQUIRED) if(WIN32) find_package(GLEW REQUIRED) endif() # wraps find_package(glfw3) and sets the glfw target include(OpenVDBGLFW3Setup) ``` -------------------------------- ### Getting Help and Documentation Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/examples/demos.md Provides commands to access help information for vdb_tool and its specific options. Use -help for general help, or -h followed by specific commands for detailed usage. ```bash vdb_tool -help ``` ```bash vdb_tool -h read write ``` ```bash vdb_tool -sphere -help -write sphere.vdb ``` -------------------------------- ### OpenVDB Hello World: Grid Creation and Voxel Access Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/examplecode.txt Demonstrates creating a FloatGrid, accessing voxels by coordinates, and iterating through active voxels. Requires OpenVDB initialization. ```cpp #include #include int main() { // Initialize the OpenVDB library. This must be called at least // once per program and may safely be called multiple times. openvdb::initialize(); // Create an empty floating-point grid with background value 0. openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create(); std::cout << "Testing random access:" << std::endl; // Get an accessor for coordinate-based access to voxels. openvdb::FloatGrid::Accessor accessor = grid->getAccessor(); // Define a coordinate with large signed indices. openvdb::Coord xyz(1000, -200000000, 30000000); // Set the voxel value at (1000, -200000000, 30000000) to 1. accessor.setValue(xyz, 1.0); // Verify that the voxel value at (1000, -200000000, 30000000) is 1. std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl; // Reset the coordinates to those of a different voxel. xyz.reset(1000, 200000000, -30000000); // Verify that the voxel value at (1000, 200000000, -30000000) is // the background value, 0. std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl; // Set the voxel value at (1000, 200000000, -30000000) to 2. accessor.setValue(xyz, 2.0); // Set the voxels at the two extremes of the available coordinate space. // For 32-bit signed coordinates these are (-2147483648, -2147483648, -2147483648) // and (2147483647, 2147483647, 2147483647). accessor.setValue(openvdb::Coord::min(), 3.0f); accessor.setValue(openvdb::Coord::max(), 4.0f); std::cout << "Testing sequential access:" << std::endl; // Print all active ("on") voxels by means of an iterator. for (openvdb::FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) { std::cout << "Grid" << iter.getCoord() << " = " << *iter << std::endl; } } ``` -------------------------------- ### Configure Installation Paths Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_maya/openvdb_maya/CMakeLists.txt Sets the installation paths for the OpenVDB Maya plugin, including the base install path, plugins directory, and scripts directory. It handles deprecated subdirectory options. ```cmake if(NOT OPENVDB_MAYA_INSTALL_PREFIX) if(OPENVDB_MAYA_SUBDIR) set(MAYA_INSTALL_LOCATION maya/${Maya_VERSION}) else() set(MAYA_INSTALL_LOCATION maya${Maya_VERSION}) endif() endif() set(OPENVDB_MAYA_INSTALL_PREFIX ${MAYA_INSTALL_LOCATION} CACHE PATH "Base install path for OpenVDB Maya libraries and headers." ) set(OPENVDB_MAYA_PLUGINS ${OPENVDB_MAYA_INSTALL_PREFIX}/plug-ins CACHE PATH "Install path for OpenVDB Maya plugins" ) set(OPENVDB_MAYA_SCRIPTS ${OPENVDB_MAYA_INSTALL_PREFIX}/scripts CACHE PATH "Install path for OpenVDB Maya scripts" ) ``` -------------------------------- ### nanovdb_convert Command-Line Tool Options Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/changes.txt The `nanovdb_convert` tool now supports `--index` and `--onIndex` options to generate NanoVDB IndexGrids. This allows for more flexible conversion workflows. ```bash nanovdb_convert --index input.vdb output.nvdb ``` ```bash nanovdb_convert --onIndex input.vdb output.nvdb ``` -------------------------------- ### Configure and Build OpenVDB with CMake Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/README.md Clone the OpenVDB repository, create a build directory, and configure the build using CMake with vcpkg integration. Then, build and install OpenVDB. The --parallel option can speed up the build process. ```bash git clone git@github.com:AcademySoftwareFoundation/openvdb.git cd openvdb mkdir build cd build cmake -DCMAKE_TOOLCHAIN_FILE=\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -A x64 .. cmake --build . --parallel 4 --config Release --target install ``` -------------------------------- ### Install OpenVDB Maya Module File Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_maya/openvdb_maya/CMakeLists.txt Conditionally writes and installs the 'openvdb.mod' module file if OPENVDB_MAYA_INSTALL_MOD is enabled. ```cmake if(OPENVDB_MAYA_INSTALL_MOD) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/openvdb.mod "+ openvdb any ${OPENVDB_MAYA_INSTALL_PREFIX}\n") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/openvdb.mod DESTINATION ${OPENVDB_MAYA_INSTALL_PREFIX} COMPONENT Runtime ) endif() ``` -------------------------------- ### Create and Populate Point Data Grid Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/examplecode.txt Demonstrates creating a PointDataGrid with positions and radii, including custom attribute registration for 'pscale' using a UnitRange codec for memory efficiency. Requires OpenVDB initialization. ```cpp #include #include #include #include #include int main() { // Initialize grid types and point attributes types. openvdb::initialize(); // Create a vector with four point positions. std::vector positions; positions.push_back(openvdb::Vec3R(0, 1, 0)); positions.push_back(openvdb::Vec3R(1.5, 3.5, 1)); positions.push_back(openvdb::Vec3R(-1, 6, -2)); positions.push_back(openvdb::Vec3R(1.1, 1.25, 0.06)); // Create a vector with four radii. std::vector radius; radius.push_back(0.1); radius.push_back(0.15); radius.push_back(0.2); radius.push_back(0.5); // The VDB Point-Partioner is used when bucketing points and requires a // specific interface. For convenience, we use the PointAttributeVector // wrapper around an stl vector wrapper here, however it is also possible to // write one for a custom data structure in order to match the interface // required. openvdb::points::PointAttributeVector positionsWrapper(positions); // This method computes a voxel-size to match the number of // points / voxel requested. Although it won't be exact, it typically offers // a good balance of memory against performance. int pointsPerVoxel = 8; float voxelSize = openvdb::points::computeVoxelSize(positionsWrapper, pointsPerVoxel); // Create a transform using this voxel-size. openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(voxelSize); // Create a PointIndexGrid. This can be done automatically on creation of // the grid, however as this index grid is required for the position and // radius attributes, we create one we can use for both attribute creation. openvdb::tools::PointIndexGrid::Ptr pointIndexGrid = openvdb::tools::createPointIndexGrid( positionsWrapper, *transform); // Create a PointDataGrid containing these four points and using the point // index grid. This requires the positions wrapper. openvdb::points::PointDataGrid::Ptr grid = openvdb::points::createPointDataGrid(*pointIndexGrid, positionsWrapper, *transform); // Append a "pscale" attribute to the grid to hold the radius. // This attribute storage uses a unit range codec to reduce the memory // storage requirements down from 4-bytes to just 1-byte per value. This is // only possible because accuracy of the radius is not that important to us // and the values are always within unit range (0.0 => 1.0). // Note that this attribute type is not registered by default so needs to be // explicitly registered. using Codec = openvdb::points::FixedPointCodec; openvdb::points::TypedAttributeArray::registerType(); openvdb::NamePair radiusAttribute = openvdb::points::TypedAttributeArray::attributeType(); openvdb::points::appendAttribute(grid->tree(), "pscale", radiusAttribute); // Create a wrapper around the radius vector. openvdb::points::PointAttributeVector radiusWrapper(radius); // Populate the "pscale" attribute on the points openvdb::points::populateAttribute int main() { openvdb::initialize(); // Create a shared pointer to a newly-allocated grid of a built-in type: // in this case, a FloatGrid, which stores one single-precision floating point // value per voxel. Other built-in grid types include BoolGrid, DoubleGrid, // Int32Grid and Vec3SGrid (see openvdb.h for the complete list). // The grid comprises a sparse tree representation of voxel data, // user-supplied metadata and a voxel space to world space transform, // which defaults to the identity transform. openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create(/*background value=*/2.0); // Populate the grid with a sparse, narrow-band level set representation // of a sphere with radius 50 voxels, located at (1.5, 2, 3) in index space. makeSphere(*grid, /*radius=*/50.0, /*center=*/openvdb::Vec3f(1.5, 2, 3)); // Associate some metadata with the grid. grid->insertMeta("radius", openvdb::FloatMetadata(50.0)); ``` -------------------------------- ### Build NanoVDB with OpenVDB Core Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/nanovdb/HowToBuild.md Builds both NanoVDB and OpenVDB core libraries. Installs NanoVDB header files and command-line tools. Ensure dependency paths are correctly set. ```bash foo@bar:~$ mkdir build foo@bar:~$ cd build foo@bar:~$ cmake .. -DUSE_NANOVDB=ON -DTBB_ROOT=/path/to/tbb -DBOOST_ROOT=/path/to/boost -DBLOSC_ROOT=/path/to/blosc -DCMAKE_INSTALL_PREFIX=/install/path foo@bar:~$ make -j 4 && make install ``` -------------------------------- ### Install CMake on Windows Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Install CMake on Windows using Chocolatey. This command ensures CMake is added to the system's PATH. ```bash choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' ``` -------------------------------- ### Build All NanoVDB Features with OpenVDB Core Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/nanovdb/HowToBuild.md Builds NanoVDB with all features enabled, including unit tests, examples, and benchmarks, alongside the OpenVDB core. Requires specifying paths for various dependencies. ```bash 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 ``` -------------------------------- ### Execute Configuration File Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/examples/EXAMPLES.md Executes a configuration file using the `vdb_tool`. ```bash ./vdb_tool -read points.[ply|obj|stl|pts] -points2ls dim=256 voxel=0.1 radius=0.2 width=3 -dilate radius=2 space=5 time=2 -gauss iter=1 width=1 -erode radius=2 -ls2mesh adapt=0.25 -write output.[ply|obj|stl|abc|pts] -write conf.txt ``` -------------------------------- ### Install OpenVDB Dependencies on MacOS Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/README.md Installs required dependencies for OpenVDB on MacOS using Homebrew. This includes Boost, TBB, and c-blosc. ```bash # MacOS # @note We are using homebrew in this example to install requried dependencies # https://brew.sh/ brew install boost brew install tbb brew install c-blosc ``` -------------------------------- ### OpenVDB Points Initialization Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/changes.txt Registration of OpenVDB Points grid and attribute types is now handled in openvdb::initialize() and points::initialize(). ```c++ vdblink::initialize() openvdb::initialize() vdblink::points::initialize() points::initialize() ``` -------------------------------- ### Print Help Documentation Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/examples/EXAMPLES.md Prints the help documentation for `vdb_tool` to the terminal and terminates the program. ```bash ./vdb_tool --help ``` -------------------------------- ### Initialize OpenVDB with Logging Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/changes.txt Ensures log4cplus is initialized if enabled, preventing "No appenders could be found" errors. Call this early in your application. ```cpp openvdb::initialize() ``` -------------------------------- ### Make Sphere Function (Example Only) Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/examplecode.txt A templated function to populate a grid with a narrow-band level set representation of a sphere. This is for example purposes only and not for production use. ```cpp // Populate the given grid with a narrow-band level set representation of a sphere. // The width of the narrow band is determined by the grid's background value. // (Example code only; use tools::createSphereSDF() in production.) template void makeSphere(GridType& grid, float radius, const openvdb::Vec3f& c) { using ValueT = typename GridType::ValueType; // Distance value for the constant region exterior to the narrow band const ValueT outside = grid.background(); // Distance value for the constant region interior to the narrow band // (by convention, the signed distance is negative in the interior of // a level set) const ValueT inside = -outside; // Use the background value as the width in voxels of the narrow band. // (The narrow band is centered on the surface of the sphere, which // has distance 0.) int padding = int(openvdb::math::RoundUp(openvdb::math::Abs(outside))); // The bounding box of the narrow band is 2*dim voxels on a side. int dim = int(radius + padding); // Get a voxel accessor. typename GridType::Accessor accessor = grid.getAccessor(); // Compute the signed distance from the surface of the sphere of each // voxel within the bounding box and insert the value into the grid // if it is smaller in magnitude than the background value. openvdb::Coord ijk; int &i = ijk[0], &j = ijk[1], &k = ijk[2]; for (i = c[0] - dim; i < c[0] + dim; ++i) { const float x2 = openvdb::math::Pow2(i - c[0]); for (j = c[1] - dim; j < c[1] + dim; ++j) { const float x2y2 = openvdb::math::Pow2(j - c[1]) + x2; for (k = c[2] - dim; k < c[2] + dim; ++k) { // The distance from the sphere surface in voxels const float dist = openvdb::math::Sqrt(x2y2 + openvdb::math::Pow2(k - c[2])) - radius; // Convert the floating-point distance to the grid's value type. ValueT val = ValueT(dist); // Only insert distances that are smaller in magnitude than // the background value. if (val < inside || outside < val) continue; // Set the distance for voxel (i,j,k). accessor.setValue(ijk, val); } } } // Propagate the outside/inside sign information from the narrow band // throughout the grid. openvdb::tools::signedFloodFill(grid.tree()); } ``` -------------------------------- ### Set Houdini Install Paths Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_houdini/openvdb_houdini/CMakeLists.txt Configures installation directories for OpenVDB Houdini components like binaries, libraries, headers, DSO files, scripts, and icons. ```cmake set(OPENVDB_HOUDINI_BIN_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} CACHE PATH "Install path for the OpenVDB Houdini shared library") set(OPENVDB_HOUDINI_LIB_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} CACHE PATH "Install path for the OpenVDB Houdini shared library") set(OPENVDB_HOUDINI_INCLUDE_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Install path for the OpenVDB Houdini headers") # Install paths for dsos and scripts set(OPENVDB_HOUDINI_DSO_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/dso CACHE PATH "Install path for the OpenVDB Houdini dsos") set(OPENVDB_HOUDINI_MANTRA_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/dso/mantra CACHE PATH "Install path for the OpenVDB Houdini mantra nodes") set(OPENVDB_HOUDINI_SOP_SCRIPT_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/scripts/sop CACHE PATH "Install path for the OpenVDB Houdini node scripts") set(OPENVDB_HOUDINI_HELP_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/help CACHE PATH "Install path for the OpenVDB Houdini help files") set(OPENVDB_HOUDINI_ICON_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/config/Icons CACHE PATH "Install path for the OpenVDB Houdini node icons") set(OPENVDB_HOUDINI_PYTHON_INSTALL_PREFIX ${OPENVDB_HOUDINI_INSTALL_PREFIX}/python2.7libs CACHE PATH "Install path for the OpenVDB Houdini startup script") ``` -------------------------------- ### Vector/Matrix Initializer Syntax Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/ax/ax.txt Shows how to create vectors and matrices using the initializer syntax `{ a, b, ... }`. This is valid for argument lists of sizes 2, 3, 4, 9, and 16, representing vec2, vec3, vec4, mat3, and mat4 types respectively. ```ax vec3f a = { 1.0f, 2.0f, 3.0f }; // right hand side of assignment creates a vec3f ``` ```ax vec3f b = dot(a, { a[0], 5.0, 6.0 }); // second argument creates a vec3d ``` -------------------------------- ### Set Output Name and Install NanoVDB Python Module Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/nanovdb/nanovdb/python/CMakeLists.txt Sets the output name for the NanoVDB Python module and defines installation rules based on the SKBUILD variable. ```cmake set_target_properties(nanovdb_python PROPERTIES OUTPUT_NAME "nanovdb") if(SKBUILD) set_target_properties(nanovdb_python PROPERTIES INSTALL_RPATH "$ORIGIN/../../openvdb/lib") install(TARGETS nanovdb_python DESTINATION ${NANOVDB_INSTALL_LIBDIR}) install(FILES __init__.py DESTINATION nanovdb) else() install(TARGETS nanovdb_python DESTINATION ${VDB_PYTHON_INSTALL_DIRECTORY}) endif() ``` -------------------------------- ### Compile Project with Make Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/build.txt Compile the project using the 'make' command with multi-threading enabled. Adjust the 'j' argument based on the number of CPU threads available. ```sh make -j4 ``` -------------------------------- ### Casting Example with Undefined Behavior Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/doc/changes.txt This example demonstrates a case of undefined behavior that was fixed in OpenVDB AX. Explicitly casting a variable to its own storage type can lead to issues. ```cpp double a; double b = double(a); ``` -------------------------------- ### Pipe to gzip and Redirect Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/openvdb_cmd/vdb_tool/README.md Combine `vdb_tool` output with `gzip` for compression and redirect the compressed output to a file. ```shell vdb_tool -sphere -o stdout.vdb | gzip > sphere.vdb.gz ``` -------------------------------- ### Install OpenVDB Dependencies on Linux Source: https://github.com/academysoftwarefoundation/openvdb/blob/master/README.md Installs necessary development libraries for OpenVDB on Debian-based Linux systems using apt-get. Ensure required versions are available or use apt pinning. ```bash # Linux # @note If your distribution does not have required versions, consider using # apt pinning. See the dependency documentation for more details. apt-get install -y libboost-iostreams-dev apt-get install -y libtbb-dev apt-get install -y libblosc-dev ```