Hi all,

I've been trying to build a point cloud visualization where the user may 
hover, click, or draw a box over points in a 3D scatter plot to highlight 
them. I don't know if there exists any built-in functionality for this. I 
found another similar post from 2016 in this group using an older version 
of pyqtgraph, but I had difficulties getting that solution to run, so I 
figured I'd bring up the issue again.

Here's my code. Right now it only aims to allow the user to click on a 
point and change its color to green, but the problem is I am using 
GLViewWidget's itemsAt method to return the GLScatterPlotItem, but it does 
not distinguish the particular point my mouse clicked, therefore all points 
turn green. Is there a short and sweet solution already out there?


import numpy as np
import pyqtgraph as pg
import pyqtgraph.opengl as gl

app = pg.mkQApp("GLScatterPlotItem Example")

class MyView(gl.GLViewWidget):

    def __init__(self):
        super().__init__()

    def mousePressEvent(self, e):
        super().mousePressEvent(e)

        items = w.itemsAt((e.pos().x()-5, e.pos().y()-5, 10, 10))
        if len(items) == 0:
            return
        print(items)
        for item in items:
            if type(item) == gl.GLScatterPlotItem:
                item.setData(color = (0,1,0,0.5))
        e.accept()

w = MyView()
w.show()
w.setCameraPosition(distance=10)

n = 100
pos = np.random.normal(0,1,(n,3))
size = 0.25*np.ones((n,))
color = np.ones((n,4))
color[:,-1] = 0.5

sp = gl.GLScatterPlotItem(pos=pos, size=size, color=color, pxMode=False)
w.addItem(sp)

if __name__ == '__main__':
    pg.exec()

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/a31e68e0-c961-4294-89c9-b5df8da7d14cn%40googlegroups.com.

Reply via email to