VTK  9.6.20260112
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
27
28#ifndef vtkmDataArray_h
29#define vtkmDataArray_h
30
31#include "vtkAcceleratorsVTKmCoreModule.h" // For export macro
32#include "vtkGenericDataArray.h"
33#include "vtkmConfigCore.h" // For template export
34
35#include <viskores/VecTraits.h> // For viskores::VecTraits
36#include <viskores/cont/ArrayHandle.h> // For viskores::cont::ArrayHandle
37#include <viskores/cont/UnknownArrayHandle.h> // For viskores::cont::UnknownArrayHandle
38
39#include <memory> // For std::unique_ptr<>
40#include <mutex> // For std::mutex
41
42namespace fromvtkm
43{
44VTK_ABI_NAMESPACE_BEGIN
45
46template <typename T>
48
49template <typename T>
51
52template <typename ArrayHandleType>
54
55template <typename ArrayHandleType>
57
58VTK_ABI_NAMESPACE_END
59} // fromvtkm
60
61VTK_ABI_NAMESPACE_BEGIN
62template <typename T>
64 : public vtkGenericDataArray<vtkmDataArray<T>, T, vtkArrayTypes::VTKM_DATA_ARRAY>
65{
66 static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
67
68 using GenericDataArrayType =
70
71public:
73 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
74 using typename Superclass::ArrayTypeTag;
75 using typename Superclass::DataTypeTag;
76 using typename Superclass::ValueType;
77
78 static vtkmDataArray* New();
79
82 void SetVtkmArrayHandle(const viskores::cont::UnknownArrayHandle& ah);
83
86 viskores::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
87
91 void* GetVoidPointer(vtkIdType valueIdx) override;
92 void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
94 void* GetDeviceVoidPointer(vtkIdType valueIdx) override;
96
98 ValueType GetValue(vtkIdType valueIdx) const;
99 void SetValue(vtkIdType valueIdx, ValueType value);
100 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
101 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
102 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
103 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
104
105protected:
107 ~vtkmDataArray() override;
108
111 using Superclass::ComputeScalarRange;
113 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
114 using Superclass::ComputeVectorRange;
116 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
117 using Superclass::ComputeFiniteScalarRange;
119 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
120 using Superclass::ComputeFiniteVectorRange;
122 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
123
125 bool AllocateTuples(vtkIdType numberOfTuples);
126 bool ReallocateTuples(vtkIdType numberOfTuples);
127
128private:
129 // To access concept methods
130 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
133 template <typename ArrayHandleType>
135 template <typename ArrayHandleType>
137
138 mutable std::unique_ptr<fromvtkm::ArrayHandleHelperBase<T>> Helper;
139
140 mutable std::mutex Mutex;
141
142 vtkmDataArray(const vtkmDataArray&) = delete;
143 void operator=(const vtkmDataArray&) = delete;
144};
145
146// Declare vtkArrayDownCast implementations for vtkmDataArray:
148
149//=============================================================================
150template <typename T, typename S>
151inline vtkmDataArray<typename viskores::VecTraits<T>::BaseComponentType>* make_vtkmDataArray(
152 const viskores::cont::ArrayHandle<T, S>& ah)
153{
155 ret->SetVtkmArrayHandle(ah);
156 return ret;
157}
158
159//=============================================================================
160template <typename TCast, typename TReal, typename S>
162 const viskores::cont::ArrayHandle<TCast, viskores::cont::StorageTagCast<TReal, S>>& ah)
163{
165 ret->SetVtkmArrayHandle(ah);
166 return ret;
167}
168
169//=============================================================================
170#ifndef vtkmDataArray_cxx
171extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
172extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
173extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
174extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
175extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
176extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
177extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
178extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
179extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
180extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
181extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
182extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
183extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
184#endif // vtkmDataArray_cxx
185
186VTK_ABI_NAMESPACE_END
187#endif // vtkmDataArray_h
188
189#include "vtkmlib/vtkmDataArray.hxx"
190
191// VTK-HeaderTest-Exclude: vtkmDataArray.h
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
Wraps a Viskores 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)
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
vtkDataArray::MemorySpace GetMemorySpace() override
~vtkmDataArray() override
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
vtkmDataArray< T > SelfType
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()
void * GetDeviceVoidPointer(vtkIdType valueIdx) override
bool AllocateTuples(vtkIdType numberOfTuples)
concept methods for vtkGenericDataArray
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
viskores::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const
Get the underlying ArrayHandle.
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
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)
void SetVtkmArrayHandle(const viskores::cont::UnknownArrayHandle &ah)
Set the Viskores ArrayHandle to be wrapped.
#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT)
Same as vtkArrayDownCast_FastCastMacro, but treats ArrayT as a single-parameter template (the paramet...
int vtkIdType
Definition vtkType.h:368
@ VTKM_DATA_ARRAY
Definition vtkType.h:86
vtkmDataArray< typename viskores::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const viskores::cont::ArrayHandle< T, S > &ah)