| 596 | // the IntersectWithLine method for more information on voxel traversal. |
| 597 | template <typename T> |
| 598 | int CellProcessor<T>::IntersectWithLine(const double p1[3], const double p2[3], double tol, |
| 599 | vtkPoints* points, vtkIdList* cellIds, vtkGenericCell* cell) |
| 600 | { |
| 601 | // Initialize the list of points/cells |
| 602 | if (points) |
| 603 | { |
| 604 | points->Reset(); |
| 605 | } |
| 606 | if (cellIds) |
| 607 | { |
| 608 | cellIds->Reset(); |
| 609 | } |
| 610 | |
| 611 | // Make sure the bounding box of the locator is hit. Also, determine the |
| 612 | // entry and exit points into and out of the locator. This is used to |
| 613 | // determine the bins where the ray starts and ends. |
| 614 | double* bounds = this->Binner->Bounds; |
| 615 | double t0, t1, x0[3], x1[3], rayDir[3], t, x[3], pcoords[3]; |
| 616 | int plane0, plane1, subId; |
| 617 | vtkMath::Subtract(p2, p1, rayDir); |
| 618 | |
| 619 | if (vtkBox::IntersectWithLine(bounds, p1, p2, t0, t1, x0, x1, plane0, plane1) == 0) |
| 620 | { |
| 621 | return 0; // No intersections possible, line is outside the locator |
| 622 | } |
| 623 | |
| 624 | // Okay process line |
| 625 | int* ndivs = this->Binner->Divisions; |
| 626 | vtkIdType prod = ndivs[0] * ndivs[1]; |
| 627 | double* h = this->Binner->H; |
| 628 | T i, numCellsInBin; |
| 629 | int ijk[3], ijkEnd[3]; |
| 630 | vtkIdType idx, cId; |
| 631 | double hitCellBoundsPosition[3], tHitCell; |
| 632 | double step[3], next[3], tMax[3], tDelta[3]; |
| 633 | double binBounds[6]; |
| 634 | |
| 635 | // Initialize intersection query array if necessary. This is done |
| 636 | // locally to ensure thread safety. |
| 637 | std::vector<bool> cellHasBeenVisited(this->NumCells, false); |
| 638 | |
| 639 | // Get the i-j-k point of intersection and bin index. This is |
| 640 | // clamped to the boundary of the locator. Also get the exit bin |
| 641 | // of the line. |
| 642 | this->Binner->GetBinIndices(x0, ijk); |
| 643 | this->Binner->GetBinIndices(x1, ijkEnd); |
| 644 | idx = ijk[0] + ijk[1] * ndivs[0] + ijk[2] * prod; |
| 645 | |
| 646 | // Set up some traversal parameters for traversing through bins |
| 647 | step[0] = (rayDir[0] >= 0.0) ? 1.0 : -1.0; |
| 648 | step[1] = (rayDir[1] >= 0.0) ? 1.0 : -1.0; |
| 649 | step[2] = (rayDir[2] >= 0.0) ? 1.0 : -1.0; |
| 650 | |
| 651 | // If the ray is going in the negative direction, then the next voxel boundary |
| 652 | // is on the "-" direction so we stay in the current voxel. |
| 653 | next[0] = bounds[0] + h[0] * (rayDir[0] >= 0.0 ? (ijk[0] + step[0]) : ijk[0]); |
| 654 | next[1] = bounds[2] + h[1] * (rayDir[1] >= 0.0 ? (ijk[1] + step[1]) : ijk[1]); |
| 655 | next[2] = bounds[4] + h[2] * (rayDir[2] >= 0.0 ? (ijk[2] + step[2]) : ijk[2]); |
nothing calls this directly
no test coverage detected