------------------------------------------------------------------------------ Used internally by FindCell to walk through neighbors from a starting cell. The arguments are the same as those for FindCell. In addition, visitedCells keeps a list of cells already traversed. If we run into such already visited, the walk terminates since we assume we already walked from that cell and found nothing.
| 130 | // internally. They are passed in so that they do not have to be continuously |
| 131 | // reallocated. |
| 132 | vtkIdType FindCellWalk(vtkClosestPointStrategy* self, vtkPointSet* ps, double x[3], vtkCell* cell, |
| 133 | vtkGenericCell* gencell, vtkIdType cellId, double tol2, int& subId, double pcoords[3], |
| 134 | double* weights, std::vector<unsigned char>& visitedCells, vtkIdList* visitedCellIds, |
| 135 | vtkIdList* ptIds, vtkIdList* neighbors) |
| 136 | { |
| 137 | constexpr int VTK_MAX_WALK = 12; |
| 138 | double closestPoint[3]; |
| 139 | double dist2; |
| 140 | for (int walk = 0; walk < VTK_MAX_WALK; walk++) |
| 141 | { |
| 142 | // Check to see if we already visited this cell. |
| 143 | if (visitedCells[cellId]) |
| 144 | { |
| 145 | break; |
| 146 | } |
| 147 | visitedCells[cellId] = true; |
| 148 | visitedCellIds->InsertNextId(cellId); |
| 149 | |
| 150 | // Get information for the cell. |
| 151 | cell = self->SelectCell(ps, cellId, cell, gencell); |
| 152 | |
| 153 | // Check to see if the current, cached cell contains the point. |
| 154 | if ((cell->EvaluatePosition(x, closestPoint, subId, pcoords, dist2, weights) == 1) && |
| 155 | (dist2 <= tol2)) |
| 156 | { |
| 157 | return cellId; |
| 158 | } |
| 159 | |
| 160 | // This is not the right cell. Find the next one. |
| 161 | cell->CellBoundary(subId, pcoords, ptIds); |
| 162 | ps->GetCellNeighbors(cellId, ptIds, neighbors); |
| 163 | // If there is no next one, exit. |
| 164 | if (neighbors->GetNumberOfIds() < 1) |
| 165 | { |
| 166 | break; |
| 167 | } |
| 168 | // Set the next cell as the current one and iterate. |
| 169 | cellId = neighbors->GetId(0); |
| 170 | cell = nullptr; |
| 171 | } |
| 172 | |
| 173 | // Could not find a cell. |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | //------------------------------------------------------------------------------ |
| 178 | vtkIdType FindCellWalk(vtkClosestPointStrategy* self, vtkPointSet* ps, double x[3], |
no test coverage detected