VTK-m  1.8
ArrayRangeCompute.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_ArrayRangeCompute_h
11 #define vtk_m_cont_ArrayRangeCompute_h
12 
13 #include <vtkm/Range.h>
14 #include <vtkm/VecTraits.h>
15 
16 #include <vtkm/cont/ArrayHandle.h>
28 
29 namespace vtkm
30 {
31 namespace cont
32 {
33 
55 
57  const vtkm::cont::UnknownArrayHandle& array,
58  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny{});
59 
60 #define VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(T, Storage) \
61  VTKM_CONT_EXPORT \
62  VTKM_CONT \
63  vtkm::cont::ArrayHandle<vtkm::Range> ArrayRangeCompute( \
64  const vtkm::cont::ArrayHandle<T, Storage>& input, \
65  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny())
66 #define VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(T, N, Storage) \
67  VTKM_CONT_EXPORT \
68  VTKM_CONT \
69  vtkm::cont::ArrayHandle<vtkm::Range> ArrayRangeCompute( \
70  const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, Storage>& input, \
71  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny())
72 
73 #define VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_SCALAR_T(Storage) \
74  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Int8, Storage); \
75  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::UInt8, Storage); \
76  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Int16, Storage); \
77  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::UInt16, Storage); \
78  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Int32, Storage); \
79  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::UInt32, Storage); \
80  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Int64, Storage); \
81  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::UInt64, Storage); \
82  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Float32, Storage); \
83  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(vtkm::Float64, Storage); \
84  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(char, Storage); \
85  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(signed VTKM_UNUSED_INT_TYPE, Storage); \
86  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T(unsigned VTKM_UNUSED_INT_TYPE, Storage)
87 
88 #define VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(N, Storage) \
89  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Int8, N, Storage); \
90  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt8, N, Storage); \
91  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Int16, N, Storage); \
92  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt16, N, Storage); \
93  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Int32, N, Storage); \
94  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt32, N, Storage); \
95  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Int64, N, Storage); \
96  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::UInt64, N, Storage); \
97  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float32, N, Storage); \
98  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float64, N, Storage); \
99  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(char, N, Storage); \
100  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(signed VTKM_UNUSED_INT_TYPE, N, Storage); \
101  VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(unsigned VTKM_UNUSED_INT_TYPE, N, Storage)
102 
103 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_SCALAR_T(vtkm::cont::StorageTagBasic);
104 
105 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(2, vtkm::cont::StorageTagBasic);
106 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(3, vtkm::cont::StorageTagBasic);
107 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(4, vtkm::cont::StorageTagBasic);
108 
109 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(2, vtkm::cont::StorageTagSOA);
110 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(3, vtkm::cont::StorageTagSOA);
111 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC(4, vtkm::cont::StorageTagSOA);
112 
113 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_SCALAR_T(vtkm::cont::StorageTagStride);
114 
115 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float32, 3, vtkm::cont::StorageTagXGCCoordinates);
116 VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC(vtkm::Float64, 3, vtkm::cont::StorageTagXGCCoordinates);
117 
118 #undef VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_T
119 #undef VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_VEC
120 #undef VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_SCALAR_T
121 #undef VTK_M_ARRAY_RANGE_COMPUTE_EXPORT_ALL_VEC
122 
126  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny());
127 
128 // Implementation of cartesian products
129 template <typename T, typename ST1, typename ST2, typename ST3>
133  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny())
134 {
136  result.Allocate(3);
137 
138  vtkm::cont::ArrayHandle<vtkm::Range> componentRangeArray;
139  vtkm::Range componentRange;
140 
144  input = input_;
145  vtkm::cont::ArrayHandle<T, ST1> firstArray = input.GetFirstArray();
146  componentRangeArray = vtkm::cont::ArrayRangeCompute(firstArray, device);
147  componentRange = componentRangeArray.ReadPortal().Get(0);
148  result.WritePortal().Set(0, componentRange);
149 
150  vtkm::cont::ArrayHandle<T, ST2> secondArray = input.GetSecondArray();
151  componentRangeArray = vtkm::cont::ArrayRangeCompute(secondArray, device);
152  componentRange = componentRangeArray.ReadPortal().Get(0);
153  result.WritePortal().Set(1, componentRange);
154 
155  vtkm::cont::ArrayHandle<T, ST3> thirdArray = input.GetThirdArray();
156  componentRangeArray = vtkm::cont::ArrayRangeCompute(thirdArray, device);
157  componentRange = componentRangeArray.ReadPortal().Get(0);
158  result.WritePortal().Set(2, componentRange);
159 
160  return result;
161 }
162 
163 // Implementation of constant arrays
164 template <typename T>
167  vtkm::cont::DeviceAdapterId vtkmNotUsed(device) = vtkm::cont::DeviceAdapterTagAny{})
168 {
169  using Traits = vtkm::VecTraits<T>;
170  const T value = vtkm::cont::ArrayHandleConstant<T>(input).GetValue();
171  vtkm::IdComponent numComponents = Traits::GetNumberOfComponents(value);
173  result.Allocate(numComponents);
174  auto portal = result.WritePortal();
175  for (vtkm::IdComponent cIndex = 0; cIndex < numComponents; ++cIndex)
176  {
177  auto component = Traits::GetComponent(value, cIndex);
178  portal.Set(cIndex, vtkm::Range(component, component));
179  }
180  return result;
181 }
182 
183 // Implementation of counting arrays
184 template <typename T>
187  vtkm::cont::DeviceAdapterId vtkmNotUsed(device) = vtkm::cont::DeviceAdapterTagAny{})
188 {
189  using Traits = vtkm::VecTraits<T>;
191  result.Allocate(Traits::NUM_COMPONENTS);
192  auto portal = result.WritePortal();
193  if (portal.GetNumberOfValues() > 0)
194  {
195  T first = input.ReadPortal().Get(0);
196  T last = input.ReadPortal().Get(input.GetNumberOfValues() - 1);
197  for (vtkm::IdComponent cIndex = 0; cIndex < Traits::NUM_COMPONENTS; ++cIndex)
198  {
199  auto firstComponent = Traits::GetComponent(first, cIndex);
200  auto lastComponent = Traits::GetComponent(last, cIndex);
201  portal.Set(cIndex,
202  vtkm::Range(vtkm::Min(firstComponent, lastComponent),
203  vtkm::Max(firstComponent, lastComponent)));
204  }
205  }
206  else
207  {
208  // Array is empty
209  for (vtkm::IdComponent cIndex = 0; cIndex < Traits::NUM_COMPONENTS; ++cIndex)
210  {
211  portal.Set(cIndex, vtkm::Range{});
212  }
213  }
214  return result;
215 }
216 
217 // Implementation of index arrays
220  vtkm::cont::DeviceAdapterId device = vtkm::cont::DeviceAdapterTagAny{});
222 
223 VTKM_CONT_EXPORT void ThrowArrayRangeComputeFailed();
224 }
225 } // namespace vtkm::cont
226 
227 #endif //vtk_m_cont_ArrayRangeCompute_h
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:497
vtkm::cont::ArrayHandle< vtkm::Range >
ArrayHandle.h
ArrayHandleStride.h
vtkm
VTKM_NO_DEPRECATED_VIRTUAL.
Definition: Algorithms.h:18
vtkm::cont::ArrayHandleCartesianProduct::GetThirdArray
VTKM_CONT ThirdHandleType GetThirdArray() const
Definition: ArrayHandleCartesianProduct.h:357
vtkm::cont::StorageTagStride
Definition: ArrayHandleStride.h:148
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:514
vtkm::cont::ArrayHandleConstant::GetValue
VTKM_CONT T GetValue() const
Returns the constant value stored in this array.
Definition: ArrayHandleConstant.h:81
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::StorageTagSOA
Definition: ArrayHandleSOA.h:124
ArrayHandleCompositeVector.h
DeviceAdapterTag.h
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:397
vtkm::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:311
vtkm::cont::StorageTagCartesianProduct
Definition: ArrayHandleCartesianProduct.h:157
ArrayHandleConstant.h
ArrayHandleUniformPointCoordinates.h
ArrayHandleSOA.h
UnknownArrayHandle.h
ArrayHandleIndex.h
vtkm::cont::ThrowArrayRangeComputeFailed
VTKM_CONT_EXPORT void ThrowArrayRangeComputeFailed()
vtkm::cont::StorageTagUniformPoints
Definition: ArrayHandleUniformPointCoordinates.h:22
vtkm::cont::ArrayHandleCartesianProduct::GetSecondArray
VTKM_CONT SecondHandleType GetSecondArray() const
Definition: ArrayHandleCartesianProduct.h:353
Range.h
ArrayHandleCartesianProduct.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::StorageTagXGCCoordinates
Definition: ArrayHandleXGCCoordinates.h:136
vtkm::cont::ArrayHandle::WritePortal
VTKM_CONT WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:487
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::cont::ArrayHandleCartesianProduct::GetFirstArray
VTKM_CONT FirstHandleType GetFirstArray() const
Definition: ArrayHandleCartesianProduct.h:349
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::Vec< vtkm::FloatDefault, 3 >
ArrayHandleCounting.h
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::cont::StorageTagBasic
A tag for the basic implementation of a Storage object.
Definition: ArrayHandle.h:46
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::VecTraits< T >
vtkm::cont::ArrayRangeCompute
VTKM_CONT_EXPORT vtkm::cont::ArrayHandle< vtkm::Range > ArrayRangeCompute(const vtkm::cont::UnknownArrayHandle &array, vtkm::cont::DeviceAdapterId device=vtkm::cont::DeviceAdapterTagAny{})
Compute the range of the data in an array handle.
ArrayHandleXGCCoordinates.h
VecTraits.h
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31