Skip to content

Commit 249a21d

Browse files
authored
Merge pull request #144 from tetov/scaling
Use scale factor for CollisionMesh (suggestion for #142)
2 parents 2ace972 + 6bbdbc1 commit 249a21d

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Unreleased
3333
``tolerance_below`` for allowing asymmetrical constraints.
3434
* In :class:``compas_fab.robots.Robot``, changed the ``constraints_from_configuration``
3535
function with ``tolerances_above`` and ``tolerances_below``.
36+
* :meth:`compas_fab.robots.CollisionMesh.scale` now takes a scale factor
37+
instead of a :class:`compas.geometry.Scale` instance as an argument.
3638

3739
**Removed**
3840

src/compas_fab/artists/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def scale(self, factor):
166166
self.robot.scale(factor) # scale the model
167167

168168
relative_factor = factor / self.scale_factor # relative scaling factor
169-
transformation = Scale([relative_factor, relative_factor, relative_factor])
169+
transformation = Scale([relative_factor] * 3)
170170
self.scale_link(self.robot.root, transformation)
171171
self.scale_factor = factor
172172

src/compas_fab/robots/planning_scene.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
from compas.datastructures import mesh_transform
65
from compas.geometry import Frame
76
from compas.geometry import Scale
87

@@ -43,14 +42,16 @@ def __init__(self, mesh, id, frame=None, root_name=None):
4342
self.frame = frame or Frame.worldXY()
4443
self.root_name = root_name or 'world'
4544

46-
def scale(self, transformation):
47-
"""Scales the collision mesh.
45+
def scale(self, scale_factor):
46+
"""Scales the collision mesh uniformly.
4847
4948
Parameters
5049
----------
51-
transformation : compas.geometry.Scale
50+
scale_factor : :obj:`float`
51+
Scale factor.
5252
"""
53-
mesh_transform(self.mesh, transformation)
53+
S = Scale([scale_factor] * 3)
54+
self.mesh.transform(S)
5455

5556

5657
class AttachedCollisionMesh(object):
@@ -140,8 +141,8 @@ def add_collision_mesh(self, collision_mesh, scale=False):
140141
collision_mesh.root_name = self.robot.root_name
141142

142143
if scale:
143-
S = Scale([1./self.robot.scale_factor] * 3)
144-
collision_mesh.scale(S)
144+
scale_factor = 1. / self.robot.scale_factor
145+
collision_mesh.scale(scale_factor)
145146

146147
self.client.add_collision_mesh(collision_mesh)
147148

@@ -194,8 +195,8 @@ def append_collision_mesh(self, collision_mesh, scale=False):
194195
collision_mesh.root_name = self.robot.root_name
195196

196197
if scale:
197-
S = Scale([1./self.robot.scale_factor] * 3)
198-
collision_mesh.scale(S)
198+
scale_factor = 1. / self.robot.scale_factor
199+
collision_mesh.scale(scale_factor)
199200

200201
self.robot.client.append_collision_mesh(collision_mesh)
201202

@@ -226,8 +227,8 @@ def add_attached_collision_mesh(self, attached_collision_mesh, scale=False):
226227
self.ensure_client()
227228

228229
if scale:
229-
S = Scale([1./self.robot.scale_factor] * 3)
230-
attached_collision_mesh.collision_mesh.scale(S)
230+
scale_factor = 1. / self.robot.scale_factor
231+
attached_collision_mesh.collision_mesh.scale(scale_factor)
231232

232233
self.client.add_attached_collision_mesh(attached_collision_mesh)
233234

@@ -293,8 +294,8 @@ def attach_collision_mesh_to_robot_end_effector(self, collision_mesh, scale=Fals
293294
self.ensure_client()
294295

295296
if scale:
296-
S = Scale([1./self.robot.scale_factor] * 3)
297-
collision_mesh.scale(S)
297+
scale_factor = 1. / self.robot.scale_factor
298+
collision_mesh.scale(scale_factor)
298299

299300
ee_link_name = self.robot.get_end_effector_link_name(group)
300301
touch_links = [ee_link_name]

0 commit comments

Comments
 (0)