-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stub out a callback handler #24
Open
matthewturk
wants to merge
5
commits into
scopatz:master
Choose a base branch
from
matthewturk:callbacks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0ca6a3
Stub out a callback handler
matthewturk 28faae5
Change ray to pass-by-references to allow modification.
langmm b42d09a
Merge pull request #1 from langmm/callbacks
matthewturk b33530a
Add a python callback handler example
matthewturk d1b57ce
Adding news item
matthewturk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
**Added:** | ||
|
||
Callbacks can now be supplied to the ray caster. This includes callbacks written in Cython, subclassing from the RayCollisionCallback cython class, and callbacks generated in Python that instantiate a PythonCallback object. | ||
|
||
**Changed:** None | ||
|
||
**Deprecated:** None | ||
|
||
**Removed:** None | ||
|
||
**Fixed:** None | ||
|
||
**Security:** None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rtcore_ray cimport RTCRay | ||
|
||
cdef enum: | ||
_CALLBACK_TERMINATE = 0 | ||
_CALLBACK_CONTINUE = 1 | ||
|
||
cdef class RayCollisionCallback: | ||
# The function callback needs to return either _CALLBACK_TERMINATE or | ||
# _CALLBACK_CONTINUE. _CALLBACK_CONTINUE will keep it running, but | ||
# assumes that you have done something to the ray. Otherwise it will | ||
# enter into an endless loop. | ||
cdef int callback(self, RTCRay &ray) | ||
|
||
cdef class RayCollisionNull(RayCollisionCallback): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from rtcore_ray cimport RTCRay | ||
|
||
# This is to make them accessible from Python | ||
CALLBACK_TERMINATE = _CALLBACK_TERMINATE | ||
CALLBACK_CONTINUE = _CALLBACK_CONTINUE | ||
|
||
cdef class RayCollisionCallback: | ||
cdef int callback(self, RTCRay &ray): | ||
return CALLBACK_TERMINATE | ||
|
||
cdef class PythonCallback(RayCollisionCallback): | ||
# This class lets you specify a python function that can modify in situ the | ||
# rays that are arriving. Changes will be reflected. | ||
cdef public object callback_function | ||
def __init__(self, callback_function): | ||
self.callback_function = callback_function | ||
|
||
cdef int callback(self, RTCRay &ray): | ||
ray_info = dict( | ||
org = (ray.org[0], ray.org[1], ray.org[2]), | ||
dir = (ray.dir[0], ray.dir[1], ray.dir[2]), | ||
tnear = ray.tnear, | ||
tfar = ray.tfar, | ||
time = ray.time, | ||
mask = ray.mask, | ||
Ng = (ray.Ng[0], ray.Ng[1], ray.Ng[2]), | ||
u = ray.u, | ||
v = ray.v, | ||
geomID = ray.geomID, | ||
primID = ray.primID, | ||
instID = ray.instID | ||
) | ||
rv = self.callback_function(ray_info) | ||
# We now update the ray contents from the dictionary | ||
for i in range(3): | ||
ray.org[i] = ray_info['org'][i] | ||
ray.dir[i] = ray_info['dir'][i] | ||
ray.Ng[i] = ray_info['Ng'][i] | ||
ray.tnear = ray_info['tnear'] | ||
ray.tfar = ray_info['tfar'] | ||
ray.mask = ray_info['mask'] | ||
ray.u = ray_info['u'] | ||
ray.v = ray_info['v'] | ||
ray.geomID = ray_info['geomID'] | ||
ray.primID = ray_info['primID'] | ||
ray.instID = ray_info['instID'] | ||
if rv == _CALLBACK_CONTINUE: | ||
return _CALLBACK_CONTINUE | ||
return _CALLBACK_TERMINATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add docstrings to this file