VTK  9.2.6
vtkmDataArray.h
Go to the documentation of this file.
1//============================================================================
2// Copyright (c) Kitware, Inc.
3// All rights reserved.
4// See LICENSE.txt for details.
5// This software is distributed WITHOUT ANY WARRANTY; without even
6// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7// PURPOSE. See the above copyright notice for more information.
8//
9// Copyright 2019 Sandia Corporation.
10// Copyright 2019 UT-Battelle, LLC.
11// Copyright 2019 Los Alamos National Security.
12//
13// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
14// the U.S. Government retains certain rights in this software.
15//
16// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17// Laboratory (LANL), the U.S. Government retains certain rights in
18// this software.
19//============================================================================
20#ifndef vtkmDataArray_h
21#define vtkmDataArray_h
22
23#include "vtkAcceleratorsVTKmCoreModule.h" // For export macro
24#include "vtkGenericDataArray.h"
25#include "vtkmConfigCore.h" // For template export
26
27#include <vtkm/List.h> // For vtkm::List
28#include <vtkm/VecFromPortal.h> // For vtkm::VecFromPortal
29#include <vtkm/VecTraits.h> // For vtkm::VecTraits
30#include <vtkm/cont/ArrayHandle.h> // For vtkm::cont::ArrayHandle
31#include <vtkm/cont/UnknownArrayHandle.h> // For vtkm::cont::UnknownArrayHandle
32
33#include <memory> // For unique_ptr
34
35namespace internal
36{
37
38template <typename T>
40
41} // internal
42
43template <typename T>
44class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
45{
46 static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
47
48 using GenericDataArrayType = vtkGenericDataArray<vtkmDataArray<T>, T>;
49
50public:
52 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
53
54 using typename Superclass::ValueType;
55
56 using VtkmTypesList = vtkm::List<T, vtkm::Vec<T, 2>, vtkm::Vec<T, 3>, vtkm::Vec<T, 4>,
57 vtkm::VecFromPortal<typename vtkm::cont::ArrayHandle<T>::WritePortalType>>;
58
59 static vtkmDataArray* New();
60
61 template <typename V, typename S>
62 void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle<V, S>& ah);
63
64 vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
65
67 ValueType GetValue(vtkIdType valueIdx) const;
68 void SetValue(vtkIdType valueIdx, ValueType value);
69 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
70 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
71 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
72 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
73
74protected:
76 ~vtkmDataArray() override;
77
79 bool AllocateTuples(vtkIdType numTuples);
80 bool ReallocateTuples(vtkIdType numTuples);
81
82private:
83 vtkmDataArray(const vtkmDataArray&) = delete;
84 void operator=(const vtkmDataArray&) = delete;
85
86 // To access AllocateTuples and ReallocateTuples
87 friend Superclass;
88
89 std::unique_ptr<internal::ArrayHandleWrapperBase<T>> VtkmArray;
90};
91
92//=============================================================================
93template <typename T, typename S>
95 const vtkm::cont::ArrayHandle<T, S>& ah)
96{
98 ret->SetVtkmArrayHandle(ah);
99 return ret;
100}
101
102//=============================================================================
103#ifndef vtkmDataArray_cxx
104extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
105extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
106extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
107extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
108extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
109extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
110extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
111extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
112extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
113extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
114extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
115extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
116extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
117#endif // vtkmDataArray_cxx
118
119#endif // vtkmDataArray_h
120
121#include "vtkmlib/vtkmDataArray.hxx"
122
123// VTK-HeaderTest-Exclude: vtkmDataArray.h
ValueType GetValue(vtkIdType valueIdx) const
concept methods for vtkGenericDataArray
void SetValue(vtkIdType valueIdx, ValueType value)
bool AllocateTuples(vtkIdType numTuples)
concept methods for vtkGenericDataArray
vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
~vtkmDataArray() override
vtkm::List< T, vtkm::Vec< T, 2 >, vtkm::Vec< T, 3 >, vtkm::Vec< T, 4 >, vtkm::VecFromPortal< typename vtkm::cont::ArrayHandle< T >::WritePortalType > > VtkmTypesList
void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle< V, S > &ah)
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
vtkmDataArray< T > SelfType
static vtkmDataArray * New()
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
bool ReallocateTuples(vtkIdType numTuples)
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
int vtkIdType
Definition vtkType.h:332
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)