question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot show Volume on Plotter in qtwindow

See original GitHub issue

I am following the code given in the examples but i could not get the volume view in qtwindow. I get a blank screen when i try to show Volume derived from ndarray but works fine on predefined shapes.

import sys
from PyQt5 import Qt
import numpy as np
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vtkplotter import Plotter, Volume, Cube, Sphere

class MainWindow(Qt.QMainWindow):
    def __init__(self, parent=None):

        Qt.QMainWindow.__init__(self, parent)
        self.frame = Qt.QFrame()
        self.vl = Qt.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl.addWidget(self.vtkWidget)

        vp = Plotter(qtWidget=self.vtkWidget, bg='black')

        c = Cube(side=30)
        s = Sphere(r=15)
        X, Y, Z = np.mgrid[:30, :30, :30]
        scalar_field = ((X-15)**2 + (Y-15)**2 + (Z-15)**2)/225
        vol = Volume(scalar_field)
        vol.alpha([0, 0, 0.4, 0.9, 0.9])

        # vp.show(c)
        # vp.show(s)
        vp.show(vol)

        self.frame.setLayout(self.vl)
        self.setCentralWidget(self.frame)

        self.show()    # <--- show the Qt Window

    def onClose(self):
        print("Disable the interactor before closing to prevent it from trying to act on a already deleted items")
        self.vtkWidget.close()


if __name__ == "__main__":
    app = Qt.QApplication(sys.argv)
    window = MainWindow()
    app.aboutToQuit.connect(window.onClose) # <-- connect the onClose event
    app.exec_()

The same Volume can be rendered without Plotter

import numpy as np
from vtkplotter import Volume

def main():
    X, Y, Z = np.mgrid[:30, :30, :30]
    scalar_field = ((X-15)**2 + (Y-15)**2 + (Z-15)**2)/225
    vol = Volume(scalar_field)
    vol.alpha([0, 0, 0.4, 0.9, 0.9])
    vol.show(bg="black")

if __name__ == '__main__':
    main()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcomusycommented, Dec 4, 2019

Thanks @pasha009 ! I will add a comment in the example.

1reaction
pasha009commented, Dec 3, 2019

This workaround is functioning for me. But no idea why. Just added

import vtk.qt
vtk.qt.QVTKRWIBase = "QGLWidget"

before any vtk imports

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot show Volume on Plotter in qtwindow · Issue #79 - GitHub
I get a blank screen when i try to show Volume derived from ndarray but works fine on predefined shapes. import sys from...
Read more >
Plot an audio waveform in C++/Qt - Stack Overflow
This is a rough guide to how loud this area might sound, but there is no way to extract or use this RMS...
Read more >
Qt Data Visualization Overview
Qt Data Visualization offers ready-made data proxies that can be used to visualize data from Qt item models and height maps. Each graph...
Read more >
Comments/Forum - Qt Plotting Widget QCustomPlot
When i spawn multiple windows without plot widget resources are freed correctly. No matter if qcustomplot is added in qtcreator, staticly added ...
Read more >
Clickable ROOT histograms in QT - ROOT Forum
Specifically I'd like to present the user with a TH2 COLZ type histogram and have each bin in the plot be click-able. ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found