-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintersect_c_wrapper.py
More file actions
43 lines (38 loc) · 1.4 KB
/
Copy pathintersect_c_wrapper.py
File metadata and controls
43 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""ctypes wrapper around intersect_c.dll / intersect_c.so"""
import ctypes, os, numpy as np
def _load():
here = os.path.dirname(os.path.abspath(__file__))
for name in ("intersect_c.dll", "intersect_c.so", "libintersect_c.so"):
path = os.path.join(here, name)
if os.path.exists(path):
return ctypes.CDLL(path)
raise FileNotFoundError("intersect_c DLL not found — run build_cy.bat first")
_lib = _load()
_lib.trace_batch_c.restype = None
_lib.trace_batch_c.argtypes = [
ctypes.c_void_p, # aabb
ctypes.c_int, # n_internal
ctypes.c_int, # max_leaf
ctypes.c_void_p, # tris
ctypes.c_int, # n_tris
ctypes.c_void_p, # origins
ctypes.c_void_p, # targets
ctypes.c_int, # n
ctypes.c_void_p, # out
ctypes.c_float, # t_origin_skip
ctypes.c_float, # t_near_horiz_dist
ctypes.c_float, # t_target_skip
]
def trace_batch(bvh_aabb, n_internal, max_leaf, tris, n_tris,
origins, targets,
t_origin_skip=2.0, t_near_horiz_dist=25.0, t_target_skip=20.0):
n = len(origins)
out = np.zeros(n, dtype=np.uint8)
_lib.trace_batch_c(
bvh_aabb.ctypes.data, n_internal, max_leaf,
tris.ctypes.data, n_tris,
origins.ctypes.data, targets.ctypes.data, n,
out.ctypes.data,
float(t_origin_skip), float(t_near_horiz_dist), float(t_target_skip),
)
return out