| 74 | } |
| 75 | |
| 76 | vtkSmartPointer<vtkAbstractArray> JoinArrays( |
| 77 | const std::vector<vtkSmartPointer<vtkAbstractArray>>& arrays) |
| 78 | { |
| 79 | if (arrays.empty()) |
| 80 | { |
| 81 | return nullptr; |
| 82 | } |
| 83 | else if (arrays.size() == 1) |
| 84 | { |
| 85 | return arrays[0]; |
| 86 | } |
| 87 | |
| 88 | vtkIdType numTuples = 0; |
| 89 | for (auto& array : arrays) |
| 90 | { |
| 91 | numTuples += array->GetNumberOfTuples(); |
| 92 | } |
| 93 | |
| 94 | vtkSmartPointer<vtkAbstractArray> result; |
| 95 | result.TakeReference(arrays[0]->NewInstance()); |
| 96 | result->CopyInformation(arrays[0]->GetInformation()); |
| 97 | result->SetName(arrays[0]->GetName()); |
| 98 | result->SetNumberOfComponents(arrays[0]->GetNumberOfComponents()); |
| 99 | result->SetNumberOfTuples(numTuples); |
| 100 | vtkIdType offset = 0; |
| 101 | for (auto& array : arrays) |
| 102 | { |
| 103 | const auto count = array->GetNumberOfTuples(); |
| 104 | result->InsertTuples(offset, count, 0, array); |
| 105 | offset += count; |
| 106 | } |
| 107 | result->Modified(); |
| 108 | assert(offset == numTuples); |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | } // end of namespace {} |
| 113 | VTK_ABI_NAMESPACE_END |
no test coverage detected