VTK  9.3.0
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
42namespace internal
43{
44VTK_ABI_NAMESPACE_BEGIN
45
46template <typename T>
48
49VTK_ABI_NAMESPACE_END
50} // internal
51
52VTK_ABI_NAMESPACE_BEGIN
53template <typename T>
54class 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
60 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
61
62public:
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
76protected:
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
95private:
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//=============================================================================
116template <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
127extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
128extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
129extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
130extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
131extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
132extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
133extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
134extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
135extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
136extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
137extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
138extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
139extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
140#endif // vtkmDataArray_cxx
141
142VTK_ABI_NAMESPACE_END
143#endif // vtkmDataArray_h
144
145#include "vtkmlib/vtkmDataArray.hxx"
146
147// VTK-HeaderTest-Exclude: vtkmDataArray.h
Abstract superclass for all arrays.
Base interface for all typed vtkDataArray subclasses.
Wraps a VTK-m ArrayHandle inside a sub-class of vtkGenericDataArray.
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
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 ...
static vtkmDataArray * New()
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 ...
int vtkIdType
Definition vtkType.h:315
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)