Skip to content
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

no Plotter.camera #42

Closed
fcollman opened this issue Jul 11, 2019 · 18 comments
Closed

no Plotter.camera #42

fcollman opened this issue Jul 11, 2019 · 18 comments
Labels

Comments

@fcollman
Copy link

fcollman commented Jul 11, 2019

in my installation of vtkplotter, the plotter class doesn't seem to have a camera attribute. I see it in the source code...

In [1]: import vtkplotter                                                                                                                  

In [2]: vp = vtkplotter.Plotter()                                                                                                          

In [3]: vp.camera                                                                                                                          
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-f88340b80664> in <module>
----> 1 vp.camera

AttributeError: 'Plotter' object has no attribute 'camera'

In [4]: print(vtkplotter.__version__)                                                                                                      
2019.3.5

any idea what might be going on?

@fcollman
Copy link
Author

i see i can set it, it just isn't there to start. Now i'm trying to figure out how to control the camera in the k3d widget.

@marcomusy
Copy link
Owner

marcomusy commented Jul 11, 2019

HI, yes the vp.cameraonly exists after the first rendering.

The k3d backend is still a bit experimental and at present has a few limitations, loops , widget are not implemented... and camera positioning!
There are 2 ways out:
1 . use the k3d commands

from vtkplotter import settings

# ...
plt = vp.show(...)
plt

print(plt.camera) # a numpy object from k3d

see https://github.com/K3D-tools/K3D-jupyter/blob/master/examples/camera_manipulation.ipynb

  1. or
from vtkplotter import embedWindow
embedWindow(False)
# ...
vp.show(...)

print(vp.camera) # a vtkCamera object

@fcollman
Copy link
Author

fcollman commented Jul 12, 2019 via email

@marcomusy
Copy link
Owner

Thanks a lot! Indeed you can already pass a whole camera object to vp.camera, the thing is that this is not yet translated to the k3d format.
One can either (not yet in jupyter):

vp = Plotter()

# place vtkCamera at a specific position
# (get these numbers by pressing Shift-C)
vp.camera.SetPosition([2.5, 2.5, 5.5])
vp.camera.SetFocalPoint([0.4, 0.4, 0.4])
vp.camera.SetParallelScale(1.8)
vp.camera.SetViewUp([-0.1, 1, -0.3])

or with your nice function:

vp = Plotter()

vp.camera = oriented_camera((1,1,1), up_vector=(0, -1, 0), backoff=500, backoff_vector=(0,0,1))

i'll see if I can extend it to the k3d backend.

@marcomusy
Copy link
Owner

@fcollman
the latest version includes the camera functions from your meshparty project:
"cameraFromQuaternion",
"cameraFromNeuroglancer",
"orientedCamera",
"vtkCameraToK3D"

https://github.com/marcomusy/vtkplotter/blob/953e2d9f9c0226bea88d93a973c85e8a210000a3/vtkplotter/utils.py#L1095

the last function is the one you were suggesting in the above messages, I hope this is addressing it, I wrote an example here:
https://github.com/marcomusy/vtkplotter/blob/master/examples/notebooks/manipulate_camera.ipynb

@fcollman
Copy link
Author

I think this does address it.. except for not yet in jupyter?

@marcomusy
Copy link
Owner

in jupyter:
https://github.com/marcomusy/vtkplotter/blob/master/examples/notebooks/manipulate_camera.ipynb

You can form your vtkCamera object
vtkcam = orientedCamera(...)

and then apply it to the rendered scene as
settings.notebook_plotter.camera = vtkCameraToK3D(vtkcam)

..or maybe you were suggesting something different?

While playing with it I realize that K3D camera has some bug (viewup is not updated if the position is not modified): K3D-tools/K3D-jupyter#180

@fcollman
Copy link
Author

Got it working.. sorry was just confused by your comment about not in Jupyter earlier in the thread

@LogWell
Copy link

LogWell commented Oct 31, 2019

Is there any convenient way to set camera parameters like in pyrender?

@marcomusy
Copy link
Owner

@LogWell
we can easily add a method in Plotter class to set camera from a numpy array..
is the k3d format adequate for it? e.i.
[posx,posy,posz, targetx,targety,targetz, upx,upy,upz]
shape in this case is (9,), or should it maybe (3,3)?

@marcomusy marcomusy reopened this Oct 31, 2019
@NaGenhao
Copy link

NaGenhao commented Nov 5, 2019

The parameter vp.camera.SetDistance(*) does not seem to work, how can I solve it?
ref1
ref2

@marcomusy
Copy link
Owner

Try with
vp.show(..., resetcam=False)

@NaGenhao
Copy link

NaGenhao commented Nov 6, 2019

from vtkplotter import *

vp = Plotter()
s1 = load('dog3.off')
vp.show(s1, resetcam=False, interactive=1)

ss1

Then interact with the window, and press Shift-C, ss2

Add the output:

from vtkplotter import *

vp = Plotter()

s1 = load('dog3.off')
vp.camera.SetPosition([13.215, 3.279, 14.645])
vp.camera.SetFocalPoint([1.382, -0.444, -1.514])
vp.camera.SetViewUp([-0.066, 0.982, -0.178])
vp.camera.SetDistance(20.371)
vp.camera.SetClippingRange([16.588, 25.183])

vp.show(s1, resetcam=False, interactive=1)

ss3

I still can't get the result of figure 2.

@jby1993
Copy link

jby1993 commented Nov 6, 2019

@marcomusy @LogWell I also has the problem, vp.camera.SetPosition() setted value will be replaced by default value when rendered. Is this a bug?

@marcomusy
Copy link
Owner

This should be now fixed in the latest commit:

from vtkplotter import *

vp = Plotter()
s1 = load(datadir+'cow.vtk')

vp.camera.SetPosition( [6.316, -3.586, 1.36] )
vp.camera.SetFocalPoint( [-0.195, -0.762, -0.802] )
vp.camera.SetViewUp( [-0.245, 0.166, 0.955] )
vp.camera.SetDistance( 7.42 )
vp.camera.SetClippingRange( [4.283, 11.386] )

vp.show(s1, resetcam=0)

image

Thanks @LogWell and @jby1993 for spotting the issue.

@NaGenhao
Copy link

NaGenhao commented Nov 7, 2019

At present, it seems that you can install by python ./setup.py install rather pip install vtkplotter.

Thank for your nice work!

@marcomusy
Copy link
Owner

thanks @NaGenhao for your feedback.

  • the command pip install vtkplotter -U installs the latest release on the pip server
  • the command python ./setup.py install or cd vtkplotter; pip install .
    will install the local copy that you may have downloaded from the git repo.

@nantille
Copy link

I'm having the same issue with this code (or any other code with camera) in a jupyter notebook.
If this is still a bug, we should reopen this issue.

!pip install vedo -U
from vedo import *

# The same issue happens without the line below and with the line below with values itk and k3d
# embedWindow('k3d')

vp = Plotter()

s1 = load(datadir+"cessna.vtk")
vp.camera.SetPosition([13.215, 3.279, 14.645])
vp.camera.SetFocalPoint([1.382, -0.444, -1.514])
vp.camera.SetViewUp([-0.066, 0.982, -0.178])
vp.camera.SetDistance(20.371)
vp.camera.SetClippingRange([16.588, 25.183])

vp.show(s1, resetcam=False, interactive=1)

Yields

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-bf81439daf12> in <module>
      7 
      8 s1 = load(datadir+"cessna.vtk")
----> 9 vp.camera.SetPosition([13.215, 3.279, 14.645])
     10 vp.camera.SetFocalPoint([1.382, -0.444, -1.514])
     11 vp.camera.SetViewUp([-0.066, 0.982, -0.178])

AttributeError: 'NoneType' object has no attribute 'SetPosition'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants