Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MeshGmshLoader] Handle recent MSH format (sofa-framework#2155)
* [GmshLoader] Add test At the moment the test fails, because there seem to be some discrepancy between the topology that the MeshGmshLoader is able to retrieve in a scene, and the data it actually contains. This might come from the fact that the doLoad() method of MeshGmshLoader doesn't call anymore its method readGmsh, and that the mesh is in fact retrieved in the scene at the MeshGmsh level. This has yet to be clarified. * [GmshLoader] Update .msh file parsing to handle version 4 Parsing method readGmsh is updated to handle more recent MSH file formats (<= 4.1). Detail of the format is available here: https://gmsh.info/doc/texinfo/gmsh.html#File-formats Handling of versions <= 2 is not changed, so this commit should not be breaking. * [GmshLoader] Update MSH format version detection Instead of assuming that the MSH file format version is either 1 or 2, we read it from the file in order to handle the most recent format (4.1 at the time). The version is then passed to the parser in MeshGmsh.cpp. With this commit, versions >= 4 are not yet handled by the parser. * [GmshLoader] Correct loop indentation * [GmshLoader] Propagate MeshGmsh new code to MeshGmshLoader Method readGmsh of MeshGmshLoader is left unused. * [GmshLoader] Add safety check on while loop In case the MSH file format is only partially respected by the input file. * [GmshLoader] Fix regression The use of std::getLine instead of the >> operator caused the parsing to read the last " " character of the last line in the "Element" section in the MSH files, instead of the line closing the section, for file formats older than 2.0. * [GmshLoader] Fix test Using the data obtained via the official Gmsh loader as a reference. * Fix unnoticed differences after master update * Fix detection of .msh files with version 1.x The first line of old .msh files (version = 1.x) seems to be "$NOD\r" instead of "$NOD", which caused them not to be detected by the MeshGmshLoader parser. This issue comes from the fact that before the update of the loader, if the header line was not recognised, then the version of the parsed .msh file was assumed to be 2.x. This fix simply adds $NOD\r$ as a recognised header line for .msh files with version 1.x, mainly to maintain compatibility with the unit tests. * Add node in MeshGmshLoader.scn to test msh v >= 4.0 Basic modification of examples/Components/loader/MeshGmshLoader.scn adding a new node which parses a .msh file with version 4.1 * Fix failing tests Some tests in the CI use .msh files with slightly different syntax than the standard. Namely, the problem comes from the presence of a carriage return character "\r", sometimes preceeded by a space " " character, at the end of main section lines such as "$MeshFormat \r", or "$Nodes\r". A solution to this is to make the parser a little bit more permessive, by only parsing the beginning of these lines and see if it corresponds to the expected section titles ("$MeshFormat", "$Nodes"). This is only implemented for versions <= 2, as it is not actually part of the standard (i.e. a .msh file starting with "$MeshFormat \r" instead of "$MeshFormat" is not technically a .msh file). The issue could come from .msh files commited from different OS, with lines ending differently. If so, the more permessive parsing should also be extended for versions >= 4. * Fix typo, fixing failing tests ">" instead of ">=" caused (logically) some header lines not to be detected as .msh header lines Co-authored-by: Camille Krewcun <camille.krewcun@inria.fr> Co-authored-by: Camille <camille.krewcun@uca.fr>
- Loading branch information