[GRASS-SVN] r66596 - grass/trunk/raster/r.in.lidar

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 24 20:55:49 PDT 2015


Author: wenzeslaus
Date: 2015-10-24 20:55:49 -0700 (Sat, 24 Oct 2015)
New Revision: 66596

Added:
   grass/trunk/raster/r.in.lidar/filters.c
   grass/trunk/raster/r.in.lidar/filters.h
Modified:
   grass/trunk/raster/r.in.lidar/local_proto.h
   grass/trunk/raster/r.in.lidar/main.c
Log:
r.in.lidar: separate class and return filters

Added: grass/trunk/raster/r.in.lidar/filters.c
===================================================================
--- grass/trunk/raster/r.in.lidar/filters.c	                        (rev 0)
+++ grass/trunk/raster/r.in.lidar/filters.c	2015-10-25 03:55:49 UTC (rev 66596)
@@ -0,0 +1,70 @@
+/*
+ * r.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 "local_proto.h"
+#include "filters.h"
+
+#include <stdlib.h>
+#include <grass/gis.h>
+
+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;
+}
+
+void class_filter_create_from_strings(struct ClassFilter *class_filter,
+                                      char **classes)
+{
+    class_filter->str_classes = classes;
+}
+
+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;
+}


Property changes on: grass/trunk/raster/r.in.lidar/filters.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Added: grass/trunk/raster/r.in.lidar/filters.h
===================================================================
--- grass/trunk/raster/r.in.lidar/filters.h	                        (rev 0)
+++ grass/trunk/raster/r.in.lidar/filters.h	2015-10-25 03:55:49 UTC (rev 66596)
@@ -0,0 +1,35 @@
+/*
+ * r.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__
+
+struct ReturnFilter
+{
+    int filter;
+};
+
+struct ClassFilter
+{
+
+    /** NULL terminated list of class numbers represented as string */
+    char **str_classes;
+};
+
+int return_filter_is_out(struct ReturnFilter *return_filter, int return_n,
+                         int n_returns);
+void 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__ */


Property changes on: grass/trunk/raster/r.in.lidar/filters.h
___________________________________________________________________
Added: svn:mime-type
   + text/x-chdr
Added: svn:eol-style
   + native

Modified: grass/trunk/raster/r.in.lidar/local_proto.h
===================================================================
--- grass/trunk/raster/r.in.lidar/local_proto.h	2015-10-25 03:42:35 UTC (rev 66595)
+++ grass/trunk/raster/r.in.lidar/local_proto.h	2015-10-25 03:55:49 UTC (rev 66596)
@@ -41,6 +41,12 @@
 #define METHOD_SKEWNESS   12
 #define METHOD_TRIMMEAN   13
 
+#define LAS_ALL 0
+#define LAS_FIRST 1
+#define LAS_LAST 2
+#define LAS_MID 3
+
+
 /* info.c */
 void print_lasinfo(LASHeaderH, LASSRSH);
 int scan_bounds(LASReaderH, int, int, double, struct Cell_head *);

Modified: grass/trunk/raster/r.in.lidar/main.c
===================================================================
--- grass/trunk/raster/r.in.lidar/main.c	2015-10-25 03:42:35 UTC (rev 66595)
+++ grass/trunk/raster/r.in.lidar/main.c	2015-10-25 03:55:49 UTC (rev 66596)
@@ -33,11 +33,8 @@
 #include "local_proto.h"
 #include "rast_segment.h"
 #include "point_binning.h"
+#include "filters.h"
 
-#define LAS_ALL 0
-#define LAS_FIRST 1
-#define LAS_LAST 2
-#define LAS_MID 3
 
 int main(int argc, char *argv[])
 {
@@ -67,7 +64,6 @@
     double pass_north, pass_south;
     int arr_row, arr_col;
     unsigned long count, count_total;
-    int skipme, i;
     int point_class;
 
     double zscale = 1.0;
@@ -298,6 +294,10 @@
 	else
 	    G_fatal_error(_("Unknown filter option <%s>"), filter_opt->answer);
     }
+    struct ReturnFilter return_filter_struct;
+    return_filter_struct.filter = return_filter;
+    struct ClassFilter class_filter;
+    class_filter_create_from_strings(&class_filter, class_opt->answers);
 
     /* Fetch input map projection in GRASS form. */
     projstr = LASSRS_GetWKT_CompoundOK(LAS_srs);
@@ -498,47 +498,16 @@
 	    else
 		z = LASPoint_GetZ(LAS_point);
 
-	if (return_filter != LAS_ALL) {
-	    int return_no = LASPoint_GetReturnNumber(LAS_point);
-	    int n_returns = LASPoint_GetNumberOfReturns(LAS_point);
-	    skipme = 1;
+        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_filtered++;
+            continue;
+        }
+        point_class = (int) LASPoint_GetClassification(LAS_point);
+        if (class_filter_is_out(&class_filter, point_class))
+            continue;
 
-	    switch (return_filter) {
-	    case LAS_FIRST:
-		if (return_no == 1)
-		    skipme = 0;
-		break;
-	    case LAS_MID:
-		if (return_no > 1 && return_no < n_returns)
-		    skipme = 0;
-		break;
-	    case LAS_LAST:
-		if (n_returns > 1 && return_no == n_returns)
-		    skipme = 0;
-		break;
-	    }
-
-	    if (skipme) {
-		n_filtered++;
-		continue;
-	    }
-	}
-	if (class_opt->answer) {
-	    point_class = (int) LASPoint_GetClassification(LAS_point);
-	    i = 0;
-	    skipme = TRUE;
-	    while (class_opt->answers[i]) {
-		if (point_class == atoi(class_opt->answers[i])) {
-		    skipme = FALSE;
-		    break;
-		}
-		i++;
-	    }
-	    if (skipme) {
-		continue;
-	    }
-	}
-
 	    if (y <= pass_south || y > pass_north) {
 		continue;
 	    }



More information about the grass-commit mailing list