Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
64f5ae7e
Commit
64f5ae7e
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Simplified rayIntersection method - I was calling trimesh ray_intersects_id
incorrectly
parent
a0ae6634
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/mesh.py
+19
-45
19 additions, 45 deletions
fsl/data/mesh.py
with
19 additions
and
45 deletions
fsl/data/mesh.py
+
19
−
45
View file @
64f5ae7e
...
...
@@ -263,67 +263,41 @@ class TriangleMesh(object):
return
self
.
__trimesh
def
rayIntersection
(
self
,
origins
,
directions
,
sort
=
False
,
vertices
=
False
):
def
rayIntersection
(
self
,
origins
,
directions
,
vertices
=
False
):
"""
Calculate the intersection between the mesh, and the rays defined by
``origins`` and ``directions``.
:arg origins: Sequence of ray origins
:arg directions: Sequence of ray directions
:arg sort: By default, the calculated intersection coordinates
are not sorted. If ``sort`` is set to ``True`` will
be sorted according to increasing distance from the
ray origin.
:arg vertices: By default, the returned coordinates are where the
ray intersects with triangles of the mesh. If
``vertices`` is set to ``True``, the returned
coordinates will be the vertices that were nearest
to the ray intersection points.
:returns: A list-of-lists, one for each input ray, containing
the points where the ray intersected the mesh.
:returns: A tuple containing:
- A ``(n, 3)`` array containing the coordinates
where the mesh was intersected by each of the
``n`` rays.
- A ``(n,)`` array containing the indices of the
triangles that were intersected by each of the
``n`` rays.
"""
hits
=
[[]
for
o
in
origins
]
trimesh
=
self
.
trimesh
()
if
trimesh
is
None
:
return
hits
return
np
.
zeros
((
0
,
3
)),
np
.
zeros
((
0
,))
tris
,
rays
,
locs
=
self
.
trimesh
()
.
ray
.
intersects_id
(
tris
,
rays
,
locs
=
trimesh
.
ray
.
intersects_id
(
origins
,
directions
,
return_locations
=
True
,
mulltiple_hits
=
False
)
# group by input ray
dists
=
[[]
for
o
in
origins
]
for
tri
,
ray
,
loc
in
zip
(
tris
,
rays
,
locs
):
hits
[
ray
].
append
(
loc
)
if
sort
:
dists
[
ray
].
append
(
transform
.
veclength
(
loc
-
origins
[
ray
]))
# returned locations are not
# sorted, so we need to sort
# them by distance from the
# origin
if
sort
:
for
i
in
range
(
len
(
hits
)):
rayHits
=
hits
[
i
]
rayDists
=
dists
[
i
]
if
len
(
rayHits
)
>
0
:
rayDists
,
rayHits
=
zip
(
*
sorted
(
zip
(
rayDists
,
rayHits
)))
hits
[
i
]
=
rayHits
dists
[
i
]
=
rayDists
multiple_hits
=
False
)
# TODO
if
vertices
:
pass
# sort by ray. I'm Not sure if this is
# needed - does trimesh do it for us?
rayIdxs
=
np
.
argsort
(
rays
)
locs
=
locs
[
rayIdxs
]
tris
=
tris
[
rayIdxs
]
return
hit
s
return
locs
,
tri
s
def
getBounds
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment