Comments (9)
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.
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.
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.
@banesullivan I just created a pull request. this is my first time so let me know if I did anything wrong :)
from pyvista-support.
Thanks Bane, that is exactly what I wanted!
from pyvista-support.
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!
from pyvista-support.
Thanks @banesullivan ! That solved the problem. Good to know the cliping planes need to be reset.
from pyvista-support.
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.
I will take a look into that
from pyvista-support.
Related Issues (20)
- create uniform mesh HOT 3
- Change the orientation of a scalar bar's title
- Applying textures on models from .obj files HOT 6
- How to create an Unstructured grid from points and faces HOT 2
- Type of data, plotting with glyphs HOT 3
- Controlling the thickness and orientation of a slice in Pyvista HOT 3
- Controlling the image position in window, without any click
- Mask/Remove Voxels in Air (small intersection with surface) HOT 3
- custom slider parameters
- running pyvista on headless machine with Centos OS HOT 1
- Seismic Horizon with Pyvista HOT 8
- Algorithm in sample function?
- Automatically updates HOT 3
- Slow interaction HOT 1
- read from text HOT 4
- Uniform Grid thresholding question HOT 8
- Take data by an input x,y,x coordinate (csv file) from vtk data file HOT 4
- Program broke when creating a mesh using pv.PolyData() HOT 4
- ATTENTION: Please move questions to PyVista's Discussions HOT 1
- plotter.enable_terrain_style not working for me HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvista-support.