-
Hello, Here is an example:
Above, I created a class that shows the cube from different cameras. For example:
Now, I am visualising the scene with the cube, and the camera positions marked red. I aim to get the corresponding view if I click on a camera point.
I want to be able to return to this plot (plt) on quitting the secondary one and selecting, maybe, another camera view from it. But all the plots quit on quitting the secondary plot. Could anybody help? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @baba-yaga dealing with opening and closing windows has always been an headache for me in vtk.
Or something like this: from vedo import *
class CubeViewer:
def __init__(self, msh, cam_positions):
self.mesh = msh.pickable(False)
self.cameras = []
self.plotter = Plotter(shape=(1, 2), sharecam=False)
for p in cam_positions:
self.cameras.append(dict(pos=p))
self.camera_positions = Points(cam_positions, r=20, c="red5")
self.labels = self.camera_positions.labels2d(justify="center")
self.axes = Axes(msh)
self.comment = Text2D(
font="Calco", pos="bottom-center", c="white", bg="red2", alpha=1
)
self.camera_positions.name = "camera_positions"
self.plotter.add_callback("mouse click", self.cam_select)
self.plotter.at(0).add(msh, self.camera_positions, self.labels, self.axes)
self.plotter.at(0).reset_camera()
self.plotter.at(1).add(msh, self.axes, self.comment)
self.plotter.show().interactive()
def update_cam(self, pid):
self.comment.text(f"Current Camera Point is {pid}")
self.plotter.at(1).camera = self.cameras[pid]
self.plotter.render()
def cam_select(self, event):
obj = event.object
if not obj:
return
pt = event.picked3d
pid = self.camera_positions.closest_point(pt, return_point_id=True)
self.update_cam(pid)
def close(self):
self.plotter.close()
shape = Mesh(dataurl + "bunny.obj").scale(10)
cam_pos = [(-2, 1, 4), (2, 3, 4), (2, 1, 1), (1, -2, 0)]
cv = CubeViewer(shape, cam_pos)
cv.close() |
Beta Was this translation helpful? Give feedback.
-
Thank you, Marco! |
Beta Was this translation helpful? Give feedback.
Hi @baba-yaga dealing with opening and closing windows has always been an headache for me in vtk.
I would first have a look at these options, maybe you will find something that fits your needs:
Or something like this: