MCPcopy Create free account
hub / github.com/Kitware/VTK / CloneGrid

Function CloneGrid

Parallel/DIY/vtkDIYGhostUtilities.cxx:3399–3502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3397 */
3398template <class GridDataSetT>
3399void 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 }

Calls 13

CloneDataObjectFunction · 0.85
maxFunction · 0.50
GetCellDataMethod · 0.45
CopyAllOnMethod · 0.45
CopyAllocateMethod · 0.45
GetNumberOfCellsMethod · 0.45
SetNumberOfTuplesMethod · 0.45
GetExtentMethod · 0.45
GetNumberOfTuplesMethod · 0.45
SetTupleMethod · 0.45
GetGhostArrayMethod · 0.45
GetPointDataMethod · 0.45

Tested by

no test coverage detected