def vertices_to_polygon(vertices): poly_vertices = [] for v in vertices: poly_vertices.append(scene_if.Vector(v[0], v[1])) shape = scene_if.Shape(polygon=scene_if.Polygon(vertices=poly_vertices)) assert is_valid_convex_polygon(poly_vertices) return shape
def update_task(self, body1, body2, relationships, over=True, phantom_vertices=None, description=None): assert body1.dynamic or body2.dynamic, ( 'At least one dynamic body needed.') assert len(relationships) == 1, 'Not supported' if relationships[0] == self.SpatialRelationship.LEFT_OF: relationships = [self.SpatialRelationship.RIGHT_OF] body1, body2 = body2, body1 self.task.relationships = relationships self.task.bodyId1 = self.body_list.index(body1) self.task.bodyId2 = self.body_list.index(body2) # Add phantom vertices. if phantom_vertices is not None: poly_vertices = [] for v in phantom_vertices: poly_vertices.append(scene_if.Vector(v[0], v[1])) shape = scene_if.Shape(polygon=scene_if.Polygon( vertices=poly_vertices)) self.task.phantomShape = shape if description is None: self._recolor_objects(body1, body2, over) # Add description. relation_name = (self.SpatialRelationship._VALUES_TO_NAMES[ relationships[0]].lower()) description = 'Make sure the %s is %s the %s.' % ( (body1.description, relation_name, body2.description)) # Check that task description is unambiguous. for task_body in ['bodyId1', 'bodyId2']: reference_body = self.body_list[getattr(self.task, task_body)] for body in self.body_list: if body != reference_body: assert body.description != reference_body.description, ( 'Ambiguous body description: %s' % body.description) self.task.description = description