Example #1
0
    def test_concatenate_partial_missing_vc(self):
        v1 = np.array([
            [0., 0., 0.],
            [5., 5., 5.],
            [5., 0., 5.],
        ])
        vc1 = np.array([
            [1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.],
        ])
        m1 = Mesh(v=v1, vc=vc1)

        v2 = np.array([
            [0., 0., 0.],
            [5., -5., 5.],
            [5., 0., 5.],
        ])
        m2 = Mesh(v=v2)

        with self.assertRaisesRegexp(ValueError, 'all args or none.'):
            Mesh.concatenate(m1, m2)
Example #2
0
    def test_concatenate_vertices_only(self):
        v1 = np.array([
            [0., 0., 0.],
            [5., 5., 5.],
            [5., 0., 5.],
        ])
        m1 = Mesh(v=v1)

        v2 = np.array([
            [0., 0., 0.],
            [5., -5., 5.],
            [5., 0., 5.],
        ])
        m2 = Mesh(v=v2)

        self.assertEqual(Mesh.concatenate(m1, m2).v.shape[0], 6)
Example #3
0
    def test_concatenate(self):
        v1 = np.array([
            [0., 0., 0.],
            [5., 5., 5.],
            [5., 0., 5.],
        ])
        vc1 = np.array([
            [1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.],
        ])
        f1 = np.array([
            [0, 1, 2],
        ])
        m1 = Mesh(v=v1, vc=vc1, f=f1)

        v2 = np.array([
            [0., 0., 0.],
            [5., -5., 5.],
            [5., 0., 5.],
        ])
        vc2 = np.array([
            [0., 1., 1.],
            [1., 0., 1.],
            [1., 1., 0.],
        ])
        f2 = np.array([
            [1, 0, 2],
        ])
        m2 = Mesh(v=v2, vc=vc2, f=f2)

        v3 = np.array([
            [0., 0., 0.],
            [3., -3., 3.],
            [3., 0., 3.],
            # Add an extra unused vertex to make the counts a little more
            # interesting.
            [3., 1., 7.],
        ])
        vc3 = np.array([
            [0., 0.5, 1.],
            [0.5, 0., 1.],
            [1., 1., 0.],
            [1., 0.5, 1.],
        ])
        f3 = np.array([
            [2, 1, 0],
        ])
        m3 = Mesh(v=v3, vc=vc3, f=f3)

        mcat = Mesh.concatenate(m1, m2, m3)

        num_v1 = v1.shape[0]
        num_v2 = v2.shape[0]
        num_v3 = v3.shape[0]
        num_vertices = num_v1 + num_v2 + num_v3

        # Check expected number of vertices, colors, and faces.
        self.assertEqual(mcat.v.shape[0], num_vertices)
        self.assertEqual(mcat.vc.shape[0], num_vertices)
        self.assertEqual(mcat.f.shape[0], 3)

        # Check the vertices.
        np.testing.assert_array_equal(v1, mcat.v[:num_v1, :])
        np.testing.assert_array_equal(v2, mcat.v[num_v1:(num_v1 + num_v2), :])
        np.testing.assert_array_equal(v3, mcat.v[(num_v1 + num_v2):, :])
        # Check vertex colors
        np.testing.assert_array_equal(vc1, mcat.vc[:3, :])
        np.testing.assert_array_equal(vc2, mcat.vc[3:6, :])
        np.testing.assert_array_equal(vc3, mcat.vc[6:, :])
        # Check faces.
        np.testing.assert_array_equal(
            f1.ravel(), mcat.f[0, :].ravel())
        np.testing.assert_array_equal(
            f2.ravel() + num_v1, mcat.f[1, :].ravel())
        np.testing.assert_array_equal(
            f3.ravel() + num_v1 + num_v2, mcat.f[2, :].ravel())