andreanicastro / cuda_voxelizer

Experimental CUDA voxelizer, to convert polygon meshes to annotated voxel grids.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Donate

cuda_voxelizer v0.3

Experimental CUDA voxelizer, to convert polygon meshes to (annotated) voxel grids.

  • Outputs data to .binvox file format (default) or a morton-ordered grid. More output formats (magicavoxel, minecraft schematic) are in development.
  • Requires a CUDA-compatible video card. Compute Capability 2.0 or higher (Nvidia Fermi or better).
  • Current project targets CUDA 10.0
  • 64-bit executables only. 32-bit might work, but you're on your own :)

Usage

Program options:

  • -f <path to model file>: (required) A path to a polygon model file. Supported input formats: .ply, .off, .obj, .3DS, .SM and RAY.
  • -s <voxel grid length>: The length of the cubical voxel grid. Default: 256, resulting in a 256 x 256 x 256 voxelization grid. Cuda_voxelizer will automatically select the tightest bounding box around the model. If you want to output to the morton file format, this should be a power of 2.
  • -o <output format>:, The output format for voxelized models, currently binvox or morton. Default: binvox. The morton format is a tightly packed, morton-order representation.
  • -t : Use Thrust library for CUDA memory operations. Might provide speed / throughput improvement. Default: disabled.

For example: cuda_voxelizer -f bunny.ply -s 256 generates you a 256 x 256 x 256 bunny voxel model which will be stored in bunny_256.binvox. You can visualize this file using viewvox.

viewvox example

Building

The project has the following build dependencies:

  • Cuda 8.0 Toolkit (or higher) for CUDA.
  • Cuda Thrust libraries (they come with the toolkit).
  • Trimesh2 for model importing. Latest version recommended.
  • GLM for vector math. Any recent version will do.

A Visual Studio 2017 project solution is provided in the msvcfolder. It is configured for CUDA 10.0, but you can edit the project file to make it work with lower CUDA versions. Philipp-M was kind enough to write CMake support as well.

Details

cuda_voxelizer implements an optimized version of the method described in M. Schwarz and HP Seidel's 2010 paper Fast Parallel Surface and Solid Voxelization on GPU's. The morton-encoded table was based on my 2013 HPG paper Out-Of-Core construction of Sparse Voxel Octrees and the work in libmorton.

cuda_voxelizer is built with a focus on performance. Usage of the routine as a per-frame voxelization step for real-time applications is viable. More performance metrics are on the todo list, but on a GTX 1060 these are the voxelization timings for the Stanford Bunny Model (1,55 MB, 70k triangles), including GPU memory transfers. Still lots of room for optimization.

Grid size Time
128^3 4.2 ms
256^3 6.2 ms
512^3 13.4 ms
1024^3 38.6 ms

Notes

  • If you want a good customizable CPU-based voxelizer, I can recommend VoxSurf.
  • Another hackable voxel viewer is Sean Barrett's excellent stb_voxel_render.h.
  • Nvidia also has a voxel library called GVDB, that does a lot more than just voxelizing.

Todo

  • Parallelize / CUDA-ify bounding box estimation
  • Output to more popular voxel formats like MagicaVoxel, Minecraft
  • Optimize grid/block size launch parameters
  • Implement partitioning for larger models
  • Do a pre-pass to categorize triangles
  • Implement capture of normals / color / texture data

About

Experimental CUDA voxelizer, to convert polygon meshes to annotated voxel grids.

License:MIT License


Languages

Language:C++ 73.0%Language:Cuda 13.7%Language:C 9.5%Language:CMake 3.8%