10 #ifndef vtk_m_cont_ArrayHandleConcatenate_h
11 #define vtk_m_cont_ArrayHandleConcatenate_h
22 template <
typename PortalType1,
typename PortalType2>
25 using WritableP1 = vtkm::internal::PortalSupportsSets<PortalType1>;
26 using WritableP2 = vtkm::internal::PortalSupportsSets<PortalType2>;
27 using Writable = std::integral_constant<bool, WritableP1::value && WritableP2::value>;
30 using ValueType =
typename PortalType1::ValueType;
34 ArrayPortalConcatenate()
42 ArrayPortalConcatenate(
const PortalType1& p1,
const PortalType2& p2)
50 template <
typename OtherP1,
typename OtherP2>
51 VTKM_EXEC_CONT ArrayPortalConcatenate(
const ArrayPortalConcatenate<OtherP1, OtherP2>& src)
52 : portal1(src.GetPortal1())
53 , portal2(src.GetPortal2())
60 return this->portal1.GetNumberOfValues() + this->portal2.GetNumberOfValues();
67 if (index < this->portal1.GetNumberOfValues())
69 return this->portal1.Get(index);
73 return this->portal2.Get(index - this->portal1.GetNumberOfValues());
78 template <
typename Writable_ = Writable,
79 typename =
typename std::enable_if<Writable_::value>::type>
82 if (index < this->portal1.GetNumberOfValues())
84 this->portal1.Set(index, value);
88 this->portal2.Set(index - this->portal1.GetNumberOfValues(), value);
93 const PortalType1& GetPortal1()
const {
return this->portal1; }
96 const PortalType2& GetPortal2()
const {
return this->portal2; }
111 template <
typename StorageTag1,
typename StorageTag2>
119 template <
typename T,
typename ST1,
typename ST2>
122 using SourceStorage1 = vtkm::cont::internal::Storage<T, ST1>;
123 using SourceStorage2 = vtkm::cont::internal::Storage<T, ST2>;
130 std::size_t NumBuffers1;
131 std::size_t NumBuffers2;
134 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> Buffers1(
135 const std::vector<vtkm::cont::internal::Buffer>& buffers)
137 Info info = buffers[0].GetMetaData<Info>();
138 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
139 buffers.begin() + 1 + info.NumBuffers1);
142 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> Buffers2(
143 const std::vector<vtkm::cont::internal::Buffer>& buffers)
145 Info info = buffers[0].GetMetaData<Info>();
146 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1 + info.NumBuffers1,
153 using ReadPortalType =
154 vtkm::internal::ArrayPortalConcatenate<
typename SourceStorage1::ReadPortalType,
155 typename SourceStorage2::ReadPortalType>;
156 using WritePortalType =
157 vtkm::internal::ArrayPortalConcatenate<
typename SourceStorage1::WritePortalType,
158 typename SourceStorage2::WritePortalType>;
161 const std::vector<vtkm::cont::internal::Buffer>& buffers)
163 vtkm::IdComponent components1 = SourceStorage1::GetNumberOfComponentsFlat(Buffers1(buffers));
164 vtkm::IdComponent components2 = SourceStorage2::GetNumberOfComponentsFlat(Buffers2(buffers));
165 if (components1 == components2)
177 const std::vector<vtkm::cont::internal::Buffer>& buffers)
179 return (SourceStorage1::GetNumberOfValues(Buffers1(buffers)) +
180 SourceStorage2::GetNumberOfValues(Buffers2(buffers)));
183 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
189 vtkm::Id size1 = SourceStorage1::GetNumberOfValues(Buffers1(buffers));
190 if ((startIndex < size1) && (endIndex <= size1))
192 SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, endIndex, token);
194 else if (startIndex < size1)
196 SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, size1, token);
197 SourceStorage2::Fill(Buffers2(buffers), fillValue, 0, endIndex - size1, token);
201 SourceStorage2::Fill(
202 Buffers2(buffers), fillValue, startIndex - size1, endIndex - size1, token);
206 VTKM_CONT static ReadPortalType CreateReadPortal(
207 const std::vector<vtkm::cont::internal::Buffer>& buffers,
211 return ReadPortalType(SourceStorage1::CreateReadPortal(Buffers1(buffers), device, token),
212 SourceStorage2::CreateReadPortal(Buffers2(buffers), device, token));
215 VTKM_CONT static WritePortalType CreateWritePortal(
216 const std::vector<vtkm::cont::internal::Buffer>& buffers,
220 return WritePortalType(SourceStorage1::CreateWritePortal(Buffers1(buffers), device, token),
221 SourceStorage2::CreateWritePortal(Buffers2(buffers), device, token));
224 VTKM_CONT static auto CreateBuffers(
const ArrayHandleType1& array1 = ArrayHandleType1{},
225 const ArrayHandleType2& array2 = ArrayHandleType2{})
226 -> decltype(vtkm::cont::internal::CreateBuffers())
229 info.NumBuffers1 = array1.GetBuffers().size();
230 info.NumBuffers2 = array2.GetBuffers().size();
231 return vtkm::cont::internal::CreateBuffers(info, array1, array2);
234 VTKM_CONT static const ArrayHandleType1 GetArray1(
235 const std::vector<vtkm::cont::internal::Buffer>& buffers)
237 return ArrayHandleType1(Buffers1(buffers));
240 VTKM_CONT static const ArrayHandleType2 GetArray2(
241 const std::vector<vtkm::cont::internal::Buffer>& buffers)
243 return ArrayHandleType2(Buffers2(buffers));
256 template <
typename ArrayHandleType1,
typename ArrayHandleType2>
259 StorageTagConcatenate<typename ArrayHandleType1::StorageTag,
260 typename ArrayHandleType2::StorageTag>>
268 typename ArrayHandleType2::StorageTag>>));
277 template <
typename ArrayHandleType1,
typename ArrayHandleType2>
279 const ArrayHandleType1& array1,
280 const ArrayHandleType2& array2)
295 template <
typename AH1,
typename AH2>
296 struct SerializableTypeString<
vtkm::cont::ArrayHandleConcatenate<AH1, AH2>>
306 template <
typename T,
typename ST1,
typename ST2>
307 struct SerializableTypeString<
308 vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConcatenate<ST1, ST2>>>
309 : SerializableTypeString<vtkm::cont::ArrayHandleConcatenate<vtkm::cont::ArrayHandle<T, ST1>,
310 vtkm::cont::ArrayHandle<T, ST2>>>
319 template <
typename AH1,
typename AH2>
320 struct Serialization<
vtkm::cont::ArrayHandleConcatenate<AH1, AH2>>
327 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
329 auto storage = obj.GetStorage();
330 vtkmdiy::save(bb, storage.GetArray1());
331 vtkmdiy::save(bb, storage.GetArray2());
346 template <
typename T,
typename ST1,
typename ST2>
347 struct Serialization<
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConcatenate<ST1, ST2>>>
348 : Serialization<vtkm::cont::ArrayHandleConcatenate<vtkm::cont::ArrayHandle<T, ST1>,
349 vtkm::cont::ArrayHandle<T, ST2>>>
356 #endif //vtk_m_cont_ArrayHandleConcatenate_h