| 387 | // \post clamped_pcoords: result implies (0<=pcoords[0]<=1 && ) |
| 388 | |
| 389 | int vtkBridgeDataSet::FindCell( |
| 390 | double x[3], vtkGenericCellIterator*& cell, double tol2, int& subId, double pcoords[3]) |
| 391 | { |
| 392 | assert("pre: not_empty" && GetNumberOfCells() > 0); |
| 393 | assert("pre: cell_exists" && cell != nullptr); |
| 394 | assert("pre: positive_tolerance" && tol2 > 0); |
| 395 | |
| 396 | vtkIdType cellid; |
| 397 | vtkBridgeCellIterator* it = static_cast<vtkBridgeCellIterator*>(cell); |
| 398 | |
| 399 | double* ignoredWeights = new double[this->Implementation->GetMaxCellSize()]; |
| 400 | |
| 401 | cellid = this->Implementation->FindCell(x, nullptr, 0, tol2, subId, pcoords, ignoredWeights); |
| 402 | |
| 403 | delete[] ignoredWeights; |
| 404 | if (cellid >= 0) |
| 405 | { |
| 406 | it->InitWithOneCell(this, cellid); // at end |
| 407 | it->Begin(); |
| 408 | // clamp: |
| 409 | int i = 0; |
| 410 | while (i < 3) |
| 411 | { |
| 412 | if (pcoords[i] < 0) |
| 413 | { |
| 414 | pcoords[i] = 0; |
| 415 | } |
| 416 | else if (pcoords[i] > 1) |
| 417 | { |
| 418 | pcoords[i] = 1; |
| 419 | } |
| 420 | ++i; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // A=>B: !A || B |
| 425 | // result => clamped pcoords |
| 426 | assert("post: clamped_pcoords" && |
| 427 | ((cellid < 0) || |
| 428 | (pcoords[0] >= 0 && pcoords[0] <= 1 && pcoords[1] >= 0 && pcoords[1] <= 1 && |
| 429 | pcoords[2] >= 0 && pcoords[2] <= 1))); |
| 430 | |
| 431 | return cellid >= 0; // bool |
| 432 | } |
| 433 | |
| 434 | //------------------------------------------------------------------------------ |
| 435 | // Description: |