VTK  9.3.20240328
vtkmDataArray.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Kitware, Inc.
3 // SPDX-FileCopyrightText: Copyright 2019 Sandia Corporation.
4 // SPDX-FileCopyrightText: Copyright 2019 UT-Battelle, LLC.
5 // SPDX-FileCopyrightText: Copyright 2019 Los Alamos National Security.
6 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-LANL-USGov
29 #ifndef vtkmDataArray_h
30 #define vtkmDataArray_h
31 
32 #include "vtkAcceleratorsVTKmCoreModule.h" // For export macro
33 #include "vtkGenericDataArray.h"
34 #include "vtkmConfigCore.h" // For template export
35 
36 #include <vtkm/VecTraits.h> // For vtkm::VecTraits
37 #include <vtkm/cont/ArrayHandle.h> // For vtkm::cont::ArrayHandle
38 #include <vtkm/cont/UnknownArrayHandle.h> // For vtkm::cont::UnknownArrayHandle
39 
40 #include <memory> // For std::unique_ptr<>
41 
42 namespace internal
43 {
44 VTK_ABI_NAMESPACE_BEGIN
45 
46 template <typename T>
48 
49 VTK_ABI_NAMESPACE_END
50 } // internal
51 
52 VTK_ABI_NAMESPACE_BEGIN
53 template <typename T>
54 class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
55 {
56  static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
57 
59  using SelfType = vtkmDataArray<T>;
60  vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
61 
62 public:
63  using typename Superclass::ValueType;
64 
65  static vtkmDataArray* New();
66 
69  template <typename V, typename S>
70  void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle<V, S>& ah);
71 
74  vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
75 
76 protected:
78  ~vtkmDataArray() override;
79 
82  using Superclass::ComputeScalarRange;
84  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
85  using Superclass::ComputeVectorRange;
87  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
88  using Superclass::ComputeFiniteScalarRange;
90  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
91  using Superclass::ComputeFiniteVectorRange;
93  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
94 
95 private:
96  // To access concept methods
97  friend Superclass;
98 
100  ValueType GetValue(vtkIdType valueIdx) const;
101  void SetValue(vtkIdType valueIdx, ValueType value);
102  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
103  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
104  ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
105  void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
106  bool AllocateTuples(vtkIdType numberOfTuples);
107  bool ReallocateTuples(vtkIdType numberOfTuples);
108 
109  std::unique_ptr<internal::ArrayHandleHelperInterface<T>> Helper;
110 
111  vtkmDataArray(const vtkmDataArray&) = delete;
112  void operator=(const vtkmDataArray&) = delete;
113 };
114 
115 //=============================================================================
116 template <typename T, typename S>
118  const vtkm::cont::ArrayHandle<T, S>& ah)
119 {
121  ret->SetVtkmArrayHandle(ah);
122  return ret;
123 }
124 
125 //=============================================================================
126 #ifndef vtkmDataArray_cxx
127 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
128 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
129 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
130 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
131 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
132 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
133 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
134 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
135 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
136 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
137 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
138 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
139 extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
140 #endif // vtkmDataArray_cxx
141 
142 VTK_ABI_NAMESPACE_END
143 #endif // vtkmDataArray_h
144 
145 #include "vtkmlib/vtkmDataArray.hxx"
146 
147 // VTK-HeaderTest-Exclude: vtkmDataArray.h
Base interface for all typed vtkDataArray subclasses.
abstract base class for most VTK objects
Definition: vtkObject.h:161
Wraps a VTK-m ArrayHandle inside a sub-class of vtkGenericDataArray.
Definition: vtkmDataArray.h:55
bool ComputeVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff) override
Returns true if the range was computed.
bool ComputeFiniteVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff) override
Returns true if the range was computed.
vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const
Get the underlying ArrayHandle.
~vtkmDataArray() override
static vtkmDataArray * New()
void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle< V, S > &ah)
Set the VTK-m ArrayHandle to be wrapped.
bool ComputeFiniteScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff) override
Computes the range for each component of an array, the length of ranges must be two times the number ...
bool ComputeScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff) override
Computes the range for each component of an array, the length of ranges must be two times the number ...
@ value
Definition: vtkX3D.h:220
@ range
Definition: vtkX3D.h:238
int vtkIdType
Definition: vtkType.h:315
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)