10 #ifndef vtk_m_cont_ArrayHandleZip_h
11 #define vtk_m_cont_ArrayHandleZip_h
26 template <
typename PortalTypeFirst,
typename PortalTypeSecond>
29 using ReadableP1 = vtkm::internal::PortalSupportsGets<PortalTypeFirst>;
30 using ReadableP2 = vtkm::internal::PortalSupportsGets<PortalTypeSecond>;
31 using WritableP1 = vtkm::internal::PortalSupportsSets<PortalTypeFirst>;
32 using WritableP2 = vtkm::internal::PortalSupportsSets<PortalTypeSecond>;
34 using Readable = std::integral_constant<bool, ReadableP1::value && ReadableP2::value>;
35 using Writable = std::integral_constant<bool, WritableP1::value && WritableP2::value>;
38 using T =
typename PortalTypeFirst::ValueType;
39 using U =
typename PortalTypeSecond::ValueType;
51 ArrayPortalZip(
const PortalTypeFirst& portalfirst,
const PortalTypeSecond& portalsecond)
52 : PortalFirst(portalfirst)
53 , PortalSecond(portalsecond)
61 template <
class OtherF,
class OtherS>
62 VTKM_CONT ArrayPortalZip(
const ArrayPortalZip<OtherF, OtherS>& src)
63 : PortalFirst(src.GetFirstPortal())
64 , PortalSecond(src.GetSecondPortal())
70 vtkm::Id GetNumberOfValues()
const {
return this->PortalFirst.GetNumberOfValues(); }
73 template <
typename Readable_ = Readable,
74 typename =
typename std::enable_if<Readable_::value>::type>
77 return vtkm::make_Pair(this->PortalFirst.Get(index), this->PortalSecond.Get(index));
81 template <
typename Writable_ = Writable,
82 typename =
typename std::enable_if<Writable_::value>::type>
85 this->PortalFirst.Set(index, value.first);
86 this->PortalSecond.Set(index, value.second);
90 const PortalTypeFirst& GetFirstPortal()
const {
return this->PortalFirst; }
93 const PortalTypeSecond& GetSecondPortal()
const {
return this->PortalSecond; }
96 PortalTypeFirst PortalFirst;
97 PortalTypeSecond PortalSecond;
108 template <
typename ST1,
typename ST2>
119 template <
typename FirstHandleType,
typename SecondHandleType>
120 struct ArrayHandleZipTraits
134 using Storage = vtkm::cont::internal::Storage<ValueType, Tag>;
141 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
144 using FirstStorage = Storage<T1, ST1>;
145 using SecondStorage = Storage<T2, ST2>;
153 std::size_t SecondBuffersOffset;
156 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> FirstArrayBuffers(
157 const std::vector<vtkm::cont::internal::Buffer>& buffers)
159 const Info& info = buffers[0].GetMetaData<Info>();
160 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
161 buffers.begin() + info.SecondBuffersOffset);
163 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> SecondArrayBuffers(
164 const std::vector<vtkm::cont::internal::Buffer>& buffers)
166 const Info& info = buffers[0].GetMetaData<
Info>();
167 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + info.SecondBuffersOffset,
172 using ReadPortalType =
173 vtkm::exec::internal::ArrayPortalZip<
typename FirstStorage::ReadPortalType,
174 typename SecondStorage::ReadPortalType>;
175 using WritePortalType =
176 vtkm::exec::internal::ArrayPortalZip<
typename FirstStorage::WritePortalType,
177 typename SecondStorage::WritePortalType>;
179 static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
180 const FirstArrayType& firstArray = FirstArrayType{},
181 const SecondArrayType& secondArray = SecondArrayType{})
184 info.SecondBuffersOffset = 1 + firstArray.GetBuffers().size();
185 return vtkm::cont::internal::CreateBuffers(info, firstArray, secondArray);
189 const std::vector<vtkm::cont::internal::Buffer>& buffers,
193 FirstStorage::ResizeBuffers(numValues, FirstArrayBuffers(buffers), preserve, token);
194 SecondStorage::ResizeBuffers(numValues, SecondArrayBuffers(buffers), preserve, token);
198 const std::vector<vtkm::cont::internal::Buffer>& buffers)
200 vtkm::Id numValues = FirstStorage::GetNumberOfValues(FirstArrayBuffers(buffers));
201 VTKM_ASSERT(numValues == SecondStorage::GetNumberOfValues(SecondArrayBuffers(buffers)));
205 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
206 const ValueType& fillValue,
211 FirstStorage::Fill(FirstArrayBuffers(buffers), fillValue.first, startIndex, endIndex, token);
212 SecondStorage::Fill(SecondArrayBuffers(buffers), fillValue.second, startIndex, endIndex, token);
215 VTKM_CONT static ReadPortalType CreateReadPortal(
216 const std::vector<vtkm::cont::internal::Buffer>& buffers,
220 return ReadPortalType(
221 FirstStorage::CreateReadPortal(FirstArrayBuffers(buffers), device, token),
222 SecondStorage::CreateReadPortal(SecondArrayBuffers(buffers), device, token));
225 VTKM_CONT static WritePortalType CreateWritePortal(
226 const std::vector<vtkm::cont::internal::Buffer>& buffers,
230 return WritePortalType(
231 FirstStorage::CreateWritePortal(FirstArrayBuffers(buffers), device, token),
232 SecondStorage::CreateWritePortal(SecondArrayBuffers(buffers), device, token));
235 static FirstArrayType GetFirstArray(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
237 return { FirstArrayBuffers(buffers) };
239 static SecondArrayType GetSecondArray(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
241 return { SecondArrayBuffers(buffers) };
250 template <
typename FirstHandleType,
typename SecondHandleType>
252 :
public internal::ArrayHandleZipTraits<FirstHandleType, SecondHandleType>::Superclass
263 typename internal::ArrayHandleZipTraits<FirstHandleType, SecondHandleType>::Storage;
272 ArrayHandleZip(
const FirstHandleType& firstArray,
const SecondHandleType& secondArray)
273 : Superclass(
StorageType::CreateBuffers(firstArray, secondArray))
280 return StorageType::GetSecondArray(this->
GetBuffers());
287 template <
typename FirstHandleType,
typename SecondHandleType>
289 const FirstHandleType& first,
290 const SecondHandleType& second)
305 template <
typename AH1,
typename AH2>
306 struct SerializableTypeString<
vtkm::cont::ArrayHandleZip<AH1, AH2>>
316 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
317 struct SerializableTypeString<
318 vtkm::cont::ArrayHandle<vtkm::Pair<T1, T2>, vtkm::cont::StorageTagZip<ST1, ST2>>>
319 : SerializableTypeString<vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<T1, ST1>,
320 vtkm::cont::ArrayHandle<T2, ST2>>>
329 template <
typename AH1,
typename AH2>
330 struct Serialization<
vtkm::cont::ArrayHandleZip<AH1, AH2>>
337 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
339 auto storage = obj.GetStorage();
340 vtkmdiy::save(bb, storage.GetFirstArray());
341 vtkmdiy::save(bb, storage.GetSecondArray());
356 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
357 struct Serialization<
358 vtkm::cont::ArrayHandle<vtkm::Pair<T1, T2>, vtkm::cont::StorageTagZip<ST1, ST2>>>
359 : Serialization<vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<T1, ST1>,
360 vtkm::cont::ArrayHandle<T2, ST2>>>
367 #endif //vtk_m_cont_ArrayHandleZip_h