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

Method AppendArrayWithOffset

Common/DataModel/vtkCellArray.cxx:515–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

operator()Method · 0.95

Calls 9

assertFunction · 0.50
transformFunction · 0.50
GetNumberOfComponentsMethod · 0.45
GetNumberOfValuesMethod · 0.45
InsertMethod · 0.45
sizeMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected