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

silx.gui.plot3d: Added HeightMapData and HeightMapRGBA items #3386

Merged
merged 7 commits into from
Mar 2, 2021

Conversation

t20100
Copy link
Member

@t20100 t20100 commented Feb 26, 2021

This PR adds 2 items to plot3d scene to provide a first display of height maps.
Both take a 2D data array that is used as the height of points based on a 2D regular grid and a second array for the colors:

  • HeightMapData for a height map with colormapped data
  • HeightMapRGBA for a height map with RGBA colors.

If both arrays (height and color) have different shapes, one is interpolated to match the other.

It can definitely be improved and provide more visualization modes (e.g., a display as a real surface), but it is already useable as it is.

closes #3379

TODO:

  • testing
  • doc example

@t20100 t20100 requested a review from juliagarriga February 26, 2021 17:17
@t20100
Copy link
Member Author

t20100 commented Feb 26, 2021

Sample code:

# coding: utf-8
import sys
import numpy

from silx.gui import qt
from silx.gui.plot3d.SceneWindow import SceneWindow, items


SIZE = 2048


qapp = qt.QApplication([])
window = SceneWindow()
sceneWidget = window.getSceneWidget()


coords = numpy.linspace(0, 1, SIZE)
x, y = numpy.meshgrid(coords, coords)
height = SIZE * numpy.exp(- 11. * ((x - .5) ** 2 + (y - .5) ** 2))

rgb_img = numpy.ones((SIZE, SIZE, 4), dtype=numpy.float32)
rgb_img[:, :, :3] = numpy.random.random(3 * SIZE ** 2).reshape(SIZE, SIZE, 3)
item = items.HeightMapRGBA()
item.setData(height)
item.setColorData(rgb_img)

sceneWidget.addItem(item)

window.show()
sys.excepthook = qt.exceptionHandler
qapp.exec_()

@t20100
Copy link
Member Author

t20100 commented Mar 1, 2021

Added basic tests, entry in documentation, picking support.

Changed interpolation mode in case the height map and the color/data map have different shapes to: use height map shape and generate color/data array of same shape through nearest interpolation to have a consistent behavior for both data and RGB(A) colors.

This is a first implementation, it can be optimised if needed (e.g., store the height and/or colors in textures, do not provide coordinates for each point, cache some info/reduce amount of transformed data in picking); and extended (adding linear color/data interpolation, display as a solid surface with some smoothing).

@t20100 t20100 marked this pull request as ready for review March 1, 2021 13:49
Copy link
Member

@juliagarriga juliagarriga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@juliagarriga juliagarriga merged commit 2b61ed8 into silx-kit:master Mar 2, 2021
@t20100 t20100 deleted the plot3d-heightmap branch March 3, 2021 12:55
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.

Add a plot3d item for colored height map
2 participants