MCPcopy
hub / github.com/DLR-RM/BlenderProc / replace

Method replace

blenderproc/python/object/ObjectReplacer.py:102–128  ·  view source on GitHub ↗

Scale, translate, rotate obj_to_add to match obj_to_remove and check if there is a bounding box collision returns a boolean. :param obj_to_remove: An object to remove from the scene. :param obj_to_add: An object to put in the scene instead of obj_to_remove. :param c

(obj_to_remove: MeshObject, obj_to_add: MeshObject,
                check_collision_with: Optional[List[MeshObject]] = None, scale: bool = True,
                relative_pose_sampler: Callable[[MeshObject], None] = None)

Source from the content-addressed store, hash-verified

100
101 @staticmethod
102 def replace(obj_to_remove: MeshObject, obj_to_add: MeshObject,
103 check_collision_with: Optional[List[MeshObject]] = None, scale: bool = True,
104 relative_pose_sampler: Callable[[MeshObject], None] = None):
105 """ Scale, translate, rotate obj_to_add to match obj_to_remove and check if there is a bounding box collision
106 returns a boolean.
107
108 :param obj_to_remove: An object to remove from the scene.
109 :param obj_to_add: An object to put in the scene instead of obj_to_remove.
110 :param check_collision_with: A list of objects, which are not checked for collisions with.
111 :param scale: Scales obj_to_add to match obj_to_remove dimensions.
112 :param relative_pose_sampler: A function that randomly perturbs the pose of the object to replace with
113 (after it has been aligned to the object to replace).
114 """
115 if check_collision_with is None:
116 check_collision_with = []
117 # New object takes location, rotation and rough scale of original object
118 obj_to_add.set_location(obj_to_remove.get_location())
119 obj_to_add.set_rotation_euler(obj_to_remove.get_rotation_euler())
120 if scale:
121 obj_to_add.set_scale(_ObjectReplacer.bb_ratio(obj_to_remove.get_bound_box(True),
122 obj_to_add.get_bound_box(True)))
123 if relative_pose_sampler is not None:
124 relative_pose_sampler(obj_to_add)
125
126 # Check for collision between the new object and other objects in the scene
127 objects_to_check_against = [obj for obj in check_collision_with if obj not in (obj_to_add, obj_to_remove)]
128 return CollisionUtility.check_intersections(obj_to_add, None, objects_to_check_against, [])

Calls 9

relative_pose_samplerFunction · 0.85
get_locationMethod · 0.80
get_rotation_eulerMethod · 0.80
set_scaleMethod · 0.80
bb_ratioMethod · 0.80
get_bound_boxMethod · 0.80
check_intersectionsMethod · 0.80
set_locationMethod · 0.45
set_rotation_eulerMethod · 0.45

Tested by

no test coverage detected