Commit 6144e9eb authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'fix-CoplanarTriangleIntersection'

b13f713e Add tests for triangle intersection fixes.
caa51b1a Fix for CoplanarTrianglesIntersect
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: T.J. Corona's avatarT.J. Corona <tj.corona@kitware.com>
Merge-request: !4532
parents 7a036b78 b13f713e
......@@ -580,6 +580,51 @@ int TestReciprocalResult(vtkRandom* seq, unsigned nTests)
return EXIT_SUCCESS;
}
int TestIssue17092()
{
// An instance where triangle intersection failed was reported here:
// https://gitlab.kitware.com/vtk/vtk/issues/17092. It was fixed here:
// https://gitlab.kitware.com/vtk/vtk/merge_requests/3886
double t1[3][3] = {{ 0., 0., 0.}, {5., 0., 0.}, {0., 5., 0.}};
double t2[3][3] = {{ 10., 5., 0.}, {5., 10., 0.}, {1., 1., 0.}};
int returnValue = vtkTriangle::TrianglesIntersect( t1[0], t1[1], t1[2],
t2[0], t2[1], t2[2] );
if (returnValue != VTK_YES_INTERSECTION)
{
std::cout<<"Triangle "<<TriangleToString(t1[0],t1[1],t1[2])<<std::endl;
std::cout<<" does not intersect "<<TriangleToString(t2[0],t2[1],t2[2])
<<" and should."<<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int TestMR4529()
{
// An instance where triangle intersection failed (along with its fix) was
// reported here: https://gitlab.kitware.com/vtk/vtk/merge_requests/4529
double t1[3][3] = {{ 1.751, -.993, 0.}, {-3.021, 2.885, 0.}, {4.14, -4.025, 0.}};
double t2[3][3] = {{ 1.751, -.5, 0.}, {1.751, 1.326, 0.}, {-3.382, 2.276, 0.}};
int returnValue = vtkTriangle::TrianglesIntersect( t1[0], t1[1], t1[2],
t2[0], t2[1], t2[2] );
if (returnValue != VTK_YES_INTERSECTION)
{
std::cout<<"Triangle "<<TriangleToString(t1[0],t1[1],t1[2])<<std::endl;
std::cout<<" does not intersect "<<TriangleToString(t2[0],t2[1],t2[2])
<<" and should."<<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int TestTriangleIntersection(vtkRandom* seq, unsigned nTests)
{
if (TestPositiveResult(seq,nTests) == EXIT_FAILURE)
......@@ -602,6 +647,14 @@ int TestTriangleIntersection(vtkRandom* seq, unsigned nTests)
{
return EXIT_FAILURE;
}
if (TestIssue17092() == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
if (TestMR4529() == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
}
......
......@@ -1056,22 +1056,42 @@ int CoplanarTrianglesIntersect(double p1[2], double q1[2], double r1[2],
return 1;
}
// If we have reached this point, then either
// 1. Two orientations are counterclockwise and one is clockwise, or
// 2. Two orientations are clockwise and one is counterclockwise.
// If we have reached this point, then
// 1. Two orientations are counterclockwise and one is clockwise, or
// 2.a Two orientations are clockwise and one is counterclockwise, or
// 2.b One orientation is counterclockwise, one is clockwise and one colinear.
// Equivalently, from "Faster Triangle-Triangle Intersection Tests":
// 1. p1 belongs to region R1
// 2. p1 belongs to region R2
// We permute T2 so that we have the following orienatation pattern:
// (counterclockwise, either orientation, clockwise).
// This orientation corresponds to p1 lying in either region R1 or R2
// 1. p1 belongs to region R1
// 2.a p1 belongs to region R2
// 2.b p1 belongs to boundary of R2
// We permute T2 so that we have the following orientation pattern:
// (counterclockwise, either orientation, clockwise/colinear).
// This orientation corresponds to p1 lying in either region R1 or R2/boundary
int index;
for (index = 0; index < 3; index++)
{
if (p1Orientation[index] == Counterclockwise &&
p1Orientation[(index+2)%3] == Clockwise)
if (p1Orientation[index] == Counterclockwise)
{
break;
if (p1Orientation[(index+1)%3] == Counterclockwise &&
p1Orientation[(index+2)%3] == Clockwise)
{
break; // R1 ++-
}
if (p1Orientation[(index+1)%3] == Clockwise &&
p1Orientation[(index+2)%3] == Clockwise)
{
break; // R2 +--
}
if (p1Orientation[(index+1)%3] == Colinear &&
p1Orientation[(index+2)%3] == Clockwise)
{
break; // R2 boundary +0-
}
if (p1Orientation[(index+1)%3] == Clockwise &&
p1Orientation[(index+2)%3] == Colinear)
{
break; // R2 boundary +-0
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment