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 SourceStorageTag =
typename ArrayHandleType::StorageTag;
98 using SourceStorage = vtkm::cont::internal::Storage<SourceValueType, SourceStorageTag>;
102 const std::vector<vtkm::cont::internal::Buffer>& buffers)
107 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> SourceBuffers(
108 const std::vector<vtkm::cont::internal::Buffer>& buffers)
110 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
113 using ReadPortalType =
114 vtkm::internal::ArrayPortalExtractComponent<typename SourceStorage::ReadPortalType>;
115 using WritePortalType =
116 vtkm::internal::ArrayPortalExtractComponent<typename SourceStorage::WritePortalType>;
119 const std::vector<vtkm::cont::internal::Buffer>& buffers)
121 return SourceStorage::GetNumberOfValues(SourceBuffers(buffers));
124 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
134 const std::vector<vtkm::cont::internal::Buffer>& buffers,
138 SourceStorage::ResizeBuffers(numValues, SourceBuffers(buffers), preserve, token);
141 VTKM_CONT static ReadPortalType CreateReadPortal(
142 const std::vector<vtkm::cont::internal::Buffer>& buffers,
146 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
147 ComponentIndex(buffers));
150 VTKM_CONT static WritePortalType CreateWritePortal(
151 const std::vector<vtkm::cont::internal::Buffer>& buffers,
155 return WritePortalType(SourceStorage::CreateWritePortal(SourceBuffers(buffers), device, token),
156 ComponentIndex(buffers));
160 const ArrayHandleType& array = ArrayHandleType{})
161 -> decltype(vtkm::cont::internal::CreateBuffers())
163 return vtkm::cont::internal::CreateBuffers(componentIndex, array);
187 template <
typename ArrayHandleType>
190 typename vtkm::VecTraits<typename ArrayHandleType::ValueType>::ComponentType,
191 StorageTagExtractComponent<ArrayHandleType>>
202 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
207 : Superclass(
StorageType::CreateBuffers(component, array))
213 return StorageType::ComponentIndex(this->
GetBuffers());
219 typename ArrayHandleType::StorageTag>;
220 return ArrayHandleType(BaseArray(StorageType::SourceBuffers(this->
GetBuffers())));
226 template <
typename ArrayHandleType>
228 const ArrayHandleType& array,
237 template <
typename ArrayHandleType>
243 -> decltype(ArrayExtractComponentImpl<typename ArrayHandleType::StorageTag>{}(
244 std::declval<ArrayHandleType>(),
248 using ValueType =
typename ArrayHandleType::ValueType;
252 return ArrayExtractComponentImpl<typename ArrayHandleType::StorageTag>{}(
253 src.GetArray(), (src.GetComponent() * FLAT_SUB_COMPONENTS) + componentIndex, allowCopy);
270 template <
typename AH>
271 struct SerializableTypeString<
vtkm::cont::ArrayHandleExtractComponent<AH>>
280 template <
typename AH>
281 struct SerializableTypeString<
282 vtkm::cont::ArrayHandle<typename vtkm::VecTraits<typename AH::ValueType>::ComponentType,
283 vtkm::cont::StorageTagExtractComponent<AH>>>
284 : SerializableTypeString<vtkm::cont::ArrayHandleExtractComponent<AH>>
293 template <
typename AH>
294 struct Serialization<
vtkm::cont::ArrayHandleExtractComponent<AH>>
301 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
303 vtkmdiy::save(bb, Type(obj).GetComponent());
304 vtkmdiy::save(bb, Type(obj).GetArray());
318 template <
typename AH>
319 struct Serialization<
320 vtkm::cont::ArrayHandle<typename vtkm::VecTraits<typename AH::ValueType>::ComponentType,
321 vtkm::cont::StorageTagExtractComponent<AH>>>
322 : Serialization<vtkm::cont::ArrayHandleExtractComponent<AH>>
328 #endif // vtk_m_cont_ArrayHandleExtractComponent_h