| 25 | |
| 26 | template <typename ArrayT> |
| 27 | void TestTupleRangeAPI(ArrayT* someArray) |
| 28 | { |
| 29 | // TupleRanges have a two-step hierarchy of iterators and references. The |
| 30 | // first layer encapsulates the concept of tuples, and the second layer |
| 31 | // provides access to the components in a tuple. The following code shows |
| 32 | // how these objects (TupleRange, TupleIterator, TupleReference, |
| 33 | // ComponentIterator, ComponentReference) can be used. |
| 34 | |
| 35 | // A TupleRange can be restricted to a subset of the array's data by passing |
| 36 | // explicit start/end values to vtk::DataArrayTupleRange: |
| 37 | { |
| 38 | auto subRange = vtk::DataArrayTupleRange(someArray, 2, 8); |
| 39 | // Iterates over tuples 2-7 (inclusive). |
| 40 | for (auto tupleRef : subRange) |
| 41 | { |
| 42 | std::cout << "Tuple: "; |
| 43 | for (auto compRef : tupleRef) |
| 44 | { |
| 45 | std::cout << compRef << " "; |
| 46 | } |
| 47 | std::cout << "\n"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // If the exact number of components in a tuple is known at compile-time, |
| 52 | // this can be passed as a template argument to vtk::DataArrayTupleRange. |
| 53 | // This will enable additional compiler optimizations to improve performance. |
| 54 | { |
| 55 | auto optimizedRange = vtk::DataArrayTupleRange<4>(someArray); |
| 56 | // Accessing data in optimizedRange will be more efficient as variables |
| 57 | // like array strides are made available to the compiler. |
| 58 | for (auto tupleRef : optimizedRange) |
| 59 | { |
| 60 | std::cout << "Tuple: "; |
| 61 | for (auto compRef : tupleRef) |
| 62 | { |
| 63 | std::cout << compRef << " "; |
| 64 | } |
| 65 | std::cout << "\n"; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Both tuple size and subrange information can be used simultaneously: |
| 70 | { |
| 71 | auto optimizedSubRange = vtk::DataArrayTupleRange<4>(someArray, 2, 8); |
| 72 | for (auto tupleRef : optimizedSubRange) |
| 73 | { |
| 74 | std::cout << "Tuple: "; |
| 75 | for (auto compRef : tupleRef) |
| 76 | { |
| 77 | std::cout << compRef << " "; |
| 78 | } |
| 79 | std::cout << "\n"; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // If tuple size is unknown and the range should encompass the full length of |
| 84 | // the array, simply pass in the array with no template arguments: |
no test coverage detected