Skip to content

Commit

Permalink
filter search => assign
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed May 17, 2024
1 parent e1d024c commit ebfbd47
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ set(CMAKE_DEBUG_POSTFIX d)

## add plugin
add_subdirectory(src/filter_grid_decimation)
add_subdirectory(src/filter_radius_search)
add_subdirectory(src/filter_radius_assign)

6 changes: 3 additions & 3 deletions doc/grid_radius_search.md → doc/grid_radius_assign.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# filter grid decimation
# filter radius assign

Purpose
---------------------------------------------------------------------------------------------------------

The **radius search filter** add a new attribut where the value depends on their neighbors in a given radius: For each point in the domain src_domain_, if it has any neighbor with a distance lower than radius_ that belongs to the domain reference_domain_, it is updated.
The **radius assign filter** add a new attribut where the value depends on their neighbors in a given radius: For each point in the domain src_domain_, if it has any neighbor with a distance lower than radius_ that belongs to the domain reference_domain_, it is updated.


Example
Expand All @@ -16,7 +16,7 @@ This pipeline updates the Keypoint dimension of all points with classification 1
[
"file-input.las",
{
"type" : "filters.radiussearch",
"type" : "filters.radius_assign",
"src_domain" : "Classification[1:2]",
"reference_domain" : "Classification[6:6]",
"radius" : 1,
Expand Down
28 changes: 14 additions & 14 deletions macro/ex_filtering_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ def parse_args():
pipeline = pdal.Reader.las(args.input)

# step 1 a 9
pipeline = macro.add_radius_search(pipeline, 1, False, "Classification==2", macro.build_condition("Classification", [4,5]), "Classification=102")
pipeline = macro.add_radius_search(pipeline, 1, False, "Classification==102", "Classification==2", "Classification=2")
pipeline = macro.add_radius_search(pipeline, 1, False, "Classification==3", "Classification==5", "Classification=103")
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==2", macro.build_condition("Classification", [4,5]), "Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==102", "Classification==2", "Classification=2")
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==3", "Classification==5", "Classification=103")
pipeline = macro.add_grid_decimation(pipeline, 0.75, "max", macro.build_condition("Classification", [4,5,102,103]), "Classification=100")
pipeline |= pdal.Filter.assign(value="Classification=2", where="Classification==102")
pipeline |= pdal.Filter.assign(value="Classification=3", where="Classification==103")
pipeline = macro.add_grid_decimation(pipeline, 0.5, "max", "Classification==2", "Classification=102")
pipeline = macro.add_grid_decimation(pipeline, 0.5, "max", macro.build_condition("Classification", [2,3,4,5,6,9,17,64,100]), "Classification=200")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [4,5,6,9,17,64,100]), "Classification=100")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [4,5,6,9,17,64,100]), "Classification=100")
pipeline |= pdal.Filter.assign(value="Classification=2", where="Classification==102")

# step 10
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==2", "Classification==17", "Classification=102")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [2,3,4,5]), "Classification=2")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==2", "Classification==17", "Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [2,3,4,5]), "Classification=2")

# step 11
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==3", "Classification==17", "Classification=103")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==103", macro.build_condition("Classification", [2,3,4,5]), "Classification=3")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==3", "Classification==17", "Classification=103")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==103", macro.build_condition("Classification", [2,3,4,5]), "Classification=3")

# step 12
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==4", "Classification==17", "Classification=104")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==104", macro.build_condition("Classification", [2,3,4,5]), "Classification=4")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==4", "Classification==17", "Classification=104")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==104", macro.build_condition("Classification", [2,3,4,5]), "Classification=4")

# step 13
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==5", "Classification==17", "Classification=105")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==105", macro.build_condition("Classification", [2,3,4,5]), "Classification=5")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==5", "Classification==17", "Classification=105")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==105", macro.build_condition("Classification", [2,3,4,5]), "Classification=5")

# step 14
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==9", "Classification==17", "Classification=109")
pipeline = macro.add_radius_search(pipeline, 1.5, False, "Classification==109", "Classification==9", "Classification=9")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==9", "Classification==17", "Classification=109")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==109", "Classification==9", "Classification=9")

pipeline |= pdal.Writer.las(extra_dims="all",minor_version=4,dataformat_id=6,filename=args.output)
pipeline.execute()
Expand Down
4 changes: 2 additions & 2 deletions macro/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""


def add_radius_search(pipeline, radius, search_3d, condition_src, condition_ref, condition_out ):
def add_radius_assign(pipeline, radius, search_3d, condition_src, condition_ref, condition_out ):
"""
search points from "condition_src" closed from "condition_ref", and reassign them to "condition_out"
This combination is equivalent to the CloseBy macro of TerraScan
Expand All @@ -18,7 +18,7 @@ def add_radius_search(pipeline, radius, search_3d, condition_src, condition_ref,
pipeline |= pdal.Filter.assign(value=["SRS_DOMAIN = 0", f"SRS_DOMAIN = 1 WHERE {condition_src}",
"REF_DOMAIN = 0", f"REF_DOMAIN = 1 WHERE {condition_ref}",
"radius_search = 0"])
pipeline |= pdal.Filter.radius_search(radius=radius, src_domain="SRS_DOMAIN",reference_domain="REF_DOMAIN",
pipeline |= pdal.Filter.radius_assign(radius=radius, src_domain="SRS_DOMAIN",reference_domain="REF_DOMAIN",
output_name_attribute="radius_search", search_3d=search_3d)
pipeline |= pdal.Filter.assign(value=condition_out,where="radius_search==1")
return pipeline
Expand Down
16 changes: 16 additions & 0 deletions src/filter_radius_assign/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

file( GLOB_RECURSE GD_SRCS
${CMAKE_SOURCE_DIR}/src/filter_radius_assign/*.hpp
${CMAKE_SOURCE_DIR}/src/filter_radius_assign/*.cpp)

PDAL_CREATE_PLUGIN(
TYPE filter
NAME radius_assign
VERSION 1.0
SOURCES ${GD_SRCS}
)

install(TARGETS
pdal_plugin_filter_radius_assign
)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "radius_searchFilter.hpp"
#include "radius_assignFilter.hpp"

#include <pdal/PipelineManager.hpp>
#include <pdal/StageFactory.hpp>
Expand All @@ -13,7 +13,7 @@ namespace pdal
{

static PluginInfo const s_info = PluginInfo(
"filters.radius_search",
"filters.radius_assign",
"Re-assign some point attributes based KNN voting",
"" );

Expand Down
16 changes: 0 additions & 16 deletions src/filter_radius_search/CMakeLists.txt

This file was deleted.

8 changes: 4 additions & 4 deletions test/test_radius_search.py → test/test_radius_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def distance3d(pt1, pt2):

def run_filter(arrays_las, distance_radius, search_3d, distance_cylinder=0. ):

filter = "filters.radius_search"
filter = "filters.radius_assign"
utils.pdal_has_plugin(filter)

with tempfile.NamedTemporaryFile(suffix="_las_tmp.las") as las:
Expand Down Expand Up @@ -99,7 +99,7 @@ def build_random_points_around_one_point(test_function):
return arrays_las, nb_points_take


def test_radius_search_3d():
def test_radius_assign_3d():

distance_radius = 1

Expand All @@ -114,7 +114,7 @@ def func_test(pt_ini, pt):
assert nb_pts_radius_3d == nb_points_take_3d


def test_radius_search_2d():
def test_radius_assign_2d():

distance_radius = 1

Expand All @@ -129,7 +129,7 @@ def func_test(pt_ini, pt):
assert nb_pts_radius_2d == nb_points_take_2d


def test_radius_search_2d_cylinder():
def test_radius_assign_2d_cylinder():

distance_radius = 1
distance_cylinder = 0.25
Expand Down

0 comments on commit ebfbd47

Please sign in to comment.