10 #ifndef vtk_m_cont_ArrayHandleView_h
11 #define vtk_m_cont_ArrayHandleView_h
30 ViewIndices() =
default;
34 , NumberOfValues(numValues)
39 template <
typename TargetPortalType>
42 using Writable = vtkm::internal::PortalSupportsSets<TargetPortalType>;
45 using ValueType =
typename TargetPortalType::ValueType;
51 ArrayPortalView(
const TargetPortalType& targetPortal, ViewIndices indices)
52 : TargetPortal(targetPortal)
57 template <
typename OtherPortalType>
58 VTKM_EXEC_CONT ArrayPortalView(
const ArrayPortalView<OtherPortalType>& otherPortal)
59 : TargetPortal(otherPortal.GetTargetPortal())
60 , Indices(otherPortal.GetStartIndex(), otherPortal.GetNumberOfValues())
65 vtkm::Id GetNumberOfValues()
const {
return this->Indices.NumberOfValues; }
70 return this->TargetPortal.Get(index + this->GetStartIndex());
73 template <
typename Writable_ = Writable,
74 typename =
typename std::enable_if<Writable_::value>::type>
77 this->TargetPortal.Set(index + this->GetStartIndex(), value);
81 const TargetPortalType& GetTargetPortal()
const {
return this->TargetPortal; }
83 vtkm::Id GetStartIndex()
const {
return this->Indices.StartIndex; }
86 TargetPortalType TargetPortal;
95 template <
typename StorageTag>
103 template <
typename T,
typename ST>
107 using SourceStorage = Storage<T, ST>;
109 static std::vector<vtkm::cont::internal::Buffer> SourceBuffers(
110 const std::vector<vtkm::cont::internal::Buffer>& buffers)
112 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
118 using ReadPortalType = vtkm::internal::ArrayPortalView<typename ArrayHandleType::ReadPortalType>;
119 using WritePortalType =
120 vtkm::internal::ArrayPortalView<typename ArrayHandleType::WritePortalType>;
123 const std::vector<vtkm::cont::internal::Buffer>& buffers)
125 return SourceStorage::GetNumberOfComponentsFlat(SourceBuffers(buffers));
129 const std::vector<vtkm::cont::internal::Buffer>& buffers)
131 return buffers[0].GetMetaData<vtkm::internal::ViewIndices>().NumberOfValues;
134 VTKM_CONT static ReadPortalType CreateReadPortal(
135 const std::vector<vtkm::cont::internal::Buffer>& buffers,
139 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
140 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
144 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
150 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
151 vtkm::Id adjustedStartIndex = startIndex + indices.StartIndex;
152 vtkm::Id adjustedEndIndex = (endIndex < indices.NumberOfValues)
153 ? endIndex + indices.StartIndex
154 : indices.NumberOfValues + indices.StartIndex;
156 SourceBuffers(buffers), fillValue, adjustedStartIndex, adjustedEndIndex, token);
159 VTKM_CONT static WritePortalType CreateWritePortal(
160 const std::vector<vtkm::cont::internal::Buffer>& buffers,
164 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
165 return WritePortalType(SourceStorage::CreateWritePortal(SourceBuffers(buffers), device, token),
169 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
172 const ArrayHandleType& array = ArrayHandleType{})
174 return vtkm::cont::internal::CreateBuffers(vtkm::internal::ViewIndices(startIndex, numValues),
178 VTKM_CONT static ArrayHandleType GetSourceArray(
179 const std::vector<vtkm::cont::internal::Buffer>& buffers)
181 return ArrayHandleType(SourceBuffers(buffers));
184 VTKM_CONT static vtkm::Id GetStartIndex(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
186 return buffers[0].GetMetaData<vtkm::internal::ViewIndices>().StartIndex;
198 template <
typename ArrayHandleType>
201 StorageTagView<typename ArrayHandleType::StorageTag>>
239 template <
typename ArrayHandleType>
254 template <
typename StorageTag>
255 struct ArrayExtractComponentImpl<StorageTagView<StorageTag>>
256 : vtkm::cont::internal::ArrayExtractComponentImpl<StorageTag>
258 template <
typename T>
259 using StrideArrayType =
262 template <
typename T>
263 StrideArrayType<T> operator()(
269 StrideArrayType<T> subArray =
270 ArrayExtractComponentImpl<StorageTag>{}(srcArray.GetSourceArray(), componentIndex, allowCopy);
272 return StrideArrayType<T>(subArray.GetBasicArray(),
273 srcArray.GetNumberOfValues(),
274 subArray.GetStride(),
275 subArray.GetOffset() +
276 (subArray.GetStride() * srcArray.GetStartIndex()),
277 subArray.GetModulo(),
278 subArray.GetDivisor());
287 #endif //vtk_m_cont_ArrayHandleView_h