| 3397 | */ |
| 3398 | template <class GridDataSetT> |
| 3399 | void CloneGrid(GridDataSetT* grid, GridDataSetT* clone, const ExtentType& extent) |
| 3400 | { |
| 3401 | ::CloneDataObject(grid, clone); |
| 3402 | |
| 3403 | vtkCellData* cloneCellData = clone->GetCellData(); |
| 3404 | vtkCellData* gridCellData = grid->GetCellData(); |
| 3405 | cloneCellData->CopyAllOn(); |
| 3406 | cloneCellData->CopyAllocate(gridCellData, clone->GetNumberOfCells()); |
| 3407 | cloneCellData->SetNumberOfTuples(clone->GetNumberOfCells()); |
| 3408 | |
| 3409 | const int* cloneExtent = clone->GetExtent(); |
| 3410 | const int* gridExtent = grid->GetExtent(); |
| 3411 | |
| 3412 | // We use `std::max` here to work for grids of dimension 2 and 1. |
| 3413 | // This gives "thickness" to the degenerate dimension |
| 3414 | int imin = extent[0]; |
| 3415 | int imax = std::max(extent[1], extent[0] + 1); |
| 3416 | int jmin = extent[2]; |
| 3417 | int jmax = std::max(extent[3], extent[2] + 1); |
| 3418 | int kmin = extent[4]; |
| 3419 | int kmax = std::max(extent[5], extent[4] + 1); |
| 3420 | |
| 3421 | int ijk[3]; |
| 3422 | |
| 3423 | if (cloneCellData->GetNumberOfTuples()) |
| 3424 | { |
| 3425 | for (ijk[2] = kmin; ijk[2] < kmax; ++ijk[2]) |
| 3426 | { |
| 3427 | for (ijk[1] = jmin; ijk[1] < jmax; ++ijk[1]) |
| 3428 | { |
| 3429 | for (ijk[0] = imin; ijk[0] < imax; ++ijk[0]) |
| 3430 | { |
| 3431 | cloneCellData->SetTuple(vtkStructuredData::ComputeCellIdForExtent(cloneExtent, ijk), |
| 3432 | vtkStructuredData::ComputeCellIdForExtent(gridExtent, ijk), gridCellData); |
| 3433 | } |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | // We need to reset the newly allocated ghost cells to 0 if there was a ghost array in the input |
| 3439 | if (vtkUnsignedCharArray* ghostCells = cloneCellData->GetGhostArray()) |
| 3440 | { |
| 3441 | auto ghostRange = vtk::DataArrayValueRange<1>(ghostCells); |
| 3442 | for (ijk[2] = cloneExtent[4]; ijk[2] < cloneExtent[5]; ++ijk[2]) |
| 3443 | { |
| 3444 | for (ijk[1] = cloneExtent[2]; ijk[1] < cloneExtent[3]; ++ijk[1]) |
| 3445 | { |
| 3446 | for (ijk[0] = cloneExtent[0]; ijk[0] < cloneExtent[1]; ++ijk[0]) |
| 3447 | { |
| 3448 | if (ijk[0] < imin || ijk[0] >= imax || ijk[1] < jmin || ijk[1] >= jmax || ijk[2] < kmin || |
| 3449 | ijk[2] >= kmax) |
| 3450 | { |
| 3451 | ghostRange[vtkStructuredData::ComputeCellIdForExtent(cloneExtent, ijk)] = 0; |
| 3452 | } |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | } |
no test coverage detected