| 44 | } |
| 45 | |
| 46 | void UpdateVTKAttributes(vtkCPInputDataDescription* idd, unsigned int numberOfPoints, |
| 47 | double* velocityData, unsigned int numberOfCells, float* pressureData) |
| 48 | { |
| 49 | if (idd->IsFieldNeeded("velocity", vtkDataObject::POINT) == true) |
| 50 | { |
| 51 | if (VTKGrid->GetPointData()->GetNumberOfArrays() == 0) |
| 52 | { |
| 53 | // velocity array |
| 54 | vtkNew<vtkDoubleArray> velocity; |
| 55 | velocity->SetName("velocity"); |
| 56 | velocity->SetNumberOfComponents(3); |
| 57 | velocity->SetNumberOfTuples(static_cast<vtkIdType>(numberOfPoints)); |
| 58 | VTKGrid->GetPointData()->AddArray(velocity); |
| 59 | } |
| 60 | vtkDoubleArray* velocity = |
| 61 | vtkDoubleArray::SafeDownCast(VTKGrid->GetPointData()->GetArray("velocity")); |
| 62 | // The velocity array is ordered as vx0,vx1,vx2,..,vy0,vy1,vy2,..,vz0,vz1,vz2,.. |
| 63 | // so we need to create a full copy of it with VTK's ordering of |
| 64 | // vx0,vy0,vz0,vx1,vy1,vz1,.. |
| 65 | for (unsigned int i = 0; i < numberOfPoints; i++) |
| 66 | { |
| 67 | double values[3] = { velocityData[i], velocityData[i + numberOfPoints], |
| 68 | velocityData[i + 2 * numberOfPoints] }; |
| 69 | velocity->SetTypedTuple(i, values); |
| 70 | } |
| 71 | } |
| 72 | if (idd->IsFieldNeeded("pressure", vtkDataObject::CELL) == true) |
| 73 | { |
| 74 | if (VTKGrid->GetCellData()->GetNumberOfArrays() == 0) |
| 75 | { |
| 76 | // pressure array |
| 77 | vtkNew<vtkFloatArray> pressure; |
| 78 | pressure->SetName("pressure"); |
| 79 | pressure->SetNumberOfComponents(1); |
| 80 | VTKGrid->GetCellData()->AddArray(pressure); |
| 81 | } |
| 82 | vtkFloatArray* pressure = |
| 83 | vtkFloatArray::SafeDownCast(VTKGrid->GetCellData()->GetArray("pressure")); |
| 84 | // The pressure array is a scalar array so we can reuse |
| 85 | // memory as long as we ordered the points properly. |
| 86 | pressure->SetArray(pressureData, static_cast<vtkIdType>(numberOfCells), 1); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void BuildVTKDataStructures(vtkCPInputDataDescription* idd, unsigned int numberOfPoints, |
| 91 | double* points, double* velocity, unsigned int numberOfCells, unsigned int* cells, |
no test coverage detected