-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
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_() |
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
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 dataHeightMapRGBA
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:
example