Replies: 2 comments
-
Hi @baba-yaga thanks for the detailed description of the problem. In fact I don't like how it is now because it's doing different things (with objects and dict) so if it looks good to you I would be in favor of making a copy inside if camera is not None:
self.resetcam = False
if isinstance(camera, vtk.vtkCamera):
copycamera = vtk.vtkCamera()
copycamera.DeepCopy(camera)
self.camera = copycamera
else:
self.camera = utils.camera_from_dict(camera)
if self.renderer:
self.renderer.SetActiveCamera(self.camera) If one wants to link different renderers with the same camera this can still be done with an extra line: plt = Plotter(N=3)
plt.at(0).show(...) # this has its own camera
plt.at(1).show(...)
cam1 = plt.camera # save camera at 1
plt.at(2).show(...)
plt.camera = cam1 # use the same camera of renderer1
plt.interactive() |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you, Marco - your suggestion suits me perfectly. I was just thinking that some may want to re-use the camera from the active renderer, but below you showed how to do it. Also, it would be helpful to specify Roll in the dictionary description of the camera
Thank you for your work!
Sergei
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, Marco,
I am not sure whether to consider this a feature or a bug, but I have discovered hard way that in interaction mode=0 Plotter changes the vtkCamera when explicitly used in the call. Here is a demo:
Define a vtk camera and a mesh:
Now plot the cube and rotate it before quitting the plot by pressing "q":
Check the mesh and the camera's position:
The cube is still the same, but the camera changed to the new position(!?) The default interaction mode is 0 which means the camera is rotated, but I am not sure it is a good practice that a function parameter is muted. See for instance here:
https://florimond.dev/en/posts/2018/08/python-mutable-defaults-are-the-source-of-all-evil/
Note that this does not happen when the camera in Plotter.show is defined via a dictionary, because
inside show(), a vtkCamera is created with utils.camera_from_dict so dict is not muted.
I realise that changing Plotter.show to a new behaviour may break old codes. So I suggest adding a new parameter modify_inplace, as in utils.camera_from_dict defaulting to True. But if set to False, a clone of the camera is created inside show() and it would not mute the camera itself.
Actually, the same can be done in mode=1, when the cube is rotated and retains its new position on quitting the plotter. Now, if one does not want this, the plot should be called with C.clone()
Beta Was this translation helpful? Give feedback.
All reactions