openGLWidget lagging when displaying a big amount of lines, how to make it work smoothly?

48 views
Skip to first unread message

Nick PV

unread,
Mar 27, 2020, 3:34:43 AM3/27/20
to pyqtgraph

I have a problem when openGLWidget (on PyQt5 Qdialog form) significantly slowing down for pan or rotate when it displaying more then 2-3 thousand lines (or thousand polygons) plotted in 3D space.

Is there any technique to make it work smoothly (change refresh rate or anything what is applicable) or it's just how openGLWidget performs, that it is not capable to hold a big amount of independent lines?

For note, I have very powerful PC with powerful discrete graphic card, so computer performance is not a case.

Just for example (cut from a context code) I'm plotting lines in this way:


import pyqtgraph.opengl as gl
from pyqtgraph.Qt import QtWidgets
import numpy as np

self.app = QtWidgets.QApplication(sys.argv)
self.w = gl.GLViewWidget()


pl_line
= ([(1, 1, 1), (2, 2, 2)])  # [Start coordinates(X,Y,Z), End coordinates (X,Y,Z)]

pl_line = np.array(pl_line)
newline
= gl.GLLinePlotItem(pos=pl_line, color=red, width=1, antialias=False) # Regular line plotting


self.w.addItem(newline)
self.w.show()
self.app.exec()

So, when I have even 500 lines on the 3D plot it's still smooth, but once I going beyond that up to 2 thousand of lines it's FPS drops to 3-5 FPS when I'm rotating the plot scene. 

Kenneth Lyons

unread,
Mar 29, 2020, 3:19:37 PM3/29/20
to pyqtgraph
I'm guessing OpenGL is probably not the bottleneck here. Each GLLinePlotItem is a Python object and each GLViewWidget.paintGL update iterates over them. If there's any way to combine your lines into a mesh or a single GLLinePlotItem, you'd probably see reasonable performance. As a test, you could try plotting an equivalent number of points in a single GLLinePlotItem and see if that brings the FPS up.

I think the opengl module handles NaNs well. You might be able to "cut" a single line into pieces by concatenating lines and inserting np.nan between them.

Nick PV

unread,
Mar 30, 2020, 3:15:18 AM3/30/20
to pyqtgraph


Highly appreciated for your respond.

So, you saying that I should use polyline and path it to GLLinePlotItem
That will be cool but I don't know how to pass such construction (I couldn't find anything at pyqtgraph documentation which showing any example of polyline;  Documentation link there just empty pages at documentation regarding this).

Could you please show me example (based on what I have in my code right now) how to implement polylines (basically in which form I should pass start and end coordinates (pl_line)  to numpy that it will be accepted by gl.GLLinePlotItem) without errors?

Or maybe you know is there any way how I can pass rectangle based on 4 points?


Thank You! 
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages