10 #ifndef vtk_m_cont_ArrayHandleExtractComponent_h
11 #define vtk_m_cont_ArrayHandleExtractComponent_h
23 template <
typename PortalType>
26 using Writable = vtkm::internal::PortalSupportsSets<PortalType>;
29 using VectorType =
typename PortalType::ValueType;
31 using ValueType =
typename Traits::ComponentType;
34 ArrayPortalExtractComponent()
41 ArrayPortalExtractComponent(
const PortalType& portal,
vtkm::IdComponent component)
43 , Component(component)
47 ArrayPortalExtractComponent(
const ArrayPortalExtractComponent&) =
default;
48 ArrayPortalExtractComponent(ArrayPortalExtractComponent&&) =
default;
49 ArrayPortalExtractComponent& operator=(
const ArrayPortalExtractComponent&) =
default;
50 ArrayPortalExtractComponent& operator=(ArrayPortalExtractComponent&&) =
default;
53 vtkm::Id GetNumberOfValues()
const {
return this->Portal.GetNumberOfValues(); }
58 return Traits::GetComponent(this->Portal.Get(index), this->Component);
61 template <
typename Writable_ = Writable,
62 typename =
typename std::enable_if<Writable_::value>::type>
65 VectorType vec = this->Portal.Get(index);
66 Traits::SetComponent(vec, this->Component, value);
67 this->Portal.Set(index, vec);
71 const PortalType& GetPortal()
const {
return this->Portal; }
83 template <
typename ArrayHandleType>
91 template <
typename ArrayHandleType>
92 class Storage<typename
vtkm::
VecTraits<typename ArrayHandleType::ValueType>::ComponentType,
95 using SourceValueType =
typename ArrayHandleType::ValueType;
97 using SourceStorage =
typename ArrayHandleType::StorageType;
101 const std::vector<vtkm::cont::internal::Buffer>& buffers)
106 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> SourceBuffers(
107 const std::vector<vtkm::cont::internal::Buffer>& buffers)
109 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
112 using ReadPortalType =
113 vtkm::internal::ArrayPortalExtractComponent<typename SourceStorage::ReadPortalType>;
114 using WritePortalType =
115 vtkm::internal::ArrayPortalExtractComponent<typename SourceStorage::WritePortalType>;
118 const std::vector<vtkm::cont::internal::Buffer>&)
124 const std::vector<vtkm::cont::internal::Buffer>& buffers)
126 return SourceStorage::GetNumberOfValues(SourceBuffers(buffers));
129 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
139 const std::vector<vtkm::cont::internal::Buffer>& buffers,
143 SourceStorage::ResizeBuffers(numValues, SourceBuffers(buffers), preserve, token);
146 VTKM_CONT static ReadPortalType CreateReadPortal(
147 const std::vector<vtkm::cont::internal::Buffer>& buffers,
151 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
152 ComponentIndex(buffers));
155 VTKM_CONT static WritePortalType CreateWritePortal(
156 const std::vector<vtkm::cont::internal::Buffer>& buffers,
160 return WritePortalType(SourceStorage::CreateWritePortal(SourceBuffers(buffers), device, token),
161 ComponentIndex(buffers));
165 const ArrayHandleType& array = ArrayHandleType{})
166 -> decltype(vtkm::cont::internal::CreateBuffers())
168 return vtkm::cont::internal::CreateBuffers(componentIndex, array);
192 template <
typename ArrayHandleType>
195 typename vtkm::VecTraits<typename ArrayHandleType::ValueType>::ComponentType,
196 StorageTagExtractComponent<ArrayHandleType>>
216 return StorageType::ComponentIndex(this->
GetBuffers());
223 typename ArrayHandleType::StorageTag>;
224 return ArrayHandleType(BaseArray(StorageType::SourceBuffers(this->
GetBuffers())));
230 template <
typename ArrayHandleType>
232 const ArrayHandleType& array,
244 template <
typename ArrayHandleType>
250 -> decltype(ArrayExtractComponentImpl<typename ArrayHandleType::StorageTag>{}(
251 std::declval<ArrayHandleType>(),
255 using ValueType =
typename ArrayHandleType::ValueType;
259 return ArrayExtractComponentImpl<typename ArrayHandleType::StorageTag>{}(
260 src.GetArray(), (src.GetComponent() * FLAT_SUB_COMPONENTS) + componentIndex, allowCopy);
279 template <
typename AH>
280 struct SerializableTypeString<
vtkm::cont::ArrayHandleExtractComponent<AH>>
289 template <
typename AH>
290 struct SerializableTypeString<
291 vtkm::cont::ArrayHandle<typename vtkm::VecTraits<typename AH::ValueType>::ComponentType,
292 vtkm::cont::StorageTagExtractComponent<AH>>>
293 : SerializableTypeString<vtkm::cont::ArrayHandleExtractComponent<AH>>
302 template <
typename AH>
303 struct Serialization<
vtkm::cont::ArrayHandleExtractComponent<AH>>
310 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
312 vtkmdiy::save(bb, Type(obj).GetComponent());
313 vtkmdiy::save(bb, Type(obj).GetArray());
327 template <
typename AH>
328 struct Serialization<
329 vtkm::cont::ArrayHandle<typename vtkm::VecTraits<typename AH::ValueType>::ComponentType,
330 vtkm::cont::StorageTagExtractComponent<AH>>>
331 : Serialization<vtkm::cont::ArrayHandleExtractComponent<AH>>
337 #endif // vtk_m_cont_ArrayHandleExtractComponent_h