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,
80 void Set(
vtkm::Id index,
const ValueType& value)
const
82 if ((&value.GetPortal() == &this->ComponentsPortal) &&
83 (value.GetOffset() == this->OffsetsPortal.Get(index)))
91 this->
Get(index) = value;
97 const ComponentsPortalType& GetComponentsPortal()
const {
return this->ComponentsPortal; }
101 const OffsetsPortalType& GetOffsetsPortal()
const {
return this->OffsetsPortal; }
104 ComponentsPortalType ComponentsPortal;
105 OffsetsPortalType OffsetsPortal;
116 template <
typename ComponentsStorageTag,
typename OffsetsStorageTag>
124 template <
typename ComponentsPortal,
typename ComponentsStorageTag,
typename OffsetsStorageTag>
128 using ComponentType =
typename ComponentsPortal::ValueType;
129 using ComponentsStorage = vtkm::cont::internal::Storage<ComponentType, ComponentsStorageTag>;
130 using OffsetsStorage = vtkm::cont::internal::Storage<vtkm::Id, OffsetsStorageTag>;
136 (std::is_same<ComponentsPortal, typename ComponentsStorage::WritePortalType>::value),
137 "Used invalid ComponentsPortal type with expected ComponentsStorageTag.");
141 std::size_t OffsetsBuffersOffset;
144 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> ComponentsBuffers(
145 const std::vector<vtkm::cont::internal::Buffer>& buffers)
147 Info info = buffers[0].GetMetaData<Info>();
148 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
149 buffers.begin() + info.OffsetsBuffersOffset);
152 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> OffsetsBuffers(
153 const std::vector<vtkm::cont::internal::Buffer> buffers)
155 Info info = buffers[0].GetMetaData<Info>();
156 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + info.OffsetsBuffersOffset,
163 using ReadPortalType =
164 vtkm::internal::ArrayPortalGroupVecVariable<
typename ComponentsStorage::ReadPortalType,
165 typename OffsetsStorage::ReadPortalType>;
166 using WritePortalType =
167 vtkm::internal::ArrayPortalGroupVecVariable<
typename ComponentsStorage::WritePortalType,
168 typename OffsetsStorage::ReadPortalType>;
171 const std::vector<vtkm::cont::internal::Buffer>&)
178 const std::vector<vtkm::cont::internal::Buffer>& buffers)
180 return OffsetsStorage::GetNumberOfValues(OffsetsBuffers(buffers)) - 1;
183 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
192 VTKM_CONT static ReadPortalType CreateReadPortal(
193 const std::vector<vtkm::cont::internal::Buffer>& buffers,
197 return ReadPortalType(
198 ComponentsStorage::CreateReadPortal(ComponentsBuffers(buffers), device, token),
199 OffsetsStorage::CreateReadPortal(OffsetsBuffers(buffers), device, token));
202 VTKM_CONT static WritePortalType CreateWritePortal(
203 const std::vector<vtkm::cont::internal::Buffer>& buffers,
207 return WritePortalType(
208 ComponentsStorage::CreateWritePortal(ComponentsBuffers(buffers), device, token),
209 OffsetsStorage::CreateReadPortal(OffsetsBuffers(buffers), device, token));
212 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
213 const ComponentsArray& componentsArray = ComponentsArray{},
214 const OffsetsArray& offsetsArray = OffsetsArray{})
217 info.OffsetsBuffersOffset = 1 + componentsArray.GetBuffers().size();
218 return vtkm::cont::internal::CreateBuffers(info, componentsArray, offsetsArray);
221 VTKM_CONT static ComponentsArray GetComponentsArray(
222 const std::vector<vtkm::cont::internal::Buffer>& buffers)
224 return ComponentsArray(ComponentsBuffers(buffers));
227 VTKM_CONT static OffsetsArray GetOffsetsArray(
228 const std::vector<vtkm::cont::internal::Buffer>& buffers)
230 return OffsetsArray(OffsetsBuffers(buffers));
270 template <
typename ComponentsArrayHandleType,
typename OffsetsArrayHandleType>
273 vtkm::VecFromPortal<typename ComponentsArrayHandleType::WritePortalType>,
274 vtkm::cont::StorageTagGroupVecVariable<typename ComponentsArrayHandleType::StorageTag,
275 typename OffsetsArrayHandleType::StorageTag>>
281 (std::is_same<vtkm::Id, typename OffsetsArrayHandleType::ValueType>::value),
282 "ArrayHandleGroupVecVariable's offsets array must contain vtkm::Id values.");
291 typename OffsetsArrayHandleType::StorageTag>>));
298 const OffsetsArrayHandleType& offsetsArray)
306 return StorageType::GetComponentsArray(this->
GetBuffers());
312 return StorageType::GetOffsetsArray(this->
GetBuffers());
321 template <
typename ComponentsArrayHandleType,
typename OffsetsArrayHandleType>
324 const OffsetsArrayHandleType& offsetsArray)
327 componentsArray, offsetsArray);
340 template <
typename SAH,
typename OAH>
341 struct SerializableTypeString<
vtkm::cont::ArrayHandleGroupVecVariable<SAH, OAH>>
351 template <
typename SP,
typename SST,
typename OST>
352 struct SerializableTypeString<
353 vtkm::cont::ArrayHandle<vtkm::VecFromPortal<SP>,
354 vtkm::cont::StorageTagGroupVecVariable<SST, OST>>>
355 : SerializableTypeString<
356 vtkm::cont::ArrayHandleGroupVecVariable<vtkm::cont::ArrayHandle<typename SP::ValueType, SST>,
357 vtkm::cont::ArrayHandle<vtkm::Id, OST>>>
366 template <
typename SAH,
typename OAH>
367 struct Serialization<
vtkm::cont::ArrayHandleGroupVecVariable<SAH, OAH>>
374 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
376 vtkmdiy::save(bb, Type(obj).GetComponentsArray());
377 vtkmdiy::save(bb, Type(obj).GetOffsetsArray());
392 template <
typename SP,
typename SST,
typename OST>
393 struct Serialization<
vtkm::cont::ArrayHandle<vtkm::VecFromPortal<SP>,
394 vtkm::cont::StorageTagGroupVecVariable<SST, OST>>>
396 vtkm::cont::ArrayHandleGroupVecVariable<vtkm::cont::ArrayHandle<typename SP::ValueType, SST>,
397 vtkm::cont::ArrayHandle<vtkm::Id, OST>>>
403 #endif //vtk_m_cont_ArrayHandleGroupVecVariable_h