Skip to content

Basic_viewer: color faces by value (distance, cell size, and a drawer value) - #9598

Open
RajdeepKushwaha5 wants to merge 19 commits into
CGAL:mainfrom
RajdeepKushwaha5:colour-by-value
Open

Basic_viewer: color faces by value (distance, cell size, and a drawer value)#9598
RajdeepKushwaha5 wants to merge 19 commits into
CGAL:mainfrom
RajdeepKushwaha5:colour-by-value

Conversation

@RajdeepKushwaha5

@RajdeepKushwaha5 RajdeepKushwaha5 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Small feature

Wiki page here

This PR adds a small feature to the public API: a drawer can attach a scalar value to each face, which the Basic_viewer maps to a colour palette, mirroring the existing colour path.

New API:

  • Graphics_scene_options: valued_face (does this face have a value), face_value (the value), face_value_name (the legend label).
  • Graphics_scene: set_face_value(float), set_value_name(const std::string&).

Purpose: mesh-quality visualisation. The viewer cannot compute a quality measure itself (it only has the boundary triangles); each drawer can. The surface mesh drawer uses this to expose the aspect ratio of each face.

Scope: small and additive. It mirrors colored_face / face_color, defaults to off (no value), and changes no existing behaviour.

Description

This adds an automatic colouring of the faces by a value, mapped to a colour from a palette, discussed with the mentors as a follow-up to the clipping work.

Palette (D key). D turns the colouring on and cycles the palette: off, then a heat, a jet, a grey ramp and viridis (a perceptually uniform map). The palette is evaluated in the face shader, so there is no texture.

Value (Shift+D key). Shift+D picks the value, skipping the ones that do not apply to the scene:

  • distance to the plane, as a smooth per-fragment gradient;
  • the same distance, one flat colour per cell (needs volumes);
  • the cell size, one flat colour per cell (needs volumes);
  • a value provided by the drawer, one flat colour per face (see below).

Distance is computed live in the shader from the clipping plane the user places with Ctrl+C. Distance and size are normalised over the range actually present in the scene, so the whole palette is used.

A value from the drawer. Following Guillaume's suggestion, the viewer does not have to compute geometric values itself. A drawer can attach a scalar value to each face, the same way it attaches a colour: the graphics-scene options gain valued_face / face_value / face_value_name, the scene stores the value next to the colour, and the viewer maps it to the palette. As the example, the surface mesh viewer exposes the aspect ratio (longest edge / shortest edge) of each face. This is the general mechanism for mesh-quality colouring (aspect ratio, Jacobian, and so on), with each drawer computing what its mesh allows.

Legend. A small legend is drawn when the colouring is on: a gradient bar in the current palette with the value range, labelled by the drawer's name (or distance / size). It uses the same range and palette as the faces, so the two match, and it is hidden when the value has no range (a uniform field).

The Basic_viewer part is contained in Basic_shaders.h and Basic_viewer.h. The value mechanism also touches Graphics_scene.h, Graphics_scene_options.h, the face-graph drawer (BGL/draw_face_graph.h), and the surface mesh drawer.

Testing: verified on grids of hexahedra (Linear_cell_complex) and on triangle meshes (Surface_mesh). The values and palettes behave as described, the per-cell and per-face modes read as flat blocks, the colours span the full palette with the legend matching the values present (including as the clipping plane is moved and rotated), the drawer-provided aspect ratio colours the surface mesh with a named legend, and the colouring holds in every clipping mode.

Note on next step (Guillaume's suggestion)

The value mechanism generalises the built-in size and enables mesh-quality colouring per data structure. The surface mesh aspect ratio is the first example; values on volumes (set_volume_val) and other measures are natural follow-ups.

@sloriot

sloriot commented Aug 11, 2026

Copy link
Copy Markdown
Member

Successfully tested in CGAL-6.3-Ic-52

@sloriot

sloriot commented Aug 11, 2026

Copy link
Copy Markdown
Member

@gdamiand I'm waiting for your approval to merge it.

@github-actions github-actions Bot removed the Tested label Aug 14, 2026
@github-actions

Copy link
Copy Markdown

This pull-request was previously marked with the label Tested, but has been modified with new commits. That label has been removed.

@RajdeepKushwaha5 RajdeepKushwaha5 changed the title Basic_viewer: colour faces by value (distance to the plane and cell size) Basic_viewer: colour faces by value (distance, cell size, and a drawer value) Aug 15, 2026
…ce mesh

In whole-volume clipping the surface-mesh path (no volumes to keep or
hide) drew every face with a plain glDrawArrays, so it ignored the
drawer's per-face value: the colour stayed on distance and did not
change when switching to the aspect ratio, and did not update when the
plane moved. Draw that path the same way the main renderer does, per
face with u_CellValue, so the drawer value applies here too.
…g the plane updates the colours

distance_value_range took the min and max of the bounding-box corner
distances to the current plane. Both ends then shifted with the plane
exactly as the per-fragment distance did, so translating the plane left
the normalised colours unchanged (they only changed on rotation). It
also put the clipped-away half in the range, so the legend advertised
colours no visible face showed. Anchor the range at the plane instead:
0 at the plane, growing into the kept half up to its farthest point.
Moving the plane now sweeps the colours (the farthest distance changes),
and the legend matches the visible faces over the full palette.
@RajdeepKushwaha5

Copy link
Copy Markdown
Member Author

hi sir @sloriot
I have finished all my work on this, and it is ready to be re-tested from my side.

@sloriot

sloriot commented Aug 19, 2026

Copy link
Copy Markdown
Member

Successfully tested in CGAL-6.3-Ic-58

@sloriot

sloriot commented Aug 21, 2026

Copy link
Copy Markdown
Member

/build:v0

@github-actions

Copy link
Copy Markdown

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/9598/v0/Manual/index.html

Comment thread Basic_viewer/doc/Basic_viewer/Concepts/GraphicsSceneOptions.h Outdated
Rename the Graphics_scene_options predicate valued_face to is_face_valued,
as sloriot asked on the pull request, so the boolean predicate reads as a
question while face_value and face_value_name return the data. Updated the
concept documentation, the surface mesh drawer, the BGL face-graph drawer,
and the changelog to match.
@github-actions github-actions Bot removed the Tested label Aug 21, 2026
@github-actions

Copy link
Copy Markdown

This pull-request was previously marked with the label Tested, but has been modified with new commits. That label has been removed.

@sloriot

sloriot commented Aug 22, 2026

Copy link
Copy Markdown
Member

Successfully tested in CGAL-6.3-Ic-61

@sloriot

sloriot commented Aug 24, 2026

Copy link
Copy Markdown
Member

colour -> color

Comment thread Basic_viewer/doc/Basic_viewer/Concepts/GraphicsSceneOptions.h Outdated
Comment thread Basic_viewer/doc/Basic_viewer/Concepts/GraphicsSceneOptions.h Outdated
Comment thread Basic_viewer/doc/Basic_viewer/Concepts/GraphicsSceneOptions.h Outdated
Co-authored-by: Sebastien Loriot <sloriot.ml@gmail.com>
@github-actions github-actions Bot removed the Tested label Aug 24, 2026
@github-actions

Copy link
Copy Markdown

This pull-request was previously marked with the label Tested, but has been modified with new commits. That label has been removed.

@afabri afabri changed the title Basic_viewer: colour faces by value (distance, cell size, and a drawer value) Basic_viewer: color faces by value (distance, cell size, and a drawer value) Aug 24, 2026
@sloriot

sloriot commented Aug 26, 2026

Copy link
Copy Markdown
Member

Successfully tested in CGAL-6.3-Ic-64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants