------------------------------------------------------------------------------
| 2837 | |
| 2838 | //------------------------------------------------------------------------------ |
| 2839 | void EnSightDataSet::ReadNFacedSection(int& numElements, vtkUnstructuredGrid* output) |
| 2840 | { |
| 2841 | vtkLogScopeFunction(TRACE); |
| 2842 | |
| 2843 | // Number of elements |
| 2844 | this->GeometryFile.ReadNumber(&numElements); |
| 2845 | |
| 2846 | // (optional) Element IDs |
| 2847 | if (this->ElementIdsListed) |
| 2848 | { |
| 2849 | this->GeometryFile.SkipNNumbers<int>(numElements); |
| 2850 | } |
| 2851 | |
| 2852 | // Number of faces per element |
| 2853 | std::vector<int> numFacesPerElement(numElements, 0); |
| 2854 | this->GeometryFile.ReadArray(numFacesPerElement.data(), numElements); |
| 2855 | |
| 2856 | // Read the whole block in one go |
| 2857 | vtkIdType totalNumFaces = std::accumulate( |
| 2858 | numFacesPerElement.begin(), numFacesPerElement.end(), static_cast<vtkIdType>(0)); |
| 2859 | |
| 2860 | std::vector<int> numNodesPerFacePerElement(totalNumFaces); |
| 2861 | this->GeometryFile.ReadArray(numNodesPerFacePerElement.data(), totalNumFaces); |
| 2862 | |
| 2863 | vtkIdType totalNumNodes = std::accumulate( |
| 2864 | numNodesPerFacePerElement.begin(), numNodesPerFacePerElement.end(), static_cast<vtkIdType>(0)); |
| 2865 | std::vector<int> faceNodesBuffer(totalNumNodes); |
| 2866 | |
| 2867 | vtkIdType offset = 0; |
| 2868 | for (vtkIdType i = 0; i < totalNumFaces; ++i) |
| 2869 | { |
| 2870 | this->GeometryFile.ReadArray( |
| 2871 | faceNodesBuffer.data() + offset, numNodesPerFacePerElement[i], true); |
| 2872 | offset += numNodesPerFacePerElement[i]; |
| 2873 | } |
| 2874 | |
| 2875 | // Now build the actual cells |
| 2876 | auto cellInfo = getVTKCellType(ElementType::NFaced); |
| 2877 | |
| 2878 | auto numNodesInFaceIt = numNodesPerFacePerElement.begin(); |
| 2879 | auto nodeIt = faceNodesBuffer.begin(); |
| 2880 | |
| 2881 | // Break through all loops if numNodesInFaceIt or nodeIt reach the end of vector |
| 2882 | bool endReached = false; |
| 2883 | vtkNew<vtkCellArray> faceStream; |
| 2884 | |
| 2885 | for (int elemIdx = 0; elemIdx < numElements; elemIdx++) |
| 2886 | { |
| 2887 | const int numFacesInElement = numFacesPerElement[elemIdx]; |
| 2888 | /// @note: we could save that value from the earlier "total" computation. It's not significant |
| 2889 | // compared to the read time though |
| 2890 | const vtkIdType numNodesInElement = std::accumulate( |
| 2891 | numNodesInFaceIt, numNodesInFaceIt + numFacesInElement, static_cast<vtkIdType>(0)); |
| 2892 | |
| 2893 | std::vector<vtkIdType> uniqueCellIDs; |
| 2894 | uniqueCellIDs.reserve(numNodesInElement); |
| 2895 | |
| 2896 | faceStream->Reset(); |
no test coverage detected