示例#1
0
 def test_shapes(self):
     RigidTransform = RigidTransform_[float]
     sphere = mut.Sphere(radius=1.0)
     self.assertEqual(sphere.radius(), 1.0)
     cylinder = mut.Cylinder(radius=1.0, length=2.0)
     self.assertEqual(cylinder.radius(), 1.0)
     self.assertEqual(cylinder.length(), 2.0)
     box = mut.Box(width=1.0, depth=2.0, height=3.0)
     self.assertEqual(box.width(), 1.0)
     self.assertEqual(box.depth(), 2.0)
     self.assertEqual(box.height(), 3.0)
     numpy_compare.assert_float_equal(box.size(), np.array([1.0, 2.0, 3.0]))
     capsule = mut.Capsule(radius=1.0, length=2.0)
     self.assertEqual(capsule.radius(), 1.0)
     self.assertEqual(capsule.length(), 2.0)
     ellipsoid = mut.Ellipsoid(a=1.0, b=2.0, c=3.0)
     self.assertEqual(ellipsoid.a(), 1.0)
     self.assertEqual(ellipsoid.b(), 2.0)
     self.assertEqual(ellipsoid.c(), 3.0)
     X_FH = mut.HalfSpace.MakePose(Hz_dir_F=[0, 1, 0], p_FB=[1, 1, 1])
     self.assertIsInstance(X_FH, RigidTransform)
     box_mesh_path = FindResourceOrThrow(
         "drake/systems/sensors/test/models/meshes/box.obj")
     mesh = mut.Mesh(absolute_filename=box_mesh_path, scale=1.0)
     self.assertEqual(mesh.filename(), box_mesh_path)
     self.assertEqual(mesh.scale(), 1.0)
     convex = mut.Convex(absolute_filename=box_mesh_path, scale=1.0)
     self.assertEqual(convex.filename(), box_mesh_path)
     self.assertEqual(convex.scale(), 1.0)
示例#2
0
 def test_shape_constructors(self):
     box_mesh_path = FindResourceOrThrow(
         "drake/systems/sensors/test/models/meshes/box.obj")
     shapes = [
         mut.Sphere(radius=1.0),
         mut.Cylinder(radius=1.0, length=2.0),
         mut.Box(width=1.0, depth=2.0, height=3.0),
         mut.HalfSpace(),
         mut.Mesh(absolute_filename=box_mesh_path, scale=1.0),
         mut.Convex(absolute_filename=box_mesh_path, scale=1.0)
     ]
     for shape in shapes:
         self.assertIsInstance(shape, mut.Shape)
示例#3
0
 def test_shape_constructors(self):
     shapes = [
         mut.Sphere(radius=1.0),
         mut.Cylinder(radius=1.0, length=2.0),
         mut.Box(width=1.0, depth=2.0, height=3.0),
         mut.Capsule(radius=1.0, length=2.0),
         mut.Ellipsoid(a=1.0, b=2.0, c=3.0),
         mut.HalfSpace(),
         mut.Mesh(absolute_filename="arbitrary/path", scale=1.0),
         mut.Convex(absolute_filename="arbitrary/path", scale=1.0),
         mut.MeshcatCone(height=1.23, a=3.45, b=6.78)
     ]
     for shape in shapes:
         self.assertIsInstance(shape, mut.Shape)
         shape_cls = type(shape)
         shape_copy = shape.Clone()
         self.assertIsInstance(shape_copy, shape_cls)
         self.assertIsNot(shape, shape_copy)
示例#4
0
 def test_shapes(self):
     sphere = mut.Sphere(radius=1.0)
     self.assertEqual(sphere.radius(), 1.0)
     cylinder = mut.Cylinder(radius=1.0, length=2.0)
     self.assertEqual(cylinder.radius(), 1.0)
     self.assertEqual(cylinder.length(), 2.0)
     box = mut.Box(width=1.0, depth=2.0, height=3.0)
     self.assertEqual(box.width(), 1.0)
     self.assertEqual(box.depth(), 2.0)
     self.assertEqual(box.height(), 3.0)
     numpy_compare.assert_float_equal(box.size(), np.array([1.0, 2.0, 3.0]))
     box_mesh_path = FindResourceOrThrow(
         "drake/systems/sensors/test/models/meshes/box.obj")
     mesh = mut.Mesh(absolute_filename=box_mesh_path, scale=1.0)
     self.assertEqual(mesh.filename(), box_mesh_path)
     self.assertEqual(mesh.scale(), 1.0)
     convex = mut.Convex(absolute_filename=box_mesh_path, scale=1.0)
     self.assertEqual(convex.filename(), box_mesh_path)
     self.assertEqual(convex.scale(), 1.0)
示例#5
0
    def test_shapes(self):
        # We'll test some invariants on all shapes as inherited from the Shape
        # API.
        def assert_shape_api(shape):
            self.assertIsInstance(shape, mut.Shape)
            shape_cls = type(shape)
            shape_copy = shape.Clone()
            self.assertIsInstance(shape_copy, shape_cls)
            self.assertIsNot(shape, shape_copy)

        # Note: these are ordered alphabetical order and not in the declared
        # order in shape_specification.h
        box = mut.Box(width=1.0, depth=2.0, height=3.0)
        assert_shape_api(box)
        self.assertEqual(box.width(), 1.0)
        self.assertEqual(box.depth(), 2.0)
        self.assertEqual(box.height(), 3.0)
        assert_pickle(
            self, box,
            lambda shape: [shape.width(
            ), shape.depth(), shape.height()])
        numpy_compare.assert_float_equal(box.size(), np.array([1.0, 2.0, 3.0]))
        self.assertAlmostEqual(mut.CalcVolume(box), 6.0, 1e-14)

        capsule = mut.Capsule(radius=1.0, length=2.0)
        assert_shape_api(capsule)
        self.assertEqual(capsule.radius(), 1.0)
        self.assertEqual(capsule.length(), 2.0)
        assert_pickle(
            self, capsule,
            lambda shape: [shape.radius(), shape.length()])

        junk_path = "arbitrary/path"
        convex = mut.Convex(absolute_filename=junk_path, scale=1.0)
        assert_shape_api(convex)
        self.assertEqual(convex.filename(), junk_path)
        self.assertEqual(convex.scale(), 1.0)
        assert_pickle(
            self, convex,
            lambda shape: [shape.filename(), shape.scale()])

        cylinder = mut.Cylinder(radius=1.0, length=2.0)
        assert_shape_api(cylinder)
        self.assertEqual(cylinder.radius(), 1.0)
        self.assertEqual(cylinder.length(), 2.0)
        assert_pickle(
            self, cylinder,
            lambda shape: [shape.radius(), shape.length()])

        ellipsoid = mut.Ellipsoid(a=1.0, b=2.0, c=3.0)
        assert_shape_api(ellipsoid)
        self.assertEqual(ellipsoid.a(), 1.0)
        self.assertEqual(ellipsoid.b(), 2.0)
        self.assertEqual(ellipsoid.c(), 3.0)
        assert_pickle(self, ellipsoid, lambda shape:
                      [shape.a(), shape.b(), shape.c()])

        X_FH = mut.HalfSpace.MakePose(Hz_dir_F=[0, 1, 0], p_FB=[1, 1, 1])
        self.assertIsInstance(X_FH, RigidTransform)

        mesh = mut.Mesh(absolute_filename=junk_path, scale=1.0)
        assert_shape_api(mesh)
        self.assertEqual(mesh.filename(), junk_path)
        self.assertEqual(mesh.scale(), 1.0)
        assert_pickle(
            self, mesh,
            lambda shape: [shape.filename(), shape.scale()])

        sphere = mut.Sphere(radius=1.0)
        assert_shape_api(sphere)
        self.assertEqual(sphere.radius(), 1.0)
        assert_pickle(self, sphere, mut.Sphere.radius)

        cone = mut.MeshcatCone(height=1.2, a=3.4, b=5.6)
        assert_shape_api(cone)
        self.assertEqual(cone.height(), 1.2)
        self.assertEqual(cone.a(), 3.4)
        self.assertEqual(cone.b(), 5.6)
        assert_pickle(self, cone,
                      lambda shape: [shape.height(
                      ), shape.a(), shape.b()])