• Stars
    star
    298
  • Rank 139,663 (Top 3 %)
  • Language
    C++
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ implementation for computing occupancy grids and signed distance functions (SDFs) from watertight meshes.

Mesh Voxelization

This is a parallel C++ implementation for efficiently voxelizing (watertight, triangular) meshes into signed distance functions (SDFs) and/or occupancy grids.

If you use this tool, please cite the following work:

@inproceedings{Stutz2018CVPR,
    title = {Learning 3D Shape Completion from Laser Scan Data with Weak Supervision },
    author = {Stutz, David and Geiger, Andreas},
    booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    publisher = {IEEE Computer Society},
    year = {2018}
}
@misc{Stutz2017,
    author = {David Stutz},
    title = {Learning Shape Completion from Bounding Boxes with CAD Shape Priors},
    month = {September},
    year = {2017},
    institution = {RWTH Aachen University},
    address = {Aachen, Germany},
    howpublished = {http://davidstutz.de/},
}

Example of voxelizations.

Overview

SDFs: The implementation uses the triangle-point distance implementation from christopherbatty/SDFGen and triangle-ray intersection implementation by Tomas Akenine-Möller. To determine the distance of each voxel (its corner or center) to the nearest mesh face as well as its sign. Negative sign corresponds to interior voxels.

Publicly available marching cubes implementations, such as PyMCubes or skimage, can be used to derive triangular meshes at sub-voxel accuracy from the computed SDFs. Most implementations use the voxel corner as reference points; this tool supports both the voxel corner and its center. For a marching cubes implementation also using the center, see the voxel_centers branch of this PyMCubes fork.

Occupancy: Occupancy grids can either be derived from the computed SDFs (not included) or computed separately using triangle-box intersections; the code from Tomas Akenine-Möller is used. This has the advantage that voxels intersecting the mesh surface are definitely identified as occupied - this is not always the case when deriving occupancy from SDFs.

The computed SDFs and occupancy grids are saved using the HDF5 file format. C++ and Python utilities for reading this format are provided; as well as C++ and Python utilities for the used (triangular) mesh format: OFF.

Color of the original mesh can be preserved in ocupancy grid mode.

Installation

Requirements for C++ tool:

  • CMake;
  • Boost;
  • HDF5;
  • Eigen;
  • OpenMP;
  • C++11.

Requirements for Python tool:

  • Numpy;
  • h5py;
  • PyMCubes or skimage.

On Ubuntu and related Linux distributions, these requirements can be installed as follows:

sudo apt-get install build-essential cmake libboost-all-dev libhdf5-dev libeigen3-dev

Make sure that the used compiler supports OpenMp and that the installed Eigen version include the unsupported Tensor module.

For using the Python tools, also make sure to install numpy, h5py and skimage (or PyMCubes):

pip install numpy
pip install h5py
pip install scikit-image

Follow the instructions here to install PyMCubes as alternative to skimage (however, only one of both is required).

To build, first adapt cmake/FindEigen3.cmake to include the correct path to Eigen3's include directory and remove NO_CMAKE_SYSTEM_PATH if necessary, and run:

mkdir build
cd build
cmake ..
make

To test the installation you can run (form within the build directory):

../bin/voxelize occ ../examples/input ../examples/output.h5

To obtain occupancy grids; or

../bin/voxelize sdf ../examples/input ../examples/output.h5

To obtain SDFs.

Also install MeshLab to visualize OFF files.

Usage

The general procedure can be summarized as follows:

  1. Scale the raw meshes to lie in [0, H] x [0, W] x [0, D] corresponding to the chosen resolution H x D x W.
  2. Voxelize the scaled meshes into SDFs or occupancy grids.
    1. Fill the occupancy grids if necessary.
  3. Convert the occupancy grids or SDFs to meshes for visualization.

The first step can be done using examples/scale_off.py which takes the meshes, for example from examples/raw, and first normalizes them to [-0.5,0.5]^3 to afterwards sale and translate them to [0, H] x [0, W] x [0, D]. This can be accomplished using:

python ../examples/scale_off.py ../examples/raw/ ../examples/input/

If your file contains color information of faces, set --color=True.

The meshes can then be voxelized; for details, check the --help option:

$ ../bin/voxelize --help
Allowed options:
  --help                produce help message
  --mode arg (=occ)     operation mode, 'occ' or 'sdf'
  --input arg           input, either single OFF file or directory containing 
                        OFF files where the names correspond to integers (zero 
                        padding allowed) and are consecutively numbered 
                        starting with zero
  --height arg (=32)    height of volume, corresponding to y-axis (=up)
  --width arg (=32)     width of volume, corresponding to x-axis (=right
  --depth arg (=32)     depth of volume, corresponding to z-axis (=forward)
  --center              by default, the top-left-front corner is used for SDF 
                        computation; if instead the voxel centers should be 
                        used, set this flag
  --color               by default, color information is not kept after 
                        voxelization, set this flag if you want to voxelize with 
                        colors
  --output arg          output file, will be a HDF5 file containing either a N 
                        x C x height x width x depth tensor or a C x height x 
                        width x depth tensor, where N is the number of files 
                        and C=2 the number of channels, N is discarded if only 
                        a single file is processed; should have the .h5 
                        extension

The mode determines whether occupancy grids or SDFs are computed. For SDFs, --center indicates that the voxel's centers are to be used for SDF computation instead of the corners (by default); this has influence on the used marching cubes implementation. The output will be a N x H x W x D tensor as HDF5 file containing the occupancy grids or SDFs per mesh.

When --color flag is set, an additional file (or files) [int]_color.h5 with the original mesh face colors is created in the input directory. Instead of occupancy grid being filled with 0 or 1 it will consist of 0s and face IDs. When converting voxelized mesh back to OFF file as in examples/occ_to_off.py, these face IDs can be used to point to the corresponding color in the color file (or files) which is then used for all 12 triangular faces of the voxel. Color file(s) should be input when calling examples/occ_to_off.py with --color argument, multiple files can be listed but ordering is important.

Note: The triangular meshes of the input OFF files should be watertight. This can, together with a simplification of the meshes, be acheived using Andreas Geiger's semi-convex hull algorithm which, however, imposes a rather crude simplification. The meshes should additionally be scaled to fit the volume used for voxelization. For the OFF files, the tool assumes the coordinate system x=right, y=up and z=forward; this means that the x and y axes are swapped for voxelization (in the output volume, the height is the first dimension).

Example

Using example meshes from ModelNet, two examples illustrate usage of the tools. In both cases, the meshes are first scaled:

python ../examples/scale_off.py ../examples/raw/ ../examples/input/

Here, we use the default resolution of 32^3.

SDFs

Given the scaled meshes, voxelization into SDFs is done as follows:

../bin/voxelize sdf ../examples/input ../examples/output.h5

In order to visualize the SDFs, marching cubes can be used to derive triangular meshes. As we used the default parameters, the voxels' corners were used for SDF computation, therefore, the standard PyMCubes can be used; alternatively, skimage can also be used:

python ../examples/marching_cubes.py ../examples/output.h5 ../examples/output/

Note that marching cubes might fail, e.g. with Surface level must be within volume data range., if the original mesh was not watertight (with significant holes) or structures within the outer surface prevents SDF computation. In this case, the SDF might not have negative values and marching cube fails.

Note that in low resolution, the reconstruction might look bad; try the same procedure with 64^3 to get significantly better results.

Occupancy Grids

Given the scaled meshes,

../bin/voxelize occ ../examples/input ../examples/output.h5

Is used to compute occupancy grids. Note that these are not "filled"; meaning that only the mesh surfaces are voxelized. Assuming the original shapes to be mostly watertight, the occupancy grids can be filled using a connected components algorithm as in examples/fill_occupancy.py:

python ../examples/fill_occupancy.py ../examples/output.h5 ../examples/filled.h5

The occupancy grids can be converted to meshes for visualization using

python ../examples/occ_to_off.py ../examples/filled.h5 ../examples/output/

License

License for source code corresponding to:

D. Stutz, A. Geiger. Learning 3D Shape Completion from Laser Scan Data with Weak Supervision. IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018.

Note that the source code is based on the following projects for which separate licenses apply:

Copyright (c) 2018 David Stutz, Max-Planck-Gesellschaft

Please read carefully the following terms and conditions and any accompanying documentation before you download and/or use this software and associated documentation files (the "Software").

The authors hereby grant you a non-exclusive, non-transferable, free of charge right to copy, modify, merge, publish, distribute, and sublicense the Software for the sole purpose of performing non-commercial scientific research, non-commercial education, or non-commercial artistic projects.

Any other use, in particular any use for commercial purposes, is prohibited. This includes, without limitation, incorporation in a commercial product, use in a commercial service, or production of other artefacts for commercial purposes.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You understand and agree that the authors are under no obligation to provide either maintenance services, update services, notices of latent defects, or corrections of defects with regard to the Software. The authors nevertheless reserve the right to update, modify, or discontinue the Software at any time.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. You agree to cite the corresponding papers (see above) in documents and papers that report on research using the Software.

More Repositories

1

bootstrap-multiselect

JQuery multiselect plugin based on Twitter Bootstrap.
HTML
3,668
star
2

latex-resources

Collection of LaTeX resources and examples.
TeX
475
star
3

superpixel-benchmark

An extensive evaluation and comparison of 28 state-of-the-art superpixel algorithms on 5 datasets.
C++
352
star
4

superpixels-revisited

Library containing 7 state-of-the-art superpixel algorithms with a total of 9 implementations used for evaluation purposes in [1] utilizing an extended version of the Berkeley Segmentation Benchmark.
C++
252
star
5

mesh-fusion

Python tool for obtaining watertight meshes using TSDF fusion.
C++
150
star
6

bootstrap-strength-meter

Password strength meter based on Twitter Bootstrap and Password Score.
HTML
83
star
7

caffe-tools

Some tools and examples for pyCaffe including LMDB I/O, custom Python layers and monitoring training error and loss.
Python
77
star
8

matlab-mnist-two-layer-perceptron

A two layer perceptron implemented in MatLab to recognize handwritten digits based on the MNIST dataset.
MATLAB
59
star
9

cvpr2018-shape-completion

CVPR 2018 paper "Learning 3D Shape Completion from Laser Scan Data with Weak Supervision".
TeX
59
star
10

password-score

Password scoring library written in Javascript.
JavaScript
56
star
11

pytorch-adversarial-examples-training-articles

PyTorch code corresponding to my blog series on adversarial examples and (confidence-calibrated) adversarial training.
Python
56
star
12

tensorflow-cpp-op-example

Simple example of implementing a new Tensorflow operation and its gradient in C++.
Python
55
star
13

bpy-visualization-utils

Blender/bpy utilities for paper-ready visualizations of meshes, point clouds and occupancy grids.
Python
55
star
14

seeds-revised

Implementation of the superpixel algorithm called SEEDS [1].
C++
52
star
15

mesh-evaluation

Efficient C++ implementation of mesh-to-mesh and mesh-to-point distance.
C++
43
star
16

disentangling-robustness-generalization

CVPR'19 experiments with (on-manifold) adversarial examples.
Python
40
star
17

graph-based-image-segmentation

Implementation of efficient graph-based image segmentation as proposed by Felzenswalb and Huttenlocher [1] that can be used to generate oversegmentations.
C++
40
star
18

extended-berkeley-segmentation-benchmark

Extended version of the Berkeley Segmentation Benchmark [1] used for evaluation in [2].
C++
39
star
19

confidence-calibrated-adversarial-training

Implementation of Confidence-Calibrated Adversarial Training (CCAT).
Python
38
star
20

grosse2009-intrinsic-images

Code from the MIT Intrinsic Images Dataset [1]; Including command line tool for Retinex algorithm.
Python
25
star
21

googlemock-example

An example of using Google Mock inspired by Martin Fowler's "Mocks Aren't Stubs".
C++
25
star
22

hierarchical-graph-based-video-segmentation

Implementation of the hierarchical graph-based video segmentation algorithm proposed by Grundmann et al. [1] based on the image segmentation algorithm by Felzenswalb and Huttenlocher [2].
C++
23
star
23

nyu-depth-v2-tools

Tools used in [2] to pre-process the ground truth segmentations to evaluate superpixel algorithms.
MATLAB
22
star
24

flow-io-opencv

Fork and OpenCV wrapper of the optical flow I/O and visualization code provided as part of the Sintel dataset [1].
C++
20
star
25

daml-shape-completion

CVPR'18 implementation of (deterministic) amortized maximum likelihood (AML) for weakly-supervised shape completion.
C++
20
star
26

sphinx-example

Example and cheat sheet for the Sphinx Python documentation generator.
Python
18
star
27

pointnet-auto-encoder

Torch PointNet auto encoder implementation.
C++
17
star
28

ijcv2018-improved-shape-completion

ArXiv'18 pre-print "Learning 3D Shape Completion under Weak Supervision".
TeX
15
star
29

robust-generalization-flatness

Implementation of average- and worst-case robust flatness measures for adversarial training.
Python
14
star
30

arxiv-submission-sanitizer-flattener

Simple Python scripts to clean up and flatten ArXiv LaTeX submissions.
Python
14
star
31

pytorch-custom-c-cuda-operations

Example of easily implementing custom tensor operations in C and CUDA.
Python
13
star
32

ipiano

Implementation of the iPiano algorithm for non-convex and non-smooth optimization as described in [1].
C++
13
star
33

opencv-2.4-cuda-9-patch

This is a quick patch for compiling OpenCV 2.4.x with CUDA 9.
CMake
13
star
34

cvpr2019-adversarial-robustness

CVPR 2019 paper "Disentangling Adversarial Robustness and Generalization".
TeX
13
star
35

kohana-hooks

Event module for Kohana.
PHP
12
star
36

seminar-convolutional-neural-networks

Seminar paper "Understanding Convolutional Neural Networks".
TeX
12
star
37

probabilistic-pca

Python probabilistic PCA (PPCA) implementation.
Python
11
star
38

bachelor-thesis-superpixels

Bachelor thesis "Superpixel Segmentation using Depth Information", including a thorough comparison of several state-of-the-art superpixel algorithms.
TeX
11
star
39

aml-improved-shape-completion

ArXiv'18 implementation of amortized maximum likelihood (AML) for high-quality, weakly-supervised shape completion.
C++
10
star
40

vlfeat-slic-example

Example of using VLFeat's SLIC implementation from C++.
C++
10
star
41

icml2020-confidence-calibrated-adversarial-training

ICML'20 paper "Confidence-Calibrated Adversarial Training: Generalizing to Unseen Attacks".
TeX
9
star
42

vedaldi2006-siftpp

Fork of SIFT++, a lightweight C++ implementation of the SIFT detector and descriptor.
C++
9
star
43

torch-examples

Collection of Torch examples for deep learning.
Lua
7
star
44

mathematical-image-processing

Implementations and examples of basic mathematical image processing algorithms. Based on the lectures "Mathematical Foundations of Image Processing" and "Variational Methods in Image Processing" by Prof. Berkels.
MATLAB
6
star
45

php-simplex

PHP library implementing the simplex algorithm.
PHP
5
star
46

jasmine-travis-example

Example for continuous integration with Jasmine, GitHub and Travis CI.
JavaScript
5
star
47

php-matrix-decompositions-demonstration

Demonstration of common matrix decompositions in PHP.
PHP
5
star
48

master-thesis-shape-completion

Master thesis "Learning 3D Shape Completion from Bounding Boxes using CAD Shape Priors".
TeX
5
star
49

iccv2021-robust-flatness

ICCV'21 paper "Relating Adversarially Robust Generalization to Flat Minima".
PostScript
5
star
50

banic2012-color-constancy

Fork of the Light Random Spray Retinex Algorithm as discussed in [1].
C++
5
star
51

jquery-pseudocode

Lightweight jQuery plugin to display algorithms similar to LaTeX pseudocode and algorithm packages.
HTML
5
star
52

functional-dependencies

Small demo application for calculating candidate keys of a given relational database schema.
PHP
5
star
53

d3-topological

Topological sort using d3.js.
JavaScript
4
star
54

wordpress-iamdavidstutz

Wordpress theme of my personal webpage.
JavaScript
4
star
55

random-bit-error-robustness

Implementation of robust quantization, weight clipping and random bit error training to improve robustness against bit errors in quantized weights.
Python
4
star
56

superpixel-benchmark-data

Converted datasets for davidstutz/superpixel-benchmark.
4
star
57

php-matrix-decompositions

PHP Library including several common matrix decompositions: LU, QR and Cholesky.
PHP
3
star
58

kohana-red

Kohana authentication module based on Kohana's ORM and Database module.
PHP
3
star
59

cmsimple-pictures

CMSimple plugin for creating different kinds of sliders and galleries.
PHP
3
star
60

gcpr2015-superpixels

GCPR 2015 paper and poster "Superpixel Segmentation: An Evaluation".
TeX
3
star
61

seminar-cnn-image-retrieval

Seminar paper "Neural Codes for Image Retreival".
TeX
3
star
62

kohana-navigation

Navigation generation module for Kohana.
PHP
3
star
63

davidstutz

Personal README.
2
star
64

cmsimple-iamdavidstutz

CMSimple theme of my personal webpage.
CSS
2
star
65

kohana-green

Kohana Access Control List implementation based on Kohana's Red module.
PHP
2
star
66

wordpress-github

Wordpress GitHub plugin.
PHP
2
star
67

cmsimple-news

CMSimple plugin for managing and publishing news.
PHP
2
star
68

matlab-multi-label-connected-components

MEX wrapper for Ali Rahimi's multi-label connected components implementation in C++.
C++
2
star
69

kohana-gaps

Kohana form creation module based on ORM models.
PHP
2
star
70

seminar-neural-networks

Seminar paper "Introduction to Neural Networks".
TeX
2
star
71

project-social-network-analysis-stackexchange

Project of "Social Network Analysis" MOOC by the University of Michigan on analyzing StackExchange sites.
PHP
2
star
72

seminar-ipiano

Seminar paper "iPiano: Inertial Proximal Algorithm for Non-Convex Optimization".
TeX
2
star
73

superpixel-benchmark-nvd3

Interactive plots of results from the superpixel benchmark davidstutz/superpixel-benchmark using NVD3.
JavaScript
2
star
74

nvd3-superpixel-comparison

Interactive compariosn of superpixel algorithms as presented in the bachelor thesis "Superpixel Segmentation using Depth Information" [1].
JavaScript
2
star
75

proseminar-dart

RWTH Aachen University Proseminar 2012 Chair for Data Management and Data Exploration: Dart - A Brief Introduction
TeX
2
star
76

tensorflow-mnist-experiments

CADL course project: different architectures implemented in TensorFlow and tested on MNIST.
Python
1
star
77

cmsimple-youtube

CMSimple plugin for creating youtube video galleries.
PHP
1
star
78

kohana-yellow

Yellow is a logging module for the Kohana Green module based on Green and Red.
PHP
1
star
79

pytorch-pgd-adversarial-examples

PyTorch implementation of projected gradient descent (PGD) to generate L_p adversarial examples.
1
star
80

pytorch-adversarial-robustness-articles

Code corresponding to a series of blog articles on adversarial robustness at davidstutz.de.
1
star
81

pytorch-tensorboard-monitoring

PyTorch example for using TensorBoard logging in a plug-and-play fashion.
1
star
82

cmsimple-bootstrap

A simple CMSimple theme based on Twitter Bootstrap.
CSS
1
star
83

cmsimple-bbclone

BBClone plugin for CMSimple.
PHP
1
star
84

cmsimple-elfinder

CMSimple elFinder filebrowser.
JavaScript
1
star
85

pytorch-loading-models

PyTorch example for loading models without initializing their architectures first.
1
star
86

pytorch-cifar10-autoaugment-cutout

PyTorch Code for getting 2.56% test error on CIFAR-10 using AugoAugment and CutOut.
1
star
87

kohana-media

Simple media/assets module for Kohana.
PHP
1
star
88

jquery-references

Naive jQuery plugin to allow referencing figures, listings, algorithms and references in a BibTex-like style.
HTML
1
star
89

kohana-blue

Blue is a user configuration module based on Kohana's Red module.
PHP
1
star