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

[Mapping] Add checks at init in TopologicalMapping #3339

Merged

Conversation

hugtalbot
Copy link
Contributor

Adding check on pointers and type of input/output topology (mostly input) before using them in TopologicalMapping


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).

@hugtalbot hugtalbot added pr: status to review To notify reviewers to review this pull-request pr: clean Cleaning the code labels Sep 27, 2022
@hugtalbot
Copy link
Contributor Author

Further to our discussion @epernod @ScheiklP

@hugtalbot
Copy link
Contributor Author

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

Copy link
Contributor

@alxbilger alxbilger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this PR. It will improve the UX for sure.

However, I see a lot of duplicated code. I consider it as a technical debt. To discuss if we temporary merge your changes, or think bigger ;)

@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 Sep 28, 2022
@hugtalbot
Copy link
Contributor Author

I am open to think bigger, or merge it and then factorize

@hugtalbot hugtalbot 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 Sep 29, 2022
@hugtalbot
Copy link
Contributor Author

Reviews taken into account 👍 @alxbilger

Copy link
Contributor

@epernod epernod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is already some checks in TopologyMapping parse method. Checking fromModel and toModel.
Might be the good timing to unify it.
Also it is not possible to put the same message in a single method inside TopologyMapping which is called by the different components.
Using toModel.GetClassName, toModel.getName() etc... ?
Which part of the check is not generic?

@fredroy fredroy 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 5, 2022
Copy link
Contributor

@epernod epernod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

several changes are not compatible with the current api of the topology and some tests are already present in TopologicalMapping create and canCreate methods.

@hugtalbot if you agree I will push a new proposal directly in this PR.

Comment on lines 103 to 109
if (!fromModel)
{
// If the input topology link isn't set by the user, the TopologicalMapping::create method tries to find it.
// If it is null at this point, it means no input mesh topology could be found.
msg_error() << "No input mesh topology found. Consider setting the '" << fromModel.getName() << "' data attribute.";
modelsOk = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 remarks regarding this check:

  • This case is never possible because fromModel is already checked in the mother class TopologicalMapping in the canCreate method. If input and output don't link to valid BaseMeshTopology, the mapping is not create (canCreate return false)
  • Hopefully this case is never possible because if fromModel is null, printing error message with fromModel.getName() will crash 😄

if (!dynamic_cast<container::dynamic::TriangleSetTopologyContainer *>(toModel.get()))
{
msg_error() << "The input topology '" << toModel.getPath() << "' is not homogeneous with a TriangleSetTopologyContainer. The '" << toModel.getName() << "' data attribute must be linked to a valid component, among the following list of eligible components:" << msgendl
<< sofa::core::ObjectFactory::getInstance()->listClassesDerivedFrom<container::dynamic::TriangleSetTopologyContainer>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested what would be the error message. In this mapping case, it is:
data attribute must be linked to a valid component, among the following list of eligible components: TetrahedronSetTopologyContainer, TriangleSetTopologyContainer

which doesn't work, because putting a TetrahedronSetTopologyContainer as output will result in a strange behavior. Not sure if it will crash or if it will be like a "TopologicalIdentityMapping" 🤔

I suggest to move the checks inside a commun method in TopologicalMapping and just test the topologyType of the containters

else
{
// Making sure the input topology includes triangle elements
if (fromModel.get()->getNbTriangles() != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still be valid if we start from an empty mesh and we add progressively triangles with a mapping on the edges... btw I thought I had a test on that.

@epernod epernod 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 25, 2022
@epernod
Copy link
Contributor

epernod commented Oct 25, 2022

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

@hugtalbot
Copy link
Contributor Author

New approach proposed in the TopologicalMapping to make the checks on input/output topologies. Some missing implementation and find a solution to get the topological element name from enum class. New review needed

@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 Oct 26, 2022
@epernod epernod force-pushed the check_topologicalmapping_init branch from 65d06d6 to 6030f26 Compare October 26, 2022 11:31
@hugtalbot
Copy link
Contributor Author

If my last question is answered by @epernod (see here), then good to be merged IMO

@hugtalbot hugtalbot 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 28, 2022
@hugtalbot
Copy link
Contributor Author

To be rebased once #3428 is merged, then ready

@epernod
Copy link
Contributor

epernod commented Nov 2, 2022

et 💥 !!

@epernod epernod 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 Nov 2, 2022
@hugtalbot
Copy link
Contributor Author

aw aw aw @epernod !

😁

@hugtalbot
Copy link
Contributor Author

hugtalbot commented Nov 2, 2022

it seems mostly to be the case of a grid linked :

The type of the input topology '@../grid' does not correspond to a valid 'Hexahedron' topology.

@epernod
Copy link
Contributor

epernod commented Nov 2, 2022

yes and it is "funny" because I had the same issue in #3368
this is just because Grid inherite from MeshTopology which doesn't define the TopoogyType as Hexahedron

@epernod epernod 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 Nov 2, 2022
@fredroy
Copy link
Contributor

fredroy commented Nov 4, 2022

Failing scenes were fixed in #3453 a fortiori, lets merge with master and have a final check

@fredroy fredroy 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 Nov 4, 2022
@fredroy fredroy merged commit a2105d0 into sofa-framework:master Nov 4, 2022
@hugtalbot hugtalbot added this to the v22.12 milestone Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants