larvaworld.lib.param.body_shape =============================== .. py:module:: larvaworld.lib.param.body_shape Attributes ---------- .. autoapisummary:: larvaworld.lib.param.body_shape.body_plans Classes ------- .. autoapisummary:: larvaworld.lib.param.body_shape.BodyContour larvaworld.lib.param.body_shape.ShapeMobile larvaworld.lib.param.body_shape.ShapeViewable larvaworld.lib.param.body_shape.SegmentedBody larvaworld.lib.param.body_shape.SegmentedBodySensored Module Contents --------------- .. py:data:: body_plans .. py:class:: BodyContour(**kwargs) Bases: :py:obj:`larvaworld.lib.param.spatial.LineClosed` Body 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 .. py:attribute:: symmetry .. py:attribute:: guide_points .. py:attribute:: base_vertices .. py:attribute:: body_plan .. py:method:: generate_base_vertices() -> None .. py:property:: width_to_length_ratio :type: float .. py:class:: ShapeMobile(**kwargs) Bases: :py:obj:`larvaworld.lib.param.spatial.LineClosed`, :py:obj:`larvaworld.lib.param.spatial.MobileVector` Mobile 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)) .. py:attribute:: length .. py:attribute:: base_vertices .. py:attribute:: length_ratio .. py:method:: get_length_ratio() -> float .. py:method:: update_vertices() -> None .. py:class:: ShapeViewable(**kwargs) Bases: :py:obj:`ShapeMobile`, :py:obj:`larvaworld.lib.param.drawable.Viewable` Mobile 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) .. py:method:: draw(v, **kwargs) -> None .. py:class:: SegmentedBody(**kwargs) Bases: :py:obj:`BodyMobile` Multi-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() .. py:attribute:: Nsegs .. py:attribute:: segment_ratio .. py:attribute:: segs .. py:attribute:: base_seg_vertices .. py:attribute:: seg_positions .. py:property:: Nangles :type: int .. py:method:: 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. .. py:method:: generate_seg_positions() -> list[tuple[float, float]] .. py:method:: generate_segs() -> None .. py:method:: compute_body_bend() -> None .. py:property:: head :type: ShapeViewable .. py:property:: tail :type: ShapeViewable .. py:property:: direction :type: float .. py:method:: get_shape(scale=1) .. py:property:: global_midspine_of_body :type: tuple[float, float] .. py:method:: update_seg_lengths() -> None .. py:method:: move_body(dx, dy) -> None .. py:method:: valid_Dbend_range(idx=0) -> tuple[float, float] .. py:method:: set_color(colors) -> None .. py:property:: midline_xy :type: list[tuple] .. py:property:: front_orientation :type: float .. py:property:: rear_orientation :type: float .. py:method:: draw_segs(v, **kwargs) -> None .. py:class:: SegmentedBodySensored(**kwargs) Bases: :py:obj:`SegmentedBody` Segmented 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 .. py:attribute:: sensors .. py:property:: olfactor_pos :type: tuple .. py:property:: olfactor_point :type: shapely.geometry.Point .. py:method:: define_sensor(sensor, pos_on_body, modality) -> None .. py:method:: get_sensor_position(sensor) -> tuple .. py:method:: add_touch_sensors(idx) -> None .. py:method:: draw_sensors(v, **kwargs) -> None .. py:method:: get_sensors_by_modality(modality) -> list[str] .. py:property:: touch_sensorIDs :type: list[str]