Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaHelper] Handle recent MSH format in MeshGmshLoader #2155

Merged
merged 15 commits into from
Oct 21, 2021

Conversation

Camille-K
Copy link
Contributor

@Camille-K Camille-K commented Jun 3, 2021

This is an attempt at fixing #1528.

At the moment, file parsing in MeshGmsh.cpp and MeshGmshLoader.cpp is (hopefully) correctly handled, including more recent MSH file formats (=>4.0).
EDIT: I don't fully understand how the loader works, mainly why MeshGmshLoader::readGmsh() is temporarily not used (commented in l.111), with the parsing apparently relying only on MeshGmsh::readGmsh(). However I tried to keep the same structure as before, simply taking into account the case where the .msh version is > 2.
A .msh file with version 4.1 is added (share/mesh/msh4_cube.msh), and its parsing by the MeshGmshLoader is tested both in examples/Components/loader/MeshGmshLoader.scn and in a new unit test. Both tests are working locally.

Regarding the original purpose of #1528, the PR should be sufficient.

Fixes #2433 #1528


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

Camille Krewcun added 3 commits June 3, 2021 20:12
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.
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.
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.
@Camille-K Camille-K added the pr: status wip Development in the pull-request is still in progress label Jun 3, 2021
@Camille-K Camille-K requested a review from epernod June 3, 2021 18:29
@Camille-K Camille-K added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Jun 9, 2021
In case the MSH file format is only partially respected by the input
file.
@hugtalbot hugtalbot added this to the v21.06 milestone Jun 9, 2021
@fredroy fredroy added the enhancement About a possible enhancement label Jun 10, 2021
@alxbilger
Copy link
Contributor

[ci-build][with-all-tests]

@hugtalbot hugtalbot modified the milestones: v21.06, v21.12 Jun 16, 2021
@hugtalbot hugtalbot added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jun 16, 2021
Camille Krewcun added 2 commits June 16, 2021 12:49
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.
Using the data obtained via the official Gmsh loader as a reference.
@Camille-K Camille-K added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Oct 19, 2021
@Camille-K
Copy link
Contributor Author

[ci-build][with-all-tests]

@guparan guparan added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Oct 20, 2021
Camille added 2 commits October 20, 2021 10:28
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.
Basic modification of examples/Components/loader/MeshGmshLoader.scn
adding a new node which parses a .msh file with version 4.1
@Camille-K Camille-K added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Oct 20, 2021
@Camille-K
Copy link
Contributor Author

[ci-build][with-all-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.
@Camille-K Camille-K added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Oct 21, 2021
">" instead of ">=" caused (logically) some header lines not to be
detected as .msh header lines
@Camille-K Camille-K added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Oct 21, 2021
@Camille-K
Copy link
Contributor Author

[ci-build][with-all-tests]

@epernod epernod added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Oct 21, 2021
@epernod epernod merged commit 17a9eef into sofa-framework:master Oct 21, 2021
@guparan guparan changed the title [MeshGmshLoader] Handle recent MSH format [SofaHelper] Handle recent MSH format in MeshGmshLoader Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement About a possible enhancement pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MeshGmshLoader does not handle latest gmsh format Gmsh recent format not supported
6 participants