| 19 | } while (false) |
| 20 | |
| 21 | int ArrayTransposeMatrix(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) |
| 22 | { |
| 23 | std::cout << setprecision(17); |
| 24 | |
| 25 | try |
| 26 | { |
| 27 | vtkSmartPointer<vtkSparseArray<double>> source = vtkSmartPointer<vtkSparseArray<double>>::New(); |
| 28 | source->Resize(vtkArrayExtents(3, 2)); |
| 29 | source->AddValue(vtkArrayCoordinates(0, 1), 1); |
| 30 | source->AddValue(vtkArrayCoordinates(1, 0), 2); |
| 31 | source->AddValue(vtkArrayCoordinates(2, 0), 3); |
| 32 | |
| 33 | std::cout << "source matrix:\n"; |
| 34 | vtkPrintMatrixFormat(std::cout, source.GetPointer()); |
| 35 | |
| 36 | vtkSmartPointer<vtkArrayData> source_data = vtkSmartPointer<vtkArrayData>::New(); |
| 37 | source_data->AddArray(source); |
| 38 | |
| 39 | vtkSmartPointer<vtkTransposeMatrix> transpose = vtkSmartPointer<vtkTransposeMatrix>::New(); |
| 40 | transpose->SetInputData(source_data); |
| 41 | transpose->Update(); |
| 42 | |
| 43 | vtkSparseArray<double>* const output = vtkSparseArray<double>::SafeDownCast( |
| 44 | transpose->GetOutput()->GetArray(static_cast<vtkIdType>(0))); |
| 45 | std::cout << "output matrix:\n"; |
| 46 | vtkPrintMatrixFormat(std::cout, output); |
| 47 | |
| 48 | test_expression(output); |
| 49 | test_expression(output->GetExtent(0).GetSize() == 2); |
| 50 | test_expression(output->GetExtent(1).GetSize() == 3); |
| 51 | |
| 52 | test_expression(output->GetValue(vtkArrayCoordinates(0, 0)) == 0); |
| 53 | test_expression(output->GetValue(vtkArrayCoordinates(0, 1)) == 2); |
| 54 | test_expression(output->GetValue(vtkArrayCoordinates(0, 2)) == 3); |
| 55 | test_expression(output->GetValue(vtkArrayCoordinates(1, 0)) == 1); |
| 56 | test_expression(output->GetValue(vtkArrayCoordinates(1, 1)) == 0); |
| 57 | test_expression(output->GetValue(vtkArrayCoordinates(1, 2)) == 0); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | catch (std::exception& e) |
| 62 | { |
| 63 | std::cerr << e.what() << std::endl; |
| 64 | return 1; |
| 65 | } |
| 66 | } |
nothing calls this directly
no test coverage detected