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 buffers[0].GetMetaData<vtkm::internal::ViewIndices>().NumberOfValues;
128 VTKM_CONT static ReadPortalType CreateReadPortal(
129 const std::vector<vtkm::cont::internal::Buffer>& buffers,
133 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
134 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
138 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
144 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
145 vtkm::Id adjustedStartIndex = startIndex + indices.StartIndex;
146 vtkm::Id adjustedEndIndex = (endIndex < indices.NumberOfValues)
147 ? endIndex + indices.StartIndex
148 : indices.NumberOfValues + indices.StartIndex;
150 SourceBuffers(buffers), fillValue, adjustedStartIndex, adjustedEndIndex, token);
153 VTKM_CONT static WritePortalType CreateWritePortal(
154 const std::vector<vtkm::cont::internal::Buffer>& buffers,
158 vtkm::internal::ViewIndices indices = buffers[0].GetMetaData<vtkm::internal::ViewIndices>();
159 return WritePortalType(SourceStorage::CreateWritePortal(SourceBuffers(buffers), device, token),
163 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
166 const ArrayHandleType& array = ArrayHandleType{})
168 return vtkm::cont::internal::CreateBuffers(vtkm::internal::ViewIndices(startIndex, numValues),
172 VTKM_CONT static ArrayHandleType GetSourceArray(
173 const std::vector<vtkm::cont::internal::Buffer>& buffers)
175 return ArrayHandleType(SourceBuffers(buffers));
178 VTKM_CONT static vtkm::Id GetStartIndex(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
180 return buffers[0].GetMetaData<vtkm::internal::ViewIndices>().StartIndex;
186 template <
typename ArrayHandleType>
189 StorageTagView<typename ArrayHandleType::StorageTag>>
201 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
206 : Superclass(
StorageType::CreateBuffers(startIndex, numValues, array))
221 template <
typename ArrayHandleType>
236 template <
typename StorageTag>
237 struct ArrayExtractComponentImpl<StorageTagView<StorageTag>>
238 : vtkm::cont::internal::ArrayExtractComponentImpl<StorageTag>
240 template <
typename T>
241 using StrideArrayType =
244 template <
typename T>
245 StrideArrayType<T> operator()(
251 StrideArrayType<T> subArray =
252 ArrayExtractComponentImpl<StorageTag>{}(srcArray.GetSourceArray(), componentIndex, allowCopy);
254 return StrideArrayType<T>(subArray.GetBasicArray(),
255 srcArray.GetNumberOfValues(),
256 subArray.GetStride(),
257 subArray.GetOffset() +
258 (subArray.GetStride() * srcArray.GetStartIndex()),
259 subArray.GetModulo(),
260 subArray.GetDivisor());
269 #endif //vtk_m_cont_ArrayHandleView_h