goo.handler

class goo.handler.BoundaryHandler(loc: tuple[float, float, float] = (0, 0, 0), radius: float = 10)[source]

Bases: Handler

Handler for updating boundary volume over time.

Parameters:
  • loc (tuple[float, float, float])

  • radius (float)

run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.ColorizeHandler(colorizer: Colorizer = Colorizer.LINEAGE_DISTANCE, metabolite: Gene | Molecule | str = None, range: tuple | None = None)[source]

Bases: Handler

Handler for coloring cells based on a specified property.

Cells are colored on a blue-red spectrum based on the relative value of the specified property to all other cells. In RANDOM mode, cells cycle through a fixed 20-color palette.

Variables:
  • colorizer (Colorizer) – The property by which cells are colored.

  • metabolite (Gene | Molecule | str) – Optional, the gene off of which cell color is based..

  • range (tuple[float, float] | None) – Optional, range of values for the colorizer. If provided, values are scaled relative to this range instead of min-max normalization.

Parameters:
run(scene, depsgraph)[source]

Applies coloring to cells based on the selected property.

class goo.handler.Colorizer(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Color map for the random cell colorizer.

GENE = 4
LINEAGE_DISTANCE = 6
MOLECULE = 5
PRESSURE = 1
RANDOM = 3
VOLUME = 2
class goo.handler.ConcentrationVisualizationHandler(spacing: float | None = None)[source]

Bases: Handler

Visualizes a 3D concentration array using color-coded transparent instanced cubes in Blender.

Parameters:

spacing (float | None)

run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

setup(get_cells: Callable[[], list], get_diffsystem: Callable[[], object], dt: float) None[source]

Set up the handler.

Parameters:
  • get_cells (Callable[[], list[Cell]]) – A function that, when called, retrieves the list of cells that may divide.

  • get_diffsystem (Callable[[], DiffusionSystem]) – A function that, when called, retrieves the diffusion system.

  • dt (float) – The time step for the simulation.

Return type:

None

class goo.handler.DataExporter(path: str | None = None, options: ~goo.handler.DataFlag = <DataFlag.DEFAULT: 1023>)[source]

Bases: Handler

Parameters:
close()[source]
run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

setup(get_cells: Callable[[], list[Cell]], get_diffsystems: Callable[[], DiffusionSystem], dt: float)[source]

Set up the handler.

Parameters:
  • get_cells (Callable[[], list[Cell]]) – A function that, when called, retrieves the list of cells that may divide.

  • get_diffsystem (Callable[[], DiffusionSystem]) – A function that, when called, retrieves the diffusion system.

  • dt (float) – The time step for the simulation.

  • get_diffsystems (Callable[[], DiffusionSystem])

class goo.handler.DataFlag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Enum of data flags used by the DataExporter() handler.

Variables:
  • TIMES – time elapsed since beginning of simulation.

  • DIVISIONS – list of cells that have divided and their daughter cells.

  • MOTION_PATH – list of the current position of each cell.

  • FORCE_PATH – list of the current positions of the associated motion force of each cell.

  • VOLUMES – list of the current volumes of each cell.

  • PRESSURES – list of the current pressures of each cell.

  • CONTACT_AREAS – list of contact areas between each pair of cells.

  • SHAPE_FEATURES – list of shape features of each cell.

  • CELL_CONCENTRATIONS – concentrations of each gene in each cell.

  • GENES – level of each gene in the simulation for each cell.

  • GRID – concentrations of each molecule in the grid system.

ALL = 2047
CELL_CONCENTRATIONS = 256
CONTACT_AREAS = 64
DEFAULT = 1023
DIVISIONS = 2
FORCE_PATH = 8
GENES = 512
GRID = 1024
MOTION_PATH = 4
PRESSURES = 32
SHAPE_FEATURES = 128
TIMES = 1
VOLUMES = 16
class goo.handler.ForceDist(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

CONSTANT = 1
GAUSSIAN = 3
UNIFORM = 2
class goo.handler.GrowthPIDHandler[source]

Bases: Handler

run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.Handler[source]

Bases: ABC

abstract run(scene: Scene, depsgraph: Depsgraph) None[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

Return type:

None

setup(get_cells: Callable[[], list[Cell]], get_diffsystem: Callable[[], DiffusionSystem], dt: float) None[source]

Set up the handler.

Parameters:
  • get_cells (Callable[[], list[Cell]]) – A function that, when called, retrieves the list of cells that may divide.

  • get_diffsystem (Callable[[], DiffusionSystem]) – A function that, when called, retrieves the diffusion system.

  • dt (float) – The time step for the simulation.

Return type:

None

class goo.handler.MolecularHandler[source]

Bases: Handler

Handler for simulating diffusion of a substance in the grid in the scene.

Parameters:

diffusionSystem – The reaction-diffusion system to simulate.

run(scene, depsgraph) None[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

Return type:

None

setup(get_cells: Callable[[], list[Cell]], get_diffsystems: Callable[[], list[DiffusionSystem]], dt)[source]

Build the KD-Tree from the grid coordinates if not already built.

Parameters:
class goo.handler.NetworkHandler[source]

Bases: Handler

Handler for gene regulatory networks.

run(scene, despgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.RandomMotionHandler(distribution: ForceDist = ForceDist.UNIFORM, strength: float = 0.0, persistence: tuple[float, float, float] = (0.0, 0.0, 0.0))[source]

Bases: Handler

Handler for simulating random cell motion.

At every frame, the direction of motion is randomly selected from a specified distribution and added to a persistent base direction.

Variables:
  • distribution (ForceDist) – The distribution of motion.

  • strength (float) – The strength of the motion.

  • persistence (tuple[float, float, float]) – The persistent base direction.

Parameters:
  • distribution (ForceDist)

  • strength (float)

  • persistence (tuple[float, float, float])

run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.RecenterHandler[source]

Bases: Handler

Handler for updating cell origin and adhesion forces every frame, and storing summary stats.

run(scene, depsgraph)[source]

Run the handler.

This is the function that gets passed to Blender, to be called upon specified events (e.g. post-frame change).

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.RemeshHandler(freq: int = 1, voxel_size: float | None = None, smooth_factor: float = 0.1)[source]

Bases: Handler

Handler for remeshing cells at given frequencies.

Variables:
  • freq (int) – Number of frames between remeshes.

  • smooth_factor (float) – Factor to pass to bmesh.ops.smooth_vert. Disabled if set to 0.

  • voxel_size (float) – Factor to pass to voxel_remesh(). Disabled if set to 0.

Parameters:
  • freq (int)

  • voxel_size (float | None)

  • smooth_factor (float)

run(scene, depsgraph)[source]

Run the handler.

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.

class goo.handler.SliceExporter(output_dir: str = '', resolution: tuple[int, int, int] = (512, 512, 512), scale: tuple[float, float, float] = (0.5, 0.5, 0.5), microscope_dt: int = 10, padding: float = 5.0, downscale: int | tuple[int, int, int] | None = None)[source]

Bases: Handler

Handler to save point cloud data of the simulation at each frame and convert to 3D array.

Parameters:
  • output_dir (str) – The directory to save the point cloud data.

  • resolution (tuple[int, int, int]) – The resolution of the grid to save the point cloud data. Default is (256, 256, 256).

  • scale (tuple[float, float, float]) – The scale of the grid to save the point cloud data. Default is (0.2, 0.2, 0.2).

  • microscope_dt (int) – The time step of the microscope. Default is 10.

  • padding (float) – The padding of the grid to save the point cloud data. Default is 5.0.

  • downscale (int | tuple[int, int, int] | None) – The downscaling factor for the low-resolution version. Can be a single integer or a tuple of integers for each dimension. Default is None (no downscaling).

downsample_volume(volume: ndarray) tuple[ndarray, tuple[float, float, float]][source]

Downsample the volume array and adjust the scale accordingly.

Parameters:

volume (numpy.ndarray) – The original volume array

Returns:

(downsampled_volume, new_scale)

Return type:

tuple[numpy.ndarray, tuple[float, float, float]]

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

Get the bounding box of all visible mesh objects in the scene.

Returns:

(min_coords, max_coords) representing the bounding box

Return type:

tuple

points_to_volume_with_labels(points: ndarray, labels: ndarray) ndarray[source]

Convert points to a volume with labels.

Parameters:
  • points (numpy.ndarray) – The points to convert to a volume.

  • labels (numpy.ndarray) – The labels for each point.

Returns:

The volume with labels.

Return type:

numpy.ndarray

run(scene: Scene, depsgraph: Depsgraph)[source]

Run the point cloud export process for each frame.

Parameters:
  • scene (Scene) – The Blender scene.

  • depsgraph (Depsgraph) – The dependency graph.

sample_mesh_points(obj: Object, num_points: int = 200000) ndarray[source]

Sample points densely and uniformly from a mesh object.

Parameters:
  • obj (Object) – The mesh object to sample from

  • num_points (int) – Number of points to sample (increased for better coverage)

Returns:

Array of sampled points in world coordinates

Return type:

ndarray

world_to_grid_coords(world_coords: ndarray) ndarray[source]

Convert world coordinates to grid coordinates.

Parameters:

world_coords (ndarray) – World space coordinates

Returns:

Grid coordinates

Return type:

ndarray

class goo.handler.StabilityHandler(length_factor: float = 3, min_volume: float = 5)[source]

Bases: Handler

Handler for detecting and fixing mesh instability.

Detects instability by checking for edges that are much longer than the mean edge length. When instability is detected, attempts to fix the cell by remeshing it.

Variables:
  • length_factor (float) – Maximum allowed ratio of any edge length to mean edge length. If any edge is longer than mean_length * length_factor, it indicates instability.

  • min_volume (float) – Minimum allowed volume for a cell, as a basic sanity check.

Parameters:
  • length_factor (float)

  • min_volume (float)

run(scene, depsgraph) bool[source]

Check all cells for instability and attempt to fix unstable cells by remeshing.

Returns:

Always returns True since we handle instability by remeshing

Return type:

bool

class goo.handler.StopHandler(max_cells=None)[source]

Bases: Handler

Handler for stopping the simulation at the end of the simulation time or when reaching max cells.

Variables:

max_cells (int | None) – The maximum number of cells to allow in the simulation.

run(scene, depsgraph)[source]

Run the handler.

Parameters:
  • scene (bpy.types.Scene) – The Blender scene.

  • depsgraph (bpy.types.Depsgraph) – The dependency graph.