larvaworld.lib.param.body_shape
Attributes
Classes
Body contour defined by guide points and symmetry. |
|
Mobile shape with dynamic vertex updates based on position and orientation. |
|
Mobile shape with rendering capabilities. |
|
Multi-segment body with articulation and mass distribution. |
|
Segmented body with configurable sensory organs. |
Module Contents
- larvaworld.lib.param.body_shape.body_plans
- class larvaworld.lib.param.body_shape.BodyContour(**kwargs)
Bases:
larvaworld.lib.param.spatial.LineClosedBody contour defined by guide points and symmetry.
Generates body vertices from guide points using bilateral or radial symmetry. Supports predefined body plans (drosophila/zebrafish larvae).
- Attributes:
symmetry: Body symmetry type (‘bilateral’ or ‘radial’) guide_points: List of 2D points outside midline to generate vertices base_vertices: Generated list of vertices forming the contour body_plan: Predefined body plan (‘drosophila_larva’ or ‘zebrafish_larva’)
- Example:
>>> contour = BodyContour(body_plan='drosophila_larva', symmetry='bilateral') >>> ratio = contour.width_to_length_ratio
- symmetry
- guide_points
- base_vertices
- body_plan
- generate_base_vertices() None
- property width_to_length_ratio: float
- class larvaworld.lib.param.body_shape.ShapeMobile(**kwargs)
Bases:
larvaworld.lib.param.spatial.LineClosed,larvaworld.lib.param.spatial.MobileVectorMobile shape with dynamic vertex updates based on position and orientation.
Combines closed line shape with mobile vector capabilities, automatically updating vertices when position, orientation, or length changes.
- Attributes:
length: Physical length of the shape in meters base_vertices: Template vertices scaled and transformed to actual position
- Example:
>>> shape = ShapeMobile(length=0.005, base_vertices=[(1,0), (0,0.1), (0,-0.1)]) >>> shape.set_position((0.01, 0.01))
- length
- base_vertices
- length_ratio
- get_length_ratio() float
- update_vertices() None
- class larvaworld.lib.param.body_shape.ShapeViewable(**kwargs)
Bases:
ShapeMobile,larvaworld.lib.param.drawable.ViewableMobile shape with rendering capabilities.
Extends ShapeMobile with visualization methods for drawing the shape as a filled polygon using a viewer object.
- Example:
>>> shape = ShapeViewable(length=0.005, color=(255, 0, 0)) >>> shape.draw(viewer)
- draw(v, **kwargs) None
- class larvaworld.lib.param.body_shape.SegmentedBody(**kwargs)
Bases:
BodyMobileMulti-segment body with articulation and mass distribution.
Divides body into configurable number of segments with independent positions and orientations. Supports custom segment length ratios and provides utilities for shape manipulation and rendering.
- Attributes:
Nsegs: Number of segments comprising the body segment_ratio: Ratio of each segment’s length to total body length segs: List of body segment shape objects
- Example:
>>> body = SegmentedBody(Nsegs=12, length=0.005) >>> body.compute_body_bend() >>> head_pos = body.head.get_position()
- Nsegs
- segment_ratio
- segs
- base_seg_vertices
- seg_positions
- property Nangles: int
- segmentize(centered: bool = True, closed: bool = False) numpy.ndarray
Segments a body into equal-length or given-length segments via vertical lines.
Args: - N: Number of segments to divide the body into. - points: Array with shape (M,2) representing the contour of the body to be segmented. - ratio: List of N floats specifying the ratio of the length of each segment to the length of the body.
Defaults to None, in which case equal-length segments will be generated.
centered: If True, centers the segments around the origin. Defaults to True.
closed: If True, the last point of each segment is connected to the first point. Defaults to False.
Returns: - ps: Numpy array with shape (Nsegs,L,2), where L is the number of vertices of each segment.
The first segment in the list is the front-most segment.
- generate_seg_positions() list[tuple[float, float]]
- generate_segs() None
- compute_body_bend() None
- property head: ShapeViewable
- property tail: ShapeViewable
- property direction: float
- get_shape(scale=1)
- property global_midspine_of_body: tuple[float, float]
- update_seg_lengths() None
- move_body(dx, dy) None
- valid_Dbend_range(idx=0) tuple[float, float]
- set_color(colors) None
- property midline_xy: list[tuple]
- property front_orientation: float
- property rear_orientation: float
- draw_segs(v, **kwargs) None
- class larvaworld.lib.param.body_shape.SegmentedBodySensored(**kwargs)
Bases:
SegmentedBodySegmented body with configurable sensory organs.
Extends SegmentedBody with support for positioning sensors (olfactory, touch, etc.) on specific body segments with local coordinates.
- Attributes:
sensors: Dictionary of sensor definitions with positions and modalities
- Example:
>>> body = SegmentedBodySensored(Nsegs=12) >>> body.add_touch_sensors([5, 10]) >>> olf_pos = body.olfactor_pos
- sensors
- property olfactor_pos: tuple
- property olfactor_point: shapely.geometry.Point
- define_sensor(sensor, pos_on_body, modality) None
- get_sensor_position(sensor) tuple
- add_touch_sensors(idx) None
- draw_sensors(v, **kwargs) None
- get_sensors_by_modality(modality) list[str]
- property touch_sensorIDs: list[str]