frontend package

Module contents

Entry point for the frontend module.

To start the application, simply import the App class from the frontend module.

class frontend.App(name: str, renew: bool, cache_dir: str = '')[source]

Bases: object

property CI: bool

Determine if the code is running in a CI environment.

Returns:

True if the code is running in a CI environment, False otherwise.

Return type:

bool

property asset: AssetManager

Get the asset manager.

Returns:

The asset manager.

Return type:

AssetManager

clear() App[source]

Clears the application state.

clear_cache() App[source]

Clears the cache directory.

static create(name: str, cache_dir: str = '') App[source]

Start a new application.

Parameters:
  • name (str) – The name of the application.

  • cache_dir (str) – The directory to store the cached files. If not provided, it will use .cache/ppf-cts directory.

Returns:

A new instance of the App class.

Return type:

App

darkmode() App[source]

Tunrs on the dark mode.

property extra: Extra

Get the extra manager.

Returns:

The extra manager.

Return type:

Extra

static get_default_param() Param[source]

Get default parameters for the application.

Returns:

The default parameters.

Return type:

Param

static get_proj_root() str[source]

Find the root directory of the project.

Returns:

Path to the root directory of the project.

Return type:

str

static load(name: str, cache_dir: str = '') App[source]

Load the saved state of the application if it exists.

Parameters:
  • name (str) – The name of the application.

  • cache_dir (str) – The directory to store the cached files. If not provided, it will use .cache/ppf-cts directory.

Returns:

A new instance of the App class.

Return type:

App

mesh

The mesh manager.

Type:

MeshManager

property plot: PlotManager

Get the plot manager.

Returns:

The plot manager.

Return type:

PlotManager

save() App[source]

Saves the application state.

property scene: SceneManager

Get the scene manager.

Returns:

The scene manager.

Return type:

SceneManager

property session: SessionManager

Get the session manager.

Returns:

The session manager.

Return type:

SessionManager

class frontend.AssetFetcher(manager: AssetManager)[source]

Bases: object

AssetFetcher class. Use this to fetch data assets from the manager.

get(name: str) dict[str, ndarray][source]

Get the asset data.

Parameters:

name (str) – The name of the asset.

Returns:

The asset data, containing the vertices and elements, such as V, F, T, E, Ind, W.

Return type:

dict[str, np.ndarray]

rod(name: str) tuple[ndarray, ndarray][source]

Get the rod mesh data.

Parameters:

name (str) – The name of the asset.

Returns:

The vertices and edges (#x2) of the rod mesh.

Return type:

tuple[np.ndarray, np.ndarray]

stitch(name: str) tuple[ndarray, ndarray][source]

Get the stitch mesh data.

Parameters:

name (str) – The name of the asset.

Returns:

Ind (index, #x3) and W (weight, #x2) of the stitch mesh. The weight encodes the liner interpolation between the last two vertices.

Return type:

tuple[np.ndarray, np.ndarray]

tet(name: str) tuple[ndarray, ndarray, ndarray][source]

Get the tetrahedral mesh data.

Parameters:

name (str) – The name of the asset.

Returns:

The vertices (#x3), surface elements (#x3), and tetrahedral (#x4) elements of the mesh.

Return type:

tuple[np.ndarray, np.ndarray, np.ndarray]

tri(name: str) tuple[ndarray, ndarray][source]

Get the triangle mesh data.

Parameters:

name (str) – The name of the asset.

Returns:

The vertices (#x3) and elements (#x3) of the triangle mesh.

Return type:

tuple[np.ndarray, np.ndarray]

class frontend.AssetManager[source]

Bases: object

AssetManager class. Use this to register or remove data assets.

property add: AssetUploader

Get the asset uploader.

clear()[source]

Clear all the assets in the manager.

property fetch: AssetFetcher

Get the asset fetcher.

list() list[str][source]

List all the assets in the manager.

Returns:

A list of asset names.

Return type:

list[str]

remove(name: str) bool[source]

Remove an asset from the manager.

Parameters:

name (str) – The name of the asset to remove.

Returns:

True if the asset was removed, False otherwise.

Return type:

bool

class frontend.AssetUploader(manager: AssetManager)[source]

Bases: object

AssetUploader class. Use this to upload data assets to the manager.

check_bounds(V: ndarray, E: ndarray)[source]

Check if the indices in E are within the bounds of V.

rod(name: str, V: ndarray, E: ndarray)[source]

Upload a rod mesh to the asset manager.

Parameters:
  • name (str) – The name of the asset.

  • V (np.ndarray) – The vertices (#x3) of the rod.

  • E (np.ndarray) – The edges of (#x2) the rod.

stitch(name: str, stitch: tuple[ndarray, ndarray])[source]

Upload a stitch mesh to the asset manager.

Parameters:
  • name (str) – The name of the asset.

  • stitch (tuple[np.ndarray, np.ndarray]) – Ind (index, #x3) and W (weight #x2) of the stitch mesh.

  • vertices. (The weight encodes the liner interpolation between the last two)

tet(name: str, V: ndarray, F: ndarray, T: ndarray)[source]

Upload a tetrahedral mesh to the asset manager.

Parameters:
  • name (str) – The name of the asset.

  • V (np.ndarray) – The vertices (#x3) of the mesh.

  • F (np.ndarray) – The surface triangle (#x3) elements of the mesh.

  • T (np.ndarray) – The tetrahedral elements (#x4) of the mesh.

tri(name: str, V: ndarray, F: ndarray)[source]

Upload a triangle mesh to the asset manager.

Parameters:
  • name (str) – The name of the asset.

  • V (np.ndarray) – The vertices (#x3) of the mesh.

  • F (np.ndarray) – The triangle elements (#x3) of the mesh.

class frontend.CppRustDocStringParser[source]

Bases: object

static get_logging_docstrings(root: str) dict[str, dict[str, str]][source]
class frontend.CreateManager(cache_dir: str)[source]

Bases: object

A Manger tghat provides mesh creation functions

This manager provides a set of functions to create various types of meshes, such as rods, triangles, and tetrahedra.

rod(vert: ndarray, edge: ndarray) Rod[source]

Create a rod mesh

Parameters:
  • vert (np.ndarray) – a list of vertices

  • edge (np.ndarray) – a list of edges

Returns:

a rod mesh, a pair of vertices and edges

Return type:

Rod

tet(vert: ndarray, elm: ndarray, tet: ndarray) TetMesh[source]

Create a tetrahedral mesh

Parameters:
  • vert (np.ndarray) – a list of vertices

  • elm (np.ndarray) – a list of surface triangle elements

  • tet (np.ndarray) – a list of tetrahedra elements

Returns:

a tetrahedral mesh, a pair of vertices and tetrahedra

Return type:

TetMesh

tri(vert: ndarray, elm: ndarray = array([], dtype=float64)) TriMesh[source]

Create a triangle mesh

Parameters:
  • vert (np.ndarray) – a list of vertices

  • elm (np.ndarray) – a list of elements

Returns:

a triangle mesh, a pair of vertices and triangles

Return type:

TriMesh

class frontend.Extra[source]

Bases: object

Extra class. Use this to perform extra operations.

load_CIPC_stitch_mesh(path: str) tuple[ndarray, ndarray, tuple[ndarray, ndarray]][source]

Load a stitch mesh data used in CIPC paper

Parameters:

path (str) – The path to the stitch mesh data.

Returns:

A tuple containing the vertices (#x3), faces (#x3), and stitch data (index #x3 and weight #x2). The weight encodes the liner interpolation between the last two vertices.

Return type:

tuple[np.ndarray, np.ndarray, tuple[np.ndarray, np.ndarray]]

class frontend.FixedScene(plot: PlotManager, name: str, vert: ndarray, color: ndarray, vel: ndarray, uv: ndarray, rod: ndarray, tri: ndarray, tet: ndarray, wall: list[Wall], sphere: list[Sphere], rod_vert_range: tuple[int, int], shell_vert_range: tuple[int, int], rod_count: int, shell_count: int)[source]

Bases: object

A fixed scene class.

bbox() tuple[ndarray, ndarray][source]

Compute the bounding box of the scene.

Returns:

The maximum and minimum coordinates of the bounding box.

Return type:

tuple[np.ndarray, np.ndarray]

center() ndarray[source]

Compute the area-weighted center of the scene.

Returns:

The area-weighted center of the scene.

Return type:

np.ndarray

check_intersection() FixedScene[source]

Check for self-intersections and intersections with the static mesh.

Returns:

The fixed scene.

Return type:

FixedScene

export(vert: ndarray, path: str, include_static: bool = True) FixedScene[source]

Export the scene to a mesh file.

Export the scene to a mesh file. The vertices must be explicitly provided.

Parameters:
  • vert (np.ndarray) – The vertices of the scene.

  • path (str) – The path to the mesh file. Supported formats are .ply, .obj

  • include_static (bool, optional) – Whether to include the static mesh. Defaults to True.

Returns:

The fixed scene.

Return type:

FixedScene

export_fixed(path: str, delete_exist: bool) FixedScene[source]

Export the fixed scene as a simulatio-readible format.

Parameters:
  • path (str) – The path to the output directory.

  • delete_exist (bool) – Whether to delete the existing directory.

Returns:

The fixed scene.

Return type:

FixedScene

preview(vert: ndarray | None = None, shading: dict = {}, show_stitch: bool = True, show_pin: bool = True) Plot | None[source]

Preview the scene.

Parameters:
  • vert (Optional[np.ndarray], optional) – The vertices to preview. Defaults to None.

  • shading (dict, optional) – The shading options. Defaults to {}.

  • show_stitch (bool, optional) – Whether to show the stitch. Defaults to True.

  • show_pin (bool, optional) – Whether to show the pin. Defaults to True.

Returns:

The plot object if in a Jupyter notebook, otherwise None.

Return type:

Optional[Plot]

report() FixedScene[source]

Print a summary of the scene.

set_pin(pin: list[PinData])[source]

Set the pinning data of all the objects.

Parameters:

pin_data (list[PinData]) – A list of pinning data.

set_spin(spin: list[SpinData])[source]

Set the spinning data of all the objects.

Parameters:

spin_data (list[SpinData]) – A list of spinning data.

set_static(vert: ndarray, tri: ndarray, color: ndarray)[source]

Set the static mesh data.

Parameters:
  • vert (np.ndarray) – The vertices of the static mesh.

  • tri (np.ndarray) – The triangle elements of the static mesh.

  • color (np.ndarray) – The colors of the static mesh.

set_stitch(ind: ndarray, w: ndarray)[source]

Set the stitch data.

Parameters:
  • ind (np.ndarray) – The stitch indices.

  • w (np.ndarray) – The stitch weights.

time(time: float) ndarray[source]

Compute the vertex positions at a specific time.

Parameters:

time (float) – The time to compute the vertex positions.

Returns:

The vertex positions at the specified time.

Return type:

np.ndarray

class frontend.InvisibleAdder(scene: Scene)[source]

Bases: object

sphere(position: list[float], radius: float) Sphere[source]

Add an invisible sphere to the scene.

Parameters:
  • position (list[float]) – The position of the sphere.

  • radius (float) – The radius of the sphere.

Returns:

The invisible sphere.

Return type:

Sphere

wall(position: list[float], normal: list[float]) Wall[source]

Add an invisible wall to the scene.

Parameters:
  • position (list[float]) – The position of the wall.

  • normal (list[float]) – The outer normal of the wall.

Returns:

The invisible wall.

Return type:

Wall

class frontend.MeshManager(cache_dir: str)[source]

Bases: object

Mesh Manager for accessing mesh creation functions

box(width: float = 1, height: float = 1, depth: float = 1) TriMesh[source]

Create a box mesh

Parameters:
  • width (float) – a width of the box

  • hight (float) – a height of the box

  • depth (float) – a depth of the box

Returns:

a box mesh, a pair of vertices and triangles

Return type:

TriMesh

circle(n: int = 32, r: float = 1, ntri: int = 1024) TriMesh[source]

Create a circle mesh

Parameters:
  • n (int) – resolution of the circle

  • r (float) – radius of the circle

  • ntri (int) – approximate number of triangles filling the circle

Returns:

a circle mesh, a pair of 2D vertices and triangles

Return type:

TriMesh

cone(Nr: int = 16, Ny: int = 16, Nb: int = 4, radius: float = 0.5, height: float = 2, sharpen: float = 1.0) TriMesh[source]

Create a cone mesh with a given number of radial, vertical, and bottom resolution, radius, and height.

Parameters:
  • Nr (int) – number of radial resolution

  • Ny (int) – number of vertical resolution

  • Nb (int) – number of bottom resolution

  • radius (float) – radius of the cone

  • height (float) – height of the cone

  • sharpen (float) – sharpening subdivision factor at the top

Returns:

a cone mesh, a pair of vertices and triangles

Return type:

TriMesh

property create: CreateManager

Get the mesh creation manager

cylinder(r: float, min_x: float, max_x: float, n: int)[source]

Create a cylinder along x-axis

Parameters:
  • r (float) – Radius of the cylinder

  • min_x (float) – Minimum x coordinate

  • max_x (float) – Maximum x coordinate

  • n (int) – Number of divisions along x-axis

Returns:

(V, F) where:
  • V: ndarray of shape (#x3) containing vertex positions

  • F: ndarray of shape (#x3) containing triangle indices

Return type:

tuple

icosphere(r: float = 1, subdiv_count: int = 3) TriMesh[source]

Create an icosphere mesh with a given radius and subdivision count.

Parameters:
  • r (float) – radius of the icosphere

  • sunbdiv_count (int) – subdivision count of the icosphere

Returns:

an icosphere mesh, a pair of vertices and triangles

Return type:

TriMesh

line(_p0: list[float], _p1: list[float], n: int) Rod[source]

Create a line mesh with a given start and end points and resolution.

Parameters:
  • _p0 (list[float]) – a start point of the line

  • _p1 (list[float]) – an end point of the line

  • n (int) – a resolution of the line

Returns:

a line mesh, a pair of vertices and edges

Return type:

Rod

load_tri(path: str) TriMesh[source]

Load a triangle mesh from a file

Parameters:

path (str) – a path to the file

Returns:

a triangle mesh, a pair of vertices and triangles

Return type:

TriMesh

make_cache_dir()[source]
mobius(length_split: int = 70, width_split: int = 15, twists: int = 1, r: float = 1, flatness: float = 1, width: float = 1, scale: float = 1) TriMesh[source]

Creatre a mobius mesh with a given length split, width split, twists, radius, flatness, width, and scale.

Parameters:
  • length_split (int) – number of length split

  • width_split (int) – number of width split

  • twists (int) – number of twists

  • r (float) – radius of the mobius

  • flatness (float) – flatness of the mobius

  • width (float) – width of the mobius

  • scale (float) – scale of the mobius

Returns:

a mobius mesh, a pair of vertices and triangles

Return type:

TriMesh

preset(name: str) TriMesh[source]

Load a preset mesh

Parameters:

name (str) – a name of the preset mesh. Available names are armadillo, knot, and bunny.

Returns:

a preset mesh, a pair of vertices and triangles

Return type:

TriMesh

rectangle(res_x: int = 32, width: float = 2, height: float = 1, ex: list[float] = [1, 0, 0], ey: list[float] = [0, 1, 0]) TriMesh[source]

Create a rectangle mesh with a given resolution, width, height, and spanned by the given vectors ex and ey.

Parameters:
  • res_x (int) – resolution of the mesh

  • width (float) – a width of the rectangle

  • height (float) – a height of the rectangle

  • ex (list[float]) – a 3D vector to span the rectangle

  • ey (list[float]) – a 3D vector to span the rectangle

Returns:

a rectangle mesh, a pair of vertices and triangles

Return type:

TriMesh

square(res: int = 32, size: float = 2, ex: list[float] = [1, 0, 0], ey: list[float] = [0, 1, 0]) TriMesh[source]

Create a square mesh with a given resolution and size, spanned by the given vectors ex and ey.

Parameters:
  • res (int) – resolution of the mesh

  • size (float) – a diameter of the square

  • ex (list[float]) – a 3D vector to span the square

  • ey (list[float]) – a 3D vector to span the square

Returns:

a square mesh, a pair of vertices and triangles

Return type:

TriMesh

torus(r: float = 1, R: float = 0.25, n: int = 32) TriMesh[source]

Create a torus mesh with a given radius, major radius, and resolution.

Parameters:
  • r (float) – hole radius of the torus

  • R (float) – major radius of the torus

  • n (int) – resolution of the torus

Returns:

a torus mesh, a pair of vertices and triangles

Return type:

TriMesh

class frontend.Object(asset: AssetManager, name: str)[source]

Bases: object

The object class.

apply_transform(x: ndarray) ndarray[source]

Apply the object’s transformation to a set of vertices.

Parameters:

x (np.ndarray) – The vertices to transform.

Returns:

The transformed vertices.

Return type:

np.ndarray

at(x: float, y: float, z: float) Object[source]

Set the position of the object.

Parameters:
  • x (float) – The x-coordinate.

  • y (float) – The y-coordinate.

  • z (float) – The z-coordinate.

Returns:

The object with the updated position.

Return type:

Object

atop(object: Object, margin: float = 0.0) Object[source]

Place the object on top of another object.

Parameters:
  • object (Object) – The reference object.

  • margin (float, optional) – The margin between the objects. Defaults to 0.0.

Returns:

The object placed on top of the reference object.

Return type:

Object

bbox() tuple[ndarray, ndarray][source]

Compute the bounding box of the object.

Returns:

The dimensions and center of the bounding box.

Return type:

tuple[np.ndarray, np.ndarray]

clear()[source]

Clear the object data.

color(red: float, green: float, blue: float) Object[source]

Set the color of the object.

Parameters:
  • red (float) – The red component.

  • green (float) – The green component.

  • blue (float) – The blue component.

Returns:

The object with the updated color.

Return type:

Object

default_color(red: float, green: float, blue: float) Object[source]

Set the default color of the object.

Parameters:
  • red (float) – The red component.

  • green (float) – The green component.

  • blue (float) – The blue component.

Returns:

The object with the updated default color.

Return type:

Object

direction(_ex: list[float], _ey: list[float]) Object[source]

Set two orthogonal directions of a shell required for Baraff-Witkin model.

Parameters:
  • _ex (list[float]) – The 3D x-direction vector.

  • _ey (list[float]) – The 3D y-direction vector.

Returns:

The object with the updated direction.

Return type:

Object

get(key: str) ndarray | None[source]

Get an associated value of the object with respect to the key.

Parameters:

key (str) – The key of the value.

Returns:

The value associated with the key.

Return type:

Optional[np.ndarray]

grab(direction: list[float], eps: float = 0.001) list[int][source]

Grab vertices max towards a specified direction.

Parameters:
  • direction (list[float]) – The direction vector.

  • eps (float, optional) – The distance threshold.

Returns:

The indices of the grabbed vertices.

Return type:

list[int]

jitter(r: float = 0.01) Object[source]

Add random jitter to the position of the object.

Parameters:

r (float, optional) – The jitter magnitude.

Returns:

The object with the jittered position.

Return type:

Object

max(dim: int)[source]

Get the maximum coordinate value along a specified dimension.

Parameters:

dim (int) – The dimension index (0 for x, 1 for y, 2 for z).

Returns:

The maximum coordinate value.

Return type:

float

min(dim: int)[source]

Get the minimum coordinate value along a specified dimension.

Parameters:

dim (int) – The dimension index (0 for x, 1 for y, 2 for z).

Returns:

The minimum coordinate value.

Return type:

float

property name: str

Get name of the object.

normalize() Object[source]

Normalize the object so that it fits within a unit cube.

Returns:

The normalized object.

Return type:

Object

pin(ind: list[int] | None = None) PinHolder[source]

Set specified vertices as pinned.

Parameters:
  • ind (Optional[list[int]], optional) – The indices of the vertices to pin.

  • None (If)

  • None. (all vertices are pinned. Defaults to)

Returns:

The pin holder.

Return type:

PinHolder

report()[source]

Report the object data.

rotate(angle: float, axis: str) Object[source]

Rotate the object around a specified axis.

Parameters:
  • angle (float) – The rotation angle in degrees.

  • axis (str) – The rotation axis (‘x’, ‘y’, or ‘z’).

Returns:

The object with the updated rotation.

Return type:

Object

scale(_scale: float) Object[source]

Set the scale of the object.

Parameters:

_scale (float) – The scale factor.

Returns:

The object with the updated scale.

Return type:

Object

set(key: str, value) Object[source]

Set a parameter of the object.

Parameters:
  • key (str) – The parameter key.

  • value – The parameter value.

Returns:

The object with the updated parameter.

Return type:

Object

property static: bool

Get whether the object is static.

static_color(red: float, green: float, blue: float) Object[source]

Set the static color of the object.

Parameters:
  • red (float) – The red component.

  • green (float) – The green component.

  • blue (float) – The blue component.

Returns:

The object with the updated static color.

Return type:

Object

stitch(name: str) Object[source]

Apply stitch to the object.

Parameters:

name (str) – The name of stitch registered in the asset manager.

Returns:

The stitched object.

Return type:

Object

update_static()[source]

Check if the object is static. When all the vertices are pinned and the object is not moving, it is considered static.

Returns:

True if the object is static, False otherwise.

Return type:

bool

velocity(u: float, v: float, w: float) Object[source]

Set the velocity of the object. If the object is static, an exception is raised.

Parameters:
  • u (float) – The velocity in the x-direction.

  • v (float) – The velocity in the y-direction.

  • w (float) – The velocity in the z-direction.

Returns:

The object with the updated velocity.

Return type:

Object

vertex() ndarray[source]

Get the transformed vertices of the object.

Returns:

The transformed vertices.

Return type:

np.ndarray

class frontend.ObjectAdder(scene: Scene)[source]

Bases: object

invisible

The invisible object adder.

Type:

InvisibleAdder

class frontend.Param(app_root: str)[source]

Bases: object

Class to manage simulation parameters.

change(value: float) Param[source]

Change the value of the dynamic parameter at the current time.

Parameters:

value (float) – The new value of the dynamic parameter.

Returns:

The updated Param object.

Return type:

Param

clear(key: str) Param[source]

Clear a parameter.

Parameters:

key (str) – The parameter key.

copy() Param[source]

Copy the Param object.

Returns:

The copied Param object.

Return type:

Param

dyn(key: str) Param[source]

Set a current dynamic parameter key.

Parameters:

key (str) – The dynamic parameter key.

Returns:

The updated Param object.

Return type:

Param

export(path: str)[source]

Export the parameters to a file.

Parameters:

path (str) – The path to the export directory.

get(key: str | None = None)[source]

Get the value of a parameter.

Parameters:
  • key (Optional[str], optional) – The parameter key.

  • specified (If not)

  • returned. (all parameters are)

Returns:

The value of the parameter.

Return type:

Any

hold() Param[source]

Hold the current value of the dynamic parameter.

Returns:

The updated Param object.

Return type:

Param

items()[source]

Get all parameter items.

Returns:

The parameter items.

Return type:

ItemsView

set(key: str, value: Any) Param[source]

Set a parameter value.

Parameters:
  • key (str) – The parameter key.

  • value (Any) – The parameter value.

Returns:

The updated Param object.

Return type:

Param

time(time: float) Param[source]

Set the current time for the dynamic parameter.

Parameters:

time (float) – The current time.

Returns:

The updated Param object.

Return type:

Param

class frontend.Plot(_darkmode: bool)[source]

Bases: object

Plot class. Use this to create a plot.

curve(vert: ndarray, _edge: ndarray = array([], dtype=float64), shading: dict = {}) Plot[source]

Plot a curve.

Parameters:
  • vert (np.ndarray) – The vertices (#x3) of the curve.

  • _edge (np.ndarray) – The edge elements (#x2) of the curve.

  • shading (dict) – The shading settings.

Returns:

The plot object.

Return type:

Plot

has_view() bool[source]

Return if the plot has a view.

is_jupyter_notebook() bool[source]

Check if the code is running in a Jupyter notebook.

overwrite_shading(shading: dict) dict[source]

Overwrite the shading settings with the default settings.

tet(vert: ndarray, tet: ndarray, axis: int = 0, cut: float = 0.5, color: ndarray = array([1., 0.85, 0.]), shading: dict = {}) Plot[source]

Plot a tetrahedral mesh.

Parameters:
  • vert (np.ndarray) – The vertices (#x3) of the mesh.

  • tet (np.ndarray) – The tetrahedral elements (#x4) of the mesh.

  • axis (int) – The axis to cut the mesh.

  • cut (float) – The cut ratio.

  • color (np.ndarray) – The color (#x3) of the mesh. Each value should be in [0,1].

  • shading (dict) – The shading settings.

Returns:

The plot object.

Return type:

Plot

to_html(path: str = '')[source]

Export an HTML file with the plot.

Parameters:

path (str) – The filename to save the HTML file.

tri(vert: ndarray, tri: ndarray, stitch: tuple[ndarray, ndarray] = (array([], dtype=float64), array([], dtype=float64)), color: ndarray = array([1., 0.85, 0.]), shading: dict = {}) Plot[source]

Plot a triangle mesh.

Parameters:
  • vert (np.ndarray) – The vertices (#x3) of the mesh.

  • tri (np.ndarray) – The triangle elements (#x3) of the mesh.

  • stitch (tuple[np.ndarray, np.ndarray]) – The stitch data (index #x3 and weight #x2).

  • color (np.ndarray) – The color (#x3) of the mesh. Each value should be in [0,1].

  • sahding (dict) – The shading settings.

Returns:

The plot object.

Return type:

Plot

update(vert: ndarray)[source]

Update the plot with new vertices.

Parameters:

vert (np.ndarray) – The new vertices (#x3).

class frontend.PlotAdder(parent: Plot)[source]

Bases: object

PlotAdder class. Use this to add elements to a plot.

edge(vert: ndarray, edge: ndarray) Plot[source]

Add edges to the plot.

Parameters:
  • vert (np.ndarray) – The vertices (#x3) of the edges.

  • edge (np.ndarray) – The edge elements (#x2) of the edges.

Returns:

The plot object.

Return type:

Plot

point(vert: ndarray) Plot[source]

Add points to the plot.

Parameters:

vert (np.ndarray) – The vertices (#x3) of the points.

Returns:

The plot object.

Return type:

Plot

tri(vert: ndarray, tri: ndarray, color: ndarray) Plot[source]

Add a triangle mesh to the plot.

Parameters:
  • vert (np.ndarray) – The vertices (#x3) of the mesh.

  • tri (np.ndarray) – The triangle elements (#x3) of the mesh.

  • color (np.ndarray) – The color (#x3) of the mesh. Each value should be in [0,1].

Returns:

The plot object.

Return type:

Plot

class frontend.PlotManager[source]

Bases: object

PlotManager class. Use this to create a plot.

create() Plot[source]

Create a plot.

darkmode(darkmode: bool) None[source]

Turn on or off dark mode.

Parameters:

darkmode (bool) – True to turn on dark mode, False otherwise.

is_jupyter_notebook() bool[source]

Check if the code is running in a Jupyter notebook.

class frontend.Rod(iterable=(), /)[source]

Bases: tuple[ndarray, ndarray]

A class representing a rod mesh

This class represents a rod mesh, which is a pair of vertices and edges. The first element of the tuple is a list of vertices, and the second element is a list of edges.

normalize() Rod[source]

Normalize the rod mesh

It normalizes the rod mesh so that the maximum bounding box size becomes 1.

scale(scale_x: float, scale_y: float, scale_z: float) Rod[source]

Scale the rod mesh

Scale the rod mesh with given scaling factors.

class frontend.Scene(name: str, plot: PlotManager, asset: AssetManager, save_func)[source]

Bases: object

A scene class.

add

The object adder.

Type:

ObjectAdder

build() FixedScene[source]

Build the fixed scene from the current scene.

Returns:

The built fixed scene.

Return type:

FixedScene

clear() Scene[source]

Clear all objects from the scene.

Returns:

The cle ared scene.

Return type:

Scene

info

The scene information.

Type:

SceneInfo

pick(name: str) Object[source]
class frontend.SceneInfo(name: str, scene: Scene)[source]

Bases: object

class frontend.SceneManager(plot: PlotManager, asset: AssetManager, save_func)[source]

Bases: object

SceneManager class. Use this to manage scenes.

clear()[source]

Clear all the scenes in the manager.

create(name: str) Scene[source]

Create a new scene.

Create a scene only if the name does not exist. Raise an exception if the name already exists.

Parameters:

name (str) – The name of the scene to create.

Returns:

The created scene.

Return type:

Scene

list() list[str][source]

List all the scenes in the manager.

Returns:

A list of scene names.

Return type:

list[str]

remove(name: str)[source]

Remove a scene from the manager.

Parameters:

name (str) – The name of the scene to remove.

select(name: str, create: bool = True) Scene[source]

Select a scene.

If the scene exists, it will be selected. If it does not exist and create is True, a new scene will be created.

Parameters:
  • name (str) – The name of the scene to select.

  • create (bool, optional) – Whether to create a new scene if it does not exist. Defaults to True.

class frontend.Session(app_root: str, proj_root: str, name: str, save_func)[source]

Bases: object

Class to manage a simulation session.

animate() Session[source]

Show the animation.

Returns:

The animated session.

Return type:

Session

delete()[source]

Delete the session.

property export: SessionExport

Get the session export object.

finished() bool[source]

Check if the session is finished.

Returns:

True if the session is finished, False otherwise.

Return type:

bool

property get: SessionGet

Get the session get object.

property info: SessionInfo

Get the session information.

init(scene: FixedScene) Session[source]

Initialize the session with a fixed scene.

Parameters:

scene (FixedScene) – The fixed scene.

Returns:

The initialized session.

Return type:

Session

property output: SessionOutput

Get the session output object.

preview(live_update: bool = True) Plot | None[source]

Live view the session.

Parameters:

live_update (bool, optional) – Whether to enable live update.

Returns:

The plot object.

Return type:

Optional[Plot]

print(message)[source]

Print a message.

Parameters:

message (str) – The message to print.

start(param: Param, force: bool = True, blocking=False) Session[source]

Start the session.

For Jupyter Notebook, the function will return immediately and the solver ill run in the background. If blocking is set to True, the function will block until the solver is finished. When Jupiter Notebook is not detected, the function will block until the solver is finished.

Parameters:
  • param (Param) – The simulation parameters.

  • force (bool, optional) – Whether to force start.

  • blocking (bool, optional) – Whether to block the execution.

Returns:

The started session.

Return type:

Session

stream(n_lines=40) Session[source]

Stream the session logs.

Parameters:

n_lines (int, optional) – The number of lines to stream. Defaults to 40.

Returns:

The session object.

Return type:

Session

class frontend.SessionExport(session: Session)[source]

Bases: object

Class to handle session export operations.

animation(path: str, ext='ply', include_static: bool = True) Zippable[source]

Export the animation frames.

Parameters:
  • path (str) – The path to the export directory.

  • ext (str, optional) – The file extension. Defaults to “ply”.

  • include_static (bool, optional) – Whether to include the static mesh.

frame(path: str, frame: int | None = None, include_static: bool = True) Session[source]

Export a specific frame.

Parameters:
  • path (str) – The path to the export file.

  • frame (Optional[int], optional) – The frame number. Defaults to None.

  • include_static (bool, optional) – Whether to include the static mesh.

Returns:

The session object.

Return type:

Session

shell_command(param: Param) str[source]

Generate a shell command to run the solver.

Parameters:

param (Param) – The simulation parameters.

Returns:

The shell command.

Return type:

str

class frontend.SessionGet(session: Session)[source]

Bases: object

Class to handle session data retrieval operations.

latest_frame() int[source]

Get the latest frame number.

Returns:

The latest frame number.

Return type:

int

property log: SessionLog

Get the session log object.

vertex(n: int | None = None) tuple[ndarray, int] | None[source]

Get the vertex data for a specific frame.

Parameters:

n (Optional[int], optional) – The frame number. If not specified, the latest frame is returned. Defaults to None.

Returns:

The vertex data and frame number.

Return type:

Optional[tuple[np.ndarray, int]]

vertex_frame_count() int[source]

Get the vertex count.

Returns:

The vertex count.

Return type:

int

class frontend.SessionInfo(name: str)[source]

Bases: object

Class to store session information.

property name: str

Get the name of the session.

property path: str

Get the path to the session directory.

set_path(path: str)[source]

Set the path to the session directory.

Parameters:

path (str) – The path to the session directory.

class frontend.SessionManager(app_root: str, proj_root: str, save_func)[source]

Bases: object

Class to manage simulation sessions.

clear(force: bool = True)[source]

Clear all sessions.

Parameters:

force (bool, optional) – Whether to force clearing.

create(scene: FixedScene, name: str = '', delete_if_exists: bool = True) Session[source]

Create a new session.

Parameters:
  • scene (FixedScene) – The scene object.

  • name (str) – The name of the session. If not specified, current time is used.

  • delete_if_exists (bool, optional) – Whether to delete the session if it exists.

Returns:

The created session.

Return type:

Session

current()[source]

Get the current session.

Returns:

The current session.

Return type:

Session

delete(name: str, force: bool = True)[source]

Delete a session.

Parameters:
  • name (str) – The name of the session.

  • force (bool, optional) – Whether to force deletion.

list()[source]

List all sessions.

Returns:

The sessions.

Return type:

dict

param() Param[source]

Get a new Param object.

Returns:

The Param object.

Return type:

Param

select(name: str)[source]

Select a session.

Parameters:

name (str) – The name of the session.

Returns:

The selected session.

Return type:

Session

class frontend.SessionOutput(session: Session)[source]

Bases: object

Class to handle session output operations.

property path: str

Get the path to the output directory.

class frontend.Sphere[source]

Bases: object

An invisible sphere class.

add(pos: list[float], radius: float) Sphere[source]

Add an invisible sphere information.

Parameters:
  • pos (list[float]) – The position of the sphere.

  • radius (float) – The radius of the sphere.

Returns:

The sphere.

Return type:

Sphere

get_entry() list[tuple[list[float], float, float]][source]

Get the time-dependent sphere entries.

hemisphere() Sphere[source]

Turn the sphere into a hemisphere, so the half of the sphere top becomes empty, like a bowl.

interp(transition: str) Sphere[source]

Set the transition type for the sphere.

invert() Sphere[source]

Invert the sphere, so the inside becomes empty and the outside becomes solid.

move_by(delta: list[float], time: float) Sphere[source]

Move the sphere by a positional delta at a specific time.

Parameters:
  • delta (list[float]) – The positional delta to move the sphere.

  • time (float) – The absolute time to move the sphere.

Returns:

The sphere.

Return type:

Sphere

move_to(pos: list[float], time: float) Sphere[source]

Move the sphere to a new position at a specific time.

Parameters:
  • list[float] (pos) – The target position of the sphere.

  • time (float) – The absolute time to move the sphere.

Returns:

The sphere.

Return type:

Sphere

radius(radius: float, time: float) Sphere[source]

Change the radius of the sphere at a specific time.

Parameters:
  • radius (float) – The target radius of the sphere.

  • time (float) – The absolute time to change the radius.

Returns:

The sphere.

Return type:

Sphere

transform_to(pos: list[float], radius: float, time: float) Sphere[source]

Change the sphere to a new position and radius at a specific time.

Parameters:
  • pos (list[float]) – The target position of the sphere.

  • radius (float) – The target radius of the sphere.

  • time (float) – The absolute time to transform the sphere.

Returns:

The sphere.

Return type:

Spere

class frontend.TetMesh(iterable=(), /)[source]

Bases: tuple[ndarray, ndarray, ndarray]

A class representing a tetrahedral mesh

This class represents a tetrahedral mesh, which is a pair of vertices, surface triangles, and tetrahedra.

normalize() TetMesh[source]

Normalize the tetrahedral mesh

It normalizes the tetrahedral mesh so that the maximum bounding box size becomes 1.

scale(scale_x: float, scale_y: float, scale_z: float) TetMesh[source]

Scale the tetrahedral mesh

Scale the tetrahedral mesh with given scaling factors.

class frontend.TriMesh(iterable=(), /)[source]

Bases: tuple[ndarray, ndarray]

A class representing a triangle mesh

This class represents a triangle mesh, which is a pair of vertices and triangles.

compute_cache_path(name: str) str[source]

Compute the cache path of the mesh

static create(vert: ndarray, elm: ndarray, cache_dir: str) TriMesh[source]

Create a triangle mesh and recompute the hash

decimate(target_tri: int) TriMesh[source]

Mesh decimation

Reduce the number of triangles in the mesh to the target number.

Parameters:

target_tri (int) – a target number of triangles

Returns:

a decimated mesh

Return type:

TriMesh

load_cache(path: str) TriMesh | None[source]

Load a cached mesh

normalize() TriMesh[source]

Normalize the triangle mesh

This function normalizes the triangle mesh so that the maximum bounding box size becomes 1.

recompute_hash() TriMesh[source]

Recompute the hash of the mesh

save_cache(path: str) TriMesh[source]

Save the mesh to a cache

scale(scale_x: float, scale_y: float, scale_z: float) TriMesh[source]

Scale the triangle mesh

Scale the triangle mesh with given scaling factors.

set_cache_dir(cache_dir: str) TriMesh[source]

Set the cache directory of the mesh

subdivide(n: int = 1, method: str = 'midpoint')[source]

Mesh subdivision

Subdivide the mesh with a given number of subdivisions and method.

Parameters:
  • n (int) – a number of subdivisions

  • method (str) – a method of subdivision. Available methods are “midpoint” and “loop”.

tetrahedralize(*args, **kwargs) TetMesh[source]

Tetrahedralize a surface triangle mesh

This function tetrahedralizes a surface triangle mesh with a given TetGen arguments.

Parameters:
  • args – a list of arguments

  • kwargs – a list of keyword arguments

Returns:

a tetrahedral mesh

Return type:

TetMesh

triangulate(target: int = 1024, min_angle: float = 20) TriMesh[source]

Triangulate a closed line shape with 2D coordinates

This function triangulates a closed 2D line shape with a given target number of triangles and minimum angle.

Parameters:
  • target (int) – a target number of triangles

  • min_angle (float) – a minimum angle of the triangles

Returns:

a triangulated mesh

Return type:

TriMesh

class frontend.Utils[source]

Bases: object

Utility class for frontend.

static in_CI() bool[source]

Determine if the code is running in a CI environment.

static in_jupyter_notebook()[source]

Determine if the code is running in a Jupyter notebook.

class frontend.Wall[source]

Bases: object

An invisible wall class.

add(pos: list[float], normal: list[float]) Wall[source]

Add an invisible wall information.

Parameters:
  • pos (list[float]) – The position of the wall.

  • normal (list[float]) – The outer normal of the wall.

Returns:

The invisible wall.

Return type:

Wall

get_entry() list[tuple[list[float], float]][source]

Get a list of time-dependent wall entries.

Returns:

A list of time-dependent entries, each containing a position and time.

Return type:

list[tuple[list[float], float]]

interp(transition: str) Wall[source]

Set the transition type for the wall.

move_by(delta: list[float], time: float) Wall[source]

Move the wall by a positional delta at a specific time.

Parameters:
  • delta (list[float]) – The positional delta to move the wall.

  • time (float) – The absolute time to move the wall.

Returns

Wall: The invisible wall.

move_to(pos: list[float], time: float) Wall[source]

Move the wall to a new position at a specific time.

Parameters:
  • pos (list[float]) – The target position of the wall.

  • time (float) – The absolute time to move the wall.

Returns:

The invisible wall.

Return type:

Wall