10 #ifndef vtk_m_cont_ArrayExtractComponent_h
11 #define vtk_m_cont_ArrayExtractComponent_h
22 #include <vtkmstd/integer_sequence.h>
24 #include <vtkm/cont/vtkm_cont_export.h>
39 template <
typename T,
typename S>
52 "Extracting component " << componentIndex <<
" of "
54 <<
" requires an inefficient memory copy.");
56 using BaseComponentType =
typename vtkm::internal::SafeVecTraits<T>::BaseComponentType;
62 for (
vtkm::Id arrayIndex = 0; arrayIndex < numValues; ++arrayIndex)
64 destPortal.Set(arrayIndex,
65 vtkm::internal::GetFlatVecComponent(srcPortal.Get(arrayIndex), componentIndex));
73 struct ArrayExtractComponentImplInefficient
78 struct ArrayExtractComponentImpl : ArrayExtractComponentImplInefficient
88 return vtkm::cont::internal::ArrayExtractComponentFallback(src, componentIndex, allowCopy);
93 struct ArrayExtractComponentImpl<
vtkm::cont::StorageTagStride>
101 return this->DoExtract(src,
104 typename vtkm::internal::SafeVecTraits<T>::HasMultipleComponents{});
108 template <
typename T>
115 using VTraits = vtkm::internal::SafeVecTraits<T>;
116 using TBase =
typename VTraits::BaseComponentType;
125 array.GetNumberOfValues(),
132 template <
typename VecType>
138 using VTraits = vtkm::internal::SafeVecTraits<VecType>;
139 using T =
typename VTraits::ComponentType;
142 constexpr
vtkm::IdComponent subStride = vtkm::internal::TotalNumComponents<T>::value;
145 array.GetNumberOfValues(),
146 array.GetStride() * N,
147 (array.GetOffset() * N) + (componentIndex / subStride),
148 array.GetModulo() * N,
150 return (*
this)(tmpIn, componentIndex % subStride, allowCopy);
155 struct ArrayExtractComponentImpl<
vtkm::cont::StorageTagBasic>
157 template <
typename T>
166 return ArrayExtractComponentImpl<vtkm::cont::StorageTagStride>{}(
176 template <std::
size_t,
typename Super>
177 struct ForwardSuper : Super
181 template <
typename sequence,
typename... Supers>
182 struct SharedSupersImpl;
184 template <std::size_t... Indices,
typename... Supers>
185 struct SharedSupersImpl<vtkmstd::index_sequence<Indices...>, Supers...>
186 : ForwardSuper<Indices, Supers>...
198 template <
typename... Supers>
199 using DuplicatedSuperclasses =
200 detail::SharedSupersImpl<vtkmstd::make_index_sequence<
sizeof...(Supers)>, Supers...>;
202 template <typename... StorageTags>
203 using ArrayExtractComponentImplInherit =
204 DuplicatedSuperclasses<vtkm::cont::internal::ArrayExtractComponentImpl<StorageTags>...>;
208 template <typename ArrayHandleType>
209 using ArrayExtractComponentIsInefficient =
typename std::is_base_of<
210 vtkm::cont::internal::ArrayExtractComponentImplInefficient,
211 vtkm::cont::internal::ArrayExtractComponentImpl<typename ArrayHandleType::StorageTag>>::type;
256 template <
typename T,
typename S>
262 return internal::ArrayExtractComponentImpl<S>{}(src, componentIndex, allowCopy);
268 #endif //vtk_m_cont_ArrayExtractComponent_h