-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong co-ordinates captured from PyVistaQt window in QStackedWidget #122
Comments
Strange indeed. I'm not sure what magic is going inside Qt, but my guess is it's passing events from the widget to VTK and the coordinates aren't being transferred properly. If you can figure out how they're being miss-translated, we could add a hook into |
I have the same problem. Do you have a solution for this problem? |
I am encountering the same issue for a DockedView. I tried to remove the integration as a DockedWidget and simply called self.show() to display the plot in a new Window. Here is some code: from pyvistaqt import QtInteractor
from pyvistaqt import BackgroundPlotter
import pyvista as pv
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
import numpy as np
import threading
from pyvista import examples
class Picker:
def __init__(self, plotter, mesh):
self.plotter = plotter
self.mesh = mesh
self._points = []
@property
def points(self):
return self._points
def __call__(self, *args):
picked_pt = np.array(self.plotter.pick_click_position())
direction = picked_pt - self.plotter.camera_position[0]
direction = direction / np.linalg.norm(direction)
start = picked_pt - 1000 * direction
end = picked_pt + 1000 * direction
self._points.append(picked_pt)
w = self.plotter.add_mesh(pv.Sphere(radius=300, center=picked_pt), color="red")
class CustomInteractor(QtInteractor):
def __init__(self, BasePlotter, root):
self.actor = None
self.mesh = None
self.current_camera_pos = None
self.scaler = 1.0
super().__init__()
def remesh(
self, mesh=None):
if mesh is not None:
if self.current_camera_pos is not None:
self.current_camera_pos = self.camera_position
self.clear_actors()
self.actor = self.add_mesh(
mesh,
smooth_shading=False,
render_lines_as_tubes=True,
show_scalar_bar=False,
# pickable=True,
)
picker = Picker(self, self.mesh)
self.track_click_position(picker, side="right")
else:
return
def plot_preview(self):
mesh = examples.load_airplane()
# open new windows with the plot
self.iren.reset_picker()
if self.iren is not None:
self.show() It would be awesome to get to the second plot (after closing the first one) or simply wrapping the normal pyvista.plotter in a qtwindow, that can be closed without crashing the whole application. When walking along the stack call I came to the same conclusion as @2umbrella, that pick_click_position() returns a wrong value. This happens in the vtk backend so there is not much we can really do. The coordinates of click_position are correct. It would be awesome if someone with more insight could have a look at this problem.Being able to dock the plotting view and beaing able to use picking would be awesome for interacting in a complex ui. |
I would like to use a simple point picker by right clicking on a mesh. The example here in issue 239 works well: pyvista/pyvista-support#239
However, when this code is incorporated into PyQt5 where the plotter has been embedded as a QStackedWidget, the captured mouse co-ordinates are wrong. I have added a line to the Issue 239 example above to plot the point of the mouse co-ordinates.
Using the existing function: enable_point_picking, also has this effect of capturing the mouse co-ordinates incorrectly.
I would expect the enable_point_picking function or issue 239 example to work when the plotter is embedded as a QStackedWidget in Pyqt5.
To Reproduce
Please include a code snippet to reproduce the bug in the block below:
Screenshots
If applicable, add screenshots to help explain your problem.
System Information:
Please run the following code wherever you are experiencing the bug and paste the output below. This report helps us track down bugs and it is critical to addressing your bug:
# Paste system info here -------------------------------------------------------------------------------- Date: Wed Jul 28 10:17:53 2021 BST OS : Darwin CPU(s) : 8 Machine : x86_64 Architecture : 64bit Environment : Python GPU Vendor : Apple GPU Renderer : Apple M1 GPU Version : 4.1 Metal - 71.0.7 Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:10:52) [Clang 6.0 (clang-600.0.57)] pyvista : 0.31.3 vtk : 9.0.20210612 numpy : 1.19.5 imageio : 2.9.0 appdirs : 1.4.4 scooby : 0.5.7 meshio : 4.4.6 matplotlib : 3.3.3 pyvistaqt : 0.5.0 PyQt5 : 5.15.4 scipy : 1.7.0 tqdm : 4.61.1 --------------------------------------------------------------------------------
The text was updated successfully, but these errors were encountered: