Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update algo MNx and test #24

Merged
merged 14 commits into from
Oct 10, 2024
4 changes: 2 additions & 2 deletions src/filter_radius_assign/RadiusAssignFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void RadiusAssignFilter::doOneNoDomain(PointRef &point)
for (PointId ptId : iNeighbors)
{
double Zpt = refView->point(ptId).getFieldAs<double>(Dimension::Id::Z);
if (m_args->m_max2d_below>=0 && Zref<Zpt && (Zref-Zpt)>m_args->m_max2d_below) {take=false; break;}
if (m_args->m_max2d_above>=0 && Zref>Zpt && (Zpt-Zref)>m_args->m_max2d_above) {take=false; break;}
if (m_args->m_max2d_below>=0 && (Zref-Zpt)>m_args->m_max2d_below) {take=false; break;}
if (m_args->m_max2d_above>=0 && (Zpt-Zref)>m_args->m_max2d_above) {take=false; break;}
}
if (!take) return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_parse_args():
"crop",
[
"crop_1.laz",
# "crop_2.laz", ToDo : rebuilt the reference crop_2 wich is false
# "crop_2.laz", ToDo : rebuild the reference for crop_2 which is false
"crop_3.laz",
],
)
Expand All @@ -158,8 +158,6 @@ def test_algo_mark_points_for_dm_with_reference(crop):
keep_temporary_dims=False,
skip_buffer=True,
)
pipeline = pdal.Pipeline()
pipeline.execute()

def sort_points(points):
sorted_index = np.lexsort((points["Y"], points["X"], points["Z"], points["GpsTime"]))
Expand Down
159 changes: 133 additions & 26 deletions test/test_radius_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pt_ini = (pt_x, pt_y, pt_z, 1)

numeric_precision = 4
distance_radius = 1


def distance2d(pt1, pt2):
Expand Down Expand Up @@ -74,7 +75,7 @@ def run_filter(arrays_las, distance_radius, search_3d, limit_z_above=-1, limit_w
return nb_pts_radius_search


def build_random_points_around_one_point(test_function, distance_radius):
def build_random_points_around_one_point(test_function):

dtype = [("X", "<f8"), ("Y", "<f8"), ("Z", "<f8"), ("Classification", "u1")]
arrays_las = np.array([pt_ini], dtype=dtype)
Expand Down Expand Up @@ -113,44 +114,160 @@ def build_random_points_around_one_point(test_function, distance_radius):

def test_radius_assign_3d():

distance_radius = 1

def func_test(pt):
distance_i = distance3d(pt_ini, pt)
if distance_i < distance_radius:
return 1
return 0

arrays_las, nb_points_take_3d = build_random_points_around_one_point(
func_test, distance_radius
)
arrays_las, nb_points_take_3d = build_random_points_around_one_point(func_test)
nb_pts_radius_3d = run_filter(arrays_las, distance_radius, True)
assert nb_pts_radius_3d == nb_points_take_3d


def test_radius_assign_2d():

distance_radius = 1

def func_test(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, distance_radius
)
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


def test_radius_assign_2d_cylinder_below():

limit_z_below = 1.75
limit_z_above = -1

def func_test(pt):
distance_i = distance2d(pt_ini, pt)
distance_z = pt[2] - pt_ini[2]
if distance_i < distance_radius and distance_z < limit_z_below:
return 1
return 0

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, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


def test_radius_assign_2d_cylinder_above():

limit_z_below = -1
limit_z_above = 1.75

def func_test(pt):
distance_i = distance2d(pt_ini, pt)
distance_z = pt_ini[2] - pt[2]
if distance_i < distance_radius and distance_z < limit_z_above:
return 1
return 0

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, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


def test_radius_assign_2d_cylinder_above_bellow_null():
alavenant marked this conversation as resolved.
Show resolved Hide resolved

limit_z_below = 0
limit_z_above = 0

def func_test(pt):
distance_i = distance2d(pt_ini, pt)
distance_z = pt_ini[2] - pt[2]
if distance_i < distance_radius and distance_z == 0:
alavenant marked this conversation as resolved.
Show resolved Hide resolved
return 1
return 0

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, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


def test_radius_assign_2d_cylinder_above_null_bellow_all():

limit_z_below = 0
limit_z_above = -1

def func_test(pt):
distance_i = distance2d(pt_ini, pt)
distance_z = pt[2] - pt_ini[2]
if distance_i < distance_radius and distance_z <= 0:
return 1
return 0

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, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


def test_radius_assign_2d_cylinder_above_bellow_all():

limit_z_below = -1
limit_z_above = -1

def func_test(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_cylinder = run_filter(
arrays_las, distance_radius, False, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


@pytest.mark.parametrize("execution_number", range(10))
def test_radius_assign_2d_cylinder_above_and_bellow(execution_number):

limit_z_below = rand.uniform(0, 2)
limit_z_above = rand.uniform(0, 2)

def func_test(pt):
distance_i = distance2d(pt_ini, pt)
distance_z = pt_ini[2] - pt[2]
if (
distance_i < distance_radius
and distance_z <= limit_z_above
and (-distance_z) <= limit_z_below
):
return 1
return 0

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, limit_z_above, limit_z_below
)
assert nb_pts_radius_2d_cylinder == nb_points_take_2d


@pytest.mark.parametrize(
"limit_z_above, limit_z_below",
[
(-1, -1), # no limit
(-1, 2), # limit below only
(2, -1), # limit above only
(-1, 1.75), # limit below only
(1.75, -1), # limit above only
(0, -1), # take all points below only
(-1, 0), # take all points above only
(-0.5, 0.5),
Expand All @@ -165,25 +282,15 @@ def test_radius_assign_2d_cylinder(limit_z_above, limit_z_below):
def func_test(pt):
alavenant marked this conversation as resolved.
Show resolved Hide resolved
distance_i = distance2d(pt_ini, pt)
if distance_i < distance_radius:
if (
(limit_z_above >= 0)
and pt[2] < pt_ini[2]
and ((pt[2] - pt_ini[2]) > limit_z_above)
):
if (limit_z_above >= 0) and ((pt_ini[2] - pt[2]) > limit_z_above):
return 0
if (
(limit_z_below >= 0)
and pt[2] > pt_ini[2]
and ((pt_ini[2] - pt[2]) > limit_z_below)
):
if (limit_z_below >= 0) and ((pt[2] - pt_ini[2]) > limit_z_below):
return 0
return 1
else:
return 0

arrays_las, nb_points_take_2d = build_random_points_around_one_point(
func_test, distance_radius
)
arrays_las, nb_points_take_2d = build_random_points_around_one_point(func_test)

assert len(arrays_las) > 0

Expand Down