| 513 | // offset added to each value. |
| 514 | template <typename SrcArrayT, typename DstArrayT> |
| 515 | void AppendArrayWithOffset( |
| 516 | SrcArrayT* srcArray, DstArrayT* dstArray, vtkIdType offset, bool skipFirst) const |
| 517 | { |
| 518 | VTK_ASSUME(srcArray->GetNumberOfComponents() == 1); |
| 519 | VTK_ASSUME(dstArray->GetNumberOfComponents() == 1); |
| 520 | |
| 521 | using SrcValueType = vtk::GetAPIType<SrcArrayT>; |
| 522 | using DstValueType = vtk::GetAPIType<DstArrayT>; |
| 523 | |
| 524 | const vtkIdType srcSize = |
| 525 | skipFirst ? srcArray->GetNumberOfValues() - 1 : srcArray->GetNumberOfValues(); |
| 526 | const vtkIdType dstBegin = dstArray->GetNumberOfValues(); |
| 527 | const vtkIdType dstEnd = dstBegin + srcSize; |
| 528 | |
| 529 | // This extends the allocation of dst to ensure we have enough space |
| 530 | // allocated: |
| 531 | { |
| 532 | vtkDataArrayAccessor<DstArrayT> dstAccessor(dstArray); |
| 533 | dstAccessor.Insert(dstEnd - 1, static_cast<DstValueType>(0)); |
| 534 | } |
| 535 | |
| 536 | const auto srcRange = vtk::DataArrayValueRange<1, vtkIdType>(srcArray, skipFirst ? 1 : 0); |
| 537 | auto dstRange = vtk::DataArrayValueRange<1, vtkIdType>(dstArray, dstBegin, dstEnd); |
| 538 | assert(srcRange.size() == dstRange.size()); |
| 539 | |
| 540 | const DstValueType dOffset = static_cast<DstValueType>(offset); |
| 541 | |
| 542 | std::transform(srcRange.cbegin(), srcRange.cend(), dstRange.begin(), |
| 543 | [&](SrcValueType x) -> DstValueType { return static_cast<DstValueType>(x) + dOffset; }); |
| 544 | } |
| 545 | }; |
| 546 | |
| 547 | } // end anon namespace |
no test coverage detected