* See CreateMixedUnstructuredGrid. */
| 890 | * See CreateMixedUnstructuredGrid. |
| 891 | */ |
| 892 | void SetMixedPolyhedralCells( |
| 893 | vtkUnstructuredGrid* ug, vtkDataArray* shapes, vtkCellArray* elements, vtkCellArray* subelements) |
| 894 | { |
| 895 | // if there are no subelements |
| 896 | if (!subelements || subelements->GetNumberOfCells() == 0) |
| 897 | { |
| 898 | // This is a simple case where we have a mixed cell type, but no polyhedra. |
| 899 | ug->SetPolyhedralCells(shapes, elements, nullptr, nullptr); |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | vtkNew<vtkCellArray> connectivity; |
| 904 | vtkNew<vtkCellArray> faces; |
| 905 | vtkNew<vtkCellArray> faceLocations; |
| 906 | subelements->IsStorage64Bit() |
| 907 | ? faces->ConvertTo64BitStorage() && faceLocations->ConvertTo64BitStorage() |
| 908 | : faces->ConvertTo64BitStorage() && faceLocations->ConvertTo32BitStorage(); |
| 909 | |
| 910 | connectivity->AllocateEstimate(elements->GetNumberOfCells(), 10); |
| 911 | faces->AllocateExact( |
| 912 | subelements->GetNumberOfCells(), subelements->GetConnectivityArray()->GetNumberOfTuples()); |
| 913 | faceLocations->AllocateExact(elements->GetNumberOfCells(), subelements->GetNumberOfCells()); |
| 914 | |
| 915 | vtkIdType numCellFaces, numFacePointIDs, numCellPointIDs; |
| 916 | const vtkIdType *cellGlobalFaceIDs, *facePointIDs, *cellPointIDs; |
| 917 | std::set<vtkIdType> cellPointIDsSet; |
| 918 | vtkIdType globalFaceId = 0; |
| 919 | auto cellTypes = vtk::DataArrayValueRange<1, unsigned char>(shapes); |
| 920 | for (vtkIdType i = 0, numCells = elements->GetNumberOfCells(); i < numCells; ++i) |
| 921 | { |
| 922 | const unsigned char& cellType = cellTypes[i]; |
| 923 | if (cellType == VTK_POLYHEDRON) |
| 924 | { |
| 925 | cellPointIDsSet.clear(); |
| 926 | // https://llnl-conduit.readthedocs.io/en/latest/blueprint_mesh.html#polyhedra |
| 927 | // This in conduit describes a polyhedron' global face IDs, and not its point IDs. |
| 928 | // Even after https://gitlab.kitware.com/vtk/vtk/-/issues/18190 was resolved, the conduit |
| 929 | // format is still different from the VTK format, so we need to do some conversions for VTK. |
| 930 | elements->GetCellAtId(i, numCellFaces, cellGlobalFaceIDs); |
| 931 | |
| 932 | faceLocations->InsertNextCell(numCellFaces); |
| 933 | for (vtkIdType j = 0; j < numCellFaces; ++j) |
| 934 | { |
| 935 | faceLocations->InsertCellPoint(globalFaceId++); |
| 936 | |
| 937 | subelements->GetCellAtId(cellGlobalFaceIDs[j], numFacePointIDs, facePointIDs); |
| 938 | // If VTK' polyhedron format had a notion of global face IDs, we could just use |
| 939 | // subelements as faces, instead of copying each face, but sadly that's not true. |
| 940 | faces->InsertNextCell(numFacePointIDs, facePointIDs); |
| 941 | // accumulate point IDs from all faces in this polyhedron |
| 942 | cellPointIDsSet.insert(facePointIDs, facePointIDs + numFacePointIDs); |
| 943 | } |
| 944 | |
| 945 | // Insert the points IDs of this polyhedron into the 'connectivity' array. |
| 946 | connectivity->InsertNextCell(static_cast<int>(cellPointIDsSet.size())); |
| 947 | for (const auto& pt : cellPointIDsSet) |
| 948 | { |
| 949 | connectivity->InsertCellPoint(pt); |
no test coverage detected