| 1018 | } |
| 1019 | |
| 1020 | void exportVTK() |
| 1021 | { |
| 1022 | std::string fileName = convertFileName(output, currentFrame); |
| 1023 | LOG_INFO << "Writing: " << fileName; |
| 1024 | |
| 1025 | FileSystem::makeDir(FileSystem::getFilePath(FileSystem::normalizePath(output))); |
| 1026 | |
| 1027 | // Open the file |
| 1028 | std::ofstream outfile(fileName, std::ios::binary); |
| 1029 | if (!outfile) |
| 1030 | { |
| 1031 | LOG_WARN << "Cannot open a file to save VTK mesh."; |
| 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | #ifdef USE_DOUBLE |
| 1036 | const char* real_str = " double\n"; |
| 1037 | #else |
| 1038 | const char* real_str = " float\n"; |
| 1039 | #endif |
| 1040 | |
| 1041 | // Header |
| 1042 | outfile << "# vtk DataFile Version 4.2\n"; |
| 1043 | outfile << "Created by SPlisHSPlasH version " << SPLISHSPLASH_VERSION << "\n"; |
| 1044 | outfile << "BINARY\n"; |
| 1045 | outfile << "DATASET UNSTRUCTURED_GRID\n"; |
| 1046 | |
| 1047 | const std::vector<Vector3r>& vertices = meshX; |
| 1048 | const std::vector<unsigned int>& faces = mesh.getFaces(); |
| 1049 | int n_vertices = (int)vertices.size(); |
| 1050 | int n_triangles = (int)faces.size() / 3; |
| 1051 | |
| 1052 | // Vertices |
| 1053 | { |
| 1054 | std::vector<Vector3r> positions; |
| 1055 | positions.reserve(n_vertices); |
| 1056 | for (int j = 0u; j < n_vertices; j++) |
| 1057 | { |
| 1058 | Vector3r x = vertices[j]; |
| 1059 | swapByteOrder(&x[0]); |
| 1060 | swapByteOrder(&x[1]); |
| 1061 | swapByteOrder(&x[2]); |
| 1062 | positions.emplace_back(x); |
| 1063 | } |
| 1064 | // export to vtk |
| 1065 | outfile << "POINTS " << n_vertices << real_str; |
| 1066 | outfile.write(reinterpret_cast<char*>(positions[0].data()), 3 * n_vertices * sizeof(Real)); |
| 1067 | outfile << "\n"; |
| 1068 | } |
| 1069 | |
| 1070 | // Connectivity |
| 1071 | { |
| 1072 | std::vector<int> connectivity_to_write; |
| 1073 | connectivity_to_write.reserve(4 * n_triangles); |
| 1074 | for (int tri_i = 0; tri_i < n_triangles; tri_i++) |
| 1075 | { |
| 1076 | int val = 3; |
| 1077 | swapByteOrder(&val); |
no test coverage detected