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

add search radius plugin #1

Merged
merged 52 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
608d380
add search radius plugin
alavenant Feb 14, 2024
4c22409
Add possibility to restrict the cylinder with 2D serach
alavenant Mar 26, 2024
518e9bf
fix test
alavenant Mar 27, 2024
7e77169
why this break ?!!
alavenant Apr 10, 2024
92cef3f
fix find cell
alavenant Apr 11, 2024
1fa4fbc
change name of attribute
alavenant Apr 12, 2024
06ef550
add pdal pipeline examples
alavenant Apr 12, 2024
83bf42c
update test
alavenant Apr 23, 2024
989e744
update DockerFile
alavenant Apr 24, 2024
285fbcc
add pip to environment.yml
alavenant May 15, 2024
dd551ed
Update macro/ex_filtering_points.py
alavenant May 15, 2024
ecd1193
Update src/filter_radius_search/radius_searchFilter.cpp
alavenant May 15, 2024
efe8f43
update exemple
alavenant May 15, 2024
f4e40b4
no more shapely + fix test
alavenant May 17, 2024
24f417f
add pre-commit
alavenant May 17, 2024
a08751a
Merge branch 'add_radius_search' of github.com:IGNF/pdal_ign_plugin i…
alavenant May 17, 2024
c3b3459
update test : 3 tests indeed one
alavenant May 17, 2024
0c27b5d
update test_radius_search
alavenant May 17, 2024
e1d024c
add test to grid_decimation
alavenant May 17, 2024
56ed739
Update doc/grid_radius_search.md
alavenant May 17, 2024
ebfbd47
filter search => assign
alavenant May 17, 2024
c72234c
Merge branch 'add_radius_search' of github.com:IGNF/pdal_ign_plugin i…
alavenant May 17, 2024
2d2b3f1
update name attribute
alavenant May 17, 2024
bc35369
update class name
alavenant May 17, 2024
20cac64
update name attribute
alavenant May 17, 2024
6f2a07b
fix equality
alavenant May 17, 2024
a2cf0be
fix : name, orthograph, ...
alavenant May 17, 2024
641dfaf
update nom attributes
alavenant May 17, 2024
c18abdb
floor => ceil
alavenant May 17, 2024
4c94f77
update macro
alavenant May 17, 2024
0559a0b
deprectated grid_decimation
alavenant May 17, 2024
cecf78e
fix test
alavenant May 17, 2024
9ed4361
fix doc
alavenant May 17, 2024
986a208
update readme
alavenant May 21, 2024
fef4da0
fix readme
alavenant May 21, 2024
c436a0c
add comment to example + try to recode example
alavenant May 22, 2024
55da6b1
V.0 script example
alavenant May 24, 2024
179b90b
update macro orthogaph
alavenant May 29, 2024
b217324
fix script orthograph
alavenant May 29, 2024
43bba12
maj nom attributs
alavenant May 29, 2024
a606882
fix doc code
alavenant May 29, 2024
8ff93f0
fix test
alavenant May 29, 2024
213c7b1
fix test
alavenant May 29, 2024
38d8bc7
Update doc/radius_assign.md
alavenant May 29, 2024
6bd89a5
fix doc + rename file
alavenant May 29, 2024
7c73b07
Merge branches 'add_radius_search' and 'add_radius_search' of github.…
alavenant May 29, 2024
030654a
gridDecimation : modification du type de sortie
alavenant May 29, 2024
fb77f91
update example
alavenant May 29, 2024
93457e9
example - fix write gdal
alavenant May 29, 2024
623a47c
grid_decimation to deprecated
alavenant May 30, 2024
2bdc54c
attribut => dimension
alavenant May 30, 2024
0c7c772
update docker
alavenant May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
xcode
install
__pycache__
test/__pycache__
test/__pycache_
test/.idea
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required( VERSION 3.5 )
project(MY_READER LANGUAGES CXX)

set(CMAKE_PREFIX_PATH ${CONDA_PREFIX})
set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed")

find_package(PDAL REQUIRED)

Expand All @@ -11,4 +12,5 @@ set(CMAKE_DEBUG_POSTFIX d)

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

5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y cmake make buil

COPY src src
COPY CMakeLists.txt CMakeLists.txt
COPY macro macro

RUN cmake -G"Unix Makefiles" -DCONDA_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release
RUN make -j4 install
Expand All @@ -17,7 +18,9 @@ FROM debian:bullseye-slim

COPY --from=build /opt/conda/envs/pdal_ign_plugin /opt/conda/envs/pdal_ign_plugin
COPY --from=build /tmp/install/lib /tmp/install/lib

COPY --from=build /tmp/macro /macro

ENV PATH=$PATH:/opt/conda/envs/pdal_ign_plugin/bin/
ENV PROJ_LIB=/opt/conda/envs/pdal_ign_plugin/share/proj/
ENV PDAL_DRIVER_PATH=/tmp/install/lib

1 change: 1 addition & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fi
conda activate pdal_ign_plugin

export CONDA_PREFIX=$CONDA_PREFIX
echo conda is $CONDA_PREFIX

mkdir build
cd build
Expand Down
51 changes: 51 additions & 0 deletions doc/grid_radius_search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# filter grid decimation

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.


Example
---------------------------------------------------------------------------------------------------------

This pipeline updates the Keypoint dimension of all points with classification 1 to 2 (unclassified and ground) that are closer than 1 meter from a point with classification 6 (building)


```
[
"file-input.las",
{
"type" : "filters.radiussearch",
"src_domain" : "Classification[1:2]",
"reference_domain" : "Classification[6:6]",
"radius" : 1,
"output_name_attribut": "radius"
},
"output.las"
]
```

Options
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

**src_domain** :
alavenant marked this conversation as resolved.
Show resolved Hide resolved
A :ref:`range <ranges>` which selects points to be processed by the filter. Can be specified multiple times. Points satisfying any range will be processed

**reference_domain** :
A :ref:`range <ranges>` which selects points that can are considered as potential neighbors. Can be specified multiple times.

**radius** :
An positive float which specifies the radius for the neighbors search.

**update_expression** :
A list of :ref:`assignment expressions <Assignment Expressions>` to be applied to the points that satisfy the radius search. The list of values is evaluated in order.

**output_name_attribut**: The name of the new attribut. [Default: radius]
alavenant marked this conversation as resolved.
Show resolved Hide resolved

**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.]

3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: pdal_ign_plugin
channels:
- conda-forge
- anaconda
dependencies:
- pdal
- python-pdal
- pytest
- black
- isort
- shapely
- gdal
- cmake
alavenant marked this conversation as resolved.
Show resolved Hide resolved
- pip:
- ign-pdal-tools

Expand Down
Empty file added macro/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions macro/ex_filtering_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import argparse
import pdal
from macro import *
alavenant marked this conversation as resolved.
Show resolved Hide resolved

"""
This tool shows how to use functions of macro in a pdal pipeline
"""

def parse_args():
parser = argparse.ArgumentParser("Tools for apply pdal pipelines")
alavenant marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument("--input", "-i", type=str, required=True, help="Input las file")
parser.add_argument("--output", "-o", type=str, required=True, help="Output las file")
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()

pipeline = pdal.Reader.las(args.input)

# step 1 a 9
pipeline = add_radius_search(pipeline, 1, False, "Classification==2", build_condition("Classification", [4,5]), "Classification=102")
pipeline = add_radius_search(pipeline, 1, False, "Classification==102", "Classification==2", "Classification=2")
pipeline = add_radius_search(pipeline, 1, False, "Classification==3", "Classification==5", "Classification=103")
pipeline = add_grid_decimation(pipeline, 0.75, "max", 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 = add_grid_decimation(pipeline, 0.5, "max", "Classification==2", "Classification=102")
pipeline = add_grid_decimation(pipeline, 0.5, "max", build_condition("Classification", [2,3,4,5,6,9,17,64,100]), "Classification=200")
pipeline = add_radius_search(pipeline, 1.5, False, "Classification==102", 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 = add_radius_search(pipeline, 1.5, False, "Classification==2", "Classification==17", "Classification=102")
pipeline = add_radius_search(pipeline, 1.5, False, "Classification==102", build_condition("Classification", [2,3,4,5]), "Classification=2")

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

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

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

# step 14
pipeline = add_radius_search(pipeline, 1.5, False, "Classification==9", "Classification==17", "Classification=109")
pipeline = add_radius_search(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()

81 changes: 81 additions & 0 deletions macro/macro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import argparse
import pdal

"""
Some useful filters combinations for complete pdal pipeline
"""


def add_radius_search(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
radius : the search distance
search_3d : the distance reseach is in 3d if True
condition_src, condition_ref, condition_out : a pdal condition as "Classification==2"
"""
pipeline |= pdal.Filter.ferry(dimensions=f"=>REF_DOMAIN, =>SRS_DOMAIN, =>radius_search")
alavenant marked this conversation as resolved.
Show resolved Hide resolved
pipeline |= pdal.Filter.assign(value=["SRS_DOMAIN = 0", f"SRS_DOMAIN = 1 WHERE {condition_src}",
alavenant marked this conversation as resolved.
Show resolved Hide resolved
"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",
output_name_attribute="radius_search", search_3d=search_3d)
pipeline |= pdal.Filter.assign(value=condition_out,where="radius_search==1")
return pipeline



def add_grid_decimation(pipeline, grid_resolution, output_type, condition, condition_out):
"""
Select a points in a grid from "condition"; points not selected are reassign to "condition_out"
This combination is equivalent to the Thin Points macro of TerraScan
grid_resolution : resolution of the grid
output_type : "max" or "min" (the highest or lower points of the grid)
condition, condition_out : a pdal condition as "Classification==2"
"""
pipeline |= pdal.Filter.ferry(dimensions=f"=>grid,")
pipeline |= pdal.Filter.assign(value="grid = 0")
pipeline |= pdal.Filter.grid_decimation(resolution=grid_resolution, output_name_attribut="grid",
alavenant marked this conversation as resolved.
Show resolved Hide resolved
output_type=output_type, where=condition)
pipeline |= pdal.Filter.assign(value=condition_out,where=f"grid==0 && ({condition})")
return pipeline



def classify_hgt_ground(pipeline, hmin, hmax, condition, condition_out):
"""
reassign points from "condition" between "hmin" and "hmax" of the ground to "condition_out"
This combination is equivalent to the ClassifyHgtGrd macro of TerraScan
condition, condition_out : a pdal condition as "Classification==2"
"""
pipeline |= pdal.Filter.hag_delaunay(allow_extrapolation=True)
condition_h = f"HeightAboveGround>{hmin} && HeightAboveGround<={hmax}"
condition_h += " && " + condition
pipeline |= pdal.Filter.assign(value=condition_out, where=condition_h)
return pipeline



def keep_non_planar_pts(pipeline, condition, condition_out):
"""
reassign points from "condition" who are planar to "condition_out"
This combination is equivalent to the ClassifyModelKey macro of TerraScan
condition, condition_out : a pdal condition as "Classification==2"
"""
pipeline |= pdal.Filter.approximatecoplanar(knn=8,thresh1=25,thresh2=6,where=condition)
pipeline |= pdal.Filter.assign(value=condition_out,where=f"Coplanar==0 && ({condition})")
return pipeline




def build_condition(key, values):
"""
build 'key==values[0] || key==values[1] ...'
"""
condition = ""
for v in values:
condition += key+"=="+str(v)
if v!=values[-1]:condition += " || "
return condition

6 changes: 3 additions & 3 deletions src/filter_grid_decimation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

file( GLOB_RECURSE GD_SRCS ${CMAKE_SOURCE_DIR} *)

message("GD_SRCS ${GD_SRCS}")
file( GLOB_RECURSE GD_SRCS
${CMAKE_SOURCE_DIR}/src/filter_grid_decimation/*.hpp
${CMAKE_SOURCE_DIR}/src/filter_grid_decimation/*.cpp)

PDAL_CREATE_PLUGIN(
TYPE filter
Expand Down
6 changes: 3 additions & 3 deletions src/filter_grid_decimation/grid_decimationFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void GridDecimationFilter::addArgs(ProgramArgs& args)
{
args.add("resolution", "Cell edge size, in units of X/Y",m_args->m_edgeLength, 1.);
args.add("output_type", "Point keept into the cells ('min', 'max')", m_args->m_methodKeep, "max" );
args.add("output_name_attribut", "Name of the add attribut", m_args->m_nameAddAttribut, "grid" );
args.add("output_name_attribut", "Name of the added attribut", m_args->m_nameAddAttribut, "grid" );
args.add("output_wkt", "Export the grid as wkt", m_args->m_nameWktgrid, "" );

}
Expand Down Expand Up @@ -81,8 +81,8 @@ void GridDecimationFilter::processOne(BOX2D bounds, PointRef& point, PointViewPt
double y = point.getFieldAs<double>(Dimension::Id::Y);
int id = point.getFieldAs<double>(Dimension::Id::PointId);

double d_width_pt = std::floor((x - bounds.minx) / m_args->m_edgeLength) + 1;
alavenant marked this conversation as resolved.
Show resolved Hide resolved
double d_height_pt = std::floor((y - bounds.miny) / m_args->m_edgeLength) + 1;
double d_width_pt = std::floor((x - bounds.minx) / m_args->m_edgeLength);
double d_height_pt = std::floor((y - bounds.miny) / m_args->m_edgeLength);

int width = static_cast<int>(d_width_pt);
int height = static_cast<int>(d_height_pt);
Expand Down
16 changes: 16 additions & 0 deletions src/filter_radius_search/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_search/*.hpp
${CMAKE_SOURCE_DIR}/src/filter_radius_search/*.cpp)

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

install(TARGETS
pdal_plugin_filter_radius_search
)

Loading
Loading