[GRASS-SVN] r68297 - grass/trunk/raster3d/r3.in.lidar
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 21 08:18:23 PDT 2016
Author: wenzeslaus
Date: 2016-04-21 08:18:23 -0700 (Thu, 21 Apr 2016)
New Revision: 68297
Added:
grass/trunk/raster3d/r3.in.lidar/filters.c
grass/trunk/raster3d/r3.in.lidar/filters.h
Modified:
grass/trunk/raster3d/r3.in.lidar/main.c
Log:
r3.in.lidar: filter points by class or return (using v.in.pdal code from r67436)
Copied: grass/trunk/raster3d/r3.in.lidar/filters.c (from rev 68277, grass/trunk/vector/v.in.pdal/filters.c)
===================================================================
--- grass/trunk/raster3d/r3.in.lidar/filters.c (rev 0)
+++ grass/trunk/raster3d/r3.in.lidar/filters.c 2016-04-21 15:18:23 UTC (rev 68297)
@@ -0,0 +1,96 @@
+/*
+ * v.in.lidar filtering functions
+ *
+ * Copyright 2011-2015 by Markus Metz, and The GRASS Development Team
+ * Authors:
+ * Markus Metz (r.in.lidar)
+ * Vaclav Petras (move code to a separate files)
+ *
+ * This program is free software licensed under the GPL (>=v2).
+ * Read the COPYING file that comes with GRASS for details.
+ *
+ */
+
+
+#include "filters.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+
+int return_filter_create_from_string(struct ReturnFilter *return_filter,
+ const char *name)
+{
+ return_filter->filter = LAS_ALL;
+ if (name) {
+ if (strcmp(name, "first") == 0)
+ return_filter->filter = LAS_FIRST;
+ else if (strcmp(name, "last") == 0)
+ return_filter->filter = LAS_LAST;
+ else if (strcmp(name, "mid") == 0)
+ return_filter->filter = LAS_MID;
+ else
+ G_fatal_error(_("Unknown return filter value <%s>"), name);
+ }
+ if (return_filter->filter == LAS_ALL)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+int return_filter_is_out(struct ReturnFilter *return_filter, int return_n,
+ int n_returns)
+{
+ if (return_filter->filter == LAS_ALL)
+ return FALSE;
+ int skipme = 1;
+
+ switch (return_filter->filter) {
+ case LAS_FIRST:
+ if (return_n == 1)
+ skipme = 0;
+ break;
+ case LAS_MID:
+ if (return_n > 1 && return_n < n_returns)
+ skipme = 0;
+ break;
+ case LAS_LAST:
+ if (n_returns > 1 && return_n == n_returns)
+ skipme = 0;
+ break;
+ }
+ if (skipme)
+ return TRUE;
+ return FALSE;
+}
+
+int class_filter_create_from_strings(struct ClassFilter *class_filter,
+ char **classes)
+{
+ class_filter->str_classes = classes;
+ if (classes)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+int class_filter_is_out(struct ClassFilter *class_filter, int class_n)
+{
+ if (!class_filter->str_classes)
+ return FALSE;
+ int i = 0;
+ int skipme = TRUE;
+
+ while (class_filter->str_classes[i]) {
+ if (class_n == atoi(class_filter->str_classes[i])) {
+ skipme = FALSE;
+ break;
+ }
+ i++;
+ }
+ if (skipme)
+ return TRUE;
+ return FALSE;
+}
Copied: grass/trunk/raster3d/r3.in.lidar/filters.h (from rev 68277, grass/trunk/vector/v.in.pdal/filters.h)
===================================================================
--- grass/trunk/raster3d/r3.in.lidar/filters.h (rev 0)
+++ grass/trunk/raster3d/r3.in.lidar/filters.h 2016-04-21 15:18:23 UTC (rev 68297)
@@ -0,0 +1,52 @@
+/*
+ * v.in.lidar filtering functions
+ *
+ * Copyright 2011-2015 by Markus Metz, and The GRASS Development Team
+ * Authors:
+ * Markus Metz (r.in.lidar)
+ * Vaclav Petras (move code to a separate files)
+ *
+ * This program is free software licensed under the GPL (>=v2).
+ * Read the COPYING file that comes with GRASS for details.
+ *
+ */
+
+#ifndef __FILTERS_H__
+#define __FILTERS_H__
+
+#define LAS_ALL 0
+#define LAS_FIRST 1
+#define LAS_LAST 2
+#define LAS_MID 3
+
+struct ReturnFilter
+{
+ int filter;
+};
+
+struct ClassFilter
+{
+
+ /** NULL terminated list of class numbers represented as string */
+ char **str_classes;
+};
+
+struct Option;
+
+int spatial_filter_from_option(struct Option *option, double *xmin,
+ double *ymin, double *xmax, double *ymax);
+int spatial_filter_from_current_region(double *xmin, double *ymin,
+ double *xmax, double *ymax);
+
+int zrange_filter_from_option(struct Option *option,
+ double *zmin, double *zmax);
+
+int return_filter_create_from_string(struct ReturnFilter *return_filter,
+ const char *name);
+int return_filter_is_out(struct ReturnFilter *return_filter, int return_n,
+ int n_returns);
+int class_filter_create_from_strings(struct ClassFilter *class_filter,
+ char **classes);
+int class_filter_is_out(struct ClassFilter *class_filter, int class_n);
+
+#endif /* __FILTERS_H__ */
Modified: grass/trunk/raster3d/r3.in.lidar/main.c
===================================================================
--- grass/trunk/raster3d/r3.in.lidar/main.c 2016-04-21 15:05:31 UTC (rev 68296)
+++ grass/trunk/raster3d/r3.in.lidar/main.c 2016-04-21 15:18:23 UTC (rev 68297)
@@ -23,6 +23,7 @@
#include <liblas/capi/liblas.h>
#include "rast_segment.h"
+#include "filters.h"
struct PointBinning3D
{
@@ -114,6 +115,7 @@
struct Option *input_opt;
struct Option *count_output_opt, *sum_output_opt, *mean_output_opt;
struct Option *prop_count_output_opt, *prop_sum_output_opt;
+ struct Option *filter_opt, *class_opt;
struct Option *base_raster_opt;
struct Flag *base_rast_res_flag;
@@ -170,6 +172,25 @@
" vertical column");
prop_sum_output_opt->guisection = _("Proportional output");
+ filter_opt = G_define_option();
+ filter_opt->key = "return_filter";
+ filter_opt->type = TYPE_STRING;
+ filter_opt->required = NO;
+ filter_opt->label = _("Only import points of selected return type");
+ filter_opt->description = _("If not specified, all points are imported");
+ filter_opt->options = "first,last,mid";
+ filter_opt->guisection = _("Selection");
+
+ class_opt = G_define_option();
+ class_opt->key = "class_filter";
+ class_opt->type = TYPE_INTEGER;
+ class_opt->multiple = YES;
+ class_opt->required = NO;
+ class_opt->label = _("Only import points of selected class(es)");
+ class_opt->description = _("Input is comma separated integers. "
+ "If not specified, all points are imported.");
+ class_opt->guisection = _("Selection");
+
base_raster_opt = G_define_standard_option(G_OPT_R_INPUT);
base_raster_opt->key = "base_raster";
base_raster_opt->required = NO;
@@ -198,6 +219,14 @@
Rast3d_init_defaults();
Rast3d_set_error_fun(Rast3d_fatal_error_noargs);
+ struct ReturnFilter return_filter_struct;
+ int use_return_filter =
+ return_filter_create_from_string(&return_filter_struct,
+ filter_opt->answer);
+ struct ClassFilter class_filter;
+ int use_class_filter =
+ class_filter_create_from_strings(&class_filter, class_opt->answers);
+
/* TODO: rename */
struct Cell_head input_region;
SEGMENT base_segment;
@@ -295,11 +324,29 @@
long unsigned inside = 0;
long unsigned outside = 0;
long unsigned in_nulls = 0; /* or outside */
+ long unsigned n_return_filtered = 0;
+ long unsigned n_class_filtered = 0;
while ((LAS_point = LASReader_GetNextPoint(LAS_reader)) != NULL) {
if (!LASPoint_IsValid(LAS_point))
continue;
+ if (use_return_filter) {
+ int return_n = LASPoint_GetReturnNumber(LAS_point);
+ int n_returns = LASPoint_GetNumberOfReturns(LAS_point);
+ if (return_filter_is_out(&return_filter_struct, return_n, n_returns)) {
+ n_return_filtered++;
+ continue;
+ }
+ }
+ if (use_class_filter) {
+ int point_class = (int) LASPoint_GetClassification(LAS_point);
+ if (class_filter_is_out(&class_filter, point_class)) {
+ n_class_filtered++;
+ continue;
+ }
+ }
+
east = LASPoint_GetX(LAS_point);
north = LASPoint_GetY(LAS_point);
top = LASPoint_GetZ(LAS_point);
@@ -344,8 +391,11 @@
outside + in_nulls);
else
G_message("Number of points outside: %lu", outside);
+ if (n_return_filtered)
+ G_message(_("%lu input points were filtered out by return number"), n_return_filtered);
+ if (n_class_filtered)
+ G_message(_("%lu input points were filtered out by class number"), n_class_filtered);
-
Rast3d_close(binning.prop_sum_raster);
Rast3d_close(binning.prop_count_raster);
Rast3d_close(binning.sum_flat_raster); /* TODO: delete */
More information about the grass-commit
mailing list