------------------------------------------------------------------------------ Intersect plane; see whether point is inside.
| 430 | // Intersect plane; see whether point is inside. |
| 431 | // |
| 432 | int vtkPixel::IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, |
| 433 | double x[3], double pcoords[3], int& subId) |
| 434 | { |
| 435 | subId = 0; |
| 436 | pcoords[0] = pcoords[1] = pcoords[2] = 0.0; |
| 437 | double pt1[3], pt4[3]; |
| 438 | this->Points->GetPoint(0, pt1); |
| 439 | this->Points->GetPoint(3, pt4); |
| 440 | |
| 441 | // |
| 442 | // Get normal for triangle |
| 443 | // |
| 444 | double n[3] = { 0.0, 0.0, 0.0 }; |
| 445 | for (int i = 0; i < 3; i++) |
| 446 | { |
| 447 | if ((pt4[i] - pt1[i]) <= 0.0) |
| 448 | { |
| 449 | n[i] = 1.0; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // Because vtkPlane::IntersectWithLine cannot handle intersection with finite |
| 455 | // plane, we need to handle the coplanar case ourself and find the closest x/t possible. |
| 456 | // EvaluatePosition will take care of filling values for subId and pcoords. |
| 457 | const double v1[3] = { p1[0] - pt1[0], p1[1] - pt1[1], p1[2] - pt1[2] }; |
| 458 | const double v2[3] = { p2[0] - pt1[0], p2[1] - pt1[1], p2[2] - pt1[2] }; |
| 459 | bool isCoplanar = (std::abs(vtkMath::Dot(v1, n)) < tol) && (std::abs(vtkMath::Dot(v2, n)) < tol); |
| 460 | if (isCoplanar) |
| 461 | { |
| 462 | // if p1 is inside the pixel then return p1. |
| 463 | if (p1[0] <= pt4[0] && p1[0] >= pt1[0] && p1[1] <= pt4[1] && p1[1] >= pt1[1] && |
| 464 | p1[2] <= pt4[2] && p1[2] >= pt1[2]) |
| 465 | { |
| 466 | t = 0; |
| 467 | x[0] = p1[0]; |
| 468 | x[1] = p1[1]; |
| 469 | x[2] = p1[2]; |
| 470 | } |
| 471 | // Else we check if we intersect any edges. If we dont that means we do not intersect the pixel. |
| 472 | else |
| 473 | { |
| 474 | double mint = VTK_DOUBLE_MAX; |
| 475 | double tmpt, tmpx[3], tmppcoords[3]; |
| 476 | int tmpid; |
| 477 | for (int i = 0; i < 4; ++i) |
| 478 | { |
| 479 | bool res = this->GetEdge(i)->IntersectWithLine(p1, p2, tol, tmpt, tmpx, tmppcoords, tmpid); |
| 480 | if (res && (tmpt < mint)) |
| 481 | { |
| 482 | mint = tmpt; |
| 483 | t = tmpt; |
| 484 | x[0] = tmpx[0]; |
| 485 | x[1] = tmpx[1]; |
| 486 | x[2] = tmpx[2]; |
| 487 | } |
| 488 | } |
| 489 |
nothing calls this directly
no test coverage detected