1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkIndexedArray.h"
#include "vtkDataArrayRange.h"
#include "vtkIdList.h"
#include "vtkIntArray.h"
#include "vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h"
#include <cstdlib>
#include <numeric>
#include <random>
int TestIndexedArray(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
int res = EXIT_SUCCESS;
vtkNew<vtkIntArray> baseArray;
baseArray->SetNumberOfComponents(1);
baseArray->SetNumberOfTuples(1000);
auto range = vtk::DataArrayValueRange<1>(baseArray);
std::iota(range.begin(), range.end(), 0);
vtkNew<vtkIdList> handles;
handles->SetNumberOfIds(100);
std::random_device randdev;
std::mt19937 generator(randdev());
auto index_rand = std::bind(std::uniform_int_distribution<vtkIdType>(0, 999), generator);
for (vtkIdType idx = 0; idx < 100; idx++)
{
handles->SetId(idx, index_rand());
}
vtkNew<vtkIndexedArray<int>> indexed;
indexed->SetBackend(std::make_shared<vtkIndexedImplicitBackend<int>>(handles, baseArray));
indexed->SetNumberOfComponents(1);
indexed->SetNumberOfTuples(100);
for (vtkIdType iArr = 0; iArr < 100; iArr++)
{
if (indexed->GetValue(iArr) != static_cast<int>(handles->GetId(iArr)))
{
res = EXIT_FAILURE;
std::cout << "get value failed with vtkIndexedArray" << std::endl;
}
}
int iArr = 0;
for (auto val : vtk::DataArrayValueRange<1>(indexed))
{
if (val != static_cast<int>(handles->GetId(iArr)))
{
res = EXIT_FAILURE;
std::cout << "range iterator failed with vtkIndexedArray" << std::endl;
}
iArr++;
}
return res;
};
|