review(IndexedArray): enforce final for backend + optimization

- Adding final keywork for backend to enforce static time dispatch for
- A small const optimization
- Removal of for centralization later
Julien Fausty 2 months ago
parent bd2f9b2d6a
commit 5b4f6f64b7

@ -61,7 +61,7 @@ VTK_ABI_NAMESPACE_BEGIN
class vtkDataArray;
class vtkIdList;
template <typename ValueType>
class vtkIndexedImplicitBackend
class vtkIndexedImplicitBackend final

@ -62,8 +62,9 @@ public:
ValueType GetValue(int idx) const override
int iTup = idx / this->Array->GetNumberOfComponents();
int iComp = idx - iTup * this->Array->GetNumberOfComponents();
const int nComps = this->Array->GetNumberOfComponents();
const int iTup = idx / nComps;
const int iComp = idx - iTup * nComps;
return static_cast<ValueType>(this->Array->GetComponent(iTup, iComp));

@ -1,27 +0,0 @@
## New `vtkIndexedArray`s
VTK now provides a family of data arrays called `vtkIndexedArray`s. These arrays are part of the `vtkImplicitArray` framework. They allow you to wrap an existing `vtkDataArray` with a layer of indirection through a list of indexes (`vtkIdList` or another `vtkDataArray`) to create a derived subset data array without any excess memory consumption. As such, by providing a `vtkIndexedImplicitBackend` with an indexation array and a `vtkDataArray`, one can effectively construct a reduced and reordered view of the base array.
While using this type of feature to create only one indexed array can be counter productive (allocation of the index array more expensive than an explicit copy of the data might be), using this feature you can share the same index list amoungst multiple indexed arrays effectively using less memory total.
Here is an example use case:
vtkNew<vtkIntArray> baseArr;
auto range = vtk::DataArrayValueRange<3>(baseArr);
std::iota(range.begin(), range.end(), 0);
vtkNew<vtkIdList> indexes;
for (idx = 0; idx < 30; idx++)
indexes->SetId(ids, 10*idx);
vtkNew<vtkIndexedArray<int>> indexed;
indexed->SetBackend(std::make_shared<vtkIndexedImplicitBackend<int>>(indexes, baseArr));
CHECK(indexed->GetValue(13) == 130); // always true