def test_get_siblings(self):
        """ Make sure children know their parent. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222)])

        assert len(cell.children) == 2
        assert cell.parent == None
        assert cell.children[0].parent == cell
        assert cell.children[1].parent == cell
示例#2
0
    def test_get_siblings(self):
        """ Make sure children know their parent. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222)])

        assert len(cell.children) == 2
        assert cell.parent is None
        assert cell.children[0].parent == cell
        assert cell.children[1].parent == cell
    def test_add_data(self):
        """ Test add and retrieve arbitrary data from tree structure. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.retrieve()
        assert isinstance(result, (list, tuple)), 'should be a list'

        self.assertEqual(len(result), 4)
示例#4
0
    def test_add_data(self):
        """ Test add and retrieve arbitrary data from tree structure. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.retrieve()
        assert isinstance(result, (list, tuple)), 'should be a list'

        self.assertEqual(len(result), 4)
示例#5
0
    def __init__(self, mesh, verbose=False):
        """Build quad tree for mesh.

        All vertex indices in the mesh are stored in a quadtree.
        """
        self.mesh = mesh

        self.set_extents()
        self.add_quad_tree()

        Cell.__init__(self, self.extents, None)  # root has no parent
    def __init__(self, mesh, verbose=False):
        """Build quad tree for mesh.

        All vertex indices in the mesh are stored in a quadtree.
        """
        self.mesh = mesh

        self.set_extents()
        self.add_quad_tree()

        Cell.__init__(self, self.extents, None)  # root has no parent
    def test_search(self):
        """ Test search tree for an intersection. """
        test_tag = 222
        cell = Cell(AABB(0, 10, 0,5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), test_tag),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.search([8.5, 1.5])
        assert isinstance(result, (list, tuple)), 'should be a list'
        assert(len(result) == 1)
        data, _ = result[0]
        self.assertEqual(data, test_tag, 'only 1 point should intersect')
示例#8
0
    def test_search(self):
        """ Test search tree for an intersection. """
        test_tag = 222
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), test_tag),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.search([8.5, 1.5])
        assert isinstance(result, (list, tuple)), 'should be a list'
        assert (len(result) == 1)
        data, _ = result[0]
        self.assertEqual(data, test_tag, 'only 1 point should intersect')
示例#9
0
    def test_build_quadtreeII(self):

        self.cell = Cell(AABB(100, 140, 0, 40), 'cell')

        p0 = [34.6292076111,-7999.92529297]
        p1 = [8000.0, 7999.0]
        p2 = [-7999.96630859, 7999.0]
        p3 = [34, 7999.97021484]

        points = [p0,p1,p2, p3]
        #bac, bce, ecf, dbe, daf, dae
        vertices = [[0,1,2],[0,3,2]]

        mesh = Mesh(points, vertices)

        #This was causing round off error
        Q = MeshQuadtree(mesh)
示例#10
0
    def test_retrieve_triangles(self):

        cell = Cell(AABB(0, 6, 0, 6), 'cell')

        p0 = [2,1]
        p1 = [4,1]
        p2 = [4.,4]
        p3 = [2,4]
        p4 = [5,4]

        points = [p0,p1,p2, p3, p4]
        #
        vertices = [[0,1,2],[0,2,3],[1,4,2]]

        mesh = Mesh(points, vertices)

        Q = MeshQuadtree(mesh)
        results = Q.search([4.5, 3])
示例#11
0
    def expanding_search(self):
        """test_larger mesh and different quad trees
        """
        
        p0 = [2,1]
        p1 = [4,1]
        p2 = [4.,4]
        p3 = [2,4]
        p4 = [5,4]

        p5 = [-1,-1]
        p6 = [1,-1]
        p7 = [1,1]
        p8 = [-1,1]

        points = [p0,p1,p2, p3,p4,p5,p6,p7,p8]
        #
        vertices = [[0,1,2],[0,2,3],[1,4,2],[5,6,7], [5,7,8]]
        mesh = Mesh(points, vertices)

        # Don't do this, want to control the max and mins
        #root = build_quadtree(mesh, max_points_per_cell=4)
    

        root = Cell(-3, 9, -3, 9,
                    max_points_per_cell = 4)
        #Insert indices of all vertices
        root.insert( list(range(mesh.number_of_nodes)) )

        #Build quad tree and return
        root.split()
        
        # One point
        #x = [3.5, 1.5]
        x = [2.5, 1.5]
        element_found, sigma0, sigma1, sigma2, k = root.search_fast(x)
        # One point
        x = [3.00005, 2.999994]
        element_found, sigma0, sigma1, sigma2, k = root.search_fast(x)
        assert element_found is True
        assert k == 1
    def expanding_search(self):
        """test_larger mesh and different quad trees
        """
        
        p0 = [2,1]
        p1 = [4,1]
        p2 = [4.,4]
        p3 = [2,4]
        p4 = [5,4]

        p5 = [-1,-1]
        p6 = [1,-1]
        p7 = [1,1]
        p8 = [-1,1]

        points = [p0,p1,p2, p3,p4,p5,p6,p7,p8]
        #
        vertices = [[0,1,2],[0,2,3],[1,4,2],[5,6,7], [5,7,8]]
        mesh = Mesh(points, vertices)

        # Don't do this, want to control the max and mins
        #root = build_quadtree(mesh, max_points_per_cell=4)
    

        root = Cell(-3, 9, -3, 9,
                    max_points_per_cell = 4)
        #Insert indices of all vertices
        root.insert( range(mesh.number_of_nodes) )

        #Build quad tree and return
        root.split()
        
        # One point
        #x = [3.5, 1.5]
        x = [2.5, 1.5]
        element_found, sigma0, sigma1, sigma2, k = root.search_fast(x)
        # One point
        x = [3.00005, 2.999994]
        element_found, sigma0, sigma1, sigma2, k = root.search_fast(x)
        assert element_found is True
        assert k == 1