MCPcopy Create free account
hub / github.com/Kitware/VTK / ArrayMatricizeArray

Function ArrayMatricizeArray

Filters/General/Testing/Cxx/ArrayMatricizeArray.cxx:21–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 } while (false)
20
21int ArrayMatricizeArray(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
22{
23 try
24 {
25 // Create an array ...
26 vtkSmartPointer<vtkSparseArray<double>> array = vtkSmartPointer<vtkSparseArray<double>>::New();
27 array->Resize(vtkArrayExtents(2, 2, 2));
28
29 double value = 0;
30 const vtkArrayExtents extents = array->GetExtents();
31 for (int i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i)
32 {
33 for (int j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j)
34 {
35 for (int k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k)
36 {
37 array->AddValue(vtkArrayCoordinates(i, j, k), value++);
38 }
39 }
40 }
41
42 std::cout << "array source:\n";
43 vtkPrintCoordinateFormat(std::cout, array.GetPointer());
44
45 // Create an array data object to hold it ...
46 vtkSmartPointer<vtkArrayData> array_data = vtkSmartPointer<vtkArrayData>::New();
47 array_data->AddArray(array);
48
49 // Matricize it ...
50 vtkSmartPointer<vtkMatricizeArray> matricize = vtkSmartPointer<vtkMatricizeArray>::New();
51 matricize->SetInputData(array_data);
52 matricize->SetSliceDimension(0);
53 matricize->Update();
54
55 vtkSparseArray<double>* const matricized_array = vtkSparseArray<double>::SafeDownCast(
56 matricize->GetOutput()->GetArray(static_cast<vtkIdType>(0)));
57 test_expression(matricized_array);
58
59 std::cout << "matricize output:\n";
60 vtkPrintCoordinateFormat(std::cout, matricized_array);
61
62 test_expression(matricized_array->GetValue(vtkArrayCoordinates(0, 0)) == 0);
63 test_expression(matricized_array->GetValue(vtkArrayCoordinates(0, 1)) == 1);
64 test_expression(matricized_array->GetValue(vtkArrayCoordinates(0, 2)) == 2);
65 test_expression(matricized_array->GetValue(vtkArrayCoordinates(0, 3)) == 3);
66 test_expression(matricized_array->GetValue(vtkArrayCoordinates(1, 0)) == 4);
67 test_expression(matricized_array->GetValue(vtkArrayCoordinates(1, 1)) == 5);
68 test_expression(matricized_array->GetValue(vtkArrayCoordinates(1, 2)) == 6);
69 test_expression(matricized_array->GetValue(vtkArrayCoordinates(1, 3)) == 7);
70
71 return EXIT_SUCCESS;
72 }
73 catch (std::exception& e)
74 {
75 std::cout << e.what() << std::endl;
76 return EXIT_FAILURE;
77 }
78}

Callers

nothing calls this directly

Calls 15

test_expressionFunction · 0.85
GetExtentsMethod · 0.80
AddValueMethod · 0.80
NewFunction · 0.50
ResizeMethod · 0.45
GetBeginMethod · 0.45
GetEndMethod · 0.45
GetPointerMethod · 0.45
AddArrayMethod · 0.45
SetInputDataMethod · 0.45
UpdateMethod · 0.45
GetArrayMethod · 0.45

Tested by

no test coverage detected