コード例 #1
0
    def test_true_shape(self):

        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        a = np.array([[0, 0, 0], [2, 2, 2], [2, 2, 2]])
        a = g.true_shape(a)
        # Test remove duplicates
        a = np.array([[0, 0, 0], [2, 2, 2], [0, 0, 0], [2, 2, 2]])
        self.assertEqual(2, g.true_shape(a).shape[0])

        # Test 3 points on the same line should return outer points
        a = np.array([[0, 0, 0], [2, 2, 2], [3, 3, 3]])
        self.assertTrue(
            np.allclose(g.true_shape(a), np.array([[0, 0, 0], [3, 3, 3]])))

        # Test 4 points that are actually a triagle
        a = np.array([[0, 0, 0], [0, 3, 0], [3, 0, 0], [1, 1, 0]])
        self.assertTrue(
            np.allclose(g.true_shape(a),
                        np.array([[0, 0, 0], [0, 3, 0], [3, 0, 0]])))

        # Test 4 points that are all outher vetecis in a convex polygon
        a = np.array([[0, 0, 0], [0, 3, 0], [3, 0, 0], [5, 5, 0]])
        self.assertTrue(
            np.allclose(g.true_shape(a),
                        np.array([[0, 0, 0], [0, 3, 0], [3, 0, 0], [5, 5,
                                                                    0]])))
コード例 #2
0
    def test_in_line(self):
        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        self.assertTrue(
            g.in_line(np.array([[2, 2, 2], [2, 2, 2]]),
                      np.array([2, 2, 2])))  # All points equal.
        self.assertFalse(g.in_line(
            line, point_not_paralell_to_line))  # Point in NOT parallel to line
        self.assertFalse(g.in_line(line, point_opposite_direction_than_line)
                         )  # Point opposite dir then line
        self.assertFalse(g.in_line(
            line,
            point_further_away_than_line))  # Point is is further then line
        self.assertTrue(g.in_line(line, point_on_line))  # Point is on line
        self.assertFalse(
            g.in_line(np.array([[3, 3, 3], [4, 4, 4]]),
                      np.array([5, 5, 5])))  # Point is on line

        self.assertFalse(g.interior(
            line, point_not_paralell_to_line))  # Point in NOT parallel to line
        self.assertFalse(g.interior(line, point_opposite_direction_than_line)
                         )  # Point opposite dir then line
        self.assertFalse(g.interior(
            line,
            point_further_away_than_line))  # Point is is further then line
        self.assertTrue(g.interior(line, point_on_line))  # Point is on line
        self.assertFalse(
            g.interior(np.array([[3, 3, 3], [4, 4, 4]]),
                       np.array([5, 5, 5])))  # Point is on line
コード例 #3
0
    def test_get_vertices(self):
        # Test for gamut.Gamut.get_vertices
        c_data = data.Data(space.srgb,
                           cube)  # Generating the colour Data object
        g = gamut.Gamut(space.srgb, c_data)
        n1_data = np.array([
            [
                0, 0, 0
            ],  # 0  vertices    # Array with just the vertices used for comparison.
            [10, 0, 0],  # 1  vertices
            [10, 10, 0],  # 2  vertices
            [0, 10, 0],  # 3  vertices
            [10, 10, 10],  # 6  vertices
            [10, 0, 10],  # 8  vertices
            [0, 0, 10],  # 9  vertices
            [0, 10, 10]
        ])  # 10 vertices

        vertices = g.get_vertices(cube)
        self.assertTrue(np.array_equiv(
            n1_data,
            vertices))  # Compares return array with the known vertices array.

        vertices = g.get_vertices(
            cube)  # Calls the function and add the vertices to the array.
        self.assertTrue(
            np.array_equiv(n1_data, vertices)
        )  # Compares returned array with the known vertices array.
コード例 #4
0
 def test_center_of_mass(self):
     c_data = data.Data(space.srgb, cube)
     g = gamut.Gamut(space.srgb, c_data)
     cm = g.center_of_mass(g.get_vertices(
         g.hull.points))  # Get coordinate for center of the cube
     cp = np.array([5., 5., 5.])  # Point in center of cube.
     self.assertEqual(cp.all(),
                      cm.all())  # Assert true that the points are the same.
コード例 #5
0
    def test_is_coplanar(self):
        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        points = np.array([[0, 0, 0], [2, 2, 0], [3, 3, 0],
                           [1, 1, 0]])  # coplanar points
        self.assertTrue(True, g.is_coplanar(points))

        points = np.array([[0, 0, 1], [2, 2, 0], [3, 3, 0],
                           [1, 1, 0]])  # non-coplanar points
        self.assertFalse(False, g.is_coplanar(points))
コード例 #6
0
    def test_gamut_initialize(self):
        # Test for convex hull
        c_data = data.Data(space.srgb,
                           cube)  # Generating the colour Data object
        g = gamut.Gamut(space.srgb, c_data)
        vertices = np.array([0, 1, 2, 3, 6, 8, 9, 10
                             ])  # Known indices of vertices for the test case

        self.assertEqual(
            vertices.tolist(),
            g.vertices.tolist())  # Checking that the vertices match
コード例 #7
0
    def test_plot_surface(self):  # Test for gamut.Gamut.plot_surface
        fig = plt.figure()  # Creates a figure
        ax = fig.add_subplot(111, projection='3d')  # Creates a 3D plot ax

        # c = self.generate_circle(1000, 10)
        # c_data = data.Data(space.srgb, c)
        # g = gamut.Gamut(space.srgb, c_data)

        c_data = data.Data(space.srgb,
                           polyhedron)  # Generating the colour Data object
        g = gamut.Gamut(space.srgb, c_data)  # Creates a new gamut

        sp = g.space  # specifies the color space
        g.plot_surface(ax, sp)  # Calls the plot function
コード例 #8
0
    def test_generate_sphere(self):
        sphere = self.generate_sphere(5, 10)

        # plt.plot(sphere[:,0],sphere[:,1])
        # plt.show()
        #
        # plt.plot(sphere[:,0],sphere[:,2])
        # plt.show()

        fig = plt.figure()  # Creates a figure
        ax = fig.add_subplot(111, projection='3d')  # Creates a 3D plot ax

        c_data = data.Data(space.srgb, sphere)
        g = gamut.Gamut(space.srgb, c_data)

        sp = g.space  # specifies the color space
        g.plot_surface(ax, sp)  # Calls the plot function
コード例 #9
0
    def test_in_tetrahedron(self):
        c_data = data.Data(space.srgb, tetrahedron)
        g = gamut.Gamut(space.srgb, c_data)

        self.assertTrue(g.in_tetrahedron(
            tetrahedron, tetra_p_inside))  # Point is on the tetrahedron
        self.assertFalse(g.in_tetrahedron(
            tetrahedron, tetra_p_not_inside))  # Point is NOT on tetrahedron
        self.assertTrue(g.in_tetrahedron(
            tetrahedron,
            tetra_p_on_surface))  # Point is on a simplex(counts as inside)

        self.assertTrue(g.interior(
            tetrahedron, tetra_p_inside))  # Point is on the tetrahedron
        self.assertFalse(g.interior(
            tetrahedron, tetra_p_not_inside))  # Point is NOT on tetrahedron
        self.assertTrue(g.interior(tetrahedron, tetra_p_on_surface))
コード例 #10
0
    def test_is_inside(self):  # Test for gamut.Gamut.is_inside
        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        c_data = data.Data(space.srgb, points_3d)
        a = g.is_inside(space.srgb, c_data)
        self.assertEqual(
            a.shape,
            points_3d.shape[:-1])  # Asserts if shape is reduced by 1dim
        self.assertEqual(a.dtype,
                         bool)  # Asserts is data type in the array is boolean
        self.assertTrue(np.allclose(
            a, bool_3d))  # Asserts that the returned values are correct

        c_data = data.Data(space.srgb, points_2d)
        a = g.is_inside(space.srgb, c_data)
        self.assertEqual(
            a.shape,
            points_2d.shape[:-1])  # Asserts if shape is reduced by 1dim
        self.assertEqual(a.dtype,
                         bool)  # Asserts is data type in the array is boolean
        self.assertTrue(np.allclose(
            a, bool_2d))  # Asserts that the returned values are correct

        c_data = data.Data(space.srgb, points_1d)
        a = g.is_inside(space.srgb, c_data)
        self.assertEqual(
            1, a.size)  # When only one point is sent, still returned a array
        self.assertEqual(a.dtype,
                         bool)  # Asserts is data type in the array is boolean
        self.assertTrue(np.allclose(
            a, bool_1d))  # Asserts that the returned values are correct

        c_data = data.Data(space.srgb, self.generate_sphere(15, 100))
        g = gamut.Gamut(space.srgb, c_data)

        c_data = data.Data(space.srgb, self.generate_sphere(
            10, 15))  # Points lie within the sphere(inclusion = true)
        a = g.is_inside(space.srgb, c_data)
        self.assertTrue(np.allclose(a, np.ones(
            a.shape)))  # Assert that all points lie within the gamut

        c_data = data.Data(space.srgb, self.generate_sphere(
            20, 15))  # Points lie outside the sphere(inclusion = true)
        a = g.is_inside(space.srgb, c_data)
        self.assertTrue(np.allclose(a, np.zeros(
            a.shape)))  # Assert that all points lie without the gamut
コード例 #11
0
    def test_feito_torres_with_sphere(self):
        gamut_sphere = self.generate_sphere(10, 100)
        outside = self.generate_sphere(12, 5)
        innside = self.generate_sphere(8, 5)
        c_idk = self.generate_sphere(9.9, 12)
        c_data = data.Data(space.srgb, gamut_sphere)
        g = gamut.Gamut(space.srgb, c_data)

        print("----------------")
        print("Should be inside")
        print("----------------")
        for i in range(0, innside.shape[0]):
            print(g.feito_torres(innside[i]))

        print("----------------")
        print("Should be outside")
        print("----------------")
        for i in range(0, innside.shape[0]):
            print(g.feito_torres(outside[i]))
        print("----------------")
        print("Uncertain")
        print("----------------")
        for i in range(0, innside.shape[0]):
            print(g.feito_torres(c_idk[i]))
コード例 #12
0
    def test_in_triangle(self):
        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        self.assertFalse(g.in_triangle(triangle, triangle_point_not_coplanar))
        self.assertFalse(
            g.in_triangle(triangle, triangle_point_coplanar_but_outside))
        self.assertTrue(g.in_triangle(triangle, triangle_point_inside))

        self.assertFalse(g.in_triangle(triangle2,
                                       triangle2_point_not_coplanar))
        self.assertFalse(
            g.in_triangle(triangle2, triangle2_point_coplanar_but_outside))
        self.assertTrue(g.in_triangle(triangle2, triangle2_point_inside))

        self.assertFalse(g.interior(triangle, triangle_point_not_coplanar))
        self.assertFalse(
            g.interior(triangle, triangle_point_coplanar_but_outside))
        self.assertTrue(g.interior(triangle, triangle_point_inside))

        self.assertFalse(g.interior(triangle2, triangle2_point_not_coplanar))
        self.assertFalse(
            g.interior(triangle2, triangle2_point_coplanar_but_outside))
        self.assertTrue(g.interior(triangle2, triangle2_point_inside))
コード例 #13
0
 def test_fix_orientation(self):
     c_data = data.Data(space.srgb, cube)
     g = gamut.Gamut(space.srgb, c_data)
     g.fix_orientation()
コード例 #14
0
    def test_sign(self):
        c_data = data.Data(space.srgb, cube)
        g = gamut.Gamut(space.srgb, c_data)

        print(g.sign(tetrahedron_two))