pycram.datastructures.world_entity
==================================

.. py:module:: pycram.datastructures.world_entity


Classes
-------

.. autoapisummary::

   pycram.datastructures.world_entity.StateEntity
   pycram.datastructures.world_entity.WorldEntity
   pycram.datastructures.world_entity.PhysicalBody


Module Contents
---------------

.. py:class:: StateEntity

   The StateEntity class is used to store the state of an object or the physics simulator. This is used to save and
   restore the state of the World.


   .. py:attribute:: SAVED_FILE_PREFIX
      :value: 'pycram_saved_state_'



   .. py:attribute:: _saved_states
      :type:  typing_extensions.Dict[int, pycram.datastructures.dataclasses.State]


   .. py:property:: saved_states
      :type: typing_extensions.Dict[int, pycram.datastructures.dataclasses.State]


      :return: the saved states of this entity.



   .. py:method:: save_state(state_id: int, save_dir: typing_extensions.Optional[str] = None) -> int

      Saves the state of this entity with the given state id.

      :param state_id: The unique id of the state.
      :param save_dir: The directory where the file should be saved.



   .. py:method:: save_state_to_file(file_path: str, state_id: typing_extensions.Optional[int] = None)

      Saves the state of this entity to a file.

      :param file_path: The path to the file.
      :param state_id: The unique id of the state if saving a specific state not the current state.



   .. py:method:: restore_state_from_file(save_dir: str, state_id: int) -> None

      Restores the state of this entity from a file.

      :param save_dir: The directory where the file is saved.
      :param state_id: The unique id of the state.



   .. py:method:: get_saved_file_path_of_state(save_dir: str, state_id: int) -> str

      Gets the path of the file that stores the state with the given id.

      :param save_dir: The directory where the file should be saved.
      :param state_id: The unique id of the state.
      :return: The name of the file that stores the state with the given id.



   .. py:property:: current_state
      :type: pycram.datastructures.dataclasses.State

      :abstractmethod:


      :return: The current state of this entity.



   .. py:method:: restore_state(state_id: int, saved_file_dir: typing_extensions.Optional[str] = None) -> None

      Restores the state of this entity from a saved state using the given state id.

      :param state_id: The unique id of the state.
      :param saved_file_dir: The directory where the file is saved.



   .. py:method:: remove_saved_states() -> None

      Removes all saved states of this entity.



.. py:class:: WorldEntity(_id: int, world: pycram.datastructures.world.World, concept: typing_extensions.Type[pycrap.ontologies.PhysicalObject] = PhysicalObject, parse_name: bool = True)

   Bases: :py:obj:`StateEntity`, :py:obj:`pycram.datastructures.mixins.HasConcept`


   A class that represents an entity of the world, such as an object or a link.


   .. py:attribute:: id


   .. py:attribute:: world
      :type:  pycram.datastructures.world.World


   .. py:method:: reset_concepts()

      Reset the concepts of this entity.



   .. py:property:: name
      :type: str

      :abstractmethod:


      :return: The name of this body.



   .. py:property:: parent_entity
      :type: typing_extensions.Optional[WorldEntity]

      :abstractmethod:


      :return: The parent entity of this entity, if it has one.



   .. py:method:: __eq__(other: WorldEntity) -> bool

      Check if this body is equal to another body.



   .. py:method:: __hash__() -> int


.. py:class:: PhysicalBody(body_id: int, world: pycram.datastructures.world.World, concept: typing_extensions.Type[pycrap.ontologies.PhysicalObject] = PhysicalObject, parse_name: bool = True)

   Bases: :py:obj:`WorldEntity`


   A class that represents a physical body in the world that has some related physical properties.


   .. py:attribute:: local_transformer


   .. py:attribute:: _is_translating
      :type:  typing_extensions.Optional[bool]
      :value: None



   .. py:attribute:: _is_rotating
      :type:  typing_extensions.Optional[bool]
      :value: None



   .. py:attribute:: _velocity
      :type:  typing_extensions.Optional[typing_extensions.List[float]]
      :value: None



   .. py:attribute:: ontology_lock
      :type:  threading.RLock


   .. py:attribute:: updated_containment_of_parts
      :type:  bool
      :value: False



   .. py:attribute:: latest_known_parts
      :type:  typing_extensions.Dict[str, PhysicalBody]


   .. py:method:: reset_concepts()

      Reset the concepts of this entity.



   .. py:property:: is_an_environment
      :type: bool


      Check if the object is of type environment.

      :return: True if the object is of type environment, False otherwise.



   .. py:property:: is_a_robot
      :type: bool


      Check if the object is a robot.
      TODO: Check if this is a the correct filter
      :return: True if the object is a robot, False otherwise.



   .. py:property:: parts
      :type: typing_extensions.Dict[str, PhysicalBody]

      :abstractmethod:


      :return: The parts of this body as a dictionary mapping the part name to the part.



   .. py:method:: update_containment(excluded_bodies: typing_extensions.Optional[typing_extensions.List[PhysicalBody]] = None, candidate_selection_method: pycram.datastructures.enums.AdjacentBodyMethod = AdjacentBodyMethod.ClosestPoints, max_distance: float = 0.5) -> None

      Update the containment of the object by checking if it is contained in other bodies,
       excluding the given excluded bodies.

      :param excluded_bodies: The bodies that should be excluded from the containment check.
      :param candidate_selection_method: The method to select the candidates for the containment check.
      :param max_distance: The maximum distance from this body to other bodies to consider a body as a candidate.



   .. py:method:: get_adjacent_bodies_using_closest_points(max_distance: float = 0.5) -> typing_extensions.List[PhysicalBody]

      Get the adjacent bodies of the body using the closest points between the bodies.

      :param max_distance: The maximum distance to consider a body as adjacent.
      :return: The bodies that are adjacent to this body if any.



   .. py:method:: get_adjacent_bodies_using_rays(max_distance: float = 0.5) -> typing_extensions.List[PhysicalBody]

      Cast rays in the 6 rays in all directions (+x, -x, +y, -y, +z,  and -z directions) to find the adjacent bodies
       of the body.

      :param max_distance: The max distance that the rays can travel.
      :return: The bodies that are adjacent to this body if any.



   .. py:method:: cast_rays_in_all_directions(max_distance: float = 0.5) -> typing_extensions.List[pycram.datastructures.dataclasses.RayResult]

      Get the rays in all 6 directions (+x, -x, +y, -y, +z,  and -z directions).

      :param max_distance: The maximum distance the rays can travel.
      :return: The rays in all 6 directions.



   .. py:method:: get_axis_rays(origin: typing_extensions.List[float], min_val: float, max_val: float, idx: int, max_distance: float = 0.5) -> typing_extensions.Tuple[typing_extensions.List[typing_extensions.List[float]], typing_extensions.List[typing_extensions.List[float]]]
      :staticmethod:


      Get the rays in the given axis.

      :param origin: The origin of the rays.
      :param min_val: The start in the -ve direction of the axis.
      :param max_val: The start in the +ve direction of the axis.
      :param idx: The index of the direction/axis.
      :param max_distance: The maximum distance the rays can travel.



   .. py:method:: contains_body(body: PhysicalBody) -> bool

      Check if this body contains another body.

      :param body: The physical body to check if it is contained by this body.
      :return: True if the body contains the other body, otherwise False.



   .. py:property:: contained_bodies
      :type: typing_extensions.List[PhysicalBody]


      :return: True if the object contains the other object, otherwise False.



   .. py:method:: get_axis_aligned_bounding_box() -> pycram.datastructures.dataclasses.AxisAlignedBoundingBox
      :abstractmethod:


      :return: The axis-aligned bounding box of this body.



   .. py:method:: get_rotated_bounding_box() -> pycram.datastructures.dataclasses.RotatedBoundingBox
      :abstractmethod:


      :return: The rotated bounding box of this body.



   .. py:method:: _plot_convex_hull()

      Plot the convex hull of the geometry.



   .. py:method:: get_convex_hull() -> trimesh.parent.Geometry3D
      :abstractmethod:


      :return: The convex hull of this body.



   .. py:property:: body_state
      :type: pycram.datastructures.dataclasses.PhysicalBodyState



   .. py:property:: velocity
      :type: typing_extensions.Optional[typing_extensions.List[float]]



   .. py:property:: is_translating
      :type: typing_extensions.Optional[bool]



   .. py:property:: is_rotating
      :type: typing_extensions.Optional[bool]



   .. py:property:: position
      :type: pycram.datastructures.pose.Point


      :return: A Point object containing the position of the link relative to the world frame.



   .. py:property:: orientation
      :type: pycram.datastructures.pose.GeoQuaternion


      :return: A Quaternion object containing the orientation of the link relative to the world frame.



   .. py:property:: pose_as_list
      :type: typing_extensions.List[typing_extensions.List[float]]


      :return: A list containing the position and orientation of the link relative to the world frame.



   .. py:property:: transform
      :type: pycram.datastructures.pose.TransformStamped


      The transform of this entity.

      :return: The transform of this entity.



   .. py:method:: update_transform(transform_time: typing_extensions.Optional[pycram.ros.Time] = None) -> None

      Update the transformation of this link at the given time.

      :param transform_time: The time at which the transformation should be updated.



   .. py:property:: pose
      :type: pycram.datastructures.pose.PoseStamped

      :abstractmethod:


      :return: A Pose object containing the pose of the link relative to the world frame.



   .. py:property:: tf_frame
      :type: str

      :abstractmethod:


      The tf frame of this entity.

      :return: The tf frame of this entity.



   .. py:property:: contact_points
      :type: pycram.datastructures.dataclasses.ContactPointsList


      :return: The contact points of this body with other physical bodies.



   .. py:method:: get_contact_points_with_body(body: PhysicalBody) -> pycram.datastructures.dataclasses.ContactPointsList

      :param body: The body to get the contact points with.
      :return: The contact points of this body with the given body.



   .. py:method:: closest_points(max_distance: float) -> pycram.datastructures.dataclasses.ClosestPointsList

      :param max_distance: The maximum distance to consider a body as close, only points closer than or equal to this
       distance will be returned.
      :return: The closest points of this body with other physical bodies within the given maximum distance.



   .. py:method:: get_closest_points_with_body(body: PhysicalBody, max_distance: float) -> pycram.datastructures.dataclasses.ClosestPointsList

      :param body: The body to get the points with.
      :param max_distance: The maximum distance to consider a body as close, only points closer than or equal to this
       distance will be returned.
      :return: The closest points of this body with the given body within the given maximum distance.



   .. py:property:: is_moving
      :type: typing_extensions.Optional[bool]


      :return: True if this body is moving, False if not, and None if not known.



   .. py:property:: is_stationary
      :type: typing_extensions.Optional[bool]


      :return: True if this body is stationary, False otherwise.



   .. py:property:: color
      :type: typing_extensions.Union[pycram.datastructures.dataclasses.Color, typing_extensions.Dict[str, pycram.datastructures.dataclasses.Color]]

      :abstractmethod:


      :return: A Color object containing the rgba_color of this body or a dictionary if the body is articulated.



   .. py:method:: set_color(color: pycram.datastructures.dataclasses.Color) -> None

      Set the color of this body, could be rgb or rgba.

      :param color: The color as a list of floats, either rgb or rgba.



   .. py:method:: get_preferred_grasp_alignment() -> pycram.datastructures.grasp.PreferredGraspAlignment

      Determines the preferred grasp alignment for an object based on its type.
      This includes the preferred axis, whether grasping from the top is preferred,
      and whether horizontal alignment (90° rotation around X) is preferred.

      :return: The preferred grasp alignment for the object.



   .. py:method:: calculate_grasp_descriptions(robot: pycram.world_concepts.world_object.Object) -> typing_extensions.List[pycram.datastructures.pose.GraspDescription]

      Calculates the grasp configurations of an object relative to the robot based on orientation and position.

      This method determines the possible grasp configurations (side and top/bottom faces) of the object,
      taking into account the object's orientation, position, and whether horizontal alignment is preferred.

      :param robot: The robot for which the grasp configurations are being calculated.

      :return: A sorted list of GraspDescription instances representing all grasp permutations.



   .. py:method:: get_grasp_pose(end_effector, grasp: pycram.datastructures.pose.GraspDescription) -> Pose

      Translates the grasp pose of the object using the desired grasp description and object knowledge.
      Leaves the orientation untouched.
      Returns the translated grasp pose.

      :param end_effector: The end effector that will be used to grasp the object.
      :param grasp: The desired grasp description.

      :return: The grasp pose of the object.



   .. py:method:: get_approach_offset() -> float

      :return: The pre-grasp offset of the object. It is the largest dimension of the object divided by 2.



