------------------------------------------------------------------------------
| 396 | |
| 397 | //------------------------------------------------------------------------------ |
| 398 | vtkIdType vtkSelectPolyData::ComputeTopologicalDistance( |
| 399 | vtkPolyData* mesh, vtkIdList* edgePointIds, vtkIntArray* pointMarks, vtkIntArray* cellMarks) |
| 400 | { |
| 401 | vtkIdType numPts = mesh->GetNumberOfPoints(); |
| 402 | vtkIdType numCells = mesh->GetNumberOfCells(); |
| 403 | |
| 404 | // Next, prepare to mark off inside/outside and on boundary of loop. |
| 405 | // Mark the boundary of the loop using point marks. Also initialize |
| 406 | // the advancing front (used to mark traversal/compute scalars). |
| 407 | // Prepare to compute the advancing front |
| 408 | |
| 409 | // Mark all points and cells as unvisited |
| 410 | cellMarks->SetNumberOfValues(numCells); |
| 411 | const int unvisited = VTK_INT_MAX; |
| 412 | for (vtkIdType i = 0; i < numCells; i++) |
| 413 | { |
| 414 | cellMarks->SetValue(i, unvisited); |
| 415 | } |
| 416 | pointMarks->SetNumberOfValues(numPts); |
| 417 | for (vtkIdType i = 0; i < numPts; i++) |
| 418 | { |
| 419 | pointMarks->SetValue(i, unvisited); |
| 420 | } |
| 421 | |
| 422 | // Current and next front contain point IDs |
| 423 | vtkSmartPointer<vtkIdList> currentFront = vtkSmartPointer<vtkIdList>::New(); |
| 424 | vtkSmartPointer<vtkIdList> nextFront = vtkSmartPointer<vtkIdList>::New(); |
| 425 | vtkIdType numMeshLoopPts = edgePointIds->GetNumberOfIds(); |
| 426 | for (vtkIdType i = 0; i < numMeshLoopPts; i++) |
| 427 | { |
| 428 | vtkIdType id = edgePointIds->GetId(i); |
| 429 | pointMarks->SetValue(id, 0); // marks the start of the front |
| 430 | currentFront->InsertNextId(id); |
| 431 | } |
| 432 | |
| 433 | // Traverse the front as long as we can. We're basically computing a |
| 434 | // topological distance. |
| 435 | int maxFrontValue = 0; |
| 436 | vtkIdType maxFrontCell = (-1); |
| 437 | int currentFrontValue = 1; |
| 438 | vtkIdType numPtsInFront = 0; |
| 439 | while ((numPtsInFront = currentFront->GetNumberOfIds())) |
| 440 | { |
| 441 | // Process all triangles around the current front points |
| 442 | for (vtkIdType i = 0; i < numPtsInFront; i++) |
| 443 | { |
| 444 | vtkIdType id = currentFront->GetId(i); |
| 445 | vtkIdType* cells; |
| 446 | vtkIdType ncells; |
| 447 | mesh->GetPointCells(id, ncells, cells); |
| 448 | for (vtkIdType j = 0; j < ncells; j++) |
| 449 | { |
| 450 | id = cells[j]; |
| 451 | if (cellMarks->GetValue(id) != unvisited) |
| 452 | { |
| 453 | // the cell is already visited |
| 454 | continue; |
| 455 | } |
no test coverage detected