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;
 
   49   VTKM_STATIC_ASSERT((std::is_same<typename VTraits::ComponentType, ComponentType>::value));
 
   52   ComponentPortalType Portals[NUM_COMPONENTS];
 
   58     : NumberOfValues(numValues)
 
   65     this->Portals[index] = portal;
 
   70   template <
typename SPT = ComponentPortalType,
 
   71             typename Supported = 
typename vtkm::internal::PortalSupportsGets<SPT>::type,
 
   72             typename = 
typename std::enable_if<Supported::value>::type>
 
   75     return this->
Get(valueIndex, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
 
   78   template <
typename SPT = ComponentPortalType,
 
   79             typename Supported = 
typename vtkm::internal::PortalSupportsSets<SPT>::type,
 
   80             typename = 
typename std::enable_if<Supported::value>::type>
 
   83     this->Set(valueIndex, value, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
 
   88   template <std::
size_t I>
 
   91     return this->Portals[I].Get(valueIndex);
 
   94   template <std::size_t... I>
 
   97     return ValueType{ this->GetComponent<I>(valueIndex)... };
 
  101   template <std::
size_t I>
 
  104     this->Portals[I].Set(valueIndex,
 
  109   template <std::size_t... I>
 
  111                           const ValueType& value,
 
  112                           vtkmstd::index_sequence<I...>)
 const 
  115     (void)std::initializer_list<bool>{ this->SetComponent<I>(valueIndex, value)... };
 
  131 template <
typename ComponentType, vtkm::IdComponent NUM_COMPONENTS>
 
  138   using ReadPortalType =
 
  139     vtkm::internal::ArrayPortalSOA<ValueType, vtkm::internal::ArrayPortalBasicRead<ComponentType>>;
 
  140   using WritePortalType =
 
  141     vtkm::internal::ArrayPortalSOA<ValueType, vtkm::internal::ArrayPortalBasicWrite<ComponentType>>;
 
  143   VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
 
  145     return std::vector<vtkm::cont::internal::Buffer>(
static_cast<std::size_t
>(NUM_COMPONENTS));
 
  149                                       const std::vector<vtkm::cont::internal::Buffer>& buffers,
 
  154       vtkm::internal::NumberOfValuesToNumberOfBytes<ComponentType>(numValues);
 
  155     for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  157       buffers[componentIndex].SetNumberOfBytes(numBytes, preserve, token);
 
  162     const std::vector<vtkm::cont::internal::Buffer>& buffers)
 
  165     return static_cast<vtkm::Id>(buffers[0].GetNumberOfBytes()) /
 
  166       static_cast<vtkm::Id>(
sizeof(ComponentType));
 
  169   VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
 
  170                              const ValueType& fillValue,
 
  179     for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  181       ComponentType source = fillValue[componentIndex];
 
  182       buffers[componentIndex].Fill(&source, sourceSize, startByte, endByte, token);
 
  186   VTKM_CONT static ReadPortalType CreateReadPortal(
 
  187     const std::vector<vtkm::cont::internal::Buffer>& buffers,
 
  191     vtkm::Id numValues = GetNumberOfValues(buffers);
 
  192     ReadPortalType portal(numValues);
 
  193     for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  195       VTKM_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
 
  196       portal.SetPortal(componentIndex,
 
  197                        vtkm::internal::ArrayPortalBasicRead<ComponentType>(
 
  198                          reinterpret_cast<const ComponentType*
>(
 
  199                            buffers[componentIndex].ReadPointerDevice(device, token)),
 
  205   VTKM_CONT static WritePortalType CreateWritePortal(
 
  206     const std::vector<vtkm::cont::internal::Buffer>& buffers,
 
  210     vtkm::Id numValues = GetNumberOfValues(buffers);
 
  211     WritePortalType portal(numValues);
 
  212     for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  214       VTKM_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
 
  215       portal.SetPortal(componentIndex,
 
  216                        vtkm::internal::ArrayPortalBasicWrite<ComponentType>(
 
  217                          reinterpret_cast<ComponentType*
>(
 
  218                            buffers[componentIndex].WritePointerDevice(device, token)),
 
  244 template <
typename T>
 
  250   using StorageType = vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagSOA>;
 
  259   ArrayHandleSOA(std::initializer_list<vtkm::cont::internal::Buffer>&& componentBuffers)
 
  260     : Superclass(std::move(componentBuffers))
 
  264   ArrayHandleSOA(
const std::array<ComponentArrayType, NUM_COMPONENTS>& componentArrays)
 
  268       this->
SetArray(componentIndex, componentArrays[componentIndex]);
 
  277       this->
SetArray(componentIndex, componentArrays[componentIndex]);
 
  285     for (
auto&& array : componentArrays)
 
  287       this->
SetArray(componentIndex, array);
 
  292   ArrayHandleSOA(std::initializer_list<std::vector<ComponentType>>&& componentVectors)
 
  296     for (
auto&& vector : componentVectors)
 
  306   template <
typename Allocator, 
typename... RemainingVectors>
 
  308                  const std::vector<ComponentType, Allocator>& vector0,
 
  309                  RemainingVectors&&... componentVectors)
 
  310     : Superclass(std::vector<
vtkm::cont::internal::Buffer>{
 
  313           .GetBuffers()[0]... })
 
  319   template <
typename... RemainingVectors>
 
  321                  std::vector<ComponentType>&& vector0,
 
  322                  RemainingVectors&&... componentVectors)
 
  323     : Superclass(std::vector<
vtkm::cont::internal::Buffer>{
 
  326           .GetBuffers()[0]... })
 
  337     for (
auto&& vectorIter = componentArrays.begin(); vectorIter != componentArrays.end();
 
  346   template <
typename... RemainingArrays>
 
  350                  const RemainingArrays&... componentArrays)
 
  351     : Superclass(std::vector<
vtkm::cont::internal::Buffer>{
 
  369 template <
typename ValueType>
 
  377 template <
typename ComponentType, 
typename... RemainingArrays>
 
  382     const RemainingArrays&... componentArrays)
 
  384   return { componentArray0, componentArrays... };
 
  387 template <
typename ValueType>
 
  396 template <
typename ComponentType, 
typename... RemainingVectors>
 
  400                       const std::vector<ComponentType>& vector0,
 
  401                       RemainingVectors&&... componentVectors)
 
  410 template <
typename ComponentType, 
typename... RemainingVectors>
 
  414                       std::vector<ComponentType>&& vector0,
 
  415                       RemainingVectors&&... componentVectors)
 
  425 template <
typename ComponentType, 
typename... RemainingVectors>
 
  429                           RemainingVectors&&... componentVectors)
 
  435 template <
typename ValueType>
 
  446 template <
typename ComponentType, 
typename... RemainingArrays>
 
  451                       const ComponentType* array0,
 
  452                       const RemainingArrays*... componentArrays)
 
  456     length, copy, array0, componentArrays...);
 
  465   template <
typename T>
 
  478     return ArrayExtractComponentImpl<vtkm::cont::StorageTagBasic>{}(
 
  479       array.GetArray(componentIndex / NUM_SUB_COMPONENTS),
 
  480       componentIndex % NUM_SUB_COMPONENTS,
 
  499 template <
typename ValueType>
 
  500 struct SerializableTypeString<
vtkm::cont::ArrayHandleSOA<ValueType>>
 
  509 template <
typename ValueType>
 
  510 struct SerializableTypeString<
vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagSOA>>
 
  511   : SerializableTypeString<vtkm::cont::ArrayHandleSOA<ValueType>>
 
  520 template <
typename ValueType>
 
  521 struct Serialization<
vtkm::cont::ArrayHandleSOA<ValueType>>
 
  526   static VTKM_CONT void save(BinaryBuffer& bb, 
const BaseType& obj)
 
  528     for (
vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  530       vtkmdiy::save(bb, obj.GetBuffers()[componentIndex]);
 
  536     std::vector<vtkm::cont::internal::Buffer> buffers(NUM_COMPONENTS);
 
  537     for (std::size_t componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
 
  541     obj = BaseType(buffers);
 
  545 template <
typename ValueType>
 
  546 struct Serialization<
vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagSOA>>
 
  547   : Serialization<vtkm::cont::ArrayHandleSOA<ValueType>>
 
  557 #ifndef vtkm_cont_ArrayHandleSOA_cxx 
  564 #define VTKM_ARRAYHANDLE_SOA_EXPORT(Type)                                                         \ 
  565   extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 2>, StorageTagSOA>; \ 
  566   extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 3>, StorageTagSOA>; \ 
  567   extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<Type, 4>, StorageTagSOA>; 
  581 #undef VTKM_ARRAYHANDLE_SOA_EXPORT 
  585 #endif // !vtkm_cont_ArrayHandleSOA_cxx 
  587 #endif //vtk_m_cont_ArrayHandleSOA_h