Spaces:
Runtime error
Runtime error
Update backup.app.py
Browse files- backup.app.py +80 -95
backup.app.py
CHANGED
@@ -1,100 +1,85 @@
|
|
|
|
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 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
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 |
import matplotlib.pyplot as plt
|
4 |
+
from mpl_toolkits.mplot3d import Axes3D
|
5 |
+
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
|
6 |
from scipy import spatial
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import pymesh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from solid import *
|
9 |
+
from solid.utils import *
|
10 |
+
import os
|
11 |
+
|
12 |
+
# Function to plot vertices and meshes
|
13 |
+
def plot_vertices_and_mesh(vertices, faces):
|
14 |
+
fig = plt.figure()
|
15 |
+
ax = fig.add_subplot(111, projection='3d')
|
16 |
+
|
17 |
+
# Plot vertices
|
18 |
+
ax.scatter(vertices[:, 0], vertices[:, 1], vertices[:, 2])
|
19 |
+
|
20 |
+
# Plot faces
|
21 |
+
for face in faces:
|
22 |
+
vertices_of_face = vertices[face]
|
23 |
+
poly = Poly3DCollection([vertices_of_face])
|
24 |
+
ax.add_collection3d(poly)
|
25 |
+
|
26 |
+
st.pyplot(fig)
|
27 |
+
|
28 |
+
# Rest of the functions remain the same
|
29 |
+
|
30 |
+
# Streamlit UI
|
31 |
+
st.title("3D Graphics and Geometry with Streamlit")
|
32 |
+
|
33 |
+
if st.button('Plot Vertices and Meshes', key='01'):
|
34 |
+
vertices = np.array([[-3, -3, 0], [+3, -3, 0], [+3, +3, 0], [-3, +3, 0], [+0, +0, +3]])
|
35 |
+
faces = np.array([[4, 1, 0], [4, 2, 1], [3, 4, 0], [3, 4, 2], [3, 2, 1], [3, 1, 0]], dtype=np.int32)
|
36 |
+
plot_vertices_and_mesh(vertices, faces)
|
37 |
+
|
38 |
+
# Function to plot convex hull
|
39 |
+
def plot_convex_hull(points):
|
40 |
+
hull = spatial.ConvexHull(points)
|
41 |
+
plt.plot(points[:,0], points[:,1], 'o')
|
42 |
+
for simplex in hull.simplices:
|
43 |
+
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
|
44 |
+
st.pyplot(plt)
|
45 |
+
|
46 |
+
# Function to create and save 3D meshes
|
47 |
+
def create_3d_meshes():
|
48 |
+
box_a = pymesh.generate_box_mesh([0,0,0], [1,1,1])
|
49 |
+
pymesh.save_mesh("pymesh_example_01.stl", box_a, ascii=False)
|
50 |
+
|
51 |
+
box_b = pymesh.generate_box_mesh([0.4,0.4,0], [0.6,0.6,1])
|
52 |
+
box_c = pymesh.boolean(box_a, box_b, operation='difference', engine="igl")
|
53 |
+
pymesh.save_mesh("pymesh_example_02.stl", box_c, ascii=False)
|
54 |
+
|
55 |
+
# Function to create and save solid models
|
56 |
+
def create_solid_models():
|
57 |
+
d = difference()(cube(size=10, center=True), sphere(r=6.5, segments=300))
|
58 |
+
scad_render_to_file(d, '/tmp/solidpython_example_01.scad')
|
59 |
+
|
60 |
+
c = circle(r=1)
|
61 |
+
t = translate([2, 0, 0])(c)
|
62 |
+
e = linear_extrude(height=10, center=True, convexity=10, twist=-500, slices=500)(t)
|
63 |
+
col = color('lightgreen')(e)
|
64 |
+
scad_render_to_file(col, 'solidpython_example_02.scad')
|
65 |
+
|
66 |
+
# Streamlit UI
|
67 |
+
st.title("3D Graphics and Geometry with Streamlit")
|
68 |
+
|
69 |
+
if st.button('Plot Vertices and Meshes', key='02'):
|
70 |
+
# Add vertices and faces data here
|
71 |
+
vertices = np.array([[-3, -3, 0], [+3, -3, 0], [+3, +3, 0], [-3, +3, 0], [+0, +0, +3]])
|
72 |
+
faces = np.array([[4, 1,0], [4, 2, 1], [3, 4, 0], [3, 4, 2], [3, 2, 1], [3, 1, 0]], dtype=int32)
|
73 |
+
plot_vertices_and_mesh(vertices, faces)
|
74 |
+
|
75 |
+
if st.button('Plot Convex Hull', key='03'):
|
76 |
+
points = np.array([[0, 0], [-2, 0], [-2, 2], [0, 1.5], [2, 2], [2, 0]])
|
77 |
+
plot_convex_hull(points)
|
78 |
+
|
79 |
+
if st.button('Create and Save 3D Meshes', key='04'):
|
80 |
+
create_3d_meshes()
|
81 |
+
st.write("3D meshes saved to files.")
|
82 |
+
|
83 |
+
if st.button('Create and Save Solid Models', key='05'):
|
84 |
+
create_solid_models()
|
85 |
+
st.write("Solid models saved to files.")
|