Skip to content

Commit

Permalink
mouse color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Oct 20, 2020
1 parent 3ad1112 commit 867dc3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions vedo/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def tips():
from vedo import colors, __version__
msg = " ==========================================================\n"
msg += "| Press: i print info about selected object |\n"
msg += "| I print the RGB color under the mouse |\n"
msg += "| <--> use arrows to reduce/increase opacity |\n"
msg += "| w/s toggle wireframe/surface style |\n"
msg += "| p/P change point size of vertices |\n"
Expand Down
16 changes: 14 additions & 2 deletions vedo/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

import vedo
from vedo.colors import printc, getColor
from vedo.colors import printc, getColor, getColorName
import vedo.utils as utils
import vedo.settings as settings
import vedo.addons as addons
Expand Down Expand Up @@ -2046,7 +2046,7 @@ def export(self, filename='scene.npz'):
def _mouseleft(self, iren, event):

x, y = iren.GetEventPosition()
#print('_mouseleft mouse at', x, y)
# print('_mouseleft mouse at', x, y)

renderer = iren.FindPokedRenderer(x, y)
self.renderer = renderer
Expand Down Expand Up @@ -2630,6 +2630,18 @@ def _keypress(self, iren, event):
else:
utils.printInfo(self)

elif key == "I": # print color under the mouse
x, y = iren.GetEventPosition()
w2if = vtk.vtkWindowToImageFilter()
w2if.SetInput(self.window)
w2if.ReadFrontBufferOff()
w2if.Update()
nx, ny = self.window.GetSize()
arr = vtk_to_numpy(w2if.GetOutput().GetPointData().GetScalars()).reshape(ny,nx,3)
printc('Pixel =', [x,y], ' RGB =', arr[y,x].tolist(), end='')
cnm = getColorName(arr[y,x])
printc(' ('+cnm+')', c=cnm)

if iren:
iren.Render()

0 comments on commit 867dc3b

Please sign in to comment.