VTK  9.1.0
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 __VTK_WRAP__
21#ifndef VTK_WRAPPING_CXX
22
23#ifndef vtkmDataArray_h
24#define vtkmDataArray_h
25
26#include "vtkAcceleratorsVTKmCoreModule.h" // For export macro
27#include "vtkGenericDataArray.h"
28#include "vtkmConfigCore.h" // For template export
29
30#include <vtkm/List.h> // For vtkm::List
31#include <vtkm/VecFromPortal.h> // For vtkm::VecFromPortal
32#include <vtkm/VecTraits.h> // For vtkm::VecTraits
33#include <vtkm/cont/ArrayHandle.h> // For vtkm::cont::ArrayHandle
34#include <vtkm/cont/UnknownArrayHandle.h> // For vtkm::cont::UnknownArrayHandle
35
36#include <memory> // For unique_ptr
37
38namespace internal
39{
40
41template <typename T>
43
44} // internal
45
46template <typename T>
47class vtkmDataArray : public vtkGenericDataArray<vtkmDataArray<T>, T>
48{
49 static_assert(std::is_arithmetic<T>::value, "T must be an integral or floating-point type");
50
52
53public:
56
57 using typename Superclass::ValueType;
58
59 using VtkmTypesList = vtkm::List<T, vtkm::Vec<T, 2>, vtkm::Vec<T, 3>, vtkm::Vec<T, 4>,
60 vtkm::VecFromPortal<typename vtkm::cont::ArrayHandle<T>::WritePortalType>>;
61
62 static vtkmDataArray* New();
63
64 template <typename V, typename S>
65 void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle<V, S>& ah);
66
67 vtkm::cont::UnknownArrayHandle GetVtkmUnknownArrayHandle() const;
68
70 ValueType GetValue(vtkIdType valueIdx) const;
72 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;
73 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple);
74 ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const;
75 void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value);
76
77protected:
79 ~vtkmDataArray() override;
80
82 bool AllocateTuples(vtkIdType numTuples);
83 bool ReallocateTuples(vtkIdType numTuples);
84
85private:
86 vtkmDataArray(const vtkmDataArray&) = delete;
87 void operator=(const vtkmDataArray&) = delete;
88
89 // To access AllocateTuples and ReallocateTuples
90 friend Superclass;
91
92 std::unique_ptr<internal::ArrayHandleWrapperBase<T>> VtkmArray;
93};
94
95//=============================================================================
96template <typename T, typename S>
98 const vtkm::cont::ArrayHandle<T, S>& ah)
99{
101 ret->SetVtkmArrayHandle(ah);
102 return ret;
103}
104
105//=============================================================================
106#ifndef vtkmDataArray_cxx
107extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<char>;
108extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<double>;
109extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<float>;
110extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<int>;
111extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long>;
112extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<long long>;
113extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<short>;
114extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<signed char>;
115extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned char>;
116extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned int>;
117extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long>;
118extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned long long>;
119extern template class VTKACCELERATORSVTKMCORE_TEMPLATE_EXPORT vtkmDataArray<unsigned short>;
120#endif // vtkmDataArray_cxx
121
122#endif // vtkmDataArray_h
123
124#include "vtkmlib/vtkmDataArray.hxx"
125
126#endif
127#endif
128// VTK-HeaderTest-Exclude: vtkmDataArray.h
Base interface for all typed vtkDataArray subclasses.
abstract base class for most VTK objects
Definition: vtkObject.h:73
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
void SetVtkmArrayHandle(const vtkm::cont::ArrayHandle< V, S > &ah)
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
static vtkmDataArray * New()
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
bool ReallocateTuples(vtkIdType numTuples)
vtkm::List< T, vtkm::Vec< T, 2 >, vtkm::Vec< T, 3 >, vtkm::Vec< T, 4 >, vtkm::VecFromPortal< typename vtkm::cont::ArrayHandle< T >::WritePortalType > > VtkmTypesList
Definition: vtkmDataArray.h:60
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
@ value
Definition: vtkX3D.h:226
int vtkIdType
Definition: vtkType.h:332
vtkmDataArray< typename vtkm::VecTraits< T >::BaseComponentType > * make_vtkmDataArray(const vtkm::cont::ArrayHandle< T, S > &ah)
Definition: vtkmDataArray.h:97