10 #ifndef vtk_m_cont_ArrayHandleSOA_h
11 #define vtk_m_cont_ArrayHandleSOA_h
22 #include <vtkmstd/integer_sequence.h>
26 #include <type_traits>
38 template <
typename ValueType_,
typename ComponentPortalType>
42 using ValueType = ValueType_;
45 using ComponentType =
typename ComponentPortalType::ValueType;
48 VTKM_STATIC_ASSERT((std::is_same<typename VTraits::ComponentType, ComponentType>::value));
51 ComponentPortalType Portals[NUM_COMPONENTS];
57 : NumberOfValues(numValues)
64 this->Portals[index] = portal;
69 template <
typename SPT = ComponentPortalType,
70 typename Supported =
typename vtkm::internal::PortalSupportsGets<SPT>::type,
71 typename =
typename std::enable_if<Supported::value>::type>
74 return this->
Get(valueIndex, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
77 template <
typename SPT = ComponentPortalType,
78 typename Supported =
typename vtkm::internal::PortalSupportsSets<SPT>::type,
79 typename =
typename std::enable_if<Supported::value>::type>
82 this->Set(valueIndex, value, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
87 template <std::
size_t I>
90 return this->Portals[I].Get(valueIndex);
93 template <std::size_t... I>
96 return ValueType{ this->GetComponent<I>(valueIndex)... };
100 template <std::
size_t I>
103 this->Portals[I].Set(valueIndex,
108 template <std::size_t... I>
110 const ValueType& value,
111 vtkmstd::index_sequence<I...>)
const
114 (void)std::initializer_list<bool>{ this->SetComponent<I>(valueIndex, value)... };
130 template <
typename ComponentType, vtkm::IdComponent NUM_COMPONENTS>
137 using ReadPortalType =
138 vtkm::internal::ArrayPortalSOA<ValueType, vtkm::internal::ArrayPortalBasicRead<ComponentType>>;
139 using WritePortalType =
140 vtkm::internal::ArrayPortalSOA<ValueType, vtkm::internal::ArrayPortalBasicWrite<ComponentType>>;
142 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
144 return std::vector<vtkm::cont::internal::Buffer>(
static_cast<std::size_t
>(NUM_COMPONENTS));
148 const std::vector<vtkm::cont::internal::Buffer>&)
154 const std::vector<vtkm::cont::internal::Buffer>& buffers,
159 vtkm::internal::NumberOfValuesToNumberOfBytes<ComponentType>(numValues);
160 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
162 buffers[componentIndex].SetNumberOfBytes(numBytes, preserve, token);
167 const std::vector<vtkm::cont::internal::Buffer>& buffers)
170 return static_cast<vtkm::Id>(buffers[0].GetNumberOfBytes()) /
171 static_cast<vtkm::Id>(
sizeof(ComponentType));
174 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
175 const ValueType& fillValue,
184 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
186 ComponentType source = fillValue[componentIndex];
187 buffers[componentIndex].Fill(&source, sourceSize, startByte, endByte, token);
191 VTKM_CONT static ReadPortalType CreateReadPortal(
192 const std::vector<vtkm::cont::internal::Buffer>& buffers,
196 vtkm::Id numValues = GetNumberOfValues(buffers);
197 ReadPortalType portal(numValues);
198 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
200 VTKM_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
201 portal.SetPortal(componentIndex,
202 vtkm::internal::ArrayPortalBasicRead<ComponentType>(
203 reinterpret_cast<const ComponentType*
>(
204 buffers[componentIndex].ReadPointerDevice(device, token)),
210 VTKM_CONT static WritePortalType CreateWritePortal(
211 const std::vector<vtkm::cont::internal::Buffer>& buffers,
215 vtkm::Id numValues = GetNumberOfValues(buffers);
216 WritePortalType portal(numValues);
217 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
219 VTKM_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
220 portal.SetPortal(componentIndex,
221 vtkm::internal::ArrayPortalBasicWrite<ComponentType>(
222 reinterpret_cast<ComponentType*
>(
223 buffers[componentIndex].WritePointerDevice(device, token)),
249 template <
typename T>
262 ArrayHandleSOA(std::initializer_list<vtkm::cont::internal::Buffer>&& componentBuffers)
278 ArrayHandleSOA(
const std::array<ComponentArrayType, NUM_COMPONENTS>& componentArrays)
282 this->
SetArray(componentIndex, componentArrays[componentIndex]);
302 this->
SetArray(componentIndex, componentArrays[componentIndex]);
321 for (
auto&& array : componentArrays)
323 this->
SetArray(componentIndex, array);
341 ArrayHandleSOA(std::initializer_list<std::vector<ComponentType>>&& componentVectors)
345 for (
auto&& vector : componentVectors)
370 template <
typename Allocator,
typename... RemainingVectors>
372 const std::vector<ComponentType, Allocator>& vector0,
373 RemainingVectors&&... componentVectors)
377 .GetBuffers()[0]... })
401 template <
typename... RemainingVectors>
403 std::vector<ComponentType>&& vector0,
404 RemainingVectors&&... componentVectors)
408 .GetBuffers()[0]... })
430 for (
auto&& vectorIter = componentArrays.begin(); vectorIter != componentArrays.end();
452 template <
typename... RemainingArrays>
456 const RemainingArrays&... componentArrays)
480 template <
typename... Remaining>
481 using VecSizeFromRemaining =
497 template <
typename ValueType>
519 template <
typename ComponentType,
typename... RemainingArrays>
521 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingArrays...>::value>>
524 const RemainingArrays&... componentArrays)
526 return { componentArray0, componentArrays... };
542 template <
typename ValueType>
566 template <
typename ComponentType,
typename... RemainingVectors>
568 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
570 const std::vector<ComponentType>& vector0,
571 RemainingVectors&&... componentVectors)
598 template <
typename ComponentType,
typename... RemainingVectors>
600 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
602 std::vector<ComponentType>&& vector0,
603 RemainingVectors&&... componentVectors)
607 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>(
626 template <
typename ComponentType,
typename... RemainingVectors>
628 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
630 RemainingVectors&&... componentVectors)
647 template <
typename ValueType>
670 template <
typename ComponentType,
typename... RemainingArrays>
672 vtkm::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingArrays...>::value>>
675 const ComponentType* array0,
676 const RemainingArrays*... componentArrays)
680 length, copy, array0, componentArrays...);
691 template <
typename T>
704 return ArrayExtractComponentImpl<vtkm::cont::StorageTagBasic>{}(
705 array.GetArray(componentIndex / NUM_SUB_COMPONENTS),
706 componentIndex % NUM_SUB_COMPONENTS,
727 template <
typename ValueType>
728 struct SerializableTypeString<
vtkm::cont::ArrayHandleSOA<ValueType>>
737 template <
typename ValueType>
738 struct SerializableTypeString<
vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagSOA>>
739 : SerializableTypeString<vtkm::cont::ArrayHandleSOA<ValueType>>
748 template <
typename ValueType>
749 struct Serialization<
vtkm::cont::ArrayHandleSOA<ValueType>>
754 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
756 for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
758 vtkmdiy::save(bb, obj.GetBuffers()[componentIndex]);
764 std::vector<vtkm::cont::internal::Buffer> buffers(NUM_COMPONENTS);
765 for (std::size_t componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
769 obj = BaseType(buffers);
773 template <
typename ValueType>
774 struct Serialization<
vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagSOA>>
775 : Serialization<vtkm::cont::ArrayHandleSOA<ValueType>>
785 #ifndef vtkm_cont_ArrayHandleSOA_cxx
794 #define VTKM_ARRAYHANDLE_SOA_EXPORT(Type) \
795 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 2>, StorageTagSOA>; \
796 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 3>, StorageTagSOA>; \
797 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 4>, StorageTagSOA>;
799 VTKM_ARRAYHANDLE_SOA_EXPORT(
char)
811 #undef VTKM_ARRAYHANDLE_SOA_EXPORT
817 #endif // !vtkm_cont_ArrayHandleSOA_cxx
819 #endif //vtk_m_cont_ArrayHandleSOA_h