@@ -27,4 +27,76 @@ function _get_pts_voxel(stl_model::STLInfo3D, h::Real; fill::Bool=true)
2727 else
2828 return PyArray (pts_cen)
2929 end
30+ end
31+
32+ function _get_pts_ray (stl_model:: STLInfo3D , h:: Real ; fill:: Bool = true , ϵ:: String = " FP32" )
33+ points, pts2 = prepareprojection (stl_model, h, ϵ)
34+ edges = projectionlist (stl_model, points)
35+ pts_cen = fill_particles (edges, pts2, h)
36+ if fill
37+ return populate_pts (pts_cen, h)
38+ else
39+ return pts_cen
40+ end
41+ end
42+
43+ function prepareprojection (stl_model:: STLInfo3D , h:: Real , ϵ)
44+ T = ϵ == " FP32" ? Float32 : Float64
45+ pts2 = meshbuilder (stl_model. vmin[1 ]- 1.5 h : h : stl_model. vmax[1 ]+ 1.5 h,
46+ stl_model. vmin[2 ]- 1.5 h : h : stl_model. vmax[2 ]+ 1.5 h, ϵ= ϵ)
47+ vzlimit = T (stl_model. vmin[3 ] - 10 h)
48+ points = vcat (pts2, vzlimit .* ones (T, 1 , size (pts2, 2 )))
49+ return points, pts2
50+ end
51+
52+ function projectionlist (stl_model:: STLInfo3D , points:: AbstractArray{T} ) where T
53+ # inputs check
54+ pts = points' ; n, m = size (pts)
55+ m == 3 || error (" points must be a 3xN array" )
56+
57+ mesh = stl_model. mesh
58+ pts = np. asarray (pts, dtype= np. float32)
59+ n_rays = pts. shape[0 ]
60+ scene = o3d. t. geometry. RaycastingScene ()
61+ tmesh = o3d. t. geometry. TriangleMesh. from_legacy (mesh, vertex_dtype= o3d. core. float32)
62+ scene. add_triangles (tmesh)
63+
64+ dirs = np. tile ([0 , 0 , 1 ], (n_rays, 1 ))
65+ rays = o3d. core. Tensor (np. hstack ((pts, dirs)), o3d. core. float32)
66+ hits = scene. list_intersections (rays)
67+ t_hit = hits[" t_hit" ]. numpy ()
68+ splits = hits[" ray_splits" ]. numpy ()
69+
70+ t_chunks = np. split (t_hit, splits[1 : - 1 ])
71+ @pyexec """
72+ def py_tmp(pts, t_chunks, n_rays, splits, t_hit):
73+ z_chunks = [pts[i, 2] + t_hit[splits[i] : splits[i + 1]] for i in range(n_rays)]
74+ return z_chunks
75+ """ => py_tmp
76+ result = py_tmp (pts, t_chunks, n, splits, t_hit)
77+ return py2ju (Vector{Vector{T}}, result)
78+ end
79+
80+ function fill_particles (edges:: AbstractArray , pts:: AbstractMatrix{T} , h:: Real ) where T
81+ x_all = Vector {T} (); sizehint! (x_all, 1024 )
82+ y_all = Vector {T} (); sizehint! (y_all, 1024 )
83+ z_all = Vector {T} (); sizehint! (z_all, 1024 )
84+ @inbounds for i in eachindex (edges)
85+ v = edges[i]
86+ if ! isempty (v) && iseven (length (v)) && any (! iszero, v)
87+ sort! (v); xi, yi = pts[1 , i], pts[2 , i]
88+ for j in 1 : 2 : (length (v) - 1 )
89+ for z in v[j]: h: v[j + 1 ]
90+ push! (x_all, xi)
91+ push! (y_all, yi)
92+ push! (z_all, z)
93+ end
94+ end
95+ end
96+ end
97+ xyz = Matrix {T} (undef, 3 , length (x_all))
98+ xyz[1 , :] .= x_all
99+ xyz[2 , :] .= y_all
100+ xyz[3 , :] .= z_all
101+ return xyz
30102end
0 commit comments