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))
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))
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))
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))
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))
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))
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))
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)
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
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))
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)
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)
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)
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)
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)
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)