------------------------------------------------------------------------------
| 509 | |
| 510 | //------------------------------------------------------------------------------ |
| 511 | void vtkStructuredGrid::Crop(const int* updateExtent) |
| 512 | { |
| 513 | // Do nothing for empty datasets: |
| 514 | for (int dim = 0; dim < 3; ++dim) |
| 515 | { |
| 516 | if (this->Extent[2 * dim] > this->Extent[2 * dim + 1]) |
| 517 | { |
| 518 | vtkDebugMacro(<< "Refusing to crop empty dataset."); |
| 519 | return; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | int i, j, k; |
| 524 | int uExt[6]; |
| 525 | const int* extent = this->Extent; |
| 526 | |
| 527 | // If the update extent is larger than the extent, |
| 528 | // we cannot do anything about it here. |
| 529 | for (i = 0; i < 3; ++i) |
| 530 | { |
| 531 | uExt[i * 2] = updateExtent[i * 2]; |
| 532 | uExt[i * 2] = std::max(uExt[i * 2], extent[i * 2]); |
| 533 | uExt[i * 2 + 1] = updateExtent[i * 2 + 1]; |
| 534 | uExt[i * 2 + 1] = std::min(uExt[i * 2 + 1], extent[i * 2 + 1]); |
| 535 | } |
| 536 | |
| 537 | // If extents already match, then we need to do nothing. |
| 538 | if (extent[0] == uExt[0] && extent[1] == uExt[1] && extent[2] == uExt[2] && |
| 539 | extent[3] == uExt[3] && extent[4] == uExt[4] && extent[5] == uExt[5]) |
| 540 | { |
| 541 | return; |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | // Get the points. Protect against empty data objects. |
| 546 | vtkPoints* inPts = this->GetPoints(); |
| 547 | if (inPts == nullptr) |
| 548 | { |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | vtkDebugMacro(<< "Cropping Grid"); |
| 553 | |
| 554 | vtkStructuredGrid* newGrid = vtkStructuredGrid::New(); |
| 555 | vtkPointData* inPD = this->GetPointData(); |
| 556 | vtkCellData* inCD = this->GetCellData(); |
| 557 | vtkPointData* outPD = newGrid->GetPointData(); |
| 558 | vtkCellData* outCD = newGrid->GetCellData(); |
| 559 | |
| 560 | // Allocate necessary objects |
| 561 | // |
| 562 | newGrid->SetExtent(uExt); |
| 563 | int outSize = (uExt[1] - uExt[0] + 1) * (uExt[3] - uExt[2] + 1) * (uExt[5] - uExt[4] + 1); |
| 564 | vtkPoints* newPts = inPts->NewInstance(); |
| 565 | newPts->SetDataType(inPts->GetDataType()); |
| 566 | newPts->SetNumberOfPoints(outSize); |
| 567 | outPD->CopyAllocate(inPD, outSize, outSize); |
| 568 | outCD->CopyAllocate(inCD, outSize, outSize); |
nothing calls this directly
no test coverage detected