From 898a42c5c71e7f57ed8ee0f5dfda1da5f5d32f7a Mon Sep 17 00:00:00 2001 From: A_Bassiouny Date: Sun, 15 Dec 2024 23:25:48 +0100 Subject: [PATCH] [PhysicalBody] removed duplicate method, added a normal property for contact points. --- src/pycram/datastructures/dataclasses.py | 19 ++++++++++++++++--- src/pycram/description.py | 13 ------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/pycram/datastructures/dataclasses.py b/src/pycram/datastructures/dataclasses.py index 68ff5b3a3..7a63668f5 100644 --- a/src/pycram/datastructures/dataclasses.py +++ b/src/pycram/datastructures/dataclasses.py @@ -710,6 +710,10 @@ class ContactPoint: lateral_friction_1: Optional[LateralFriction] = None lateral_friction_2: Optional[LateralFriction] = None + @property + def normal(self) -> List[float]: + return self.normal_on_body_b + def __str__(self): return f"ContactPoint: {self.body_a.name} - {self.body_b.name}" @@ -795,7 +799,7 @@ def get_links_in_contact_of_object(self, obj: Object) -> List[PhysicalBody]: :param obj: An instance of the Object class that represents the object. :return: A list of Link instances that represent the links in contact of the object. """ - return [point.body_b for point in self if point.body_b.parent == obj] + return [point.body_b for point in self if point.body_b.parent_entity == obj] def get_points_of_object(self, obj: Object) -> 'ContactPointsList': """ @@ -813,7 +817,16 @@ def get_points_of_link(self, link: Link) -> 'ContactPointsList': :param link: An instance of the Link class that represents the link that the points are related to. :return: A ContactPointsList instance that represents the contact points of the link. """ - return ContactPointsList([point for point in self if link == point.body_b]) + return self.get_points_of_body(link) + + def get_points_of_body(self, body: PhysicalBody) -> 'ContactPointsList': + """ + Get the points of the body. + + :param body: An instance of the PhysicalBody class that represents the body that the points are related to. + :return: A ContactPointsList instance that represents the contact points of the body. + """ + return ContactPointsList([point for point in self if body == point.body_b]) def get_objects_that_got_removed(self, previous_points: 'ContactPointsList') -> List[Object]: """ @@ -860,7 +873,7 @@ def get_objects_that_have_points(self) -> List[Object]: :return: A list of Object instances that represent the objects that have points in the list. """ - return list({point.body_b.parent for point in self if isinstance(point.body_b.parent, Object)}) + return list({point.body_b.parent_entity for point in self}) def __str__(self): return f"ContactPointsList: {', '.join([point.__str__() for point in self])}" diff --git a/src/pycram/description.py b/src/pycram/description.py index 3c0c5df94..ff14c1f91 100644 --- a/src/pycram/description.py +++ b/src/pycram/description.py @@ -253,19 +253,6 @@ def get_axis_aligned_bounding_box_from_geometry(self) -> AxisAlignedBoundingBox: if isinstance(geom, MeshVisualShape) else geom.get_axis_aligned_bounding_box() return bounding_box - def get_axis_aligned_bounding_box_from_geometry(self) -> AxisAlignedBoundingBox: - if isinstance(self.geometry, List): - all_boxes = [geom.get_axis_aligned_bounding_box(self.get_mesh_path(geom)) - if isinstance(geom, MeshVisualShape) else geom.get_axis_aligned_bounding_box() - for geom in self.geometry - ] - bounding_box = AxisAlignedBoundingBox.from_multiple_bounding_boxes(all_boxes) - else: - geom = self.geometry - bounding_box = geom.get_axis_aligned_bounding_box(self.get_mesh_path(geom)) \ - if isinstance(geom, MeshVisualShape) else geom.get_axis_aligned_bounding_box() - return bounding_box - def get_convex_hull(self) -> Geometry3D: """ :return: The convex hull of the link geometry.