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

clip entire plot at a given elevation with slider #32

Closed
laserman781 opened this issue Jul 29, 2019 · 6 comments
Closed

clip entire plot at a given elevation with slider #32

laserman781 opened this issue Jul 29, 2019 · 6 comments
Assignees
Labels
filtering General topics around filtering and usage of filters plotting General plotting/rendering topics

Comments

@laserman781
Copy link

I have points and lined that are viewed together on a plot using pyvista.plotter and adding a mesh. I am having difficulty

Code:

p = pv.Plotter(notebook=False)
p.add_mesh(points,color='blue',render_points_as_spheres=all)
for i in range(0, len(DH)):
    p.add_mesh(globals()['segment{}'.format(i)],color='white',)
p.view_yz()
p.show_axes()

clipper = pv.Clip(p,plotter=p)

image

@banesullivan
Copy link
Member

Hi @Quadius - at this time, clipping an entire scene is not implemented and the pyvista.Clip tool only handles a single mesh in the scene. I could hack together a solution for you soon here but not immediately.

The errors you are experiencing have to do with the arguments for the Clip tool. It takes the mesh you'd like to clip and an optional BackgroundPlotter object (not a standard Plotter).

Try this in the meantime:

p = pv.BackgroundPlotter()
for i in range(0, len(DH)):
    p.add_mesh(globals()['segment{}'.format(i)],color='white',)
p.view_yz()
p.show_axes()

clipper = pv.Clip(points, plotter=p, display_params=dict(color='blue', 
                                                         render_points_as_spheres=True))

@banesullivan
Copy link
Member

Also, reference this currently closed issue: pyvista/pyvista#162

@laserman781
Copy link
Author

Basically, I have rendered each line using pv.Line and each point using PolyData. Maybe I could combine all of them into one vtk object so I can then clip at a given elevation? Also, with your last solution I received the following without any viewer:

image

@banesullivan
Copy link
Member

banesullivan commented Jul 29, 2019

Also, with your last solution I received the following without any viewer

Sometimes the BackgroundPlotter appears in the background behind your current application (which is not intended given the name - the "Background" refers to the fact that it runs in a background thread)

@banesullivan
Copy link
Member

banesullivan commented Jul 29, 2019

Basically, I have rendered each line using pv.Line and each point using PolyData. Maybe I could combine all of them into one vtk object so I can then clip at a given elevation?

Ah, yes!! You could easily merge these all into one pyvista.UnstructuredGrid - there are a few ways to do this...

  1. Create a pyvista.MultiBlock dataset containing everything and run its .comine() filter
blocks = pv.MultiBlock
blocks.append(points)
for i in range(0, len(DH)):
    blocks.append(globals()['segment{}'.format(i)])
merged = blocks.combine()
  1. Use the .boolean_add() filter on the PolyData objects or the + operator which is pretty nifty (if poth inputs are PolyData):
merged = points.copy()
for i in range(0, len(DH)):
   merged = merged + globals()['segment{}'.format(i)]

@banesullivan
Copy link
Member

banesullivan commented Jul 29, 2019

Then if you still want to color the points and the line segments differently, you could add scalar values to them before merging:

import numpy as np
points['chunk'] = np.zeros(points.n_points)
for i in range(0, len(DH)):
    m = globals()['segment{}'.format(i)]
    m['chunk'] = np.ones(m.n_points)

Then when plotting the merged grid, simply choose a colormap (cmap) that you like, specify n_colors=2, and make sure the scalars are set to 'chunk'

@banesullivan banesullivan transferred this issue from pyvista/pyvista Jul 29, 2019
@banesullivan banesullivan added filtering General topics around filtering and usage of filters plotting General plotting/rendering topics labels Aug 1, 2019
@banesullivan banesullivan self-assigned this Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filtering General topics around filtering and usage of filters plotting General plotting/rendering topics
Projects
None yet
Development

No branches or pull requests

2 participants