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

[OMEdit] Distinguish length/radius scale invariance for vector visualizers #11663

Merged

Conversation

anotheruserofgithub
Copy link
Contributor

@anotheruserofgithub anotheruserofgithub commented Nov 29, 2023

Related Issues

#9390 (comment)

Purpose

Split scale invariance of vectors into two attributes to accommodate for rotation/translation/zoom:

  • length scale invariance: vector length is frozen to the screen but shaft radius plus head(s) length and radius keep varying with the scale of the model;
  • radius scale invariance: shaft radius plus head(s) length and radius are frozen to the screen but vector length keeps varying with the scale of the model.

Following those definitions, users should be aware of which combinations of parameters are meaningful:

  • invariance of neither length nor radius scales: always valid;
  • invariance of both length and radius scales: always valid;
  • invariance of either length or radius scale: quantity comparisons are meaningful if only the shaft length is counted, otherwise as long as the shaft has a positive length (i.e., visible), which cannot be guaranteed even if the sampling of time-varying vectors is enabled when adjusting scales at initialization.

Approach

Split scale invariance parameter into two distinct parameters.
Cancel out appropriate dimensions of AutoTransform's scale in its cull callback.

Alternative

The proposed implementation is probably not the most efficient because it requires to recompute the geometries of cylinder and cone(s) every time a scale value changes.
Instead, it may be possible to only modify the scale and post-translation components of the transform matrix, which is already updated at every cull traversal anyway.
However, this is not possible with a single AutoTransform because it would not preserve the aspect ratio between length and radius of the head(s).
To avoid this deformation, two AutoTransforms shall be used, one for the shaft and one for the head(s), see this schema.
The idea would be to define two geodes inside independent AutoTransforms and place their junction at the frame origin so that a scaling can be applied separately to each of the geodes.
The head(s) would always scale all dimensions together in order to preserve the aspect ratio, whilst the shaft could be scaled along the direction of its axis (meaning, its length) differently than across the other dimensions (which correspond to its radius).
Then, an offset would be applied to reposition the geodes, either +s or -h depending whether the tail or the head of the vector shall be placed at the frame origin.
That can be achieved at very little cost by overriding the AutoTransform's method dedicated to computing the transform matrix, but should be done in two different versions so as to maintain compatibility with older versions of OpenSceneGraph (typically, v3.2.3 which is packaged by default in Ubuntu 18.04).
Furthermore, having two geodes for the same visualizer would require to substantially rewrite the way its drawables are updated.
Hence this is too cumbersome to implement for the little benefit it could bring.

Test

Change these two methods to return either true or false and simulate this simple model with animation:

model Test
  inner Modelica.Mechanics.MultiBody.World world;
  Modelica.Mechanics.MultiBody.Visualizers.Advanced.Vector vector(
    coordinates={time+1,0,0},
    headAtOrigin=true
  );
end Test;

Then play with rotation, translation, zoom, and time.

@anotheruserofgithub
Copy link
Contributor Author

@adeas31 Your review would be very much appreciated. :)

@adeas31 adeas31 self-requested a review November 30, 2023 11:33
@adeas31 adeas31 merged commit 26f58c4 into OpenModelica:master Dec 4, 2023
2 checks passed
@anotheruserofgithub anotheruserofgithub deleted the split_vector_scale_invariance branch December 4, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants