VTK-m  2.2
ArrayHandleIndex.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 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_ArrayHandleIndex_h
11 #define vtk_m_cont_ArrayHandleIndex_h
12 
13 #include <vtkm/Range.h>
15 
16 namespace vtkm
17 {
18 
19 namespace internal
20 {
21 
22 struct VTKM_ALWAYS_EXPORT IndexFunctor
23 {
24  VTKM_EXEC_CONT vtkm::Id operator()(vtkm::Id index) const { return index; }
25 };
26 
27 } // namespace internal
28 
29 namespace cont
30 {
31 
33 {
34 };
35 
36 namespace internal
37 {
38 
39 using StorageTagIndexSuperclass =
41 
42 template <>
43 struct Storage<vtkm::Id, vtkm::cont::StorageTagIndex> : Storage<vtkm::Id, StorageTagIndexSuperclass>
44 {
45 };
46 
47 } // namespace internal
48 
55 class ArrayHandleIndex : public vtkm::cont::ArrayHandle<vtkm::Id, StorageTagIndex>
56 {
57 public:
60 
62  VTKM_CONT
64  : Superclass(
65  internal::FunctorToArrayHandleImplicitBuffers(vtkm::internal::IndexFunctor{}, length))
66  {
67  }
68 };
69 
73 {
74  return vtkm::cont::ArrayHandleIndex(length);
75 }
76 
77 namespace internal
78 {
79 
80 template <typename S>
81 struct ArrayRangeComputeImpl;
82 
83 template <>
84 struct VTKM_CONT_EXPORT ArrayRangeComputeImpl<vtkm::cont::StorageTagIndex>
85 {
88  const vtkm::cont::ArrayHandle<vtkm::UInt8>& maskArray,
89  bool computeFiniteRange,
90  vtkm::cont::DeviceAdapterId device) const;
91 };
92 
93 template <typename S>
94 struct ArrayRangeComputeMagnitudeImpl;
95 
96 template <>
97 struct VTKM_CONT_EXPORT ArrayRangeComputeMagnitudeImpl<vtkm::cont::StorageTagIndex>
98 {
99  VTKM_CONT vtkm::Range operator()(
101  const vtkm::cont::ArrayHandle<vtkm::UInt8>& maskArray,
102  bool computeFiniteRange,
103  vtkm::cont::DeviceAdapterId device) const
104  {
105  auto rangeAH = ArrayRangeComputeImpl<vtkm::cont::StorageTagIndex>{}(
106  input, maskArray, computeFiniteRange, device);
107  return rangeAH.ReadPortal().Get(0);
108  }
109 };
110 
111 } // namespace internal
112 
113 }
114 } // namespace vtkm::cont
115 
116 //=============================================================================
117 // Specializations of serialization related classes
119 
120 namespace vtkm
121 {
122 namespace cont
123 {
124 
125 template <>
126 struct SerializableTypeString<vtkm::cont::ArrayHandleIndex>
127 {
128  static VTKM_CONT std::string Get() { return "AH_Index"; }
129 };
130 
131 template <>
132 struct SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagIndex>>
133  : SerializableTypeString<vtkm::cont::ArrayHandleIndex>
134 {
135 };
136 }
137 } // vtkm::cont
138 
139 namespace mangled_diy_namespace
140 {
141 
142 template <>
143 struct Serialization<vtkm::cont::ArrayHandleIndex>
144 {
145 private:
147 
148 public:
149  static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
150  {
151  vtkmdiy::save(bb, obj.GetNumberOfValues());
152  }
153 
154  static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
155  {
156  vtkm::Id length = 0;
157  vtkmdiy::load(bb, length);
158 
159  obj = vtkm::cont::ArrayHandleIndex(length);
160  }
161 };
162 
163 template <>
164 struct Serialization<vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagIndex>>
165  : Serialization<vtkm::cont::ArrayHandleIndex>
166 {
167 };
168 } // diy
170 
171 #endif //vtk_m_cont_ArrayHandleIndex_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
VTKM_ARRAY_HANDLE_SUBCLASS_NT
#define VTKM_ARRAY_HANDLE_SUBCLASS_NT(classname, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:266
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::cont::ArrayHandleIndex::Superclass
vtkm::cont::detail::GetTypeInParentheses< void(vtkm::cont::ArrayHandle< vtkm::Id, StorageTagIndex >) >::type Superclass
Definition: ArrayHandleIndex.h:59
vtkm::cont::StorageTagIndex
Definition: ArrayHandleIndex.h:32
mangled_diy_namespace
Definition: Particle.h:351
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
Range.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandleIndex::ArrayHandleIndex
ArrayHandleIndex(vtkm::Id length)
Construct an index array containing values from 0 to length - 1.
Definition: ArrayHandleIndex.h:63
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::ArrayHandleImplicit::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleImplicit.h:189
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
vtkm::cont::make_ArrayHandleIndex
vtkm::cont::ArrayHandleIndex make_ArrayHandleIndex(vtkm::Id length)
A convenience function for creating an ArrayHandleIndex.
Definition: ArrayHandleIndex.h:72
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
ArrayHandleImplicit.h
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:55
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31