Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,71 @@
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
-
from myplot import plot_verticles
|
| 3 |
-
vertices = np.array([
|
| 4 |
-
[-3, -3, 0],
|
| 5 |
-
[+3, -3, 0],
|
| 6 |
-
[+3, +3, 0],
|
| 7 |
-
[-3, +3, 0],
|
| 8 |
-
[+0, +0, +3]
|
| 9 |
-
])
|
| 10 |
-
plot_verticles(vertices = vertices, isosurf = False)
|
| 11 |
-
|
| 12 |
-
plot_verticles(vertices = vertices, isosurf = True)
|
| 13 |
-
|
| 14 |
-
array([
|
| 15 |
-
[4, 1, 0],
|
| 16 |
-
[4, 2, 1],
|
| 17 |
-
[3, 4, 0],
|
| 18 |
-
[3, 4, 2],
|
| 19 |
-
[3, 2, 1],
|
| 20 |
-
[3, 1, 0]
|
| 21 |
-
], dtype=int32)
|
| 22 |
-
|
| 23 |
-
myramid_mesh = mesh.Mesh(
|
| 24 |
-
np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)
|
| 25 |
-
)
|
| 26 |
-
for i, f in enumerate(faces):
|
| 27 |
-
for j in range(3):
|
| 28 |
-
myramid_mesh.vectors[i][j] = vertices[f[j],:]
|
| 29 |
-
plot_mesh(myramid_mesh)
|
| 30 |
-
|
| 31 |
import matplotlib.pyplot as plt
|
| 32 |
from scipy import spatial
|
| 33 |
-
import numpy as np
|
| 34 |
-
points = np.array([
|
| 35 |
-
[0,0],
|
| 36 |
-
[-2,0],
|
| 37 |
-
[-2,2],
|
| 38 |
-
[0,1.5],
|
| 39 |
-
[2,2],
|
| 40 |
-
[2,0]
|
| 41 |
-
])
|
| 42 |
-
hull = spatial.ConvexHull(points)
|
| 43 |
-
|
| 44 |
-
array([
|
| 45 |
-
[2, 1],
|
| 46 |
-
[2, 4],
|
| 47 |
-
[5, 1],
|
| 48 |
-
[5, 4]
|
| 49 |
-
], dtype=int32)
|
| 50 |
-
|
| 51 |
-
plt.plot(points[:,0], points[:,1], 'o')
|
| 52 |
-
for simplex in hull.simplices:
|
| 53 |
-
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
|
| 54 |
-
|
| 55 |
-
plt.plot(points[:,0], points[:,1], 'o')
|
| 56 |
-
for simplex in hull.simplices:
|
| 57 |
-
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
|
| 58 |
-
|
| 59 |
-
|
| 60 |
import pymesh
|
| 61 |
-
box_a = pymesh.generate_box_mesh([0,0,0], [1,1,1])
|
| 62 |
-
filename = "/pymesh_examples/pymesh_example_01.stl"
|
| 63 |
-
pymesh.save_mesh(filename, box_a, ascii=False)
|
| 64 |
-
|
| 65 |
-
import pymesh
|
| 66 |
-
box_a = pymesh.generate_box_mesh([0,0,0], [1,1,1])
|
| 67 |
-
box_b = pymesh.generate_box_mesh([0.4,0.4,0], [0.6,0.6,1])
|
| 68 |
-
box_c = pymesh.boolean(
|
| 69 |
-
box_a,
|
| 70 |
-
box_b,
|
| 71 |
-
operation='difference',
|
| 72 |
-
engine="igl"
|
| 73 |
-
)
|
| 74 |
-
filename = "/pymesh_examples/pymesh_example_02.stl"
|
| 75 |
-
pymesh.save_mesh(filename, box_c, ascii=False)
|
| 76 |
-
|
| 77 |
-
from solid import *
|
| 78 |
-
d = difference()(
|
| 79 |
-
cube(size = 10, center = True),
|
| 80 |
-
sphere(r = 6.5, segments=300)
|
| 81 |
-
)
|
| 82 |
-
path = scad_render_to_file(d, 'solidpython_example_01.scad')
|
| 83 |
-
|
| 84 |
-
|
| 85 |
from solid import *
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
+
from myplot import plot_verticles, plot_mesh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
from scipy import spatial
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import pymesh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from solid import *
|
| 8 |
+
from solid.utils import *
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
# Function to plot vertices and meshes
|
| 12 |
+
def plot_vertices_and_mesh(vertices, faces):
|
| 13 |
+
# Assuming 'plot_verticles' and 'plot_mesh' are defined in 'myplot'
|
| 14 |
+
plot_verticles(vertices=vertices, isosurf=False)
|
| 15 |
+
plot_verticles(vertices=vertices, isosurf=True)
|
| 16 |
+
|
| 17 |
+
# Create and plot mesh
|
| 18 |
+
myramid_mesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))
|
| 19 |
+
for i, f in enumerate(faces):
|
| 20 |
+
for j in range(3):
|
| 21 |
+
myramid_mesh.vectors[i][j] = vertices[f[j],:]
|
| 22 |
+
plot_mesh(myramid_mesh)
|
| 23 |
|
| 24 |
+
# Function to plot convex hull
|
| 25 |
+
def plot_convex_hull(points):
|
| 26 |
+
hull = spatial.ConvexHull(points)
|
| 27 |
+
plt.plot(points[:,0], points[:,1], 'o')
|
| 28 |
+
for simplex in hull.simplices:
|
| 29 |
+
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
|
| 30 |
+
st.pyplot(plt)
|
| 31 |
+
|
| 32 |
+
# Function to create and save 3D meshes
|
| 33 |
+
def create_3d_meshes():
|
| 34 |
+
box_a = pymesh.generate_box_mesh([0,0,0], [1,1,1])
|
| 35 |
+
pymesh.save_mesh("/tmp/pymesh_example_01.stl", box_a, ascii=False)
|
| 36 |
+
|
| 37 |
+
box_b = pymesh.generate_box_mesh([0.4,0.4,0], [0.6,0.6,1])
|
| 38 |
+
box_c = pymesh.boolean(box_a, box_b, operation='difference', engine="igl")
|
| 39 |
+
pymesh.save_mesh("/tmp/pymesh_example_02.stl", box_c, ascii=False)
|
| 40 |
+
|
| 41 |
+
# Function to create and save solid models
|
| 42 |
+
def create_solid_models():
|
| 43 |
+
d = difference()(cube(size=10, center=True), sphere(r=6.5, segments=300))
|
| 44 |
+
scad_render_to_file(d, '/tmp/solidpython_example_01.scad')
|
| 45 |
+
|
| 46 |
+
c = circle(r=1)
|
| 47 |
+
t = translate([2, 0, 0])(c)
|
| 48 |
+
e = linear_extrude(height=10, center=True, convexity=10, twist=-500, slices=500)(t)
|
| 49 |
+
col = color('lightgreen')(e)
|
| 50 |
+
scad_render_to_file(col, '/tmp/solidpython_example_02.scad')
|
| 51 |
+
|
| 52 |
+
# Streamlit UI
|
| 53 |
+
st.title("3D Graphics and Geometry with Streamlit")
|
| 54 |
+
|
| 55 |
+
if st.button('Plot Vertices and Meshes'):
|
| 56 |
+
# Add vertices and faces data here
|
| 57 |
+
vertices = np.array([[-3, -3, 0], [+3, -3, 0], [+3, +3, 0], [-3, +3, 0], [+0, +0, +3]])
|
| 58 |
+
faces = np.array([[4, 1,0], [4, 2, 1], [3, 4, 0], [3, 4, 2], [3, 2, 1], [3, 1, 0]], dtype=int32)
|
| 59 |
+
plot_vertices_and_mesh(vertices, faces)
|
| 60 |
+
|
| 61 |
+
if st.button('Plot Convex Hull'):
|
| 62 |
+
points = np.array([[0, 0], [-2, 0], [-2, 2], [0, 1.5], [2, 2], [2, 0]])
|
| 63 |
+
plot_convex_hull(points)
|
| 64 |
+
|
| 65 |
+
if st.button('Create and Save 3D Meshes'):
|
| 66 |
+
create_3d_meshes()
|
| 67 |
+
st.write("3D meshes saved to files.")
|
| 68 |
+
|
| 69 |
+
if st.button('Create and Save Solid Models'):
|
| 70 |
+
create_solid_models()
|
| 71 |
+
st.write("Solid models saved to files.")
|