VTK
Namespaces | Classes | Typedefs | Enumerations | Functions
vtk Namespace Reference

Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate. More...

Namespaces

 atomic
 
 detail
 
 hypertreegrid
 

Classes

class  CompositeDataSetNodeReference
 A reference proxy into a vtkCompositeDataSet, obtained by dereferencing an iterator from the vtk::Range(vtkCompositeDataSet*) overloads. More...
 

Typedefs

using ComponentIdType = int
 
using TupleIdType = vtkIdType
 
using ValueIdType = vtkIdType
 
template<typename ArrayType , typename = detail::EnableIfVtkDataArray<ArrayType>>
using GetAPIType = typename vtkDataArrayAccessor< ArrayType >::APIType
 

Enumerations

enum  CompositeDataSetOptions : unsigned int { CompositeDataSetOptions::None = 0, CompositeDataSetOptions::SkipEmptyNodes = 1 << 1 }
 
enum  DataObjectTreeOptions : unsigned int { DataObjectTreeOptions::None = 0, DataObjectTreeOptions::SkipEmptyNodes = 1 << 1, DataObjectTreeOptions::VisitOnlyLeaves = 1 << 2, DataObjectTreeOptions::TraverseSubTree = 1 << 3 }
 

Functions

template<ComponentIdType TupleSize = detail::DynamicTupleSize, typename ArrayType = vtkDataArray*>
VTK_ITER_INLINE auto DataArrayTupleRange (const ArrayType &array, TupleIdType start=-1, TupleIdType end=-1) -> detail::TupleRange< typename detail::StripPointers< ArrayType >::type, TupleSize >
 Generate an stl and for-range compatible range of tuple iterators from a vtkDataArray. More...
 
template<ComponentIdType TupleSize = detail::DynamicTupleSize, typename ArrayType = vtkDataArray*>
VTK_ITER_INLINE auto DataArrayValueRange (const ArrayType &array, ValueIdType start=-1, ValueIdType end=-1) -> detail::ValueRange< typename detail::StripPointers< ArrayType >::type, TupleSize >
 Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray. More...
 
template<typename IterablePtr , typename... Options>
auto Range (IterablePtr iterable, Options &&...opts) -> typename detail::IterableTraits< typename detail::StripPointers< IterablePtr >::type >::RangeType
 Generate an iterable STL proxy object for a VTK container. More...
 

Detailed Description

Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.

Specialization of value ranges and iterators for vtkAOSDataArrayTemplate.

Generic implementation of value ranges and iterators, suitable for vtkDataArray and all subclasses.

Typedef Documentation

using vtk::ComponentIdType = typedef int

Definition at line 64 of file vtkDataArrayMeta.h.

using vtk::TupleIdType = typedef vtkIdType

Definition at line 65 of file vtkDataArrayMeta.h.

using vtk::ValueIdType = typedef vtkIdType

Definition at line 66 of file vtkDataArrayMeta.h.

template<typename ArrayType , typename = detail::EnableIfVtkDataArray<ArrayType>>
using vtk::GetAPIType = typedef typename vtkDataArrayAccessor<ArrayType>::APIType

Definition at line 166 of file vtkDataArrayMeta.h.

Enumeration Type Documentation

enum vtk::CompositeDataSetOptions : unsigned int
strong
Enumerator
None 
SkipEmptyNodes 

Definition at line 34 of file vtkCompositeDataSetRange.h.

enum vtk::DataObjectTreeOptions : unsigned int
strong
Enumerator
None 
SkipEmptyNodes 
VisitOnlyLeaves 
TraverseSubTree 

Definition at line 34 of file vtkDataObjectTreeRange.h.

Function Documentation

template<ComponentIdType TupleSize = detail::DynamicTupleSize, typename ArrayType = vtkDataArray*>
VTK_ITER_INLINE auto vtk::DataArrayTupleRange ( const ArrayType &  array,
TupleIdType  start = -1,
TupleIdType  end = -1 
) -> detail::TupleRange<typename detail::StripPointers<ArrayType>::type, TupleSize>

Generate an stl and for-range compatible range of tuple iterators from a vtkDataArray.

This function returns a TupleRange object that is compatible with C++11 for-range syntax. As an example usage, consider a function that takes some instance of vtkDataArray (or a subclass) and prints the magnitude of each tuple:

template <typename ArrayType>
void PrintMagnitudes(ArrayType *array)
{
for (const auto& tuple : vtk::DataArrayTupleRange(array))
{
double mag = 0.;
for (const auto& comp : tuple)
{
mag += static_cast<double>(comp) * static_cast<double>(comp));
}
std::cerr << mag < "\n";
}
}

Note that ArrayType is generic in the above function. When vtk::DataArrayTupleRange is given a vtkDataArray pointer, the generated code produces iterators and reference proxies that rely on the vtkDataArray API. However, when a more derived ArrayType is passed in (for example, vtkFloatArray), specialized implementations are used that generate highly optimized code.

Performance can be further improved when the number of components in the array is known. By passing a compile-time-constant integer as a template parameter, e.g. vtk::DataArrayTupleRange<3>(array), specializations are enabled that allow the compiler to perform additional optimizations.

vtk::DataArrayTupleRange takes an additional two arguments that can be used to restrict the range of tuples to [start, end).

There is a compiler definition / CMake option called VTK_DEBUG_RANGE_ITERATORS that enables checks for proper usage of the range/iterator/reference classes. This slow things down significantly, but is useful for diagnosing problems.

In some situations, developers may want to build in Debug mode while still maintaining decent performance for data-heavy computations. For these usecases, and additional CMake option VTK_ALWAYS_OPTIMIZE_ARRAY_ITERATORS may be enabled to force optimization of code using these iterators. This option will force inlining and enable -O3 (or equivalent) optimization level for iterator code when compiling on platforms that support these features. This option has no effect when VTK_DEBUG_RANGE_ITERATORS is enabled.

Note
References obtained through iterators are invalidated when the iterator is modified.
operator[] is disabled for the iterators and tuple reference types, as they cannot be implemented for vtkDataArray without dangling references. These index operations may still be accessible when used with other array classes, but their use is discouraged to ensure portability and any code using them will not compile with VTK_DEBUG_RANGE_ITERATORS defined.

Definition at line 115 of file vtkDataArrayRange.h.

template<ComponentIdType TupleSize = detail::DynamicTupleSize, typename ArrayType = vtkDataArray*>
VTK_ITER_INLINE auto vtk::DataArrayValueRange ( const ArrayType &  array,
ValueIdType  start = -1,
ValueIdType  end = -1 
) -> detail::ValueRange<typename detail::StripPointers<ArrayType>::type, TupleSize>

Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray.

This function returns a ValueRange object that is compatible with C++11 for-range syntax. The array is traverse as if calling vtkGenericDataArray::GetValue with consecutive, increase indices. As an example usage, consider a function that takes some instance of vtkDataArray (or a subclass) and sums the values it contains:

template <typename ArrayType>
auto ComputeSum(ArrayType *array) -> vtk::GetAPIType<ArrayType>
{
T sum = 0.;
for (const auto& val : vtk::DataArrayValueType(array))
{
sum += val;
}
return sum;
}

Note that ArrayType is generic in the above function. When vtk::DataArrayValueRange is given a vtkDataArray pointer, the generated code produces iterators and reference proxies that rely on the vtkDataArray API. However, when a more derived ArrayType is passed in (for example, vtkFloatArray), specialized implementations are used that generate highly optimized code.

Performance can be further improved when the number of components in the array is known. By passing a compile-time-constant integer as a template parameter, e.g. vtk::DataArrayValueRange<3>(array), specializations are enabled that allow the compiler to perform additional optimizations.

vtk::DataArrayValueRange takes an additional two arguments that can be used to restrict the range of values to [start, end).

There is a compiler definition / CMake option called VTK_DEBUG_RANGE_ITERATORS that enables checks for proper usage of the range/iterator/reference classes. This slow things down significantly, but is useful for diagnosing problems.

In some situations, developers may want to build in Debug mode while still maintaining decent performance for data-heavy computations. For these usecases, and additional CMake option VTK_ALWAYS_OPTIMIZE_ARRAY_ITERATORS may be enabled to force optimization of code using these iterators. This option will force inlining and enable -O3 (or equivalent) optimization level for iterator code when compiling on platforms that support these features. This option has no effect when VTK_DEBUG_RANGE_ITERATORS is enabled.

Note
References obtained through iterators are invalidated when the iterator is modified.
operator[] is disabled for the iterators and tuple reference types, as they cannot be implemented for vtkDataArray without dangling references. These index operations may still be accessible when used with other array classes, but their use is discouraged to ensure portability and any code using them will not compile with VTK_DEBUG_RANGE_ITERATORS defined.

Definition at line 201 of file vtkDataArrayRange.h.

template<typename IterablePtr , typename... Options>
auto vtk::Range ( IterablePtr  iterable,
Options &&...  opts 
) -> typename detail::IterableTraits< typename detail::StripPointers<IterablePtr>::type >::RangeType

Generate an iterable STL proxy object for a VTK container.

Currently supports:

Usage:

for (auto item : vtk::Range(myCollection))
{
// Use item.
}
// or:
using Opts = vtk::vtkDataObjectTreeOptions;
auto range = vtk::Range(dataObjTree,
some_algo(range.begin(), range.end());

Definition at line 85 of file vtkRange.h.