diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33b1f06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +./xcode +./install +__pycache__ +./test/__pycache__ diff --git a/ci/launch_test.sh b/ci/launch_test.sh new file mode 100755 index 0000000..248bd27 --- /dev/null +++ b/ci/launch_test.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +FILE=~/anaconda3/etc/profile.d/conda.sh +if [ -e ~/anaconda3/etc/profile.d/conda.sh ] +then + source ~/anaconda3/etc/profile.d/conda.sh +elif [ -e ~/miniconda3/etc/profile.d/conda.sh ] +then + source ~/miniconda3/etc/profile.d/conda.sh +elif [ -e ~/miniforge3/etc/profile.d/conda.sh ] +then + source ~/miniforge3/etc/profile.d/conda.sh +elif [[ -z "${CONDASH}" ]]; then + echo ERROR: Failed to load conda.sh : ~/anaconda3/etc/profile.d/conda.sh or ~/miniforge3/etc/profile.d/conda.sh or env CONDASH + exit 1 # terminate and indicate error +else + echo DEBUG "$FILE does not exist, using env CONDASH." + source $CONDASH +fi + +conda activate pdal_ign_plugin + +export PDAL_DRIVER_PATH=./install/lib +echo $PDAL_DRIVER_PATH + +python -m pytest + +conda deactivate \ No newline at end of file diff --git a/environment.yml b/environment.yml index 3fa069b..fdc1eaf 100755 --- a/environment.yml +++ b/environment.yml @@ -5,7 +5,10 @@ dependencies: - pdal - python-pdal - pytest - - pytest-dependency - black - isort + - shapely + - pip: + - ign-pdal-tools + diff --git a/src/filter_grid_decimation/grid_decimationFilter.cpp b/src/filter_grid_decimation/grid_decimationFilter.cpp index 6d7849a..30ded38 100755 --- a/src/filter_grid_decimation/grid_decimationFilter.cpp +++ b/src/filter_grid_decimation/grid_decimationFilter.cpp @@ -10,8 +10,6 @@ #include #include -#include - #include #include @@ -25,7 +23,7 @@ static StaticPluginInfo const s_info "", }; -CREATE_STATIC_STAGE(GridDecimationFilter, s_info) +CREATE_SHARED_STAGE(GridDecimationFilter, s_info) std::string GridDecimationFilter::getName() const { return s_info.name; } @@ -42,6 +40,8 @@ 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_wkt", "Export the grid as wkt", m_args->m_nameWktgrid, "" ); + } void GridDecimationFilter::initialize() @@ -116,9 +116,24 @@ void GridDecimationFilter::createGrid(BOX2D bounds) int width = static_cast(d_width); int height = static_cast(d_height); - for (size_t l(0); l vgrid; + + for (size_t l(0); lm_edgeLength, bounds.miny + l*m_args->m_edgeLength, + bounds.minx + (c+1)*m_args->m_edgeLength, bounds.miny + (l+1)*m_args->m_edgeLength ); + vgrid.push_back(Polygon(bounds_dalle)); this->grid.insert( std::make_pair( std::make_pair(c,l), -1) ); + } + + if (!m_args->m_nameWktgrid.empty()) + { + std::ofstream oss (m_args->m_nameWktgrid); + for (auto pol : vgrid) + oss << pol.wkt() << std::endl; + } + } PointViewSet GridDecimationFilter::run(PointViewPtr view) @@ -126,7 +141,7 @@ PointViewSet GridDecimationFilter::run(PointViewPtr view) BOX2D bounds; view->calculateBounds(bounds); createGrid(bounds); - + for (PointId i = 0; i < view->size(); ++i) { PointRef point = view->point(i); diff --git a/src/filter_grid_decimation/grid_decimationFilter.hpp b/src/filter_grid_decimation/grid_decimationFilter.hpp index 1f95fe2..781d8eb 100755 --- a/src/filter_grid_decimation/grid_decimationFilter.hpp +++ b/src/filter_grid_decimation/grid_decimationFilter.hpp @@ -33,6 +33,7 @@ class PDAL_DLL GridDecimationFilter : public Filter std::string m_methodKeep; // type of output (min, max) double m_edgeLength; // lenght of grid std::string m_nameAddAttribut; // name of the new attribut + std::string m_nameWktgrid; // export wkt grid Dimension::Id m_dim; }; diff --git a/test/test_grid_decimation.py b/test/test_grid_decimation.py index 7b64d43..9491d5a 100755 --- a/test/test_grid_decimation.py +++ b/test/test_grid_decimation.py @@ -1,34 +1,48 @@ -import pytest +import csv import json -import pdal +import math import os import tempfile - from test import utils +import pdal +import pdaltools.las_info as li +import pytest +import shapely + + def test_grid_decimation(): + ini_las = "test/data/4_6.las" + resolution = 10 - tmp_out_las = tempfile.NamedTemporaryFile(suffix='.las').name + tmp_out_las = tempfile.NamedTemporaryFile(suffix=".las").name + tmp_out_wkt = tempfile.NamedTemporaryFile(suffix=".wkt").name - filter = 'filters.grid_decimation' + filter = "filters.grid_decimation" utils.pdal_has_plugin(filter) + bounds = li.las_get_xy_bounds(ini_las) + + d_width = math.floor((bounds[0][1] - bounds[0][0]) / resolution) + 1 + d_height = math.floor((bounds[1][1] - bounds[1][0]) / resolution) + 1 + nb_dalle = d_width * d_height + print("size of the grid", nb_dalle) + PIPELINE = [ + {"type": "readers.las", "filename": ini_las}, { - "type":"readers.las", - "filename":"test/data/4_6.las" + "type": filter, + "resolution": resolution, + "output_type": "max", + "output_name_attribut": "grid", + "output_wkt": tmp_out_wkt, }, { - "type":filter, - "resolution":1, - "output_type":"max", - "output_name_attribut":"grid" + "type": "writers.las", + "extra_dims": "all", + "filename": tmp_out_las, + "where": "grid==1", }, - { - "type":"writers.las", - "extra_dims":"all", - "filename":tmp_out_las - } ] pipeline = pdal.Pipeline(json.dumps(PIPELINE)) @@ -36,10 +50,20 @@ def test_grid_decimation(): # execute the pipeline pipeline.execute() arrays = pipeline.arrays + array = arrays[0] + + nb_pts_grid = 0 + for pt in array: + if pt["grid"] > 0: + nb_pts_grid += 1 + + assert nb_pts_grid == 3196 + assert nb_pts_grid <= nb_dalle - NbPtsGrid = 0 - for pt in arrays: - if pt[grid] > 0: - NbPtsGrid += 1 + data = [] + with open(tmp_out_wkt, "r") as f: + reader = csv.reader(f, delimiter="\t") + for i, line in enumerate(reader): + data.append(line[0]) - assert nbThreadPts == 65067 \ No newline at end of file + assert len(data) == nb_dalle diff --git a/test/utils.py b/test/utils.py index 89b9c75..71334cc 100755 --- a/test/utils.py +++ b/test/utils.py @@ -1,10 +1,11 @@ -import pdal import os import subprocess +import pdal + + def pdal_has_plugin(name_filter): - os.environ["PDAL_DRIVER_PATH"] = os.path.abspath('./install/lib') print("init pdal driver : ", os.environ["PDAL_DRIVER_PATH"]) - result = subprocess.run(['pdal', '--drivers'], stdout=subprocess.PIPE) - if name_filter not in result.stdout.decode('utf-8'): + result = subprocess.run(["pdal", "--drivers"], stdout=subprocess.PIPE) + if name_filter not in result.stdout.decode("utf-8"): raise ValueError("le script " + name_filter + " n'est pas visible") diff --git a/test/version.py b/test/version.py index dc9f20a..bb4f2a7 100755 --- a/test/version.py +++ b/test/version.py @@ -2,4 +2,4 @@ if __name__ == "__main__": - print(__version__) \ No newline at end of file + print(__version__)