Skip to content

Update #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
367ea2e
Merge pull request #33 from conceptclear/master
Forceflow Jun 28, 2020
9267125
Integrate solid voxelization
Forceflow Jun 28, 2020
570b200
Changes to program launch parameters
Forceflow Jun 28, 2020
50f47b2
OpenMP multi-threading support
Forceflow Jun 28, 2020
bb77c2f
Update README.md
Forceflow Jun 28, 2020
71a6033
Update README.md
Forceflow Jun 28, 2020
b242f4b
Skip CUDA init when forced CPU voxelization
Forceflow Jun 28, 2020
29ce371
Merge pull request #34 from Forceflow/dev
Forceflow Jun 28, 2020
8a24b7e
Fix debug build
Forceflow Jun 28, 2020
eef1486
Merge pull request #35 from Forceflow/dev
Forceflow Jun 28, 2020
28ecce0
Using full voxelization_info struct when writing files (helps for non…
Jun 29, 2020
476c980
Added translate and scale to binvox header, to comply with spec (see …
Jun 29, 2020
66546e5
Merge remote-tracking branch 'origin/master' into dev
Jun 29, 2020
a32b879
Updated voxelization performance table with GPU / CPU results
Forceflow Jun 29, 2020
462e39b
Added timer for CPU voxelization
Forceflow Jun 29, 2020
8e0bf17
Merge branch 'dev' of https://github.com/Forceflow/cuda_voxelizer int…
Forceflow Jun 29, 2020
20aa493
Added note about CPU multithreading
Forceflow Jun 29, 2020
60a2227
Updated binvox format info
Forceflow Jun 29, 2020
e23826b
Correct copying of debug build to binaries dir
Forceflow Jun 29, 2020
71eaa0e
Merge branch 'dev' of https://github.com/Forceflow/cuda_voxelizer int…
Forceflow Jun 29, 2020
3f6a926
Version bump to 0.4.7
Forceflow Jun 29, 2020
eaadcc2
Version bump
Forceflow Jun 29, 2020
a1f150a
Merge pull request #37 from Forceflow/dev
Forceflow Jun 29, 2020
755fcb3
Cleaned up .obj export function
Forceflow Jun 29, 2020
4f3e8fd
Merge remote-tracking branch 'origin/master' into dev
Forceflow Jun 29, 2020
ab493c1
Using ³ instead of ^3
Forceflow Jun 29, 2020
992bca0
Renamed master to main
Forceflow Jul 4, 2020
5595aaf
Merge pull request #38 from Forceflow/dev
Forceflow Jul 4, 2020
1859190
Universal CMake added
KernelA Jul 11, 2020
72c67d3
Fixed Linux build
KernelA Jul 11, 2020
16a62a7
Fixed building on Windows and Linux
KernelA Jul 11, 2020
3d60fb2
README updated
KernelA Jul 11, 2020
a51c3a2
Small improvements in CMakeLists
KernelA Jul 11, 2020
1e9ae81
Dellete old GLM cmake config
KernelA Jul 11, 2020
0bf821a
Increase minimum CMake required version
KernelA Jul 11, 2020
20e44a8
Changed travis build process
KernelA Jul 12, 2020
ca7804c
Remove PUBLIC modifier from CMake
KernelA Jul 12, 2020
49020e2
Merge pull request #39 from KernelA/universal-cmake
Forceflow Jul 13, 2020
3338a24
Build documentation refresh, version bump
Forceflow Jul 25, 2020
23f4c4b
Merge pull request #41 from Forceflow/dev
Forceflow Jul 25, 2020
456f954
Create CONTRIBUTING.md
Forceflow Aug 2, 2020
1441dc5
Added #pragma guard for including
Forceflow Aug 12, 2020
e28f2bc
Ported solid voxelization code to CPU voxelizer
Forceflow Aug 12, 2020
75af0ed
Added CPU solid voxelization
Forceflow Aug 12, 2020
0840ccc
Update README.md
Forceflow Aug 12, 2020
b5f89d6
Version bump, CPU solid voxelization
Forceflow Aug 12, 2020
d6245ef
Merge pull request #42 from Forceflow/dev
Forceflow Aug 12, 2020
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- CUDA=10.1.105-1
- CUDA_SHORT=10.1
- UBUNTU_VERSION=ubuntu1804
- CUDA_ARCH=30
dist: bionic

before_install:
Expand All @@ -34,11 +35,16 @@ before_install:
- sudo apt-get install -y mesa-common-dev libglu1-mesa-dev libxi-dev
- git clone https://github.com/Forceflow/trimesh2.git
- cd trimesh2 && make && cd ..
- wget https://github.com/Kitware/CMake/releases/download/v3.13.0/cmake-3.13.0-Linux-x86_64.sh -q -O ./cmake-install.sh
- chmod u+x ./cmake-install.sh
- mkdir ./cmake
- ./cmake-install.sh --skip-license --prefix=./cmake
- rm ./cmake-install.sh

script:
- mkdir build
- cd build
- cmake ..
- make
- ../cmake/bin/cmake -DTrimesh2_INCLUDE_DIR="../trimesh2/include" -DTrimesh2_LINK_DIR="../trimesh2/lib.Linux64" -DCUDA_ARCH=${CUDA_ARCH} ..
- ../cmake/bin/cmake --build . -j 2
# Force CPU voxelization to test on Travis (we won't have a GPU here)
- ./cuda_voxelizer -f ../test_models/bunny.OBJ -cpu
68 changes: 49 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)

PROJECT ( CudaVoxelizer )
PROJECT(CudaVoxelize LANGUAGES CXX)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
IF(MSVC)
ENABLE_LANGUAGE(CUDA)
ENDIF()

FIND_PACKAGE(CUDA QUIET REQUIRED)
FIND_PACKAGE(GLM REQUIRED)
FIND_PACKAGE(glm REQUIRED)
FIND_PACKAGE(OpenMP REQUIRED)


IF(NOT MSVC)
FIND_PACKAGE(CUDA REQUIRED)
ENDIF()

SET(CUDA_VOXELIZER_EXECUTABLE cuda_voxelizer)

SET(Trimesh2_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/trimesh2/include" CACHE PATH "Path to Trimesh2 includes")
SET(Trimesh2_INCLUDE_DIR CACHE PATH "Path to Trimesh2 includes")
SET(CUDA_ARCH CACHE STRING "CUDA compute capability. It is prefer to set native value for your video card. Example: 61")

IF(NOT CUDA_ARCH)
MESSAGE(FATAL_ERROR "You must set CUDA_ARCH variable. For example: 61.")
ENDIF()

IF(NOT Trimesh2_INCLUDE_DIR)
MESSAGE(FATAL_ERROR "You need to set variable Trimesh2_INCLUDE_DIR")
ENDIF()

FIND_FILE(Trimesh2_TriMesh_h TriMesh.h ${Trimesh2_INCLUDE_DIR})
IF(NOT Trimesh2_TriMesh_h)
message(SEND_ERROR "Can't find TriMesh.h in ${Trimesh2_INCLUDE_DIR}")
message(FATAL_ERROR "Can't find TriMesh.h in ${Trimesh2_INCLUDE_DIR}")
ENDIF()
MARK_AS_ADVANCED(Trimesh2_TriMesh_h)
INCLUDE_DIRECTORIES(${Trimesh2_INCLUDE_DIR})

SET(Trimesh2_LINK_DIR "${CMAKE_SOURCE_DIR}/trimesh2/lib.Linux64" CACHE PATH "Path to Trimesh2 libraries")
SET(Trimesh2_LINK_DIR CACHE PATH "Path to Trimesh2 library dir.")

IF(NOT Trimesh2_LINK_DIR)
MESSAGE(FATAL_ERROR "You need to set variable Trimesh2_LINK_DIR")
ENDIF()

IF(NOT EXISTS "${Trimesh2_LINK_DIR}")
MESSAGE(FATAL_ERROR "Trimesh2 library dir does not exist")
ENDIF()

FIND_LIBRARY(Trimesh2_LIBRARY trimesh ${Trimesh2_LINK_DIR})

IF(NOT Trimesh2_LIBRARY)
message(SEND_ERROR "Can't find libtrimesh.a in ${Trimesh2_LINK_DIR}")
ENDIF()
MARK_AS_ADVANCED(Trimesh2_LIBRARY)

MESSAGE(STATUS "CUDA compute capability set to ${CUDA_ARCH}")
MESSAGE(STATUS "Found Trimesh2 include: ${Trimesh2_TriMesh_h}")
MESSAGE(STATUS "Found Trimesh2 lib: ${Trimesh2_LIBRARY}")

SET(CUDA_VOXELIZER_SRCS
./src/main.cpp
./src/util_cuda.cpp
Expand All @@ -39,15 +65,19 @@ SET(CUDA_VOXELIZER_SRCS_CU
./src/voxelize_solid.cu
)

IF(MSVC)
ADD_EXECUTABLE(
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_SRCS}
${CUDA_VOXELIZER_SRCS_CU})
ELSE()
CUDA_ADD_EXECUTABLE(
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_SRCS}
${CUDA_VOXELIZER_SRCS_CU})
ENDIF()

TARGET_INCLUDE_DIRECTORIES( ${CUDA_VOXELIZER_EXECUTABLE} PUBLIC
${Trimesh2_INCLUDE_DIR})

TARGET_LINK_LIBRARIES ( ${CUDA_VOXELIZER_EXECUTABLE}
${Trimesh2_LIBRARY}
gomp
)
TARGET_COMPILE_FEATURES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE cxx_std_11)
TARGET_INCLUDE_DIRECTORIES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE ${Trimesh2_INCLUDE_DIR})
TARGET_LINK_LIBRARIES (${CUDA_VOXELIZER_EXECUTABLE} ${Trimesh2_LIBRARY} glm OpenMP::OpenMP_CXX)
TARGET_COMPILE_OPTIONS(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}>)
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Please make PR's to the `dev` branch
* Update the CMake and MSVC projects to include any extra files you add
* Avoid pulling in extra dependencies (but I'll allow if needed)
82 changes: 53 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[![Build Status](https://travis-ci.org/Forceflow/cuda_voxelizer.svg?branch=master)](https://travis-ci.org/Forceflow/cuda_voxelizer) ![](https://img.shields.io/github/license/Forceflow/cuda_voxelizer.svg) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/Forceflow)

# cuda_voxelizer v0.4.5
CUDA voxelizer, a command-line tool to convert polygon meshes to (annotated) voxel grids using the GPU (with a CPU fallback if no compatible GPU is found).
# cuda_voxelizer v0.4.9
A command-line tool to convert polygon meshes to (annotated) voxel grids.
* Supported input formats: .ply, .off, .obj, .3DS, .SM and RAY
* Supported output formats: .binvox, .obj, morton ordered grid
* Requires a CUDA-compatible video card. Compute Capability 2.0 or higher (Nvidia Fermi or better).
* Since v0.4.4, the voxelizer reverts to a (slower) CPU voxelization method when no CUDA device is found
* 64-bit executables only. 32-bit might work, but you're on your own :)

## Usage
Program options:
Expand All @@ -17,56 +16,82 @@ Program options:
* `obj`: A mesh containing actual cubes (made up of triangle faces) for each voxel.
* `obj_points`: A mesh containing a point cloud, with a vertex for each voxel. Can be viewed using any compatible viewer that can just display vertices, like [Blender](https://www.blender.org/) or [Meshlab](https://www.meshlab.net/).
* `morton`: a binary file containing a Morton-ordered grid. This is a format I personally use for other tools.
* `-cpu`: Force voxelization on the CPU instead of GPU. For when a CUDA device is not detected/compatible, or for very small models where GPU call overhead is not worth it.
* `-t` : Use Thrust library for CUDA memory operations. Might provide speed / throughput improvement. Default: disabled.
* `-solid` : Use solid voxelization (it is not available for cpu). Default: disabled.
* `-cpu`: Force voxelization on the CPU instead of GPU. For when a CUDA device is not detected/compatible, or for very small models where GPU call overhead is not worth it. This is done multi-threaded, but will be slower for large models / grid sizes.
* `-thrust` : Use Thrust library for copying the model data to the GPU, for a possible speed / throughput improvement. I found this to be very system-dependent. Default: disabled.
* `-solid` : (Experimental) Use solid voxelization instead of voxelizing the mesh faces. Needs a watertight input mesh.


## Examples

`cuda_voxelizer -f bunny.ply -s 256` generates a 256 x 256 x 256 bunny voxel model which will be stored in `bunny_256.binvox`.
`cuda_voxelizer -f bunny.ply -s 256` generates a 256 x 256 x 256 binvox-based voxel model which will be stored in `bunny_256.binvox`.

`cuda_voxelizer -f bunny.ply -s 64 -o obj -t` generates a 64 x 64 x 64 bunny .obj voxel model which will be stored in `bunny_64.obj`. During voxelization, the Cuda Thrust library will be used for a possible speedup, but YMMV.
`cuda_voxelizer -f torus.ply -s 64 -o obj -thrust -solid` generates a solid (filled) 64 x 64 x 64 .obj voxel model which will be stored in `torus_64.obj`. During voxelization, the Cuda Thrust library will be used for a possible speedup, but YMMV.

![output_examples](https://raw.githubusercontent.com/Forceflow/cuda_voxelizer/master/img/output_examples.jpg)
![output_examples](https://raw.githubusercontent.com/Forceflow/cuda_voxelizer/main/img/output_examples.jpg)

## Building
The build process is aimed at 64-bit executables. It might be possible to build for 32-bit as well, but I'm not actively testing/supporting this.
You can build using CMake, or using the provided Visual Studio project. Since November 2019, cuda_voxelizer also builds on [Travis CI](https://travis-ci.org/Forceflow/cuda_voxelizer), so check out the [yaml config file](https://github.com/Forceflow/cuda_voxelizer/blob/main/.travis.yml) for more Linux build support.

### Dependencies
The project has the following build dependencies:
* [Cuda 8.0 Toolkit (or higher)](https://developer.nvidia.com/cuda-toolkit) for CUDA.
* Cuda Thrust libraries (they come with the toolkit).
* [Nvidia Cuda 8.0 Toolkit (or higher)](https://developer.nvidia.com/cuda-toolkit) for CUDA + Thrust libraries (standard included)
* [Trimesh2](https://github.com/Forceflow/trimesh2) for model importing. Latest version recommended.
* [GLM](http://glm.g-truc.net/0.9.8/index.html) for vector math. Any recent version will do.
* [OpenMP](https://www.openmp.org/)

### Windows
### Build using CMake (Windows, Linux)

After installing dependencies, do `mkdir build` and `cd build`, followed by:

For Windows with Visual Studio 2019:
```
cmake -A x64 -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
```

For Linux:
```
cmake -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
```
Where `your_cuda_compute_capability` is a string specifying your CUDA architecture ([more info here](https://docs.nvidia.com/cuda/archive/10.2/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation-gpu-architecture)). For example: `-DCUDA_ARCH:STRING=61` or `-DCUDA_ARCH:STRING=60`.

Finally, run
```
cmake --build . -j number_of_cores
```

### Build using Visual Studio project (Windows)

A Visual Studio 2019 project solution is provided in the `msvc`folder. It is configured for CUDA 11, but you can edit the project file to make it work with lower CUDA versions. You can edit the `custom_includes.props` file to configure the library locations, and specify a place where the resulting binaries should be placed.

```
<TRIMESH_DIR>C:\libs\trimesh2\</TRIMESH_DIR>
<GLM_DIR>C:\libs\glm\</GLM_DIR>
<BINARY_OUTPUT_DIR>D:\dev\Binaries\</BINARY_OUTPUT_DIR>
```

### Linux
[Philipp-M](https://github.com/Philipp-M) and [andreanicastro](https://github.com/andreanicastro) were kind enough to write [CMake](https://cmake.org/) support. Since November 2019, cuda_voxelizer also builds on [Travis CI](https://travis-ci.org/Forceflow/cuda_voxelizer), so check out the [yaml config file](https://github.com/Forceflow/cuda_voxelizer/blob/master/.travis.yml) for more Linux build support.

## 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*](http://research.michael-schwarz.com/publ/2010/vox/). The morton-encoded table was based on my 2013 HPG paper [*Out-Of-Core construction of Sparse Voxel Octrees*](http://graphics.cs.kuleuven.be/publications/BLD14OCCSVO/) and the work in [*libmorton*](https://github.com/Forceflow/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.
`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. These are the voxelization timings for the [Stanford Bunny Model](https://graphics.stanford.edu/data/3Dscanrep/) (1,55 MB, 70k triangles).
* This is the voxelization time for a non-solid voxelization. No I/O - from disk or to GPU - is included in this timing.
* CPU voxelization time is heavily dependent on how many cores your CPU has - OpenMP allocates 1 thread per core.

| Grid size | Time |
|-----------|---------|
| 128^3 | 4.2 ms |
| 256^3 | 6.2 ms |
| 512^3 | 13.4 ms |
| 1024^3 | 38.6 ms |
| Grid size | GPU (GTX 1050 TI) | CPU (Intel i7 8750H, 12 threads) |
|-----------|--------|--------|
| 64³ | 0.2 ms | 39.8 ms |
| 128³ | 0.3 ms | 63.6 ms |
| 256³ | 0.6 ms | 118.2 ms |
| 512³ | 1.8 ms | 308.8 ms |
| 1024³ | 8.6 ms | 1047.5 ms |
| 2048³ | 44.6 ms | 4147.4 ms |

## Notes / See Also
* The .binvox file format was created by [Patrick Min](https://www.patrickmin.com/binvox/). Check some other interesting tools he wrote:
* [viewvox](https://www.patrickmin.com/viewvox/): Visualization of voxel grids (a copy of this tool is included in cuda_voxelizer releases)
* [thinvox](https://www.patrickmin.com/thinvox/): Thinning of voxel grids
* The [.binvox file format](https://www.patrickmin.com/binvox/binvox.html) was created by Michael Kazhdan.
* [Patrick Min](https://www.patrickmin.com/binvox/) wrote some interesting tools to work with it:
* [viewvox](https://www.patrickmin.com/viewvox/): Visualization of voxel grids (a copy of this tool is included in cuda_voxelizer releases)
* [thinvox](https://www.patrickmin.com/thinvox/): Thinning of voxel grids
* [binvox-rw-py](https://github.com/dimatura/binvox-rw-py) is a Python module to interact with .binvox files
* Thanks to [conceptclear](https://github.com/conceptclear) for implementing solid voxelization
* If you want a good customizable CPU-based voxelizer, I can recommend [VoxSurf](https://github.com/sylefeb/VoxSurf).
* Another hackable voxel viewer is Sean Barrett's excellent [stb_voxel_render.h](https://github.com/nothings/stb/blob/master/stb_voxel_render.h).
* Nvidia also has a voxel library called [GVDB](https://developer.nvidia.com/gvdb), that does a lot more than just voxelizing.
Expand All @@ -77,7 +102,6 @@ This is on my list of nice things to add. Don't hesistate to crack one of these
* Noncubic grid support
* Memory limits test
* 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
Expand All @@ -91,4 +115,4 @@ title = "Cuda Voxelizer: A GPU-accelerated Mesh Voxelizer",
howpublished = "\url{https://github.com/Forceflow/cuda_voxelizer}",
year = "2017"}
</pre>
If you end up using cuda_voxelizer in something cool, drop me an e-mail (mail (at) jeroen-baert.be)!
If you end up using cuda_voxelizer in something cool, drop me an e-mail: **mail (at) jeroen-baert.be**
63 changes: 0 additions & 63 deletions cmake/FindGLM.cmake

This file was deleted.

Loading