VTK  9.5.20250807
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
41namespace fromvtkm
42{
43VTK_ABI_NAMESPACE_BEGIN
44
45template <typename T>
47
48template <typename T>
50
51VTK_ABI_NAMESPACE_END
52} // fromvtkm
53
54VTK_ABI_NAMESPACE_BEGIN
55template <typename T>
56class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
57{
58 static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
59
62 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
63
64public:
65 using typename Superclass::ValueType;
66
67 static vtkmDataArray* New();
68
71 void SetVtkmArrayHandle(const viskores::cont::UnknownArrayHandle& ah);
72
75 viskores::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
76
80 void* GetVoidPointer(vtkIdType valueIdx) override;
81 void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
83
85 ValueType GetValue(vtkIdType valueIdx) const;
86 void SetValue(vtkIdType valueIdx, ValueType value);
87 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
88 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
89 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
90 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
91
92protected:
94 ~vtkmDataArray() override;
95
98 using Superclass::ComputeScalarRange;
100 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
101 using Superclass::ComputeVectorRange;
103 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
104 using Superclass::ComputeFiniteScalarRange;
106 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
107 using Superclass::ComputeFiniteVectorRange;
109 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff) override;
110
112 bool AllocateTuples(vtkIdType numberOfTuples);
113 bool ReallocateTuples(vtkIdType numberOfTuples);
114
115private:
116 // To access concept methods
117 friend Superclass;
119
120 mutable std::unique_ptr<fromvtkm::ArrayHandleHelperBase<T>> Helper;
121
122 vtkmDataArray(const vtkmDataArray&) = delete;
123 void operator=(const vtkmDataArray&) = delete;
124};
125
126//=============================================================================
127template <typename T, typename S>
129 const viskores::cont::ArrayHandle<T, S>& ah)
130{
132 ret->SetVtkmArrayHandle(ah);
133 return ret;
134}
135
136//=============================================================================
137#ifndef vtkmDataArray_cxx
138extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
139extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
140extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
141extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
142extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
143extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
144extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
145extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
146extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
147extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
148extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
149extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
150extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
151#endif // vtkmDataArray_cxx
152
153VTK_ABI_NAMESPACE_END
154#endif // vtkmDataArray_h
155
156#include "vtkmlib/vtkmDataArray.hxx"
157
158// VTK-HeaderTest-Exclude: vtkmDataArray.h
Abstract superclass for all arrays.
Base interface for all typed vtkDataArray subclasses.
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
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
viskores::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const
Get the underlying ArrayHandle.
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.
int vtkIdType
Definition vtkType.h:332
vtkmDataArray< typename viskores::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const viskores::cont::ArrayHandle< T, S > &ah)