Ejemplo n.º 1
0
 def test_incremental_volume_area_random_input(self):
     """Test that incremental mode gives the same volume/area as
     non-incremental mode and incremental mode with restart"""
     nr_points = 20
     dim = 3
     points = np.random.random((nr_points, dim))
     inc_hull = qhull.ConvexHull(points[:dim+1, :], incremental=True)
     inc_restart_hull = qhull.ConvexHull(points[:dim+1, :], incremental=True)
     for i in range(dim+1, nr_points):
         hull = qhull.ConvexHull(points[:i+1, :])
         inc_hull.add_points(points[i:i+1, :])
         inc_restart_hull.add_points(points[i:i+1, :], restart=True)
         assert_allclose(hull.volume, inc_hull.volume, rtol=1e-7)
         assert_allclose(hull.volume, inc_restart_hull.volume, rtol=1e-7)
         assert_allclose(hull.area, inc_hull.area, rtol=1e-7)
         assert_allclose(hull.area, inc_restart_hull.area, rtol=1e-7)
Ejemplo n.º 2
0
    def test_volume_area(self):
        # Basic check that we get back the correct volume and area for a cube
        points = np.array([(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0),
                           (0, 0, 1), (0, 1, 1), (1, 0, 1), (1, 1, 1)])
        tri = qhull.ConvexHull(points)

        assert_allclose(tri.volume, 1., rtol=1e-14)
        assert_allclose(tri.area, 6., rtol=1e-14)
Ejemplo n.º 3
0
    def test_incremental(self, name):
        # Test incremental construction of the convex hull
        chunks, _ = INCREMENTAL_DATASETS[name]
        points = np.concatenate(chunks, axis=0)

        obj = qhull.ConvexHull(chunks[0], incremental=True)
        for chunk in chunks[1:]:
            obj.add_points(chunk)

        obj2 = qhull.ConvexHull(points)

        obj3 = qhull.ConvexHull(chunks[0], incremental=True)
        if len(chunks) > 1:
            obj3.add_points(np.concatenate(chunks[1:], axis=0), restart=True)

        # Check that the incremental mode agrees with upfront mode
        assert_hulls_equal(points, obj.simplices, obj2.simplices)
        assert_hulls_equal(points, obj.simplices, obj3.simplices)
Ejemplo n.º 4
0
 def test_good2d(self, incremental):
     # Make sure the QGn option gives the correct value of "good".
     points = np.array([[0.2, 0.2], [0.2, 0.4], [0.4, 0.4], [0.4, 0.2],
                        [0.3, 0.6]])
     hull = qhull.ConvexHull(points=points,
                             incremental=incremental,
                             qhull_options='QG4')
     expected = np.array([False, True, False, False], dtype=bool)
     actual = hull.good
     assert_equal(actual, expected)
Ejemplo n.º 5
0
    def test_volume_area(self):
        #Basic check that we get back the correct volume and area for a cube
        points = np.array([(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0),
                           (0, 0, 1), (0, 1, 1), (1, 0, 1), (1, 1, 1)])
        hull = qhull.ConvexHull(points)

        assert_allclose(hull.volume, 1., rtol=1e-14,
                        err_msg="Volume of cube is incorrect")
        assert_allclose(hull.area, 6., rtol=1e-14,
                        err_msg="Area of cube is incorrect")
Ejemplo n.º 6
0
 def test_good2d_inside(self, incremental):
     # Make sure the QGn option gives the correct value of "good".
     # When point n is inside the convex hull of the rest, good is
     # all False.
     points = np.array([[0.2, 0.2], [0.2, 0.4], [0.4, 0.4], [0.4, 0.2],
                        [0.3, 0.3]])
     hull = qhull.ConvexHull(points=points,
                             incremental=incremental,
                             qhull_options='QG4')
     expected = np.array([False, False, False, False], dtype=bool)
     actual = hull.good
     assert_equal(actual, expected)
Ejemplo n.º 7
0
    def test_vertices_2d(self):
        # The vertices should be in counterclockwise order in 2-D
        np.random.seed(1234)
        points = np.random.rand(30, 2)

        hull = qhull.ConvexHull(points)
        assert_equal(np.unique(hull.simplices), np.sort(hull.vertices))

        # Check counterclockwiseness
        x, y = hull.points[hull.vertices].T
        angle = np.arctan2(y - y.mean(), x - x.mean())
        assert_(np.all(np.diff(np.unwrap(angle)) > 0))
Ejemplo n.º 8
0
 def test_good3d(self, incremental):
     # Make sure the QGn option gives the correct value of "good"
     # for a 3d figure
     points = np.array([[0.0, 0.0, 0.0],
                        [0.90029516, -0.39187448, 0.18948093],
                        [0.48676420, -0.72627633, 0.48536925],
                        [0.57651530, -0.81179274, -0.09285832],
                        [0.67846893, -0.71119562, 0.18406710]])
     hull = qhull.ConvexHull(points=points,
                             incremental=incremental,
                             qhull_options='QG0')
     expected = np.array([True, False, False, False], dtype=bool)
     assert_equal(hull.good, expected)
Ejemplo n.º 9
0
 def test_good2d_no_option(self, incremental):
     # handle case where good attribue doesn't exist
     # because Qgn or Qg-n wasn't specified
     points = np.array([[0.2, 0.2], [0.2, 0.4], [0.4, 0.4], [0.4, 0.2],
                        [0.3, 0.6]])
     hull = qhull.ConvexHull(points=points, incremental=incremental)
     actual = hull.good
     assert actual is None
     # preserve None after incremental addition
     if incremental:
         hull.add_points(np.zeros((1, 2)))
         actual = hull.good
         assert actual is None
Ejemplo n.º 10
0
 def test_good2d_incremental_changes(self, new_gen, expected, visibility):
     # use the usual square convex hull
     # generators from test_good2d
     points = np.array([[0.2, 0.2], [0.2, 0.4], [0.4, 0.4], [0.4, 0.2],
                        [0.3, 0.6]])
     hull = qhull.ConvexHull(points=points,
                             incremental=True,
                             qhull_options=visibility)
     hull.add_points(new_gen)
     actual = hull.good
     if '-' in visibility:
         expected = np.invert(expected)
     assert_equal(actual, expected)
Ejemplo n.º 11
0
    def test_hull_consistency_tri(self, name):
        # Check that a convex hull returned by qhull in ndim
        # and the hull constructed from ndim delaunay agree
        points = DATASETS[name]

        tri = qhull.Delaunay(points)
        hull = qhull.ConvexHull(points)

        assert_hulls_equal(points, tri.convex_hull, hull.simplices)

        # Check that the hull extremes are as expected
        if points.shape[1] == 2:
            assert_equal(np.unique(hull.simplices), np.sort(hull.vertices))
        else:
            assert_equal(np.unique(hull.simplices), hull.vertices)
Ejemplo n.º 12
0
    def test_random_volume_area(self):
        #Test that the results for a random 10-point convex are
        #coherent with the output of qconvex Qt s FA
        points = np.array([(0.362568364506, 0.472712355305, 0.347003084477),
                           (0.733731893414, 0.634480295684, 0.950513180209),
                           (0.511239955611, 0.876839441267, 0.418047827863),
                           (0.0765906233393, 0.527373281342, 0.6509863541),
                           (0.146694972056, 0.596725793348, 0.894860986685),
                           (0.513808585741, 0.069576205858, 0.530890338876),
                           (0.512343805118, 0.663537132612, 0.037689295973),
                           (0.47282965018, 0.462176697655, 0.14061843691),
                           (0.240584597123, 0.778660020591, 0.722913476339),
                           (0.951271745935, 0.967000673944, 0.890661319684)])

        hull = qhull.ConvexHull(points)
        assert_allclose(hull.volume, 0.14562013, rtol=1e-07,
                        err_msg="Volume of random polyhedron is incorrect")
        assert_allclose(hull.area, 1.6670425, rtol=1e-07,
                        err_msg="Area of random polyhedron is incorrect")