VTK  9.1.0
vtkDataArrayRange.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkDataArrayRange.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15
26#ifndef vtkDataArrayRange_h
27#define vtkDataArrayRange_h
28
30#include "vtkDataArray.h"
31#include "vtkDataArrayMeta.h"
36#include "vtkMeta.h"
37#include "vtkSmartPointer.h"
38
39#include <cassert>
40#include <iterator>
41#include <type_traits>
42
97
98namespace vtk
99{
100
101namespace detail
102{
103
104// Internal detail: This utility is not directly needed by users of
105// DataArrayRange.
106//
107// These classes are used to detect when specializations exist for a given
108// array type. They are necessary because given:
109//
110// template <typename ArrayType> class SomeTemplateClass;
111// template <typename T> class SomeTemplateClass<vtkAOSDataArrayTemplate<T>>;
112//
113// SomeTemplateClass<vtkFloatArray> will pick the generic version, as ArrayType
114// is a better match than vtkAOSDataArrayTemplate<T>. This class works around
115// that by using Declare[Tuple|Value]RangeSpecialization functions that map an
116// input ArrayTypePtr and tuple size to a specific version of the appropriate
117// Range.
118template <typename ArrayTypePtr, ComponentIdType TupleSize>
120{
121private:
122 // Allow this to work with vtkNew, vtkSmartPointer, etc.
123 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
124
125 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
126 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
127
128public:
129 using type =
130 typename std::decay<decltype(vtk::detail::DeclareTupleRangeSpecialization<ArrayType, TupleSize>(
131 std::declval<ArrayType*>()))>::type;
132};
133
134template <typename ArrayTypePtr, ComponentIdType TupleSize>
136{
137private:
138 // Allow this to work with vtkNew, vtkSmartPointer, etc.
139 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
140
141 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
142 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
143
144public:
145 using type =
146 typename std::remove_reference<decltype(vtk::detail::DeclareValueRangeSpecialization<ArrayType,
147 TupleSize>(std::declval<ArrayType*>()))>::type;
148};
149
150} // end namespace detail
151
256template <ComponentIdType TupleSize = detail::DynamicTupleSize,
257 typename ArrayTypePtr = vtkDataArray*>
258VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr& array, TupleIdType start = -1,
260{
261 // Lookup specializations:
263
264 assert(array);
265
266 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfTuples() : end);
267}
268
366template <ComponentIdType TupleSize = detail::DynamicTupleSize,
367 typename ArrayTypePtr = vtkDataArray*>
368VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr& array, ValueIdType start = -1,
370{
372
373 assert(array);
374
375 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfValues() : end);
376}
377
378} // end namespace vtk
379
381
382#endif // vtkDataArrayRange_h
383
384// VTK-HeaderTest-Exclude: vtkDataArrayRange.h
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
static constexpr ComponentIdType DynamicTupleSize
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
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.
vtkIdType ValueIdType
vtkIdType TupleIdType
int ComponentIdType
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.
typename std::decay< decltype(vtk::detail::DeclareTupleRangeSpecialization< ArrayType, TupleSize >(std::declval< ArrayType * >()))>::type type
typename std::remove_reference< decltype(vtk::detail::DeclareValueRangeSpecialization< ArrayType, TupleSize >(std::declval< ArrayType * >()))>::type type
This file contains a variety of metaprogramming constructs for working with vtkDataArrays.
#define VTK_ITER_OPTIMIZE_START
#define VTK_ITER_INLINE
#define VTK_ITER_OPTIMIZE_END
This file contains a variety of metaprogramming constructs for working with vtk types.