コード例 #1
0
 def test_with_27_voxels(self):
     voxels = [i for i in Octree.get_all_voxels([0, 0, 0], 1, 3)]
     tree = Octree(voxels, 1, [[0, 3], [0, 3], [0, 3]], True)
     tree.fill_tree()
     self.assertEqual(self.get_count_voxels_on_upper_node(1, 3), len(tree.Start.Objects))
     for i in range(8):
         self.assertEqual(1, len(tree.Start.Children[i]), str(i))
コード例 #2
0
 def test_with_125_voxels(self):
     voxels =[i for i in Octree.get_all_voxels([0, 0, 0], 1, 5)]
     tree = Octree(voxels, 1, [[0, 5], [0, 5], [0, 5]], True)
     tree.fill_tree()
     #tree.Start.distribute(True, 1)
     self.assertEqual(self.get_count_voxels_on_upper_node(1, 5), len(tree.Start.Objects))
     for child in range(8):
         self.assertEqual(7, len(tree.Start.Children[child]), str(child))
         for i in range(8):
             ch = tree.Start.Children[child]
             self.assertTrue(len(ch.Children[i]) == 1 or len(ch.Children[i]) == 0)
コード例 #3
0
 def test_with_voxels_in_child(self):
     # TODO
     #  Работает правильно, но лень настраивать тест
     voxels = Node.get_all_voxels_vertex([0, 0, 0], 1)
     v = []
     for i in voxels:
         temp = Node.get_all_voxels_vertex(i, 0.5)
         for t in temp:
             if 2 not in t:
                 v.append(t)
     tree = Octree(v, 0.5, [[0, 4], [0, 4], [0, 4]], True)
     tree._fill_tree(tree.Start)
     print(1)
コード例 #4
0
 def test_with_64_voxels(self):
     voxels = [i for i in Octree.get_all_voxels([0, 0, 0], 1, 4)]
     tree = get_octree(voxels, 1, True)
     tree._fill_tree(tree.Start)
     self.assertEqual(self.get_count_voxels_on_upper_node(1, 4), len(tree.Start.Objects))
     for child in tree.Start.Children:
         self.assertEqual(self.get_count_voxels_on_upper_node(1, 1), len(child.Objects))
コード例 #5
0
 def test_bounding_boxes_on_negative_side_with_8_voxels(self):
     node = get_simple_node(4, [-4, -4, -4])
     node.add_objects(Octree.get_all_voxels([-4, -4, -4], 2, 4))
     node.distribute(True, 2)
     self.assertEqual(8, len(node))
     for i in range(8):
         child = node.Children[i]
         self.assertEqual(0, len(child), "child num: " + str(i))
コード例 #6
0
 def test_with_512_voxels(self):
     voxels = [i for i in Octree.get_all_voxels([0, 0, 0], 0.5, 4)]
     tree = get_octree(voxels, 0.5, True)
     tree._fill_tree(tree.Start)
     self.assertEqual(self.get_count_voxels_on_upper_node(0.5, 4), len(tree.Start.Objects))
     for child in range(8):
         ch = tree.Start.Children[child]
         self.assertEqual(26, len(ch), str(child))
コード例 #7
0
 def test_bounding_boxes_on_start_coordinates_with_64_voxels(self):
     node = get_simple_node(4, [-2, -2, -2])
     node.add_objects([i for i in Octree.get_all_voxels([-2, -2, -2], 1, 4)])
     node.distribute(True, 1)
     self.assertEqual(TestsFillOctree.get_count_voxels_on_upper_node(1, 4), len(node), "start node")
     for i in range(8):
         child = node.Children[i]
         self.assertEqual(1, len(child), "child num: " + str(i))
コード例 #8
0
 def test_with_27_voxels(self):
     node = get_simple_node(3)
     node.add_objects(Octree.get_all_voxels([0, 0, 0], 1, 3))
     node.distribute(True, 1)
     self.assertEqual(TestsFillOctree.get_count_voxels_on_upper_node(1, 3), len(node))
     for i in range(8):
         child = node.Children[i]
         self.assertEqual(1, len(child))
コード例 #9
0
 def test_bounding_boxes_on_start_coordinates_with_125_voxels(self):
     node = get_simple_node(5, [-2.5, -2.5, -2.5])
     node.add_objects(Octree.get_all_voxels([-2.5, -2.5, -2.5], 1, 5))
     node.distribute(True, 1)
     self.assertEqual(TestsFillOctree.get_count_voxels_on_upper_node(1, 5), len(node))
     for i in range(8):
         child = node.Children[i]
         self.assertEqual(8, len(child), "child num: " + str(i))
コード例 #10
0
def get_voxel_model(model, size_mod, size_voxel):
    """

    :param model:
    :param size_mod: [[min_x, max_x], [min_y, max_y], [min_z, max_z]]
    :param size_voxel:
    :return:
    """
    max_size_model = max(*[i[1] - i[0] for i in size_mod])
    start_pos = [i[0] for i in size_mod]
    voxels = Octree.get_all_voxels(start_pos, size_voxel, max_size_model)
    tree = Octree(voxels, size_voxel, size_mod, True)
    tree.fill_tree()
    for mesh in model:
        temp = tree.get_all_crossing(mesh, tree.Start)
        for i in temp:
            yield i
コード例 #11
0
 def test_with_8_voxels(self):
     node = get_simple_node()
     node.add_objects(Octree.get_all_voxels([0, 0, 0], 2, 4))
     node.distribute(True, 2)
     self.assertEqual(8, len(node))
コード例 #12
0
 def test_with_negative_start_coords(self):
     res = [i for i in Octree.get_all_voxels([-1, -1, -1], 1, 2)]
     true = [[-1, -1, -1], [-1, -1, 0], [-1, 0, -1], [-1, 0, 0], [0, -1, -1], [0, -1, 0], [0, 0, -1], [0, 0, 0]]
     self.assertEqual(true, res)
コード例 #13
0
 def test_with_float_size_voxe_and_float_max_size(self):
     res = [i for i in Octree.get_all_voxels([0, 0, 0], 0.5, 0.5)]
     true = [[0, 0, 0]]
     self.assertEqual(true, res)
コード例 #14
0
 def test_with_float_size_vozel(self):
     res = [i for i in Octree.get_all_voxels([0, 0, 0], 0.5, 1)]
     true = [[0, 0, 0], [0, 0, 0.5], [0, 0.5, 0], [0, 0.5, 0.5], [0.5, 0, 0], [0.5, 0, 0.5], [0.5, 0.5, 0], [0.5, 0.5, 0.5]]
     self.assertEqual(true, res)
コード例 #15
0
 def test_one_voxel(self):
     res = [i for i in Octree.get_all_voxels([0, 0, 0], 1, 1)]
     true = [[0, 0, 0]]
     self.assertEqual(true, res)
コード例 #16
0
 def test_simple(self):
     res = [i for i in Octree.get_all_voxels([0, 0, 0], 1, 2)]
     true = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
     self.assertEqual(true, res)
コード例 #17
0
def get_octree(objects=[], size_voxel=1.0, is_voxel=True):
    return Octree(objects, size_voxel, [[0, 4], [0, 4], [0, 4]], is_voxel)
コード例 #18
0
 def test_with_8_voxels(self):
     voxels = [i for i in Octree.get_all_voxels([0, 0, 0], 2, True)]
     tree = get_octree(voxels, 2, True)
     tree._fill_tree(tree.Start)
     count_voxels = self.get_count_voxels_on_upper_node(2, 4)
     self.assertEqual(voxels, tree.Start.Objects)