-
Notifications
You must be signed in to change notification settings - Fork 16
Added line_segment flag and Unit Test for Moller Trumbore Line Triangle Intersection Function #131
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
Conversation
this new version allows treating the given vector to be treated as line segement rather than a ray, i.e. it won't intersect a face if the intersection doesn't occur between the origin and destination.
|
We may want to wrap the current version in a function that does that final check so it will not be called if not needed. |
|
If I do it then the line segment length has to be calculated twice effectively since the original one doesn't return the length of the line segment. Moreover, the original function doesn't return
|
|
I think if you do the following it's the least amount of work and will have the effect we want. // new function that gives back the parametric coordinate
// put in the comment that we are using moller_trumbore method here
OMEGA_H_DEVICE bool ray_intersects_triangle(const o::Few<o::Vector<3>, 3>& faceVerts,
const o::Vector<3>& orig, const o::Vector<3>& dest,
o::Vector<3>& xpoint, const o::Real tol, const o::LO flip,
o::Real& dproj, o::Real& closeness, double& intersection_parametric_coord);
// current function that really should be ray/line intersection
// consider marking as deprecated https://en.cppreference.com/w/cpp/language/attributes/deprecated
OMEGA_H_DEVICE bool moller_trumbore_line_triangle(const o::Few<o::Vector<3>, 3>& faceVerts,
const o::Vector<3>& orig, const o::Vector<3>& dest,
o::Vector<3>& xpoint, const o::Real tol, const o::LO flip,
o::Real& dproj, o::Real& closeness)
{
double parametric_coord;
return ray_triangle_intersection(faceVerts,
orig, dest,
xpoint, tol, const o::LO flip,
dproj, closeness, parametric_coord);
}
// new function that just checks line segment triangle intersection
// might as well pass back the parametric coord since someone may want to use it
OMEGA_H_DEVICE bool line_segment_intersects_triangle(const o::Few<o::Vector<3>, 3>& faceVerts,
const o::Vector<3>& orig, const o::Vector<3>& dest,
o::Vector<3>& xpoint, const o::Real tol, const o::LO flip,
o::Real& dproj, o::Real& closeness, double& intersection_parametric_coord)
{
line_triangle_intersection(faceVerts,
orig, dest,
xpoint, tol, const o::LO flip,
dproj, closeness, intersection_parametric_coord);
return intersection_parametric_coord > 0 && intersection_parametric_coord <1;
}New functions could be called |
deprecated against line_segment_intersects_triangle and ray_intersects_triangle
|
Thank you so much for the suggestion. I have added the changes in the above commit. |
|
These tests need the newly added meshes in the pumipic-data pull request 2 |
|
I merged the changes in pumi-pic data |
|
@Fuad-HH can you also update the usage of the |
|
Otherwise this looks great. |
|
@cwsmith this is ready to review. This does not change the behavior of the search method. |
cwsmith
left a comment
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.
LGTM. Thank you.
The
moller_trumbore_line_trianglefunction returns true if a ray (given the origin and destination coordinates) intersects a triangle. But, for some applications, we need it to be intersected only if the intersection point lies within the line segment. In the new version, it takes a flag which if set to true checks if the the line segment intersects within origin to destination, not extrapolated.In the test, the line enters the tetrahedral (id = 12) and stops inside it. It has faces 28, 29, 33, and 39. Face 28 (face nodes are 5,11,4) is the top face where the given line segment doesn't intersect but when treated as a ray it intersects.
Ray origin: 0.000000 -0.200000 -0.500000
Ray Destination: 0.000000 -0.200000 0.900000
Face 28 Nodes:
5 (1.000000 -1.000000 1.000000),
11 (0.000000 0.000000 1.000000),
4 (-1.000000 -1.000000 1.000000)
An interactive plot for the tested line and faces is attached here. The HTML file can be downloaded and opened in a browser to view it.
https://drive.google.com/file/d/1H1K41VDQc-BldMaXLUYcWaWQxLxGBkzi/view?usp=sharing