Logbook + Scratchpad


I've decided to try VisPy by adapting my previous PyQtGraph example. In the process I have figured out something I got wrong about the update function: I thought the loop that updates the points for the scatterplot had to be inside the update, and this works with PyQtGraph but doesn't with VisPy. (A GitHub Issue gave me the idea.) This brought me to reconsider the role of update as a function that should include the changes to data as a timer-controlled operation too. In other words, there should not be a loop inside update; rather, the loop (or the condition) variable has to be updated inside but declared outside.

Beside this important realization (which I would have probably come across had I read more about Qt and timers), for this use case I haven't seen any big differences between VisPy and PyQtGraph except that VisPy has an easier API to work with, for example:

  • The main application in VisPy can just be imported from the main module with from vispy import app.
  • Views are added to a SceneCanvas in VisPy.
  • There are no specific “GL widgets” in VisPy, so a PyQtGraph GLScatterPlotItem is just a Markers “visual element”.
  • There are no “Qt modules” in VisPy, so a QTimer from pyqtgraph.Qt.QtCore in PyQtGraph is just an app.Timer.

#Python #OpenGL

One of the experiments I did as part of the old project I have recently written about was about animating a 3D plot using OpenGL from PyQtGraph. The code was inspired pretty much to one of the PyQtGraph examples from its GitHub repository, where – for future memory – the main components are the following:

  • A Qt QApplication as the container Qt app.
  • A GLViewWidget as the main OpenGL view component.
  • A GLGridItem to visualize a grid (not essential).
  • A GLScatterPlotItem as the actual scatterplot graph.
  • A QTimer to repeatedly call an update function, which includes two actions:
    • setData to plot the data points
    • orbit to make the camera spin around the view center (neat!)

I've recently revisited the example to put everything in a class rather than relying on globals. I'll publish it at some point.

#Python #OpenGL

While looking again at some code I wrote quite some time ago to animate a graph with OpenGL in PyQtGraph, I learned that some OpenGL libraries (including PyQtGraph) still use the Fixed Function Pipeline. Apparently, VisPy is a good replacement as it is based on the more modern shaders instead.

I haven't looked at any other Python OpenGL packages yet, but I might give VisPy a try.

#TIL #OpenGL #Python