VTK  9.5.20251114
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
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
70
71public:
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
96 ValueType GetValue(vtkIdType valueIdx) const;
97 void SetValue(vtkIdType valueIdx, ValueType value);
98 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
99 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
100 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
101 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
102
103protected:
105 ~vtkmDataArray() override;
106
109 using Superclass::ComputeScalarRange;
111 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
112 using Superclass::ComputeVectorRange;
114 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
115 using Superclass::ComputeFiniteScalarRange;
117 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
118 using Superclass::ComputeFiniteVectorRange;
120 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
121
123 bool AllocateTuples(vtkIdType numberOfTuples);
124 bool ReallocateTuples(vtkIdType numberOfTuples);
125
126private:
127 // To access concept methods
128 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
131 template <typename ArrayHandleType>
133 template <typename ArrayHandleType>
135
136 mutable std::unique_ptr<fromvtkm::ArrayHandleHelperBase<T>> Helper;
137
138 mutable std::mutex Mutex;
139
140 vtkmDataArray(const vtkmDataArray&) = delete;
141 void operator=(const vtkmDataArray&) = delete;
142};
143
144// Declare vtkArrayDownCast implementations for vtkmDataArray:
146
147//=============================================================================
148template <typename T, typename S>
149inline vtkmDataArray<typename viskores::VecTraits<T>::BaseComponentType>* make_vtkmDataArray(
150 const viskores::cont::ArrayHandle<T, S>& ah)
151{
153 ret->SetVtkmArrayHandle(ah);
154 return ret;
155}
156
157//=============================================================================
158template <typename TCast, typename TReal, typename S>
160 const viskores::cont::ArrayHandle<TCast, viskores::cont::StorageTagCast<TReal, S>>& ah)
161{
163 ret->SetVtkmArrayHandle(ah);
164 return ret;
165}
166
167//=============================================================================
168#ifndef vtkmDataArray_cxx
169extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
170extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
171extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
172extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
173extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
174extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
175extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
176extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
177extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
178extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
179extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
180extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
181extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
182#endif // vtkmDataArray_cxx
183
184VTK_ABI_NAMESPACE_END
185#endif // vtkmDataArray_h
186
187#include "vtkmlib/vtkmDataArray.hxx"
188
189// VTK-HeaderTest-Exclude: vtkmDataArray.h
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
Base interface for all typed vtkDataArray subclasses.
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)
~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
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:367
@ VTKM_DATA_ARRAY
Definition vtkType.h:86
vtkmDataArray< typename viskores::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const viskores::cont::ArrayHandle< T, S > &ah)