VTK  9.0.1
vtkmDataArray.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2019 Sandia Corporation.
10 // Copyright 2019 UT-Battelle, LLC.
11 // Copyright 2019 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 #ifndef __VTK_WRAP__
21 #ifndef VTK_WRAPPING_CXX
22 
23 #ifndef vtkmDataArray_h
24 #define vtkmDataArray_h
25 
26 #include "vtkAcceleratorsVTKmModule.h" // For export macro
27 #include "vtkGenericDataArray.h"
28 #include "vtkmConfig.h" // For template export
29 
30 #include <vtkm/List.h> // For vtkm::List
31 #include <vtkm/VecFromPortal.h> // For vtkm::VecFromPortal
32 #include <vtkm/VecTraits.h> // For vtkm::VecTraits
33 #include <vtkm/cont/ArrayHandle.h> // For vtkm::cont::ArrayHandle
34 #include <vtkm/cont/VariantArrayHandle.h> // For vtkm::cont::VariantArrayHandle
35 
36 #include <memory> // For unique_ptr
37 
38 namespace internal
39 {
40 
41 template <typename T>
43 
44 } // internal
45 
46 template <typename T>
47 class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
48 {
49  static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
50 
52 
53 public:
56 
57  using typename Superclass::ValueType;
58 
59  using VtkmTypesList = vtkm::List<T, vtkm::Vec<T, 2>, vtkm::Vec<T, 3>, vtkm::Vec<T, 4>,
60  vtkm::VecFromPortal<typename vtkm::cont::ArrayHandle<T>::PortalControl> >;
61 
62  static vtkmDataArray* New();
63 
64  template <typename V, typename S>
65  void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle<V, S>& ah);
66 
67  vtkm::cont::VariantArrayHandle GetVtkmVariantArrayHandle() const;
68 
70  ValueType GetValue(vtkIdType valueIdx) const;
71  void SetValue(vtkIdType valueIdx, ValueType value);
72  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
73  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
74  ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
75  void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
76 
77 protected:
79  ~vtkmDataArray() override;
80 
82  bool AllocateTuples(vtkIdType numTuples);
83  bool ReallocateTuples(vtkIdType numTuples);
84 
85 private:
86  vtkmDataArray(const vtkmDataArray&) = delete;
87  void operator=(const vtkmDataArray&) = delete;
88 
89  // To access AllocateTuples and ReallocateTuples
90  friend Superclass;
91 
92  std::unique_ptr<internal::ArrayHandleWrapperBase<T> > VtkmArray;
93 };
94 
95 //=============================================================================
96 template <typename T, typename S>
98  const vtkm::cont::ArrayHandle<T, S>& ah)
99 {
101  ret->SetVtkmArrayHandle(ah);
102  return ret;
103 }
104 
105 //=============================================================================
106 #ifndef vtkmDataArray_cxx
107 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<char>;
108 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<double>;
109 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<float>;
110 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<int>;
111 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<long>;
112 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<long long>;
113 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<short>;
114 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<signed char>;
115 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
116 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
117 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
118 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
119 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
120 #endif // vtkmDataArray_cxx
121 
122 #endif // vtkmDataArray_h
123 
124 #include "vtkmDataArray.hxx"
125 
126 #endif
127 #endif
128 // VTK-HeaderTest-Exclude: vtkmDataArray.h
Base interface for all typed vtkDataArray subclasses.
abstract base class for most VTK objects
Definition: vtkObject.h:54
ValueType GetValue(vtkIdType valueIdx) const
concept methods for vtkGenericDataArray
vtkm::cont::VariantArrayHandle GetVtkmVariantArrayHandle() const
void SetValue(vtkIdType valueIdx, ValueType value)
bool AllocateTuples(vtkIdType numTuples)
concept methods for vtkGenericDataArray
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
vtkm::List< T, vtkm::Vec< T, 2 >, vtkm::Vec< T, 3 >, vtkm::Vec< T, 4 >, vtkm::VecFromPortal< typename vtkm::cont::ArrayHandle< T >::PortalControl > > VtkmTypesList
Definition: vtkmDataArray.h:60
~vtkmDataArray() override
static vtkmDataArray * New()
void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle< V, S > &ah)
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
bool ReallocateTuples(vtkIdType numTuples)
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
@ value
Definition: vtkX3D.h:226
int vtkIdType
Definition: vtkType.h:338
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)
Definition: vtkmDataArray.h:97