diff --git a/test/test_radius_search.py b/test/test_radius_search.py index f12e283..373cbb3 100755 --- a/test/test_radius_search.py +++ b/test/test_radius_search.py @@ -18,21 +18,6 @@ def distance2d(pt1, pt2): def distance3d(pt1, pt2): return sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2 + (pt1[2] - pt2[2]) ** 2) -def build_random_points_arround_one_point(pt_ini): - - nb_points = randint(20, 50) - arrays_pts = [] - for i in range(nb_points): - pti_x = pt_ini[0] + rand.uniform(-1.5, 1.5) - pti_y = pt_ini[1] + rand.uniform(-1.5, 1.5) - - # pdal write takes 2 numbers precision (scale_z=0.01 and offset_z=0 by default) - pti_z = round(pt_ini[2] + rand.uniform(-1.5, 1.5), 2) - pt_i = (pti_x, pti_y, pti_z, 2) - arrays_pts.append(pt_i) - - return arrays_pts - def run_filter(arrays_las, distance_radius, search_3d, distance_cylinder=0. ): filter = "filters.radius_search" @@ -78,71 +63,69 @@ def run_filter(arrays_las, distance_radius, search_3d, distance_cylinder=0. ): arrays = pipeline.arrays array = arrays[0] - return array + nb_pts_radius_search = 0 + for pt in array: + if pt["radius_search"] > 0: + nb_pts_radius_search += 1 -def test_radius_search_3d(): + return nb_pts_radius_search - distance_radius = 1 - nb_points_take_3d = 0 + +def build_random_points_around_one_point(test_function): pt_x = 1639825.15 pt_y = 1454924.63 pt_z = 7072.17 pt_ini = (pt_x, pt_y, pt_z, 1) - arrays_pts = build_random_points_arround_one_point(pt_ini) - dtype = [('X', ' 0: - nb_pts_radius_3d += 1 + nb_points_take += test_function(pt_ini, pt_i) - assert nb_pts_radius_3d == nb_points_take_3d + return arrays_las, nb_points_take -def test_radius_search_2d(): +def test_radius_search_3d(): distance_radius = 1 - nb_points_take_2d = 0 - - pt_x = 1639825.15 - pt_y = 1454924.63 - pt_z = 7072.17 - pt_ini = (pt_x, pt_y, pt_z, 1) - arrays_pts = build_random_points_arround_one_point(pt_ini) + def func_test(pt_ini, pt): + distance_i = distance3d(pt_ini, pt) + if distance_i < distance_radius: + return 1 + return 0 - dtype = [('X', ' 0: - nb_pts_radius_2d += 1 + def func_test(pt_ini, pt): + distance_i = distance2d(pt_ini, pt) + if distance_i < distance_radius: + return 1 + return 0 + arrays_las, nb_points_take_2d = build_random_points_around_one_point(func_test) + nb_pts_radius_2d = run_filter(arrays_las, distance_radius, False) assert nb_pts_radius_2d == nb_points_take_2d @@ -151,32 +134,13 @@ def test_radius_search_2d_cylinder(): distance_radius = 1 distance_cylinder = 0.25 - nb_points_take_2d = 0 - - pt_x = 1639825.15 - pt_y = 1454924.63 - pt_z = 7072.17 - pt_ini = (pt_x, pt_y, pt_z, 1) - - arrays_pts = build_random_points_arround_one_point(pt_ini) - - dtype = [('X', ' 0: - nb_pts_radius_2d += 1 + return 1 + return 0 - assert nb_pts_radius_2d == nb_points_take_2d \ No newline at end of file + arrays_las, nb_points_take_2d = build_random_points_around_one_point(func_test) + nb_pts_radius_2d_cylinder = run_filter(arrays_las, distance_radius, False, distance_cylinder) + assert nb_pts_radius_2d_cylinder == nb_points_take_2d \ No newline at end of file