iblviewer.utils
Functions
Modified function from vedo. |
|
Add a 2D or 3D overlay (aka caption in VTK). |
|
Create a new 2D scalar bar. |
|
Initializes a box widget on the given target |
|
Change the file name from the given file path |
|
Get the bounds of an actor as xmin, xmax, ymin, ymax, zmin, zmax |
|
Get the absolute center position of an actor |
|
Get the dimensions of an actor |
|
Get bounding planes for an actor |
|
Get full file name |
|
Get data path |
|
Get the bounding box coordinates of a series of planes. |
|
Get a surface mesh file path |
|
Get transformation matrix for a plane given by its origin and normal |
|
Get the type of object as a string :return: String |
|
Create a unique key for a collection by appending numbers when entries exist |
|
Read surface data from a binary GLTF scene |
|
Load a surface mesh with vedo. |
|
Convert a numpy array into a vtkDataArray |
|
Pick an object |
|
Initializes a line widget on the given target |
|
Clip the volume and move the slicing planes according the given planes |
|
Convert spherical degree angles to XYZ coordinates |
|
Split any given file path to folder path, file name and extension :return: Folder path, file name and extension |
|
Get a time difference in seconds |
|
Update a scalar bar with a new LUT |
- get_unique_name(collection, name, spacer='_')[source]
Create a unique key for a collection by appending numbers when entries exist
- Parameters
collection – A list, collection, array, …
name – Name (for instance ‘Points’)
spacer – Spacer char
- Returns
New name, for instance ‘Points_4’
- numpy2vtk(arr, dtype=None, deep=True, name='')[source]
Convert a numpy array into a vtkDataArray
- Parameters
arr – Array
dtype – Data type. Allows to set a specific data type to the VTK array
deep – Whether a deep copy is made. Defaults to True
name – Name of the array
- spherical_degree_angles_to_xyz(radius, theta, phi)[source]
Convert spherical degree angles to XYZ coordinates
- Parameters
radius – Radius
theta – Theta angle value in degrees
phi – Phi angle value in degrees
- Returns
List of 3 coordinates
- add_callback(plot, event_name, func, priority=0.0)[source]
Modified function from vedo. The issue is that the way vedo (and pyvista for that matter) is structured is that it helps using vtk but sometimes hinders using it with code that makes assumptions we don’t want.
Add a function to be executed while show() is active. Information about the event can be acquired with method
getEvent()
. Return a unique id for the callback. The callback function (see example below) exposes a dictionary Frequently used events are:KeyPress, KeyRelease: listen to keyboard events
LeftButtonPress, LeftButtonRelease: listen to mouse clicks
MiddleButtonPress, MiddleButtonRelease
RightButtonPress, RightButtonRelease
MouseMove: listen to mouse pointer changing position
MouseWheelForward, MouseWheelBackward
Enter, Leave: listen to mouse entering or leaving the window
Pick, StartPick, EndPick: listen to object picking
ResetCamera, ResetCameraClippingRange
Error, Warning
Char
Timer
- Check the complete list of events here:
- get_file_name(file_name, extension)[source]
Get full file name
- Parameters
file_name – File name without extension
extension – File extension
- Returns
File name with extension
- get_local_data_file_path(file_name, extension, sub_folder='')[source]
Get data path
- Parameters
file_name – File name without extension
extension – File extension
- Returns
File path
- get_surface_mesh_path(file_name, meshes_path=None, extension='ply', default_meshes_path=None)[source]
Get a surface mesh file path
- Parameters
file_name – File name without extension
meshes_path – Folder path. If None given, this method will look into the data folder of iblviewer
extension – File extension
default_meshes_path – Fallback local or remote path
- Returns
Full mesh file path
- load_surface_mesh(file_name, meshes_path=None, extension='ply')[source]
Load a surface mesh with vedo.
- Parameters
file_name – File name without extension
meshes_path – Folder path. If None given, this method will look into the data folder of iblviewer
extension – File extension
- Returns
Mesh or None if path is invalid
- change_file_name(file_path, prefix=None, name=None, suffix=None)[source]
Change the file name from the given file path
- Parameters
file_path – Input file path
prefix – Prefix to the file name
name – Whether a new name is set instead of the current name. If None, the current file name is used.
suffix – Suffix to the file name
- Returns
New file path
- split_path(path)[source]
Split any given file path to folder path, file name and extension :return: Folder path, file name and extension
- time_diff(t)[source]
Get a time difference in seconds
- Parameters
t – Time
- Returns
Number of seconds
- get_actor_center(actor)[source]
Get the absolute center position of an actor
- Parameters
actor – VTK actor
- Returns
3d array
- get_actor_bounds(actor)[source]
Get the bounds of an actor as xmin, xmax, ymin, ymax, zmin, zmax
- Parameters
actor – VTK actor
- Returns
Array with 6 values
- get_actor_dimensions(actor)[source]
Get the dimensions of an actor
- Parameters
actor – VTK actor
- Returns
3d array
- get_bounding_planes(actor)[source]
Get bounding planes for an actor
- Parameters
actor – VTK actor
- Returns
vtkPlanes
- get_planes_bounds(planes)[source]
Get the bounding box coordinates of a series of planes. [WARNING] Only works for six planes (box mode) at the moment
- Parameters
planes – vtkPlaneCollection
- Returns
6 values
- get_transformation_matrix(origin, normal)[source]
Get transformation matrix for a plane given by its origin and normal
- Parameters
origin – Origin 3D vector
normal – Normal 3D vector
- Returns
Matrix and Translation
- set_clipping_planes(target, planes, flip_normals=False)[source]
Clip the volume and move the slicing planes according the given planes
- Parameters
target – vedo.Mesh (can be iblviewer.objects.Points or similar)
planes – vtkPlanes
flip_normals – Whether clipping normals are flipped
- probe(plot, target, widget=None, interaction_callback=None, point1=None, point2=None, place_factor=1, handle_size=0.005, color=None)[source]
Initializes a line widget on the given target
- Parameters
plot – vtk plot
target – Target object
widget – Existing widget. In case a valid vtkLineWidget is given,
it will be used and modified directly :param interaction_callback: Function that will be called every time there is an interaction with the widget. That’s where you set the clipping planes to the object for instance :param point1: Initial position of point 1 :param point2: Initial position of point 2 :param place_factor: see vtkBoxWidget.setPlaceFactor() :param handle_size: set the relative handle size, see vtkBoxWidget.SetHandleSize() :param color: Color of the line :return: vtkLineWidget
- box_widget(plot, target, interaction_callback=None, place_factor=1, handle_size=0.005, outline_color=None)[source]
Initializes a box widget on the given target
- Parameters
plot – vtk plot
target – Target object
interaction_callback – Function that will be called every time there is an interaction with the widget. That’s where you set the clipping planes to the object for instance
place_factor – see vtkBoxWidget.setPlaceFactor()
handle_size – set the relative handle size, see vtkBoxWidget.SetHandleSize()
outline_color – Color of the outline
- Returns
vtkBoxWidget
- update_scalar_bar(sb, lut, use_alpha=False, nan_color=None)[source]
Update a scalar bar with a new LUT
- Parameters
sb – vtkScalarBarActor
lut – vtkLookupTable
use_alpha – whether alpha is used in the scalar bar
- add_scalar_bar(lut, pos=(0.8, 0.05), font_color=[0, 0, 0], title='', titleYOffset=15, titleFontSize=12, size=(None, None), nlabels=None, horizontal=False, use_alpha=False)[source]
Create a new 2D scalar bar. This is a modified method from vedo.addons.addScalarBar
- Parameters
lut – Color map LUT
pos (list) – fractional x and y position in the 2D window
size (list) – size of the scalarbar in pixel units (width, heigth)
nlabels (int) – number of numeric labels to be shown
use_alpha (bool) – retain trasparency in scalarbar
horizontal (bool) – show in horizontal layout