1+ #= =========================================================================================+
2+ | TABLE OF CONTENTS: |
3+ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4+ | struct: |
5+ | - STLInfo2D |
6+ | - STLInfo3D |
7+ +------------------------------------------------------------------------------------------+
8+ | function: |
9+ | - readSTL2D |
10+ | - readSTL3D |
11+ +==========================================================================================#
12+
13+ export STLInfo2D, STLInfo3D
14+ export readSTL2D, readSTL3D
15+
16+ struct STLInfo2D
17+ mesh :: Py
18+ vmin :: Vector
19+ vmax :: Vector
20+ py_vertices :: Py
21+ py_triangles:: Py
22+ stl_path :: String
23+ end
24+
25+ function Base. show (io:: IO , info:: STLInfo2D )
26+ println (io, " STLInfo2D:" )
27+ println (io, " Path : " , info. stl_path)
28+ println (io, " Vertices : " , info. py_vertices. shape[0 ])
29+ println (io, " Triangles: " , info. py_triangles. shape[0 ])
30+ println (io, " X-Y Min : (" , info. vmin[1 ], " , " , info. vmin[2 ], " )" )
31+ println (io, " X-Y Max : (" , info. vmax[1 ], " , " , info. vmax[2 ], " )" )
32+ end
33+
34+ struct STLInfo3D
35+ mesh :: Py
36+ vmin :: Vector
37+ vmax :: Vector
38+ py_vertices :: Py
39+ py_triangles:: Py
40+ stl_path :: String
41+ end
42+
43+ function Base. show (io:: IO , info:: STLInfo3D )
44+ println (io, " STLInfo3D:" )
45+ println (io, " Path : " , info. stl_path)
46+ println (io, " Vertices : " , info. py_vertices. shape[0 ])
47+ println (io, " Triangles: " , info. py_triangles. shape[0 ])
48+ println (io, " X-Y-Z Min: (" , info. vmin[1 ], " , " , info. vmin[2 ], " , " , info. vmin[3 ], " )" )
49+ println (io, " X-Y-Z Max: (" , info. vmax[1 ], " , " , info. vmax[2 ], " , " , info. vmax[3 ], " )" )
50+ end
51+
52+ """
53+ readSTL2D(stl_file::String)
54+
55+ Description:
56+ ---
57+ Read a STL file as a 2D object (z=0) containing the mesh, bounding box, vertices, and
58+ triangles.
59+
60+ Example:
61+ ---
62+ ```julia
63+ stl_info = readSTL2D("path/to/your/file.stl")
64+ ```
65+ """
66+ function readSTL2D (stl_file)
67+ isfile (stl_file) || error (" stl_file should be a valid file path" )
68+ mesh = o3d. io. read_triangle_mesh (stl_file)
69+ rows = pyslice (nothing , nothing , nothing )
70+ cols = pyslice (nothing , 2 , nothing )
71+ vertices = np. asarray (mesh. vertices)[rows, cols]
72+ triangles = np. asarray (mesh. triangles)
73+ aabb = mesh. get_axis_aligned_bounding_box ()
74+ vmin = py2ju (Vector, aabb. get_min_bound ())[1 : 2 ]
75+ vmax = py2ju (Vector, aabb. get_max_bound ())[1 : 2 ]
76+ return STLInfo2D (mesh, vmin, vmax, vertices, triangles, stl_file)
77+ end
78+
79+ """
80+ readSTL3D(stl_file::String)
81+
82+ Description:
83+ ---
84+ Read a STL file as a 3D object containing the mesh, bounding box, vertices, and triangles.
85+
86+ Example:
87+ ---
88+ ```julia
89+ stl_info = readSTL3D("path/to/your/file.stl")
90+ ```
91+ """
92+ function readSTL3D (stl_file)
93+ isfile (stl_file) || error (" stl_file should be a valid file path" )
94+ mesh = o3d. io. read_triangle_mesh (stl_file)
95+ vertices = np. asarray (mesh. vertices)
96+ triangles = np. asarray (mesh. triangles)
97+ aabb = mesh. get_axis_aligned_bounding_box ()
98+ vmin = py2ju (Vector, aabb. get_min_bound ())
99+ vmax = py2ju (Vector, aabb. get_max_bound ())
100+ return STLInfo3D (mesh, vmin, vmax, vertices, triangles, stl_file)
101+ end
0 commit comments