| 16 | namespace |
| 17 | { |
| 18 | int TestCompressible() |
| 19 | { |
| 20 | vtkNew<vtkSphereSource> sphere; |
| 21 | sphere->Update(); |
| 22 | |
| 23 | vtkPolyData* output = vtkPolyData::SafeDownCast(sphere->GetOutput()); |
| 24 | |
| 25 | auto pointData = output->GetPointData(); |
| 26 | |
| 27 | vtkNew<vtkIntArray> constArr; |
| 28 | constArr->SetNumberOfComponents(2); |
| 29 | constArr->SetNumberOfTuples(output->GetNumberOfPoints()); |
| 30 | constArr->Fill(42); |
| 31 | constArr->SetName("Constant"); |
| 32 | pointData->AddArray(constArr); |
| 33 | |
| 34 | vtkNew<vtkToImplicitArrayFilter> toImpArr; |
| 35 | vtkNew<vtkToConstantArrayStrategy> strat; |
| 36 | toImpArr->SetStrategy(strat); |
| 37 | toImpArr->SetInputConnection(sphere->GetOutputPort()); |
| 38 | auto select = toImpArr->GetPointDataArraySelection(); |
| 39 | select->EnableArray("Constant"); |
| 40 | toImpArr->Update(); |
| 41 | |
| 42 | output = vtkPolyData::SafeDownCast(toImpArr->GetOutput()); |
| 43 | if (!output) |
| 44 | { |
| 45 | std::cout << "Output of filter is not poly data" << std::endl; |
| 46 | return EXIT_FAILURE; |
| 47 | } |
| 48 | |
| 49 | pointData = output->GetPointData(); |
| 50 | |
| 51 | vtkConstantArray<int>* arr = |
| 52 | vtkArrayDownCast<vtkConstantArray<int>>(pointData->GetArray("Constant")); |
| 53 | if (!arr) |
| 54 | { |
| 55 | std::cout << "Does not have constant array in output" << std::endl; |
| 56 | return EXIT_FAILURE; |
| 57 | } |
| 58 | |
| 59 | if (arr->GetNumberOfComponents() != constArr->GetNumberOfComponents()) |
| 60 | { |
| 61 | std::cout << "Resulting compressed array does not have correct number of components" |
| 62 | << std::endl; |
| 63 | return EXIT_FAILURE; |
| 64 | } |
| 65 | |
| 66 | if (arr->GetNumberOfTuples() != constArr->GetNumberOfTuples()) |
| 67 | { |
| 68 | std::cout << "Resulting compressed array does not have correct number of tuples" << std::endl; |
| 69 | return EXIT_FAILURE; |
| 70 | } |
| 71 | |
| 72 | for (int iV = 0; iV < output->GetNumberOfPoints() * 2; ++iV) |
| 73 | { |
| 74 | if (constArr->GetValue(iV) != arr->GetValue(iV)) |
| 75 | { |
no test coverage detected