VTK: Common/Core/vtkDataArrayRange.h Source File

| VTK 9.3.1

vtkDataArrayRange.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3
14 #ifndef vtkDataArrayRange_h
15 #define vtkDataArrayRange_h
16
17 #include "vtkAOSDataArrayTemplate.h"
18 #include "vtkDataArray.h"
19 #include "vtkDataArrayMeta.h"
20 #include "vtkDataArrayTupleRange_AOS.h"
21 #include "vtkDataArrayTupleRange_Generic.h"
22 #include "vtkDataArrayValueRange_AOS.h"
23 #include "vtkDataArrayValueRange_Generic.h"
24 #include "vtkMeta.h"
25 #include "vtkSmartPointer.h"
26
27 #include <cassert>
28 #include <iterator>
29 #include <type_traits>
30
84 VTK_ITER_OPTIMIZE_START
85
86 namespace vtk
87 {
88 namespace detail
89 {
90 VTK_ABI_NAMESPACE_BEGIN
91
92 // Internal detail: This utility is not directly needed by users of
93 // DataArrayRange.
94 //
95 // These classes are used to detect when specializations exist for a given
96 // array type. They are necessary because given:
97 //
98 // template <typename ArrayType> class SomeTemplateClass;
99 // template <typename T> class SomeTemplateClass<vtkAOSDataArrayTemplate<T>>;
100 //
101 // SomeTemplateClass<vtkFloatArray> will pick the generic version, as ArrayType
102 // is a better match than vtkAOSDataArrayTemplate<T>. This class works around
103 // that by using Declare[Tuple|Value]RangeSpecialization functions that map an
104 // input ArrayTypePtr and tuple size to a specific version of the appropriate
105 // Range.
106 template <typename ArrayTypePtr, ComponentIdType TupleSize>
107 struct SelectTupleRange
108 {
109 private:
110 // Allow this to work with vtkNew, vtkSmartPointer, etc.
111 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
112
113 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
114 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
115
116 public:
117 using type =
118 typename std::decay<decltype(vtk::detail::DeclareTupleRangeSpecialization<ArrayType, TupleSize>(
119 std::declval<ArrayType*>()))>::type;
120 };
121
122 template <typename ArrayTypePtr, ComponentIdType TupleSize>
123 struct SelectValueRange
124 {
125 private:
126 // Allow this to work with vtkNew, vtkSmartPointer, etc.
127 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
128
129 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
130 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
131
132 public:
133 using type =
134 typename std::remove_reference<decltype(vtk::detail::DeclareValueRangeSpecialization<ArrayType,
135 TupleSize>(std::declval<ArrayType*>()))>::type;
136 };
137
138 VTK_ABI_NAMESPACE_END
139 } // end namespace detail
140
245 VTK_ABI_NAMESPACE_BEGIN
246 template <ComponentIdType TupleSize = detail::DynamicTupleSize,
247 typename ArrayTypePtr = vtkDataArray*>
248 VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr& array, TupleIdType start = -1,
249 TupleIdType end = -1) -> typename detail::SelectTupleRange<ArrayTypePtr, TupleSize>::type
250 {
251 // Lookup specializations:
252 using RangeType = typename detail::SelectTupleRange<ArrayTypePtr, TupleSize>::type;
253
254 assert(array);
255
256 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfTuples() : end);
257 }
258
356 template <ComponentIdType TupleSize = detail::DynamicTupleSize,
357 typename ArrayTypePtr = vtkDataArray*>
358 VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr& array, ValueIdType start = -1,
359 ValueIdType end = -1) -> typename detail::SelectValueRange<ArrayTypePtr, TupleSize>::type
360 {
361 using RangeType = typename detail::SelectValueRange<ArrayTypePtr, TupleSize>::type;
362
363 assert(array);
364
365 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfValues() : end);
366 }
367
368 VTK_ABI_NAMESPACE_END
369 } // end namespace vtk
370
371 VTK_ITER_OPTIMIZE_END
372
373 #endif // vtkDataArrayRange_h
374
375 // VTK-HeaderTest-Exclude: vtkDataArrayRange.h
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
detail
Definition: vtkCellTreeLocator.h:59
vtk::detail::DeclareValueRangeSpecialization
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
vtk::detail::DynamicTupleSize
static constexpr ComponentIdType DynamicTupleSize
Definition: vtkDataArrayMeta.h:70
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition: vtkSMPThreadLocalAPI.h:30
vtk::DataArrayTupleRange
VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr &array, TupleIdType start=-1, TupleIdType end=-1) -> typename detail::SelectTupleRange< ArrayTypePtr, TupleSize >::type
Generate an stl and for-range compatible range of tuple iterators from a vtkDataArray.
Definition: vtkDataArrayRange.h:248
vtk::ValueIdType
vtkIdType ValueIdType
Definition: vtkDataArrayMeta.h:61
vtk::TupleIdType
vtkIdType TupleIdType
Definition: vtkDataArrayMeta.h:60
vtk::ComponentIdType
int ComponentIdType
Definition: vtkDataArrayMeta.h:59
vtk::DataArrayValueRange
VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr &array, ValueIdType start=-1, ValueIdType end=-1) -> typename detail::SelectValueRange< ArrayTypePtr, TupleSize >::type
Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray.
Definition: vtkDataArrayRange.h:358
vtk::detail::IsValidTupleSize
Definition: vtkDataArrayMeta.h:86
vtk::detail::IsVtkDataArray
Definition: vtkDataArrayMeta.h:76
vtk::detail::SelectTupleRange
Definition: vtkDataArrayRange.h:108
vtk::detail::SelectTupleRange::type
typename std::decay< decltype(vtk::detail::DeclareTupleRangeSpecialization< ArrayType, TupleSize >(std::declval< ArrayType * >()))>::type type
Definition: vtkDataArrayRange.h:119
vtk::detail::SelectValueRange
Definition: vtkDataArrayRange.h:124
vtk::detail::SelectValueRange::type
typename std::remove_reference< decltype(vtk::detail::DeclareValueRangeSpecialization< ArrayType, TupleSize >(std::declval< ArrayType * >()))>::type type
Definition: vtkDataArrayRange.h:135
vtk::detail::StripPointers::type
T type
Definition: vtkMeta.h:39
vtkAOSDataArrayTemplate.h
vtkDataArrayMeta.h
This file contains a variety of metaprogramming constructs for working with vtkDataArrays.
VTK_ITER_OPTIMIZE_START
#define VTK_ITER_OPTIMIZE_START
Definition: vtkDataArrayMeta.h:42
VTK_ITER_INLINE
#define VTK_ITER_INLINE
Definition: vtkDataArrayMeta.h:40
VTK_ITER_OPTIMIZE_END
#define VTK_ITER_OPTIMIZE_END
Definition: vtkDataArrayMeta.h:43
vtkDataArrayTupleRange_AOS.h
vtkDataArrayTupleRange_Generic.h
vtkDataArrayValueRange_AOS.h
vtkDataArrayValueRange_Generic.h
vtkDataArray.h
vtkMeta.h
This file contains a variety of metaprogramming constructs for working with vtk types.
vtkSmartPointer.h