Spaces:
Runtime error
Runtime error
fixed error
Browse files- mesh_utils.py +20 -7
mesh_utils.py
CHANGED
@@ -3,18 +3,25 @@ from mpl_toolkits import mplot3d
|
|
3 |
from matplotlib import pyplot as plt
|
4 |
from typing import List, Tuple
|
5 |
|
6 |
-
|
|
|
7 |
"""
|
8 |
-
Generate images of an STL file from different viewing angles.
|
9 |
|
10 |
Args:
|
11 |
file_path (str): Path to the STL file.
|
12 |
viewing_angles (List[Tuple[int, int]]): List of tuples containing the elevation and azimuth angles for viewing.
|
13 |
output_prefix (str, optional): Prefix for the output image filenames. Defaults to 'mesh_'.
|
|
|
|
|
|
|
14 |
"""
|
15 |
# Load the STL file
|
16 |
your_mesh = mesh.Mesh.from_file(file_path)
|
17 |
|
|
|
|
|
|
|
18 |
# Iterate over each viewing angle and generate an image
|
19 |
for i, (elev, azim) in enumerate(viewing_angles, start=1):
|
20 |
# Create a new plot with a larger figure size
|
@@ -37,12 +44,18 @@ def generate_mesh_images(file_path: str, viewing_angles: List[Tuple[int, int]],
|
|
37 |
ax.view_init(elev=elev, azim=azim)
|
38 |
|
39 |
# Save the plot as an image
|
40 |
-
|
|
|
|
|
41 |
|
42 |
# Close the plot to avoid memory leaks
|
43 |
plt.close()
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
3 |
from matplotlib import pyplot as plt
|
4 |
from typing import List, Tuple
|
5 |
|
6 |
+
|
7 |
+
def generate_mesh_images(file_path: str, viewing_angles: List[Tuple[int, int]], output_prefix: str = 'mesh_') -> List[str]:
|
8 |
"""
|
9 |
+
Generate images of an STL file from different viewing angles and return their file paths.
|
10 |
|
11 |
Args:
|
12 |
file_path (str): Path to the STL file.
|
13 |
viewing_angles (List[Tuple[int, int]]): List of tuples containing the elevation and azimuth angles for viewing.
|
14 |
output_prefix (str, optional): Prefix for the output image filenames. Defaults to 'mesh_'.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
List[str]: List of file paths of the generated images.
|
18 |
"""
|
19 |
# Load the STL file
|
20 |
your_mesh = mesh.Mesh.from_file(file_path)
|
21 |
|
22 |
+
# List to store the file paths of the generated images
|
23 |
+
image_paths = []
|
24 |
+
|
25 |
# Iterate over each viewing angle and generate an image
|
26 |
for i, (elev, azim) in enumerate(viewing_angles, start=1):
|
27 |
# Create a new plot with a larger figure size
|
|
|
44 |
ax.view_init(elev=elev, azim=azim)
|
45 |
|
46 |
# Save the plot as an image
|
47 |
+
image_path = f'{output_prefix}{i}.png'
|
48 |
+
plt.savefig(image_path)
|
49 |
+
image_paths.append(image_path)
|
50 |
|
51 |
# Close the plot to avoid memory leaks
|
52 |
plt.close()
|
53 |
|
54 |
+
return image_paths
|
55 |
+
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
# Example usage:
|
59 |
+
# file_path = 'sample_data.stl'
|
60 |
+
viewing_angles = [(30, 45), (60, 90), (45, 135)]
|
61 |
+
# generate_mesh_images(file_path, viewing_angles)
|