CPU Sparse Voxel Octree Implementation

Overview

XYZRGB Dragon

Sparse Voxel Octrees

This project provides a multithreaded, CPU Sparse Voxel Octree implementation in C++, capable of raytracing large datasets in real-time, converting raw voxel files to octrees and converting mesh data (in form of PLY files) to voxel octrees.

The conversion routines are capable of handling datasets much larger than the working memory, allowing the creation and rendering of very large octrees (resolution 8192x8192x8192 and up).

This implementation closely follows the paper Efficient Sparse Voxel Octrees by Samuli Laine and Tero Karras.

The XYZRGB dragon belongs the the Stanford 3D Scanning Repository and is available from their homepage

Compilation

A recent compiler cupporting C++11, CMake 2.8 and SDL 1.2 are required to build.

To build on Linux, you can use the setup_builds.sh shell script to setup build and release configurations using CMake. After running setup_builds.sh, run make inside the newly created build/release/ folder. Alternatively, you can use the standard CMake CLI to configure the project.

To build on Windows, you will need Visual Studio 2013 or later. Before running CMake, make sure that

  • CMake is on the PATH environment variable. An easy check to verify that this is the case is to open CMD and type cmake, which should output the CMake CLI help.
  • You have Windows 64bit binaries of SDL 1.2. These are available here. Make sure to grab the SDL-devel-1.2.XX-VC.zip. Note that if you are using a newer version of Visual Studio, you may need to compile SDL yourself in order to be compatible. Please see the SDL website for details
  • The environment variable SDLDIR exists and is set to the path to the folder containing SDL1.2 (you will have to set it up manually - it needs to be a system environment variable, not a user variable, for CMake to find it). CMake will use this variable to find the SDL relevant files and configure MSVC to use them

After these prerequisites are setup, you can run setup_builds.bat to create the Visual Studio files. It will create a folder vstudio containing the sparse-voxel-octrees.sln solution.

Alternatively, you can also run CMake manually or setup the MSVC project yourself, without CMake. The sources don't require special build flags, so the latter is easily doable if you can't get CMake to work.

To build on macOS, you will need to install SDL first (i.e. brew install sdl). Then build it like a regular CMake project:

mkdir build
cd build
cmake ../
make
./sparse-voxel-octrees -viewer ../models/XYZRGB-Dragon.oct

On macOS, you may need to click+drag within the application window first to make the render visible.

Note: If building fails on macOS, you can try commenting out the follow lines in CMakeLists.txt

#if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#    set(Sources ${Sources} "src/SDLMain.m")
#endif()

Usage

On startup, the program will load the sample octree and render it. Left mouse rotates the model, right mouse zooms. Escape quits the program. In order to make CLI arguments easier on Windows, you can use run_viewer.bat to start the viewer.

Note that due to repository size considerations, the sample octree has poor resolution (256x256x256). You can generate larger octrees using the code, however. See Main.cpp:initScene for details. You can also use run_builder.bat to build the XYZ RGB dragon model. To do this, simply download the XYZ RGB dragon model from http://graphics.stanford.edu/data/3Dscanrep/ and place it in the models folder.

Code

Main.cpp controls application setup, thread spawning and basic rendering (should move this into a different file instead at some point).

VoxelOctree.cpp provides routines for octree raymarching as well as generating, saving and loading octrees. It uses VoxelData.cpp, which robustly handles fast access to non-square, non-power-of-two voxel data not completely loaded in memory.

The VoxelData class can also pull voxel data directly from PlyLoader.cpp, generating data from triangle meshes on demand, instead of from file, which vastly improves conversion performance due to elimination of file I/O.

Comments
  • Program stoped to work with larger lutMemory and dataMemory

    Program stoped to work with larger lutMemory and dataMemory

    Hi, Benedikt,

    Just to report to you a strange problem encountered when i used a larger lutMemory and dataMemory to generate voxels of different resolutions.

    My computer configuration: 10GB memory, Win7 64 bit and the program is compiled with vs2013 with 64 bit release configuration (with the latest code). tested model: xyzrgb_dragon

    I have used a lutMemory and dataMemory size of double the default value. static const size_t lutMemory = 2 * 512 * 1024 * 1024; static const size_t dataMemory = 2 * 512 * 1024 * 1024;

    The test results is as below: resolution result 256 [ok] 512 [ok] 1024 [crashed] 2048 [crashed]

    The problem can be easily reproduced. can you help us to see what is wrong there? Thanks in advance!

    Best, Junjie

    opened by bitxue 19
  • cannot generate .oct file

    cannot generate .oct file

    Hi, Benedikt

    Great work! I am using MinGW + SDL under WIN7 x64, I can compile the code using the makefile and render the 256 demo octree fine. But i cannot generate '.oct' file using '#define GENERATE_IN_MEMORY 1' or '#define GENERATE_ON_DISK 1' (I have put the .ply file under the 'models' folder). I did not look deep into the code. But it was not like what the code comment has promised to do. Can you give me some advice? Thank you!

    opened by bitxue 9
  • implementation in voxel.js

    implementation in voxel.js

    Do you see any problem for this source to be ported to javascript? (Voxel.js benefits from webGL via three.js) If no major problem, any advice on how someone could tackle this?

    opened by ctzurcanu 4
  • problems with vs2017

    problems with vs2017

    hello, setup_builds.bat doesn't seem to work. And i found the param of cmake is wrong. cmake ../ -G "Visual Studio 12 Win64 by using cmake --help i found the correct generator name cmake ../ -G "Visual Studio 12 2013 Win64 error:

    CMake Error at CMakeLists.txt:2 (project):
      No CMAKE_C_COMPILER could be found.
    

    then i try cmake ../ -G "Visual Studio 15 2017 Win64 then the error:

    CMake Error at CMakeLists.txt:12 (message):
      The compiler d:/Program Files (x86)/Microsoft Visual
      Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x64/cl.exe
      seems to have no C++11 support.  Please try again with a more recent
      compiler version.
    

    cmake file where error occur:

    if(CXX11_COMPILER)
        enable_cxx11()
    else()
        message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} seems to have no C++11 support. Please try again with a more recent compiler version.")
    endif()
    

    doesn't vs2017 support cxx11?

    opened by w33haa 3
  • Fix header files missing in project file tree and add program arguments support

    Fix header files missing in project file tree and add program arguments support

    Hi, Benedikt,

    I made a little change to the CMakeLists file to fix the missing header files in project file tree. Also i added program arguments support in order to conveniently setup the parameters without the need of modifing and recompiling the code. You can merge these changes if you find them useful.

    Thanks!

    opened by bitxue 3
  • more OSX fixes

    more OSX fixes

    turns out I forgot to add SDLMain.* in my first PR (which @maxharris9 noticed shortly after landing). I've also if'd out the inclusion of these new files if not on osx.

    I've run this on Win32 to ensure it still works

    screen shot 2015-06-28 at 1 35 47 pm

    Sorry for the churn! I blame my broken elbow/onehandedness for this mistake haha

    opened by tmpvar 2
  • unexpected holes at the boundary of the bounding box

    unexpected holes at the boundary of the bounding box

    Hi, Benedikt

    In some cases, the program will result in unexpected holes at the boundary of the bounding box.

    20150201144152 20150201145946

    Use the head model at 2048 resolution to reproduce. The head model can be downloaded here: http://graphics.cs.williams.edu/data/meshes/head.zip

    Best, Junjie

    opened by bitxue 2
  • can not generate low-resolution voxels model

    can not generate low-resolution voxels model

    Hi, Benedikt,

    If we want to generate a multi-resolution voxel representation, it is necessary to generate the low-resolution voxel model, too. I tested the latest code, it could not generate voxels using a resolution of 128x128x128 or lower. Can you see what is wrong there?

    Best, Junjie

    opened by bitxue 2
  • it seems that the voxels model and the original model are axisymmetric

    it seems that the voxels model and the original model are axisymmetric

    Hi,

    I compared the original model with the generated voxel model together and found that they seems axisymmetric (see the figures bellow). I think the two models should look the same before and after the voxelization. Maybe we can check the code to locate the issue.

    thanks!

    junjie

    polygon_model voxel_model

    opened by bitxue 2
  • Segmentation fault on OSX 10.12.5

    Segmentation fault on OSX 10.12.5

    I am getting Segmentation Fault 11 when trying to run ./sparse-voxel-octrees -viewer ./models/YZRGB-Dragon.oct on my Mac. On the off chance that someone is still checking this repo and might know what's going on, I'm posting here. It seems to be coming from the renderLoop in Main.cpp.

    opened by zach-babb-moovel 1
  • Seeking suggestion for old compiler w/a template<bool isTop> void VoxelData::upsampleLutLevel(int l)

    Seeking suggestion for old compiler w/a template void VoxelData::upsampleLutLevel(int l)

    The member template template void VoxelData::upsampleLutLevel(int l) runs afoul of a compiler issue. The issue was repaired in the compiler in the very next version after the one I'm using. I have to freeze my software, including gcc, for the time being (months). I am not looking to have the problem solved for me. Instead, I hope to get advice I can follow to fix the problem for myself.

    The compiler issue was recorded in GCC's tracker at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56402

    I get two warnings when compiling VoxelData.cpp related to the instantiations of this member template. Here's an example of one of them: In instantiation of ‘void VoxelData::upsampleLutLevel(int) [with bool isTop = true]’: /path/to/src/VoxelData.cpp:157:33: required from here /path/to/src/VoxelData.cpp:91:22: warning: missing initializer for member ‘VoxelData::upsampleLutLevel(int) [with bool isTop = true]::<lambda(int)>::__this’ [-Wmissing-field-initializers]

    BTW it is complicated to debug this project because it seems the C++11 macros in "cmake/" somehow disable -g partially so that line-by-line debugging is not available. I can open an issue for that if desired, with a work-around for the benefit of others perhaps.

    opened by cardiffman 1
  • Floating point exception (core dumped)

    Floating point exception (core dumped)

    Hey there, I'm having trouble converting a ply file to oct

    the scene is a sponza scene converted from obj to drc and then ply. It is complete as I can render it ok elsewhere, but when I try to run with the appon builder mode I get:

    Triangle count: 262267, taking up 33 MB of memory
    Partitioning cache block into 2x1x2 over 4 threads (per thread block is 6x6x4)
    PlyLoader block lists take up an additional 846 KB of memory
    Floating point exception (core dumped)
    
    
    opened by JoseETeixeira 0
  • Win 10 Compiling Issues

    Win 10 Compiling Issues

    I followed all the instructions in the post but CMake outputs the following:

    WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15\lib\x86". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15\lib\x86". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15\lib\x86". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15". Targets may link only to libraries. CMake is dropping the item. WARNING: Target "sparse-voxel-octrees" requests linking to directory "E:\CPP\TunaBrain\SDL-1.2.15\lib\x86". Targets may link only to libraries. CMake is dropping the item

    I'm using VS2017 but have not yet tried recompiling SDL 1.2 - perhaps that?

    opened by TombstoneTumbleweedArt 2
Owner
Benedikt Bitterli
Benedikt Bitterli
Fast, hierarchical, sparse Voxel Grid

Treexy is a library that implements a compact hierarchical data structure that can store and manipulate volumetric data, discretized on a three-dimens

Davide Faconti 323 Dec 21, 2022
Implementation of Monocular Direct Sparse Localization in a Prior 3D Surfel Map (DSL)

Implementation of Monocular Direct Sparse Localization in a Prior 3D Surfel Map (DSL)

Haoyang Ye 93 Nov 30, 2022
this is my simple voxel engine, appart from librairies like glad it is entierly written in C++ and GLSL

simple-voxel-raycaster this is my simple voxel engine, appart from librairies like glad it is entierly written in C++ and GLSL here is a gif: https://

null 2 Sep 26, 2022
(R) Efficient methods and operators for the sparse matrix classes in 'Matrix' (esp. CSR format or "RsparseMatrix")

MatrixExtra MatrixExtra is an R package which extends the sparse matrix and sparse vector types in the Matrix package, particularly the CSR or Rsparse

null 15 Aug 29, 2022
The QPEP-Enhanced Direct Sparse Odometry (DSO) with Loop Closure

QPEP-DSO: Quadratic Pose Estimation Problems (QPEP) Enhanced Direct Sparse Odometry with Loop Closure Code Arch The codes are motivated by DSO (https:

Jin Wu 8 Jun 23, 2022
An FPGA accelerator for general-purpose Sparse-Matrix Dense-Matrix Multiplication (SpMM).

Sextans Sextans is an accelerator for general-purpose Sparse-Matrix Dense-Matrix Multiplication (SpMM). One exciting feature is that we only need to p

linghao.song 30 Dec 29, 2022
OpenVDB - Sparse volume data structure and tools

OpenVDB AX Nano Houdini Website | Discussion Forum | Documentation OpenVDB is an open source C++ library comprising a novel hierarchical data structur

Academy Software Foundation 1.9k Jan 6, 2023
The official SuiteSparse library: a suite of sparse matrix algorithms authored or co-authored by Tim Davis, Texas A&M University

SuiteSparse: A Suite of Sparse matrix packages at http://suitesparse.com May 17, 2021. SuiteSparse VERSION 5.10.1 Now includes GraphBLAS, SLIP_LU, and

Tim Davis 720 Dec 31, 2022
CPU implementation of Seidel aberrations for screen-space DOF by Niels Asberg.

PrimeFocusCPU CPU implementation of Seidel aberrations for screen-space DOF by Niels Asberg. MIT License Copyright (c) 2021 Niels Asberg Permission is

Zeno Pelgrims 3 Nov 24, 2021
kianv a simple implementation of a rv32im riscv cpu and soc in verilog with firmware that runs raytracer, mandelbrot, etc.....

A very simple riscv cpu/soc one single file implementation created in my spare time! But it is full rv32im CPU :) I have wrote all from scratch to lea

splinedrive 122 Dec 26, 2022
a small C library for x86 CPU detection and feature extraction

libcpuid libcpuid provides CPU identification for the x86 (and x86_64). For details about the programming API, you might want to take a look at the pr

Veselin Georgiev 358 Dec 26, 2022
LiteX is a Migen/MiSoC based Core/SoC builder that provides the infrastructure to easily create Cores/SoCs (with or without CPU).

LiteX is a Migen/MiSoC based Core/SoC builder that provides the infrastructure to easily create Cores/SoCs (with or without CPU). The common components of a SoC are provided directly: Buses and Streams (Wishbone, AXI, Avalon-ST), Interconnect, Common cores (RAM, ROM, Timer, UART, etc...), CPU wrappers/integration, etc... and SoC creation capabilities can be greatly extended with the ecosystem of LiteX cores (DRAM, PCIe, Ethernet, SATA, etc...) that can be integrated/simulated/build easily with LiteX.

null 1.9k Jan 3, 2023
TinyE8 - Ben Eater's 8 Bit CPU Emulator

TinyE8 - Ben Eater's 8 Bit CPU Emulator TinyE8 emulates Ben Eater's 8 bit breadboard CPU. Implemented all the Instructions except JC and JZ, I need to

null 67 Nov 10, 2022
seg's WONDELFUL, INCREDIBLE and POWERFUL 16-bit CPU (:

seg's WONDELFUL, INCREDIBLE and POWERFUL 16-bit CPU (: Not really ): This is just a tiny emulated ISA and CPU with an assembler, a simple debugg

null 18 Nov 8, 2021
Performance Evaluation of a Parallel Image Enhancement Technique for Dark Images on Multithreaded CPU and GPU Architectures

Performance Evaluation of a Parallel Image Enhancement Technique for Dark Images on Multithreaded CPU and GPU Architectures Image processing is a rese

Batuhan Hangün 5 Nov 4, 2021
Crappy RISC-V CPU and fancy peripherals designed to be useful.

Crappy RISC-V CPU and fancy peripherals designed to be useful. Always half-baked. Prioritize compatibility over performance.

Peter Gu 29 Dec 9, 2022
Newlib for Xuantie RISC-V CPU, a lightweight C library for embedded systems.

README for GNU development tools This directory contains various GNU compilers, assemblers, linkers, debuggers, etc., plus their support routines, d

T-Head Semiconductor Co., Ltd. 5 Sep 9, 2022
The CPU Simulation Project for ECGR 4181 at UNCC

ECGR 4181 CPU Simulation The CPU Simulation Project for ECGR 4181 at UNCC Project Members Jonathon Nguyen Jarrett Long Features 32-bit Words 32-bit In

Jonathon Nguyen 2 Dec 21, 2021
UEFI Application for CPU Voltage/Frquency and Power Management adjustment. Great for undervolting.

Reduce CPU Power Waste and Gain Performance. Greener and Meaner! ______ ______ _ (_____ \

null 125 Dec 30, 2022