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

[All] Fix visualisation #5152

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

bakpaul
Copy link
Contributor

@bakpaul bakpaul commented Dec 6, 2024

Visual models where broken since this PR #4827

Actually they were not always broken, when you started the simulation, everything was ok, but then if you unchecked visualModels in the View panel, and check it back, the visual models didn't follow the mechanical one anymore. The visual models where stuck in the position when you unchecked the VisualModel (see gif).

The problem was that the Visual params where not updated from the VisualStyle component at the right moment. It was only done in the VisualDrawVisitor, through the fwdDraw method. This enabled the drawing, but not the update of the visual models, because it was done before.

Why was it working when the visual flags remained untouched ? I don't know.

SOFA_visual_bug


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

@bakpaul bakpaul added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request labels Dec 6, 2024
@bakpaul bakpaul added this to the v24.12 milestone Dec 6, 2024
@bakpaul bakpaul requested a review from hugtalbot December 6, 2024 21:28
@hugtalbot
Copy link
Contributor

hugtalbot commented Dec 8, 2024

Shouldn't we rather properly update the visualparams ?
Before this change in #4827 the update was working fine.

The update process is done by RealGUI while the draw is done by the Viewer (Qt or QGL):

  • Viewer calls the function Simulation::draw(sofa::core::visual::VisualParams* vparams, Node* root) ending in the object draw() function with up-to-date visual flags:
    • DefaultVisualManagerLoop::drawStep() ➡️ VisualDrawVisitor::processObject() ➡️ drawVisual() ➡️ draw()
  • RealGUI calls sofa::simulation::node::updateVisual(root); (from Simulation::updateVisualContext()) ending in calling updateVisual() in OglModel where the visual flags are not up to date
    • DefaultVisualManagerLoop::updateStep() ➡️ VisualUpdateVisitor::processVisualModel() ➡️ updateVisual()

I therefore suspect the problem to come from the inconsistent API where draw relies on the VisualParams while the updateVisual needs to recover itself the VisualParams using :

sofa::core::visual::VisualParams* vparams = sofa::core::visual::visualparams::defaultInstance();

To sum up, could it be possible to make sure that using the defaultInstance() method returns up-to-date VisualParams?

@hugtalbot hugtalbot requested a review from fredroy December 8, 2024 10:51
@hugtalbot hugtalbot added the topic for next dev-meeting PR to be discussed in sofa-dev meeting label Dec 8, 2024
@bakpaul
Copy link
Contributor Author

bakpaul commented Dec 9, 2024

The defaultInstance() actually returns a singleton. It coud stay updated. The thing that makes the VisualParams come back to outdated values if the call to bwdVisual in the end of the drawVisual call. This put back the old ones. I don't actually know why we need to go back to the old ones. It is such as we don't want to keep the values present in the visual style component in the global instance.

IMO, VisualStyle should have a DataCallback where every modification of its visual flag data is applied to the defaultInstance(). This removes all that I have introduced but impose that the default instance always follows the VisualStyle.

@fredroy
Copy link
Contributor

fredroy commented Dec 10, 2024

The defaultInstance() actually returns a singleton. It coud stay updated. The thing that makes the VisualParams come back to outdated values if the call to bwdVisual in the end of the drawVisual call. This put back the old ones. I don't actually know why we need to go back to the old ones. It is such as we don't want to keep the values present in the visual style component in the global instance.

IMO, VisualStyle should have a DataCallback where every modification of its visual flag data is applied to the defaultInstance(). This removes all that I have introduced but impose that the default instance always follows the VisualStyle.

To be franck this is a bit confusing 🤔 it seems that there are some mixup between VisualParams & VisualStyle. It would have been great to directly quote the aforementioned code with a direct link 😅

In any case, I think this is a good idea to remove the VisualModel inheritance of VisualStyle, this does not make sense

@bakpaul
Copy link
Contributor Author

bakpaul commented Dec 10, 2024

No mixup here :
The fwd and bwd methods in VisualStyle :

void VisualStyle::fwdDraw(VisualParams* vparams)

Those are called by the drawVisualVisitor. This is when the DefaultInstance is modified. And this is the reason why in the VisualModels, during the the call to drawVisual vparams->displayFlags().getShowVisualModels() returned true, but not in the method updateVisual. here :

void VisualModel::drawVisual(const VisualParams* vparams)

The drawVisual visitor called fwdDraw first, so the VisualStyle updated the DefaultInstance, then he does the draw, then the call to bwdDraw put back the old values of the flags inside DefaultInstance. Because this was not called for the updateVisual, then it wasn't working. So removing the inheritance might make sense but doesn't solve the problem.

Why don't we leave the most updated values of the visual flags inside the default instance. Why do we reupload the backup values inside ? Couldn't it be constantly consistent with the actual visual flag values ?

@fredroy
Copy link
Contributor

fredroy commented Dec 10, 2024

This is much clearer with direct quote with the code 🧑‍💻

Why don't we leave the most updated values of the visual flags inside the default instance. Why do we reupload the backup values inside ? Couldn't it be constantly consistent with the actual visual flag values ?

A wild guess would be to manage the fact there can be other VisualStyle deeper in your scene. A node can set some flags, and its subnodes can set(or unset) other flags.

@bakpaul
Copy link
Contributor Author

bakpaul commented Dec 11, 2024

PR updated regarding discussions. I'll add an issue regarding the testing of this feature in a unit test, I'll not have time to do it here.

@hugtalbot
Copy link
Contributor

hugtalbot commented Dec 12, 2024

Just tested the PR, it fixes indeed the visualization problem

It remains that if we want to have specific VisualStyle : it has to be defined per Node and the last one override for the rest of the graph. VisualStyle should follow the mechanism we plan to deploy on gravity with data/links and tests should be added as suggested in #5157

@alxbilger
Copy link
Contributor

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

@alxbilger
Copy link
Contributor

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

@fredroy fredroy force-pushed the 24_12_fix_gui_visual_model branch from 01dd45b to 503f178 Compare December 16, 2024 23:34
@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 Dec 17, 2024
@fredroy fredroy merged commit 02b3366 into sofa-framework:master Dec 17, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix Fix a bug pr: status ready Approved a pull-request, ready to be squashed topic for next dev-meeting PR to be discussed in sofa-dev meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants