Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ pyembree/*.pyc
pyembree.egg-info/
dist/
*.png

.idea
4 changes: 4 additions & 0 deletions pyembree/rtcore_scene.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ cdef extern from "embree2/rtcore_scene.h":

cdef class EmbreeScene:
cdef RTCScene scene_i

cdef enum rayQueryType:
intersect,
occluded
22 changes: 19 additions & 3 deletions pyembree/rtcore_scene.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cimport rtcore as rtc
cimport rtcore_ray as rtcr
cimport rtcore_geometry as rtcg


cdef void error_printer(const rtc.RTCError code, const char *_str):
print "ERROR CAUGHT IN EMBREE"
rtc.print_error(code)
Expand All @@ -19,12 +20,21 @@ cdef class EmbreeScene:

def run(self, np.ndarray[np.float64_t, ndim=2] vec_origins,
np.ndarray[np.float64_t, ndim=2] vec_directions,
dists=None):
dists=None,query='INTERSECT'):
rtcCommit(self.scene_i)
cdef int nv = vec_origins.shape[0]
cdef int vo_i, vd_i, vd_step
cdef np.ndarray[np.int32_t, ndim=1] intersect_ids
cdef np.ndarray[np.float32_t, ndim=1] tfars
cdef rayQueryType query_type

if query == 'INTERSECT':
query_type = intersect
elif query == 'OCCLUDED':
query_type = occluded
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why be based on strings rather than a Python enums? Does pyembree still support Python 2.7?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, yt uses pyembree and still supports Python2.7, so it would be in our interests to keep it there for a little while longer. There are other bits in pyembree that use strings, IIRC.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fair. I was just wondering. It isn't 2020 yet :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'm still using it in a python 2.7 project as well.

else:
raise ValueError("Embree ray query type %s not recognized" % (query))

if dists is None:
tfars = np.empty(nv, 'float32')
tfars.fill(1e37)
Expand All @@ -36,6 +46,7 @@ cdef class EmbreeScene:
vd_step = 1
# If vec_directions is 1 long, we won't be updating it.
if vec_directions.shape[0] == 1: vd_step = 0

for i in range(nv):
for j in range(3):
ray.org[j] = vec_origins[i, j]
Expand All @@ -49,8 +60,13 @@ cdef class EmbreeScene:
ray.mask = -1
ray.time = 0
vd_i += vd_step
rtcIntersect(self.scene_i, ray)
intersect_ids[i] = ray.primID

if query_type == intersect:
rtcIntersect(self.scene_i, ray)
intersect_ids[i] = ray.primID
else:
rtcOccluded(self.scene_i, ray)
intersect_ids[i] = ray.geomID

return intersect_ids

Expand Down