open_viewmin.filter_tree_plot.filter_formulas

Contents

open_viewmin.filter_tree_plot.filter_formulas#

Define classes for reusable PyVista filters and widgets, which can be re-applied in the Plotter based on changes to other meshes.

Module Contents#

Classes#

FilterFormula

Class for reusable PyVista filters.

WidgetFormula

Class for creating re-usable widgets

class open_viewmin.filter_tree_plot.filter_formulas.FilterFormula(plotter, name=None, parent_mesh_name=None, filter_callable=None, filter_kwargs=None, mesh_kwargs=None, random=None, has_actor=True, in_place=False, ovm_info=None, widget_name=None, apply_upon_creation=True, children=None, colorbar=None, **extra_filter_kwargs)#

Class for reusable PyVista filters.

Parameters:
  • plotter (open_viewmin.FilterTreePlot) – Parent plotter

  • name (str or None) – Name of filter formula and its mesh. Pass None to default to plotter’s default mesh name.

  • parent_mesh_name (str or None) – Name of parent mesh. Pass None to default to plotter’s default mesh name.

  • filter_callable (callable(), str, or None) – Function of parent mesh that returns a callable, which when called applies a filter to (re-)create a child mesh. Pass None to use an “identity filter”, making the parent its own child.

  • filter_kwargs (dict or None, optional) – Dictionary of keyword arguments supplied to the function returned by filter_callable. None is equivalent to dict().

  • mesh_kwargs (dict or None, optional) – Dictionary of keyword arguments to pyvista.Plotter.add_mesh for customization of mesh visualization. None is equivalent to dict().

  • random (bool or None, optional) – Whether to use random sampling, if applicable.

  • has_actor (bool, optional) – Whether to create an actor visualizing the mesh.

  • in_place (bool, optional) – Whether to modify a mesh in-place rather than creating a child mesh.

  • ovm_info (dict or None) – Dictionary of keyword arguments for ad-hoc purposes. None is equivalent to dict().

  • widget_name (str or None) – Name of widget, if applicable, that creates this filter formula

  • apply_upon_creation (bool, optional) – Whether to apply the filter formula, creating its mesh, immediately upon creating the filter formula.

  • children (list of str, or None, optional) – List of names of child meshes. None is equivalent to []`.

  • colorbar (VTK scalar bar actor or None, optional) – Existing colorbar actor, if applicable.

  • **extra_filter_kwargs (dict, optional) – Extra keyword arguments to append to filter_kwargs (for convenience).

property array_names#

Get mesh’s dataset names

Return type:

list[str]

property is_filter_tree_root#

Check whether mesh is a root of the filter tree

Return type:

bool

property is_glyphs#

Check whether mesh is glyphs

Return type:

bool

property mesh#

Get child mesh

Return type:

pyvista.dataset

property normal#
property orientations#
property origin#
property parent_filter_formula#

Get parent mesh’s filter formula

Return type:

FilterFormula

property parent_mesh#

Get parent mesh

Return type:

pyvista.dataset

property points#

Get mesh’s points

Return type:

numpy.ndarray

property random#

Check whether random sampling has been selected

Return type:

bool

property root_ancestor#
__getitem__(key)#

Access mesh’s datasets in dictionary-like manner

__repr__()#

Print keyword arguments to self.__init__ and their current values

Return type:

str

__setitem__(key, set_to)#

Set mesh’s datasets in dictionary-like manner

_interpret_color_or_scalars(mesh_kwargs)#

Check if mesh coloring should be updated as a solid color or color array.

Parameters:

mesh_kwargs (dict) – Mesh visualizing settings

Returns:

Whether to update solid color, whether to update color array, and mesh visualizing settings dictionary

Return type:

(bool, bool, dict)

_remove_bad_mesh_kwargs(mesh_kwargs)#

Remove unexpected keyword arguments to pyvista.Plotter.add_mesh

Parameters:

mesh_kwargs (dict) – Mesh visualization settings

Returns:

Mesh visualization settings with bad keyword arguments removed

Return type:

dict

_update_actor_color_array()#

Visualize mesh with color array

_update_actor_solid_color()#

Visualize mesh with solid color

add_calculation(name, calc_callable)#

Create a data array for this mesh that is recalculated whenever the mesh is updated. The function accomplishing this is added to the filter_formula’s do_after_update list.

Example: If we have a NematicPlot p, with a glyphs filter_formula called “director”, the following creates a scalar data array holding the normal component of the “director” orientation field.

>>> p["director"].add_calculation("normal_component", lambda a: np.inner(a.orientations, a.normal))

Equivalently, you can assign calc_callable as the value corresponding to key name:

>>> p["director"]["normal_component"] = lambda a: np.inner(a.orientations, a.normal)
Parameters:
  • name (str) –

  • calc_callable (callable()) – Function mapping filter_formula to calculated data array.

add_filter(filter_callable, **kwargs)#

Create a callable that returns a filter formula whose parent mesh is this formula’s child mesh

Used for dictionary-style assignment of new filter formula to plotter.

Parameters:
  • filter_callable (callable()) – Function mapping new mesh name to new filter formula

  • kwargs (dict, optional) – Keyword arguments to FilterFormula

Return type:

callable()

add_glyphs(**kwargs)#

Create a glyphs child filter formula

Parameters:

kwargs (dict, optional) –

Returns:

Function of new mesh name; adds glyphs filter formula

Return type:

callable()

color_by_active_scalars(categories=None)#
get_auto_color()#

Get next color in plotter’s color sequence

Returns:

color rgb values

Return type:

tuple(float)

get_centroids(num_centroids=10, ref_pt_idx=0, mesh_name_to_probe=None)#

Add centroids filter formula

Child filter formula probes a given mesh at centroids calculated from the points of this filter formula’s mesh.

Parameters:
  • num_centroids (int, optional) – Number of centroids

  • ref_pt_idx (int, optional) – Index of starting point for calculating centroids

  • mesh_name_to_probe (str or None, optional) – Name of mesh to probe (source of datasets). Pass None to default to self.plotter.default_mesh_name.

Returns:

Name of sampled (child) mesh

Return type:

str

get_circuits(mesh_to_probe_name=None, normals_name=None, radius=3, n_samples=100, use_ints=False)#

Add circuits filter formula

Parameters:
  • mesh_to_probe_name (str) – Name of mesh to probe

  • normals_name (str or None, optional) – Name of vectors dataset defined on mesh_of_circuit_centers to be used as normal directions to circuits. Pass None to default to name of active_vectors dataset of parent mesh.

  • radius (float, optional) – Radius of each circuit.

  • n_samples (int, optional) – Number of circuits.

  • use_ints (bool, optional) – Whether to round coordinates of circuit points to integers.

Returns:

Name of sampled (child) mesh, or None if no child mesh was created.

Return type:

str or None

get_eigenvec(tensors_name=None, evec_idx=-1, new_dataset_name=None)#

Calculate an eigenvector of symmetric second-rank tensor dataset

Parameters:
  • tensors_name (str or None, optional) – Name of symmetric rank-2 tensors dataset. Pass None to default to name of most recently created symmetric rank-2 tensors dataset.

  • evec_idx (int, optional) – Index of eigenvector to take, ordered by ascending eigenvalues

  • new_dataset_name (str or None) – Name of vector dataset storing eigenvector. Pass None to default to “_eigenvec” appended to tensors_name.

Return type:

numpy.ndarray

give_colorbar_unique_title()#

Check if color bar lacks a title, and assign one if so

Returns:

Color bar title

Return type:

str

static handle_filter_or_numpy(filter_result, parent_mesh, filter_name)#

Properly handle filter results that may be mesh or array

If the filter result is an array, assigns the filter result as a new dataset on a copy of the parent mesh.

Parameters:
  • filter_result (pyvista.dataset or numpy.ndarray) – Result of filter

  • parent_mesh (pyvista.dataset) – Parent mesh

  • filter_name (str) – Name for new dataset in case filter_result is an array.

Returns:

New child mesh

Return type:

pyvista.dataset

hide()#

Make mesh’s actor invisible

static identity_callable(mesh)#

Get a filter formula callable that simply copies the parent mesh

Parameters:

mesh (pyvista.dataset) –

Return type:

callable()

inherit(filter_kwarg)#
make_sure_parent_knows_about_me()#

Make sure that this filter formula’s name is in the parent mesh filter formula’s list of children

remove_child_relationship_to_all_parents()#

Cause any meshes claiming this mesh as a child to forget that relationship, a prerequisite for deleting this mesh.

remove_colorbar()#

Remove color bar for this filter formula’s mesh

set(**mesh_kwargs)#

Shorthand for self.update_actor

Parameters:

**mesh_kwargs – New or modified keyword arguments to pyvista.Plotter.add_mesh

Returns:

Updated actor

Return type:

vtkmodules.vtkRenderingOpenGL2.vtkOpenGLActor

set_glyph_shape(new_shape, **geom_args)#

Modify shape of glyphs

Parameters:
  • new_shape (str) – Shape name

  • geom_args (dict, optional) – Keyword arguments for shape

set_glyphs_scale(new_scale)#

Set global scale factor for glyphs

Parameters:

new_scale (float) – New scale factor

set_glyphs_stride(new_stride)#

Set spacing between glyphs

Parameters:

new_stride (int) – New spacing

static string_to_filter(filter_string)#

Convert filter name to callable

Convert string name of PyVista filter to a callable that produces that filter. If the argument is not a string, return the argument (for cases where the filter callable is passed rather than its string name).

Parameters:

filter_string (str or object) –

Returns:

  • callable() – Function mapping existing mesh to a new mesh via the named filter.

  • object – If filter_string is not a string, returns filter_string

update(update_actor=True, ovm_info=None, **filter_kwargs)#

Update a mesh by calling its creator filter

Parameters:
  • update_actor (bool, optional) – Whether to update the actor visualizing the mesh

  • ovm_info (dict or None, optional) – New or modified items for mesh settings dictionary

  • **filter_kwargs – New or modified keyword arguments for filter callable

Returns:

Updated child mesh

Return type:

pyvista.dataset

update_actor(is_new=False, **mesh_kwargs)#

Update or create mesh visualizing actor

Parameters:
  • is_new (bool, optional) – Whether actor has just been created (to avoid duplicate warnings)

  • mesh_kwargs (dict, optional) – New or modified keyword arguments to pyvista.Plotter.add_mesh

Returns:

Updated actors

Return type:

list of vtkmodules.vtkRenderingOpenGL2.vtkOpenGLActor

update_children()#

Update child meshes

Calls update function of each filter formula named in self.children

class open_viewmin.filter_tree_plot.filter_formulas.WidgetFormula(plotter, name=None, mesh_name=None, enabled=True, callback=None, creator=None, configure=None, widget_args=None, **kwargs)#

Class for creating re-usable widgets

Parameters:
  • plotter (open_viewmin.FilterTreePlot) –

  • name (str or None) – Name of widget. Pass None to default to “_widget” appended to parent_mesh_name.

  • mesh_name (str or None) – Name of mesh controlled by widget. Pass None to default to plotter’s default mesh name.

  • enabled (bool, optional) – Whether to initialize widget as enabled.

  • callback (callable()) – Function mapping (plotter, parent_mesh_name) to a callable that applies the widget to update its mesh.

  • creator (callable()) – Function creating the widget. First argument must be a function of the kind created by callback(plotter, parent_mesh_name). Must also accept all arguments in widget_args and keyword arguments in kwargs.

  • configure (callable() or None, optional) – Function configuring a widget based on previously existing widget, mapping the widget to a two-element tuple (enabled: bool, widget_args: tuple). Pass None to ignore.

  • widget_args (tuple or None) – Positional arguments, besides callback, to creator. None is equivalent to empty tuple.

  • kwargs (dict, optional) – Keyword arguments to creator.

property widget#

Get widget

Return type:

VTK widget

apply()#

Create the widget and apply it to create the mesh it controls

check_existing_widget_configuration()#

Get information to configure widget according to previous settings

Returns:

Whether widget is enabled; widget arguments.

Return type:

(bool, tuple)

get_creator_func()#

If self.creator is a string, get the corresponding callable

Return type:

callable()

set_color(*widget_color)#

Set widget color

Note that this does not control the color of any mesh.

Parameters:

widget_color (tuple) – Color as rgb floats, or as one-element tuple containing string of color name or hex value.

set_outline_visibility(visibility)#

Set visibility of a widget’s box outline

Parameters:

visibility (int) – Make outline visible unless visibility equals 0.

update()#

Update mesh controlled by widget.

Configure widget according to previous settings, then apply the widget’s callback.