10 #ifndef vtk_m_cont_ArrayHandleGroupVec_h
11 #define vtk_m_cont_ArrayHandleGroupVec_h
23 template <
typename PortalType, vtkm::IdComponent N_COMPONENTS>
26 using Writable = vtkm::internal::PortalSupportsSets<PortalType>;
30 using ComponentsPortalType = PortalType;
32 using ComponentType =
typename std::remove_const<typename ComponentsPortalType::ValueType>::type;
44 ArrayPortalGroupVec(
const ComponentsPortalType& componentsPortal)
45 : ComponentsPortal(componentsPortal)
53 template <
typename OtherComponentsPortalType>
55 const ArrayPortalGroupVec<OtherComponentsPortalType, NUM_COMPONENTS>& src)
56 : ComponentsPortal(src.GetPortal())
64 return this->ComponentsPortal.GetNumberOfValues() / NUM_COMPONENTS;
72 vtkm::Id componentsIndex = index * NUM_COMPONENTS;
73 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
75 result[componentIndex] = this->ComponentsPortal.Get(componentsIndex);
82 template <
typename Writable_ = Writable,
83 typename =
typename std::enable_if<Writable_::value>::type>
86 vtkm::Id componentsIndex = index * NUM_COMPONENTS;
87 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
89 this->ComponentsPortal.Set(componentsIndex, value[componentIndex]);
96 const ComponentsPortalType& GetPortal()
const {
return this->ComponentsPortal; }
99 ComponentsPortalType ComponentsPortal;
109 template <
typename ComponentsStorageTag, vtkm::IdComponent NUM_COMPONENTS>
117 template <
typename ComponentType, vtkm::IdComponent NUM_COMPONENTS,
typename ComponentsStorageTag>
118 class Storage<
vtkm::
Vec<ComponentType, NUM_COMPONENTS>,
121 using ComponentsStorage = vtkm::cont::internal::Storage<ComponentType, ComponentsStorageTag>;
125 using ReadPortalType =
126 vtkm::internal::ArrayPortalGroupVec<typename ComponentsStorage::ReadPortalType, NUM_COMPONENTS>;
127 using WritePortalType =
128 vtkm::internal::ArrayPortalGroupVec<
typename ComponentsStorage::WritePortalType,
131 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
133 return ComponentsStorage::CreateBuffers();
137 const std::vector<vtkm::cont::internal::Buffer>& buffers,
141 ComponentsStorage::ResizeBuffers(NUM_COMPONENTS * numValues, buffers, preserve, token);
145 const std::vector<vtkm::cont::internal::Buffer>& buffers)
147 return ComponentsStorage::GetNumberOfComponentsFlat(buffers) * NUM_COMPONENTS;
151 const std::vector<vtkm::cont::internal::Buffer>& buffers)
153 vtkm::Id componentsSize = ComponentsStorage::GetNumberOfValues(buffers);
154 return componentsSize / NUM_COMPONENTS;
157 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
166 VTKM_CONT static ReadPortalType CreateReadPortal(
167 const std::vector<vtkm::cont::internal::Buffer>& buffers,
171 if ((ComponentsStorage::GetNumberOfValues(buffers) % NUM_COMPONENTS) != 0)
174 "ArrayHandleGroupVec's components array does not divide evenly into Vecs.");
176 return ReadPortalType(ComponentsStorage::CreateReadPortal(buffers, device, token));
179 VTKM_CONT static WritePortalType CreateWritePortal(
180 const std::vector<vtkm::cont::internal::Buffer>& buffers,
184 if ((ComponentsStorage::GetNumberOfValues(buffers) % NUM_COMPONENTS) != 0)
187 "ArrayHandleGroupVec's components array does not divide evenly into Vecs.");
189 return WritePortalType(ComponentsStorage::CreateWritePortal(buffers, device, token));
212 template <
typename ComponentsArrayHandleType, vtkm::IdComponent NUM_COMPONENTS>
215 vtkm::Vec<typename ComponentsArrayHandleType::ValueType, NUM_COMPONENTS>,
216 vtkm::cont::StorageTagGroupVec<typename ComponentsArrayHandleType::StorageTag,
242 return ComponentsArrayHandleType(this->
GetBuffers());
251 template <vtkm::IdComponent NUM_COMPONENTS,
typename ArrayHandleType>
253 const ArrayHandleType& array)
265 template <
typename ComponentsStorageTag, vtkm::IdComponent NUM_COMPONENTS>
266 struct ArrayExtractComponentImpl<
268 : vtkm::cont::internal::ArrayExtractComponentImpl<ComponentsStorageTag>
270 template <
typename T>
283 ArrayExtractComponentImpl<ComponentsStorageTag>{}(
284 srcArray.GetComponentsArray(), componentIndex % NUM_SUB_COMPONENTS, allowCopy);
310 template <
typename AH, vtkm::IdComponent NUM_COMPS>
311 struct SerializableTypeString<
vtkm::cont::ArrayHandleGroupVec<AH, NUM_COMPS>>
315 static std::string name =
321 template <
typename T, vtkm::IdComponent NUM_COMPS,
typename ST>
322 struct SerializableTypeString<
323 vtkm::cont::ArrayHandle<vtkm::Vec<T, NUM_COMPS>, vtkm::cont::StorageTagGroupVec<ST, NUM_COMPS>>>
324 : SerializableTypeString<
325 vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<T, ST>, NUM_COMPS>>
334 template <
typename AH, vtkm::IdComponent NUM_COMPS>
335 struct Serialization<
vtkm::cont::ArrayHandleGroupVec<AH, NUM_COMPS>>
342 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
344 vtkmdiy::save(bb, Type(obj).GetComponentsArray());
352 obj = vtkm::cont::make_ArrayHandleGroupVec<NUM_COMPS>(array);
356 template <
typename T, vtkm::IdComponent NUM_COMPS,
typename ST>
357 struct Serialization<
358 vtkm::cont::ArrayHandle<vtkm::Vec<T, NUM_COMPS>, vtkm::cont::StorageTagGroupVec<ST, NUM_COMPS>>>
359 : Serialization<vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<T, ST>, NUM_COMPS>>
366 #endif //vtk_m_cont_ArrayHandleGroupVec_h