Skip to content

Added 2d generate support and mesh.show() previews based on matplotlib and vtkplotlib #27

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions examples/generate_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from sdf import *
import numpy as np

f = rectangle(1) - circle(0.5)
points = f.generate(workers=1)

print(np.array(points).shape)
6 changes: 6 additions & 0 deletions examples/show_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sdf import *
from matplotlib import pyplot as plt

f = polygon([[0,0], [1,0], [0,1]]).translate([-3.5, -0.5]) | rectangle(1) | circle(0.5).translate([3, 0])

f.show()
11 changes: 11 additions & 0 deletions examples/show_3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from sdf import *

t = torus(2, 0.5)
f = union(
t.orient(X),
t.orient(Y),
t.orient(Z),
k=0.1,
)

f.show()
7 changes: 6 additions & 1 deletion sdf/d2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import operator

from . import dn, d3, ease
from . import dn, d3, ease, mesh

# Constants

Expand All @@ -20,6 +20,7 @@
class SDF2:
def __init__(self, f):
self.f = f
self.dim = 2
def __call__(self, p):
return self.f(p).reshape((-1, 1))
def __getattr__(self, name):
Expand All @@ -36,6 +37,10 @@ def __sub__(self, other):
def k(self, k=None):
self._k = k
return self
def generate(self, *args, **kwargs):
return mesh.generate(self, *args, **kwargs)
def show(self, *args, **kwargs):
return mesh.show(self, *args, **kwargs)

def sdf2(f):
def wrapper(*args, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions sdf/d3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class SDF3:
def __init__(self, f):
self.f = f
self.dim = 3
def __call__(self, p):
return self.f(p).reshape((-1, 1))
def __getattr__(self, name):
Expand All @@ -41,6 +42,8 @@ def generate(self, *args, **kwargs):
return mesh.generate(self, *args, **kwargs)
def save(self, path, *args, **kwargs):
return mesh.save(path, self, *args, **kwargs)
def show(self, *args, **kwargs):
return mesh.show(self, *args, **kwargs)
def show_slice(self, *args, **kwargs):
return mesh.show_slice(self, *args, **kwargs)

Expand Down
Loading