Skip to content

Add overlay grid option to GLSurfacePlotItem#3349

Merged
j9ac9k merged 9 commits intopyqtgraph:masterfrom
swvanbuuren:swvanbuuren/3d-grid-surface
Nov 15, 2025
Merged

Add overlay grid option to GLSurfacePlotItem#3349
j9ac9k merged 9 commits intopyqtgraph:masterfrom
swvanbuuren:swvanbuuren/3d-grid-surface

Conversation

@swvanbuuren
Copy link
Copy Markdown
Contributor

@swvanbuuren swvanbuuren commented Jul 31, 2025

This PR adds the possibility to overlay rectangular grids on 3D surfaces as provided by GLSurfacePlotItem. It also extends the current example of 3D surface plots to showcase the rectangular grids.

Here's a screenshot of the updated example:
image

The current implementation already features adding a wireframe to a 3D surface plot, but unfortunately the grid lines don't look nice and it's only possible to show the actual triangle mesh wireframes and not rectangular grids, which IMO is useful to visualize and analyze data.

To nicely overlay the grid, the only feasible I could find, is to create additional GLLinePlotItems that are added to the scene. To have this working, I added the _setView method, to make sure the view is available. As soon as this is the case, the grid lines are added to the scene. For proper display, certain OpenGL options need be set for the GLMeshItem and GLLinePlotItem.

Not sure if there would be a better way to handle this, but at least this seems to do the trick. I am open for suggestions for improvements or alternatives to this approach.

Also note, that adding rectangular grids to animated surfaces imposes a serious performance drop. Because of this, I didn't add the grid to animated surface in the example. Maybe we should a note about this somewhere, although I am note sure where. (With the latest changes, this doesn't seem to be an issue anymore)

Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Jul 31, 2025

It should be possible to use a single GLLinePlotItem in "lines" mode (default is "line-strip") to draw the entire grid.

GLGridItem, GLGraphItem use this technique.

This is equivalent to the "pairs" mode of PlotCurveItem.

@swvanbuuren
Copy link
Copy Markdown
Contributor Author

It should be possible to use a single GLLinePlotItem in "lines" mode (default is "line-strip") to draw the entire grid.

GLGridItem, GLGraphItem use this technique.

This is equivalent to the "pairs" mode of PlotCurveItem.

I will look into this and will try to come up with a version which only calls GLLinePlotItem once with mode='lines'.

Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
@swvanbuuren
Copy link
Copy Markdown
Contributor Author

swvanbuuren commented Sep 5, 2025

@pijyoi I changed the default setting for anti-aliasing for the grid lines to False.

Is there anything else that needs to be addressed/changed/fixed in this PR from your pov?

Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 15, 2025

Thanks for the PR @swvanbuuren (and thanks for the review @pijyoi ). My apologies for letting this sit for so long. Diff looks great, merging!

@j9ac9k j9ac9k merged commit 6e80c43 into pyqtgraph:master Nov 15, 2025
36 checks passed
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.

3 participants