GithubHelp home page GithubHelp logo

Comments (13)

banesullivan avatar banesullivan commented on June 19, 2024 1

@banesullivan You could make a plugin to PyVista using PyQt to show these tables and allow selections to callback to the extract filters. Making the GUI would be the hard part... all the extraction and PyVista stuff is already implemented".

@laserman781 Do you have any ideas on how I could do this? Also, how do I get the mesh data (point data and or cell data) in a table for this?

On the lastest version of PyVista, the Table class was introduced - a wrapped implementation of vtkTable which can also go back and forth to a Pandas DataFrame. I'd start by making tables of the mesh's point/cell data by passing those dictionaries to the Table constructor:

import pyvista as pv
from pyvista import examples

# Any mesh
mesh = examples.download_st_helens().warp_by_scalar()

# Make a table
point_table = pv.Table(mesh.point_arrays)

Also, now you have a Table which can be converted to a Pandas DataFrame:

df = point_table.to_pandas()

I'd recommend starting there and then taking a look at the Qt Table Widget and this SO post about making Qt Tables from data frames. Then you'd want to display that widget in an app (maybe link it to PyVista's BackgroundPlotter) and enable row selection in the qt widget which would call back to function that extracts the cell/point indices (row indices from the table) using either extract_cells or extract_points

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Cell selection is currently possible - check out the .enable_cell_picking method on the plotter: https://docs.pyvista.org/plotting/plotting.html#pyvista.BasePlotter.enable_cell_picking

You could pass a custom callback function to save out the mesh or grab the saved mesh after closing the plotter from the .picked_cells attribute

Otherwise, I'm not sure what you mean by selecting elements/holes...

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

What kind of function would I need to create to do this? I simply want to be able to select a mesh from the plot and export it as it's own vtk file using the save function.

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

Or more specifically selecting a vtk cell

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

The goal is to try and get something similar to extract selection from ParaView.

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

After making a selection with the plotter's .enable_cell_picking (which recently had some enhancements that aren't released yet), you can grab the mesh from the .picked_cells attribute on that plotter - then you could save that mesh if desired.

Here's an example

import pyvista as pv
from pyvista import examples

mesh = examples.download_dragon()

p = pv.Plotter(notebook=False)
p.add_mesh(mesh)
p.enable_cell_picking(mesh)
p.show()

2019-08-19 12 02 23

selection = p.picked_cells
selection.plot(color='white')

download

# Save it
selection.save('my_selection.vtk')

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

This works great! I am getting the option "Press P to pick a single cell under the mouse"

Is this coming in the next release?

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Yes, a few new features with cell selection are coming in the next release! Along with many other point selection tools and widgets.

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

Awesome! Final question... I mentioned above being able to select from a table. In ParaView there is the option to have a spreadsheet view side by side with the plot and be able to select the cells by their rows (see screenshot in email). from there I can apply the extract cellls filter. Is something like this possible in PyVista as well?

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

In short, not really as PyVista isn't designed to be GUI application like ParaView.

But if you know the cell IDs (the rows in the spreadsheet view) then you can use PyVista's .extract_cells filter to extract cells by their IDs which is exactly what ParaView's extract selection filter is doing.

Coming in the next release of PyVista is support for vtkTable objects in a new Table class which can go back and forth with Pandas DataFrame objects. Perhaps there are good tools for interactively making selections from Pandas data frames that would be well suited for this? I image we could make a tool that would display the cell data (or point data) as a pandas DataFrame and perhaps leverage some sort of interactive DataFrame tool to make selections and extract cells in a similar fashion.

Unfortunately it is out of scope for us to deisgn any sort of interactive selection tool based on a table representation.

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Or if you are feeling really adventurous, you could make a plugin to PyVista using PyQt to show these tables and allow selections to callback to the extract filters. Making the GUI would be the hard part... all the extraction and PyVista stuff is already implemented

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

Okay, I will give this a try. Thank you!

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

FYI... there are some custom Qt widgets implemented in VTK for tables but I'm not sure if they are available on the Python distribution: https://vtk.org/doc/nightly/html/classvtkQtTableView.html

It might require a custom build of VTK

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.