------------------------------------------------------------------------------ Return intersection point (if any) AND the cell which was intersected by finite line.
| 133 | // Return intersection point (if any) AND the cell which was intersected by |
| 134 | // finite line. |
| 135 | int vtkCellLocator::IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, |
| 136 | double x[3], double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) |
| 137 | { |
| 138 | this->BuildLocator(); |
| 139 | if (this->Tree == nullptr) |
| 140 | { |
| 141 | return 0; |
| 142 | } |
| 143 | double* bounds = this->Bounds; |
| 144 | double* h = this->H; |
| 145 | double t0, t1, x0[3], x1[3], tHitCell; |
| 146 | double hitCellBoundsPosition[3], cellBounds[6], *cellBoundsPtr; |
| 147 | double octantBounds[6]; |
| 148 | int prod = this->NumberOfDivisions * this->NumberOfDivisions; |
| 149 | vtkIdType cellIdBest = -1, cId, i, idx, numberOfCellsInBucket; |
| 150 | int ijk[3], ijkEnd[3]; |
| 151 | int plane0, plane1, subIdBest = -1, hitCellBounds; |
| 152 | double tBest = VTK_FLOAT_MAX, xBest[3], pCoordsBest[3], step[3], next[3], tMax[3], tDelta[3]; |
| 153 | double rayDir[3]; |
| 154 | vtkMath::Subtract(p2, p1, rayDir); |
| 155 | int leafStart = this->NumberOfOctants - |
| 156 | this->NumberOfDivisions * this->NumberOfDivisions * this->NumberOfDivisions; |
| 157 | |
| 158 | // Make sure the bounding box of the locator is hit. Also, determine the |
| 159 | // entry and exit points into and out of the locator. This is used to |
| 160 | // determine the bins where the ray starts and ends. |
| 161 | cellId = -1; |
| 162 | subId = 0; |
| 163 | if (vtkBox::IntersectWithLine(bounds, p1, p2, t0, t1, x0, x1, plane0, plane1) == 0) |
| 164 | { |
| 165 | return 0; // No intersections possible, line is outside the locator |
| 166 | } |
| 167 | |
| 168 | // Initialize intersection query array if necessary. This is done |
| 169 | // locally to ensure thread safety. |
| 170 | std::vector<bool> cellHasBeenVisited(this->DataSet->GetNumberOfCells(), false); |
| 171 | |
| 172 | // Get the i-j-k point of intersection and bin index. This is |
| 173 | // clamped to the boundary of the locator. |
| 174 | this->GetBucketIndices(x0, ijk); |
| 175 | this->GetBucketIndices(x1, ijkEnd); |
| 176 | idx = leafStart + ijk[0] + ijk[1] * this->NumberOfDivisions + ijk[2] * prod; |
| 177 | |
| 178 | // Set up some traversal parameters for traversing through bins |
| 179 | step[0] = (rayDir[0] >= 0.0) ? 1.0 : -1.0; |
| 180 | step[1] = (rayDir[1] >= 0.0) ? 1.0 : -1.0; |
| 181 | step[2] = (rayDir[2] >= 0.0) ? 1.0 : -1.0; |
| 182 | |
| 183 | // If the ray is going in the negative direction, then the next voxel boundary |
| 184 | // is on the "-" direction so we stay in the current voxel. |
| 185 | next[0] = bounds[0] + h[0] * (rayDir[0] >= 0.0 ? (ijk[0] + step[0]) : ijk[0]); |
| 186 | next[1] = bounds[2] + h[1] * (rayDir[1] >= 0.0 ? (ijk[1] + step[1]) : ijk[1]); |
| 187 | next[2] = bounds[4] + h[2] * (rayDir[2] >= 0.0 ? (ijk[2] + step[2]) : ijk[2]); |
| 188 | |
| 189 | tMax[0] = (rayDir[0] != 0.0) ? (next[0] - x0[0]) / rayDir[0] : VTK_FLOAT_MAX; |
| 190 | tMax[1] = (rayDir[1] != 0.0) ? (next[1] - x0[1]) / rayDir[1] : VTK_FLOAT_MAX; |
| 191 | tMax[2] = (rayDir[2] != 0.0) ? (next[2] - x0[2]) / rayDir[2] : VTK_FLOAT_MAX; |
| 192 |
nothing calls this directly
no test coverage detected