Skip to content

[Helper,Visual] Visualize scalar field on meshes using color palette#6192

Merged
hugtalbot merged 11 commits into
sofa-framework:masterfrom
alxbilger:colormap
Jul 23, 2026
Merged

[Helper,Visual] Visualize scalar field on meshes using color palette#6192
hugtalbot merged 11 commits into
sofa-framework:masterfrom
alxbilger:colormap

Conversation

@alxbilger

Copy link
Copy Markdown
Contributor

This PR adds visual coloring capabilities to mesh rendering by introducing vertex value-based color mapping. The implementation creates a color mapping system that converts scalar values to colors using a color palette, enabling temperature visualization in heat diffusion simulations. This enhancement provides a direct way to visualize scalar fields like temperature across mesh elements through color gradients.

Changes:

  • TrailRenderer changes the type of the Data color from RGBAColor to ColorMap (breaking). This allows to use gradients of colors for the trail, including fading effect.
  • Introduce color visualization of vertex values in VisualMesh. If vertex values are provided, they are converted to colors using a ColorMap and rendered on the mesh.
  • DrawTool: introduce an overload of drawLineStrip where a vector of colors is provided. This allows to create color gradients in the TrailRenderer. It is implemented in DrawToolGL.
  • DrawColoredMesh: introduction of reusable class to draw a mesh with colors. Used in VisualMesh.
  • ColorMap: refactoring (breaking):
    • Improve serialization/deserialization so it can be used easily in a Data. It is also symmetric.
    • Color presets using enums
    • Remove API related to color preset because it supposed that a ColorMap is only created using presets. It is no longer the case.

Possibilities to define a color map in a scene:

<!-- Using hexadecimal codes -->
<VisualMesh colorMap="#277DA1 #577590 #4D908E #43AA8B #90BE6D #F9C74F #F9844A #F8961E #F3722C #F94144"/>

<!-- Also using transparency -->
<VisualMesh colorMap="#ff0000ff #ff000000"/>

<!-- Using pre-defined colors -->
<VisualMesh colorMap="blue white red"/>

<!-- A combination of the two -->
<VisualMesh colorMap="#277DA1 yello #F94144 navy"/>

<!-- Using presets -->
<VisualMesh colorMap="GreenInv"/>

Tip: use https://coolors.co to generate your own palette, or explore existing ones https://coolors.co/palettes/trending

Diffusion example:

raptor_diffusion.mp4

Trail renderer:

pendulum.mp4

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

@alxbilger alxbilger added pr: enhancement About a possible enhancement pr: breaking Change possibly inducing a compilation error pr: status to review To notify reviewers to review this pull-request pr: new feature Implement a new feature labels Jul 17, 2026
@alxbilger

Copy link
Copy Markdown
Contributor Author

Note that I did not implement DrawElementColoredMesh for other types of element than tetrahedra. It will be done in another PR when I will need it for von Mises stress.

@hugtalbot hugtalbot added the pr: highlighted in next release Highlight this contribution in the notes of the upcoming release label Jul 23, 2026
@hugtalbot hugtalbot 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 Jul 23, 2026
@hugtalbot
hugtalbot merged commit 3a303c1 into sofa-framework:master Jul 23, 2026
9 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: breaking Change possibly inducing a compilation error pr: enhancement About a possible enhancement pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: new feature Implement a new feature 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