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 vtkm::Id componentsSize = ComponentsStorage::GetNumberOfValues(buffers);
148 return componentsSize / NUM_COMPONENTS;
151 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
160 VTKM_CONT static ReadPortalType CreateReadPortal(
161 const std::vector<vtkm::cont::internal::Buffer>& buffers,
165 if ((ComponentsStorage::GetNumberOfValues(buffers) % NUM_COMPONENTS) != 0)
168 "ArrayHandleGroupVec's components array does not divide evenly into Vecs.");
170 return ReadPortalType(ComponentsStorage::CreateReadPortal(buffers, device, token));
173 VTKM_CONT static WritePortalType CreateWritePortal(
174 const std::vector<vtkm::cont::internal::Buffer>& buffers,
178 if ((ComponentsStorage::GetNumberOfValues(buffers) % NUM_COMPONENTS) != 0)
181 "ArrayHandleGroupVec's components array does not divide evenly into Vecs.");
183 return WritePortalType(ComponentsStorage::CreateWritePortal(buffers, device, token));
206 template <
typename ComponentsArrayHandleType, vtkm::IdComponent NUM_COMPONENTS>
209 vtkm::Vec<typename ComponentsArrayHandleType::ValueType, NUM_COMPONENTS>,
210 vtkm::cont::StorageTagGroupVec<typename ComponentsArrayHandleType::StorageTag,
234 return ComponentsArrayHandleType(this->
GetBuffers());
243 template <vtkm::IdComponent NUM_COMPONENTS,
typename ArrayHandleType>
245 const ArrayHandleType& array)
257 template <
typename ComponentsStorageTag, vtkm::IdComponent NUM_COMPONENTS>
258 struct ArrayExtractComponentImpl<
260 : vtkm::cont::internal::ArrayExtractComponentImpl<ComponentsStorageTag>
262 template <
typename T>
275 ArrayExtractComponentImpl<ComponentsStorageTag>{}(
276 srcArray.GetComponentsArray(), componentIndex % NUM_SUB_COMPONENTS, allowCopy);
302 template <
typename AH, vtkm::IdComponent NUM_COMPS>
303 struct SerializableTypeString<
vtkm::cont::ArrayHandleGroupVec<AH, NUM_COMPS>>
307 static std::string name =
313 template <
typename T, vtkm::IdComponent NUM_COMPS,
typename ST>
314 struct SerializableTypeString<
315 vtkm::cont::ArrayHandle<vtkm::Vec<T, NUM_COMPS>, vtkm::cont::StorageTagGroupVec<ST, NUM_COMPS>>>
316 : SerializableTypeString<
317 vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<T, ST>, NUM_COMPS>>
326 template <
typename AH, vtkm::IdComponent NUM_COMPS>
327 struct Serialization<
vtkm::cont::ArrayHandleGroupVec<AH, NUM_COMPS>>
334 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
336 vtkmdiy::save(bb, Type(obj).GetComponentsArray());
344 obj = vtkm::cont::make_ArrayHandleGroupVec<NUM_COMPS>(array);
348 template <
typename T, vtkm::IdComponent NUM_COMPS,
typename ST>
349 struct Serialization<
350 vtkm::cont::ArrayHandle<vtkm::Vec<T, NUM_COMPS>, vtkm::cont::StorageTagGroupVec<ST, NUM_COMPS>>>
351 : Serialization<vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<T, ST>, NUM_COMPS>>
358 #endif //vtk_m_cont_ArrayHandleGroupVec_h