Skip to content

Generates 2D/3D signed distance functions based on the paper Primitive3D

License

Notifications You must be signed in to change notification settings

kecol/SDF-Sampler

Repository files navigation

SDF-Sampler

Generates 2D and 3D Signed Distance Field samples based on the paper "Primitive3D: 3D Object Dataset Synthesis from Randomly Assembled Primitives". We extend the idea to the SDF world resulting into a simple library that might open/simplify new ML explorations.

How to install

git clone https://github.com/kecol/SDF-Sampler.git
pip install -e .

How to use it

2D Sampler

import numpy as np
from sdf_sampler.sampler import SDF_2DSampler

# create sampler with default primitives and operations
tree_depth = 10
sampler = SDF_2DSampler(N=tree_depth)

# generate random sdf sample
sample = sampler()

# display sample composition (sdf primitives and operations used)
print(sample.root)

# define space's coordinates we are courious about in range (-1,-1) to (1, 1)
n_points = 100
points = (np.random.rand(n_points, 2)-.5)*2

# query sdf values for defined points
sdf_values = sample().f(points)

SDF 2D Sampler notebook

3D Sampler

import numpy as np
from sdf_sampler.sampler import SDF_3DSampler

# create sampler with default primitives and operations
tree_depth = 6
sampler = SDF_3DSampler(N=tree_depth)

# generate random sdf sample
sample = sampler()

# display sample composition (sdf primitives and operations used)
print(sample.root)

# define space's coordinates we are courious about in range (-1,-1,-1) to (1, 1, 1)
n_points = 100
points = (np.random.rand(n_points, 3)-.5)*2

# query sdf values for defined points
sdf_values = sample().f(points)

SDF 3D Sampler notebook

TODOs

  • Implement rotations, translation and scaling in 2D (sampler.sample_primitive)
  • Add more primitives (primitives.primitives_2D)
  • Add more operations (operations.operations_2D)
  • Replicate the whole sampling idea for 3D
  • Add alternative 3D plots (utils)
  • Add more primitives (primitives.primitives_3D)
  • Add more operations (operations.operations_3D)
  • Simplify video generation for 3D
  • Add animated/video 3D slice exploration
  • Add STL plotting: simply install k3d for this task

About

Generates 2D/3D signed distance functions based on the paper Primitive3D

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published