Skip to content

Commit

Permalink
Add possibility to restrict the cylinder with 2D serach
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed Mar 26, 2024
1 parent 608d380 commit 4c22409
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/grid_radius_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ Options

**output_name_attribut**: The name of the new attribut. [Default: radius]

**3d_search**: Search in 3d (as a ball). [Default: false]

**2d_search_above**: If 3d_search is false, take points only if exists points between the referent point and a distance above. [Default: 0.]

**2d_search_bellow**: If 3d_search is false, take points only if exists points between the referent point and a distance bellow. [Default: 0.]

20 changes: 19 additions & 1 deletion src/filter_radius_search/radius_searchFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void RadiusSearchFilter::addArgs(ProgramArgs& args)
args.add("radius", "Distance of neighbors to consult", m_args->m_radius, 1.);
args.add("output_name_attribute", "Name of the added attribut", m_args->m_nameAddAttribute, "radius" );
args.add("3d_search", "Search in 3d", m_args->search3d, false );
args.add("2d_search_above", "if search in 2d : filter point above the distance", m_args->m_search_bellow, 0. );
args.add("2d_search_bellow", "if search in 2d : filter point bellow the distance", m_args->m_search_above, 0. );
}

void RadiusSearchFilter::addDimensions(PointLayoutPtr layout)
Expand Down Expand Up @@ -68,14 +70,30 @@ void RadiusSearchFilter::ready(PointTableRef)

void RadiusSearchFilter::doOneNoDomain(PointRef &point)
{
// build3dIndex and build2dIndex are buuild once
// build3dIndex and build2dIndex are build once
PointIdList iNeighbors;
if (m_args->search3d) iNeighbors = refView->build3dIndex().radius(point, m_args->m_radius);
else iNeighbors = refView->build2dIndex().radius(point, m_args->m_radius);

if (iNeighbors.size() == 0)
return;

if (!m_args->search3d)
{
double Zref = point.getFieldAs<double>(Dimension::Id::Z);
if (m_args->m_search_bellow>0 || m_args->m_search_above>0)
{
bool take (false);
for (PointId ptId : iNeighbors)
{
double Zpt = refView->point(ptId).getFieldAs<double>(Dimension::Id::Z);
if (m_args->m_search_bellow>0 && Zpt>Zref && (Zpt-Zref)<m_args->m_search_bellow) {take=true; break;}
if (m_args->m_search_above>0 && Zpt<Zref && (Zref-Zpt)<m_args->m_search_above) {take=true; break;}
}
if (!take) return;
}
}

m_args->m_ptsToUpdate.push_back(point.pointId());
}

Expand Down
1 change: 1 addition & 0 deletions src/filter_radius_search/radius_searchFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PDAL_DLL RadiusSearchFilter : public Filter
Dimension::Id m_dim;
bool search3d;
Dimension::Id m_dim_ref, m_dim_src;
double m_search_bellow, m_search_above;
};
std::unique_ptr<RadiusSearchArgs> m_args;
PointViewPtr refView;
Expand Down
23 changes: 21 additions & 2 deletions test/test_radius_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def distance3d(pt1, pt2):
nb_points = randint(10, 20)
nb_points_take_2d = 0
nb_points_take_3d = 0
nb_points_take_2d_above_bellow = 0

for i in range(nb_points):
pti_x = pt_x + rand.uniform(-1.5, 1.5)
Expand All @@ -51,6 +52,10 @@ def distance3d(pt1, pt2):

if distance_i_2d < distance_radius:
nb_points_take_2d += 1
if pti_z>pt_z and pti_z-pt_z>0.5:
nb_points_take_2d_above_bellow += 1
if pti_z<pt_z and pt_z-pti_z>0.5:
nb_points_take_2d_above_bellow += 1
if distance_i_3d < distance_radius:
nb_points_take_3d += 1

Expand Down Expand Up @@ -86,7 +91,17 @@ def distance3d(pt1, pt2):
"src_domain": "SRS_DOMAIN",
"reference_domain": "REF_DOMAIN",
"output_name_attribute": "radius_2D",
"3d_search":False
"3d_search":False,
},
{
"type": filter,
"radius": "1.",
"src_domain": "SRS_DOMAIN",
"reference_domain": "REF_DOMAIN",
"output_name_attribute": "radius_2D_above_bellow",
"3d_search": False,
"2d_search_above": 0.5,
"2d_search_bellow": 0.5,
},
{
"type": filter,
Expand All @@ -107,11 +122,15 @@ def distance3d(pt1, pt2):

nb_pts_radius_2d = 0
nb_pts_radius_3d = 0
nb_pts_radius_2d_above_bellow = 0
for pt in array:
if pt["radius_2D_above_bellow"] > 0:
nb_pts_radius_2d_above_bellow += 1
if pt["radius_2D"] > 0:
nb_pts_radius_2d += 1
if pt["radius_3D"] > 0:
nb_pts_radius_3d += 1

assert nb_pts_radius_2d == nb_points_take_2d
assert nb_pts_radius_3d == nb_points_take_3d
assert nb_pts_radius_3d == nb_points_take_3d
assert nb_pts_radius_2d_above_bellow == nb_points_take_2d_above_bellow

0 comments on commit 4c22409

Please sign in to comment.