10 #ifndef vtk_m_cont_ArrayHandleGroupVecVariable_h
11 #define vtk_m_cont_ArrayHandleGroupVecVariable_h
26 template <
typename ComponentsPortalType,
typename OffsetsPortalType>
30 using ComponentType =
typename std::remove_const<typename ComponentsPortalType::ValueType>::type;
35 ArrayPortalGroupVecVariable()
43 ArrayPortalGroupVecVariable(
const ComponentsPortalType& componentsPortal,
44 const OffsetsPortalType& offsetsPortal)
45 : ComponentsPortal(componentsPortal)
46 , OffsetsPortal(offsetsPortal)
54 template <
typename OtherComponentsPortalType,
typename OtherOffsetsPortalType>
56 const ArrayPortalGroupVecVariable<OtherComponentsPortalType, OtherOffsetsPortalType>& src)
57 : ComponentsPortal(src.GetComponentsPortal())
58 , OffsetsPortal(src.GetOffsetsPortal())
64 vtkm::Id GetNumberOfValues()
const {
return this->OffsetsPortal.GetNumberOfValues() - 1; }
70 vtkm::Id offsetIndex = this->OffsetsPortal.Get(index);
71 vtkm::Id nextOffsetIndex = this->OffsetsPortal.Get(index + 1);
73 return ValueType(this->ComponentsPortal,
90 const ComponentsPortalType& GetComponentsPortal()
const {
return this->ComponentsPortal; }
94 const OffsetsPortalType& GetOffsetsPortal()
const {
return this->OffsetsPortal; }
97 ComponentsPortalType ComponentsPortal;
98 OffsetsPortalType OffsetsPortal;
109 template <
typename ComponentsStorageTag,
typename OffsetsStorageTag>
117 template <
typename ComponentsPortal,
typename ComponentsStorageTag,
typename OffsetsStorageTag>
121 using ComponentType =
typename ComponentsPortal::ValueType;
122 using ComponentsStorage = vtkm::cont::internal::Storage<ComponentType, ComponentsStorageTag>;
123 using OffsetsStorage = vtkm::cont::internal::Storage<vtkm::Id, OffsetsStorageTag>;
129 (std::is_same<ComponentsPortal, typename ComponentsStorage::WritePortalType>::value),
130 "Used invalid ComponentsPortal type with expected ComponentsStorageTag.");
134 std::size_t OffsetsBuffersOffset;
137 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> ComponentsBuffers(
138 const std::vector<vtkm::cont::internal::Buffer>& buffers)
140 Info info = buffers[0].GetMetaData<Info>();
141 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
142 buffers.begin() + info.OffsetsBuffersOffset);
145 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> OffsetsBuffers(
146 const std::vector<vtkm::cont::internal::Buffer> buffers)
148 Info info = buffers[0].GetMetaData<Info>();
149 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + info.OffsetsBuffersOffset,
156 using ReadPortalType =
157 vtkm::internal::ArrayPortalGroupVecVariable<
typename ComponentsStorage::ReadPortalType,
158 typename OffsetsStorage::ReadPortalType>;
159 using WritePortalType =
160 vtkm::internal::ArrayPortalGroupVecVariable<
typename ComponentsStorage::WritePortalType,
161 typename OffsetsStorage::ReadPortalType>;
164 const std::vector<vtkm::cont::internal::Buffer>& buffers)
166 return OffsetsStorage::GetNumberOfValues(OffsetsBuffers(buffers)) - 1;
169 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
178 VTKM_CONT static ReadPortalType CreateReadPortal(
179 const std::vector<vtkm::cont::internal::Buffer>& buffers,
183 return ReadPortalType(
184 ComponentsStorage::CreateReadPortal(ComponentsBuffers(buffers), device, token),
185 OffsetsStorage::CreateReadPortal(OffsetsBuffers(buffers), device, token));
188 VTKM_CONT static WritePortalType CreateWritePortal(
189 const std::vector<vtkm::cont::internal::Buffer>& buffers,
193 return WritePortalType(
194 ComponentsStorage::CreateWritePortal(ComponentsBuffers(buffers), device, token),
195 OffsetsStorage::CreateReadPortal(OffsetsBuffers(buffers), device, token));
198 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
199 const ComponentsArray& componentsArray = ComponentsArray{},
200 const OffsetsArray& offsetsArray = OffsetsArray{})
203 info.OffsetsBuffersOffset = 1 + componentsArray.GetBuffers().size();
204 return vtkm::cont::internal::CreateBuffers(info, componentsArray, offsetsArray);
207 VTKM_CONT static ComponentsArray GetComponentsArray(
208 const std::vector<vtkm::cont::internal::Buffer>& buffers)
210 return ComponentsArray(ComponentsBuffers(buffers));
213 VTKM_CONT static OffsetsArray GetOffsetsArray(
214 const std::vector<vtkm::cont::internal::Buffer>& buffers)
216 return OffsetsArray(OffsetsBuffers(buffers));
254 template <
typename ComponentsArrayHandleType,
typename OffsetsArrayHandleType>
257 vtkm::VecFromPortal<typename ComponentsArrayHandleType::WritePortalType>,
258 vtkm::cont::StorageTagGroupVecVariable<typename ComponentsArrayHandleType::StorageTag,
259 typename OffsetsArrayHandleType::StorageTag>>
265 (std::is_same<vtkm::Id, typename OffsetsArrayHandleType::ValueType>::value),
266 "ArrayHandleGroupVecVariable's offsets array must contain vtkm::Id values.");
275 typename OffsetsArrayHandleType::StorageTag>>));
280 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
285 const OffsetsArrayHandleType& offsetsArray)
286 : Superclass(
StorageType::CreateBuffers(componentsArray, offsetsArray))
292 return StorageType::GetComponentsArray(this->
GetBuffers());
297 return StorageType::GetOffsetsArray(this->
GetBuffers());
306 template <
typename ComponentsArrayHandleType,
typename OffsetsArrayHandleType>
309 const OffsetsArrayHandleType& offsetsArray)
312 componentsArray, offsetsArray);
329 template <
typename SAH,
typename OAH>
330 struct SerializableTypeString<
vtkm::cont::ArrayHandleGroupVecVariable<SAH, OAH>>
340 template <
typename SP,
typename SST,
typename OST>
341 struct SerializableTypeString<
342 vtkm::cont::ArrayHandle<vtkm::VecFromPortal<SP>,
343 vtkm::cont::StorageTagGroupVecVariable<SST, OST>>>
344 : SerializableTypeString<
345 vtkm::cont::ArrayHandleGroupVecVariable<vtkm::cont::ArrayHandle<typename SP::ValueType, SST>,
346 vtkm::cont::ArrayHandle<vtkm::Id, OST>>>
355 template <
typename SAH,
typename OAH>
356 struct Serialization<
vtkm::cont::ArrayHandleGroupVecVariable<SAH, OAH>>
363 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
365 vtkmdiy::save(bb, Type(obj).GetComponentsArray());
366 vtkmdiy::save(bb, Type(obj).GetOffsetsArray());
381 template <
typename SP,
typename SST,
typename OST>
382 struct Serialization<
vtkm::cont::ArrayHandle<vtkm::VecFromPortal<SP>,
383 vtkm::cont::StorageTagGroupVecVariable<SST, OST>>>
385 vtkm::cont::ArrayHandleGroupVecVariable<vtkm::cont::ArrayHandle<typename SP::ValueType, SST>,
386 vtkm::cont::ArrayHandle<vtkm::Id, OST>>>
392 #endif //vtk_m_cont_ArrayHandleGroupVecVariable_h