Skip to content

Commit

Permalink
[PhysicalBody] removed duplicate method, added a normal property for …
Browse files Browse the repository at this point in the history
…contact points.
  • Loading branch information
AbdelrhmanBassiouny committed Dec 15, 2024
1 parent 3f1ee35 commit 898a42c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
19 changes: 16 additions & 3 deletions src/pycram/datastructures/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down Expand Up @@ -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':
"""
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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])}"
Expand Down
13 changes: 0 additions & 13 deletions src/pycram/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 898a42c

Please sign in to comment.