GithubHelp home page GithubHelp logo

Camera view about pyvista-support HOT 9 CLOSED

pyvista avatar pyvista commented on July 18, 2024 1
Camera view

from pyvista-support.

Comments (9)

banesullivan avatar banesullivan commented on July 18, 2024 5

Hi @gunjan71011, this an excellent question! Like most tasks in PyVista, there are a few ways this can be done. One of the easiest would be to tell the plotter that the camera has been set after adding the small mesh to the scene. For example, create a plotter and add the mesh you'd like to focus on first:

p = pv.Plotter()
p.add_mesh(focus_mesh) # this is the one to focus on
p.camera_set = True # tell the plotter that the camera has been set and to not automatically adjust
p.add_mesh(some_mesh)
p.add_mesh(another_mesh)
p.show()

another easy option would be to use a convenience method like set_focus with the center of the mesh as the focus point:

p = pv.Potter()
p.add_mesh(focus_mesh)
p.add_mesh(some_mesh)
p.add_mesh(another_mesh)
p.set_focus(focus_mesh.center)
p.camera_set = True
p.show()

Or you could manually set the camera position if you have that already - FYI after the show() call, the last used camera position if returned. You could zoom/pan to a view you like and copy/paste that position into your code to set the position manually:

p = pv.Potter()
p.add_mesh(focus_mesh)
p.add_mesh(some_mesh)
p.add_mesh(another_mesh)
# tuple: camera location, focus point, viewup vector
p.camera_position = [(x,y,z), (fx,fy,fz,), (nx,ny,nz)]
p.show()

from pyvista-support.

banesullivan avatar banesullivan commented on July 18, 2024 4

Pro tip if you weren't aware: you can hold the shift key while clicking the scene to pan/translate the camera

from pyvista-support.

banesullivan avatar banesullivan commented on July 18, 2024 2

Ah, this is actually intentional behavior. The clipping planes for the camera only get reset on a full camera position set by PyVista (e.g. reset_camera or on the camera_position property. Setting intermediate values will not trigger the clipping planes to reset. This is needed by some folks (and myself at one point). To mitigate, call plotter.renderer.ResetCameraClippingRange() after calling each of the set methods.

If you predefine the camera position and want the clipping planes to reset, then use the .camera_position property setter to do all three at once.

from pyvista-support.

mli0603 avatar mli0603 commented on July 18, 2024 2

@banesullivan I just created a pull request. this is my first time so let me know if I did anything wrong :)

from pyvista-support.

gunjan71011 avatar gunjan71011 commented on July 18, 2024 1

Thanks Bane, that is exactly what I wanted!

from pyvista-support.

mli0603 avatar mli0603 commented on July 18, 2024

Hi Bane @banesullivan , I ran into a similar but not exact problem. I need to control the camera position, focal point, view up and view angle individually. It looks like the view angle (the zoom level) is not supported yet. But the first three do not work if I use the interface from the BasePlotter. Here is a minimal example.

import pyvista as pv
from pyvista import examples

mesh = examples.load_airplane()

# set camera position
cpos = [(-15862.8819973254, 5342.483170010628, 4153.88265742117),
 (896.9955291748047, 676.0221252441406, 132.19440269470215),
 (0.20163101424110583, -0.114200357111363, 0.9727811740220615)]

# this works
plotter = pv.Plotter(off_screen=True)
plotter.add_mesh(mesh, color='tan')
plotter.camera_position = cpos
plotter.show(screenshot='airplane_1.png')

# this should render exactly the same image but the output is blank
plotter = pv.Plotter(off_screen=True)
plotter.add_mesh(mesh, color='tan')
plotter.set_position([-15862.8819973254, 5342.483170010628, 4153.88265742117])
plotter.set_focus([896.9955291748047, 676.0221252441406, 132.19440269470215])
plotter.set_viewup([0.20163101424110583, -0.114200357111363, 0.9727811740220615])
plotter.show(screenshot='airplane_2.png')

In both cases, the camera parameters are identical. The second image should be the same as the first one. However, the second image renders only background. Do you know why this is the case? Thank you!

airplane_1.png
airplane_1

airplane_2.png
airplane_2

from pyvista-support.

mli0603 avatar mli0603 commented on July 18, 2024

Thanks @banesullivan ! That solved the problem. Good to know the cliping planes need to be reset.

from pyvista-support.

banesullivan avatar banesullivan commented on July 18, 2024

It would be good to add a reset_camera_clipping_planes wrapper on the Renderer and BasePlotter if you are up for a pull request

from pyvista-support.

mli0603 avatar mli0603 commented on July 18, 2024

I will take a look into that

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.