VTK  9.4.20241103
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 fromvtkm
43{
44VTK_ABI_NAMESPACE_BEGIN
45
46template <typename T>
48
49template <typename T>
51
52VTK_ABI_NAMESPACE_END
53} // fromvtkm
54
55VTK_ABI_NAMESPACE_BEGIN
56template <typename T>
57class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
58{
59 static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
60
63 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
64
65public:
66 using typename Superclass::ValueType;
67
68 static vtkmDataArray* New();
69
72 void SetVtkmArrayHandle(const vtkm::cont::UnknownArrayHandle& ah);
73
76 vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
77
81 void* GetVoidPointer(vtkIdType valueIdx) override;
82 void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
84
86 ValueType GetValue(vtkIdType valueIdx) const;
87 void SetValue(vtkIdType valueIdx, ValueType value);
88 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
89 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
90 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
91 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
92
93protected:
95 ~vtkmDataArray() override;
96
99 using Superclass::ComputeScalarRange;
101 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
102 using Superclass::ComputeVectorRange;
104 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
105 using Superclass::ComputeFiniteScalarRange;
107 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
108 using Superclass::ComputeFiniteVectorRange;
110 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
111
113 bool AllocateTuples(vtkIdType numberOfTuples);
114 bool ReallocateTuples(vtkIdType numberOfTuples);
115
116private:
117 // To access concept methods
118 friend Superclass;
120
121 mutable std::unique_ptr<fromvtkm::ArrayHandleHelperBase<T>> Helper;
122
123 vtkmDataArray(const vtkmDataArray&) = delete;
124 void operator=(const vtkmDataArray&) = delete;
125};
126
127//=============================================================================
128template <typename T, typename S>
130 const vtkm::cont::ArrayHandle<T, S>& ah)
131{
133 ret->SetVtkmArrayHandle(ah);
134 return ret;
135}
136
137//=============================================================================
138#ifndef vtkmDataArray_cxx
139extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
140extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
141extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
142extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
143extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
144extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
145extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
146extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
147extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
148extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
149extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
150extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
151extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
152#endif // vtkmDataArray_cxx
153
154VTK_ABI_NAMESPACE_END
155#endif // vtkmDataArray_h
156
157#include "vtkmlib/vtkmDataArray.hxx"
158
159// 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.
void * GetVoidPointer(vtkIdType valueIdx) override
ValueType GetValue(vtkIdType valueIdx) const
Support methods for vtkGenericDataArray.
void * WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override
bool ComputeFiniteVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff) override
Returns true if the range was computed.
void SetValue(vtkIdType valueIdx, ValueType value)
vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const
Get the underlying ArrayHandle.
void SetVtkmArrayHandle(const vtkm::cont::UnknownArrayHandle &ah)
Set the VTK-m ArrayHandle to be wrapped.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
~vtkmDataArray() override
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
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 AllocateTuples(vtkIdType numberOfTuples)
concept methods for vtkGenericDataArray
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
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 ...
bool ReallocateTuples(vtkIdType numberOfTuples)
int vtkIdType
Definition vtkType.h:315
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)