80 MeshData data{Eigen::MatrixXd(), Eigen::MatrixXi()};
83 std::string extension = std::filesystem::path(path).extension().string();
84 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
85 if (extension ==
".msh")
87 else if (extension ==
".hybrid")
92 else if (extension ==
".obj")
99 "Unsupported mesh format '{}' for {} (supported: .msh, .hybrid, .obj).",
105 const std::string vertices_path = child_path(path,
"vertices");
106 const std::string cells_path = child_path(path,
"cells");
112 if ((dimension != 2 && dimension != 3) || vertices.cols() != dimension)
114 if (vertices.rows() == 0 || cells.rows() == 0 || cells.cols() < 3)
116 if (cells.minCoeff() < -1 || cells.maxCoeff() >= vertices.rows())
119 data =
MeshData(std::move(vertices), std::move(cells));
123 if (ordered != 0 && ordered != 1)
125 data.elements_are_ordered = ordered != 0;
128 const std::string body_ids_path = child_path(path,
"body_ids");
131 const std::string geometry_ids_path = child_path(path,
"geometry_ids");
134 const std::string node_ids_path = child_path(path,
"node_ids");
137 const std::string boundary_ids_path = child_path(path,
"boundary_ids");
138 const std::string boundary_elements_path = child_path(path,
"boundary_elements");
146 data.boundary_elements.resize(elements.rows());
147 for (
int i = 0; i < elements.rows(); ++i)
149 bool found_padding =
false;
150 for (
int j = 0; j < elements.cols(); ++j)
152 const int vertex = elements(i, j);
155 found_padding =
true;
158 if (vertex < 0 || found_padding)
160 data.boundary_elements[i].push_back(vertex);
165 const std::string higher_nodes_path = child_path(path,
"higher_order_nodes");
166 const std::string higher_connectivity_path = child_path(path,
"higher_order_connectivity");
167 const std::string higher_offsets_path = child_path(path,
"higher_order_offsets");
174 data.higher_order_connectivity = unpack_connectivity(
180 const std::string weights_path = child_path(path,
"higher_order_weights");
181 const std::string weight_offsets_path = child_path(path,
"higher_order_weight_offsets");
187 data.higher_order_weights = unpack_weights(
192 const std::string faces_path = child_path(path,
"faces");
193 const std::string face_offsets_path = child_path(path,
"face_offsets");
194 const std::string cell_faces_path = child_path(path,
"cell_faces");
195 const std::string cell_face_offsets_path = child_path(path,
"cell_face_offsets");
203 for (
const std::string &required : {
204 faces_path, face_offsets_path, cell_faces_path, cell_face_offsets_path,
205 child_path(path,
"cell_face_orientations"), child_path(path,
"cell_is_hex"),
206 child_path(path,
"cell_kernel_points")})
209 data.faces = unpack_connectivity(
213 data.cell_faces = unpack_connectivity(
216 data.cell_face_orientations = unpack_connectivity(
220 if (std::any_of(cell_is_hex.begin(), cell_is_hex.end(), [](
const int value) { return value != 0 && value != 1; }))
222 data.cell_is_hex.assign(cell_is_hex.begin(), cell_is_hex.end());
236 std::string extension = std::filesystem::path(path).extension().string();
237 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
238 if (extension ==
".msh")
240 else if (extension ==
".obj")
244 "Unable to decode surface {} (supported: .msh, .obj, and the triangle meshes read by libigl: .off, .ply, .stl, .mesh, .wrl).",
250 const std::string vertices_path = child_path(path,
"vertices");
256 const std::string points_path = child_path(path,
"points");
260 result.
points = Eigen::Map<const Eigen::VectorXi>(values.data(), values.size());
262 const std::string edges_path = child_path(path,
"edges");
265 const std::string faces_path = child_path(path,
"faces");
268 const auto valid = [&](
const Eigen::MatrixXi &elements) {
269 return elements.size() == 0 || (elements.minCoeff() >= 0 && elements.maxCoeff() < result.
vertices.rows());
272 || !valid(result.
edges) || !valid(result.
faces))