[GRASS-SVN] r67316 - grass/trunk/vector/v.in.lidar

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 21 18:02:07 PST 2015


Author: wenzeslaus
Date: 2015-12-21 18:02:07 -0800 (Mon, 21 Dec 2015)
New Revision: 67316

Added:
   grass/trunk/vector/v.in.lidar/count_decimation.c
   grass/trunk/vector/v.in.lidar/count_decimation.h
Modified:
   grass/trunk/vector/v.in.lidar/main.c
Log:
v.in.lidar: move out count-based decimation

Files identical with v.decimate.


Copied: grass/trunk/vector/v.in.lidar/count_decimation.c (from rev 67294, grass/trunk/vector/v.decimate/count_decimation.c)
===================================================================
--- grass/trunk/vector/v.in.lidar/count_decimation.c	                        (rev 0)
+++ grass/trunk/vector/v.in.lidar/count_decimation.c	2015-12-22 02:02:07 UTC (rev 67316)
@@ -0,0 +1,134 @@
+/****************************************************************************
+ *
+ * MODULE:       v.decimate
+ * AUTHOR(S):    Vaclav Petras
+ * PURPOSE:      Reduce the number of points in a vector map
+ * COPYRIGHT:    (C) 2015 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the COPYING file that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+
+/* TODO: change int */
+/* TODO: revise names */
+
+#include "count_decimation.h"
+
+#include <grass/gis.h>
+
+#include <stdlib.h>
+
+
+void count_decimation_init(struct CountDecimationControl *control,
+                           int *skip, int *preserve,
+                           int *offset, int *limit)
+{
+    control->skip_every = 0;
+    control->preserve_every = 0;
+    /* counter used by both but that's ok, skip and preserve are exclusive */
+    control->every_counter = 0;
+    control->n_count_filtered = 0;
+    control->offset_n = 0;
+    control->offset_n_counter = 0;
+    control->limit_n = 0;
+    control->limit_n_counter = 0;
+    if (skip)
+        control->skip_every = *skip;
+    if (preserve)
+        control->preserve_every = *preserve;
+    if (offset)
+        control->offset_n = *offset;
+    if (limit)
+        control->limit_n = *limit;
+}
+
+
+int count_decimation_is_valid(struct CountDecimationControl *control)
+{
+    if (control->skip_every == 1)
+        return FALSE;
+    if (control->skip_every && control->preserve_every > 1)
+        return FALSE;
+    return TRUE;
+}
+
+
+int count_decimation_is_noop(struct CountDecimationControl *control)
+{
+    if (control->skip_every < 2 && control->preserve_every < 2
+            && !control->offset_n && !control->limit_n)
+        return TRUE;
+    return FALSE;
+}
+
+void count_decimation_init_from_str(struct CountDecimationControl *control,
+                                    const char *skip, const char *preserve,
+                                    const char *offset, const char *limit)
+{
+    control->skip_every = 0;
+    control->preserve_every = 0;
+    control->every_counter = 0;
+    control->n_count_filtered = 0;
+    control->offset_n = 0;
+    control->offset_n_counter = 0;
+    control->limit_n = 0;
+    control->limit_n_counter = 0;
+    /* TODO: atoi is probably not appropriate */
+    if (skip)
+        control->skip_every = atoi(skip);
+    if (preserve)
+        control->preserve_every = atoi(preserve);
+    if (offset)
+        control->offset_n = atoi(offset);
+    if (limit)
+        control->limit_n = atoi(limit);
+}
+
+
+/* TODO: eliminate noop cases */
+int count_decimation_is_out(struct CountDecimationControl *control)
+{
+    if (control->offset_n) {
+        if (control->offset_n_counter < control->offset_n) {
+            control->offset_n_counter++;
+            return TRUE;
+        }
+        else {
+            control->offset_n = 0;  /* disable offset check */
+        }
+    }
+    if (control->skip_every) {
+        control->every_counter++;
+        if (control->every_counter == control->skip_every) {
+            control->n_count_filtered++;
+            control->every_counter = 0;
+            return TRUE;
+        }
+    }
+    else if (control->preserve_every) {
+        control->every_counter++;
+        if (control->every_counter == control->preserve_every) {
+            control->every_counter = 0;
+        }
+        else {
+            control->n_count_filtered++;
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
+
+int count_decimation_is_end(struct CountDecimationControl *control)
+{
+    if (control->limit_n) {
+        control->limit_n_counter++;
+        /* this matches the last successfully imported point */
+        if (control->limit_n_counter == control->limit_n)
+            return TRUE;
+    }
+    return FALSE;
+}

Copied: grass/trunk/vector/v.in.lidar/count_decimation.h (from rev 67262, grass/trunk/vector/v.decimate/count_decimation.h)
===================================================================
--- grass/trunk/vector/v.in.lidar/count_decimation.h	                        (rev 0)
+++ grass/trunk/vector/v.in.lidar/count_decimation.h	2015-12-22 02:02:07 UTC (rev 67316)
@@ -0,0 +1,43 @@
+/****************************************************************************
+ *
+ * MODULE:       v.decimate
+ * AUTHOR(S):    Vaclav Petras
+ * PURPOSE:      Reduce the number of points in a vector map
+ * COPYRIGHT:    (C) 2015 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the COPYING file that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+
+#ifndef GRASS_COUNT_DECIMATION_H
+#define GRASS_COUNT_DECIMATION_H
+
+/* TODO: change int to ul/ull */
+/* TODO: revise names (now partially on some vars in v.in.lidar code) */
+
+struct CountDecimationControl {
+    int offset_n;
+    int offset_n_counter;
+    int skip_every;
+    int preserve_every;
+    int every_counter;
+    int n_count_filtered;
+    int limit_n;
+    int limit_n_counter;
+};
+
+void count_decimation_init(struct CountDecimationControl *control,
+                           int *skip, int *preserve,
+                           int *offset, int *limit);
+int count_decimation_is_valid(struct CountDecimationControl *control);
+int count_decimation_is_noop(struct CountDecimationControl *control);
+void count_decimation_init_from_str(struct CountDecimationControl *control,
+                                    const char *skip, const char *preserve,
+                                    const char *offset, const char *limit);
+int count_decimation_is_out(struct CountDecimationControl *control);
+int count_decimation_is_end(struct CountDecimationControl *control);
+
+#endif /* GRASS_COUNT_DECIMATION_H */

Modified: grass/trunk/vector/v.in.lidar/main.c
===================================================================
--- grass/trunk/vector/v.in.lidar/main.c	2015-12-22 01:50:12 UTC (rev 67315)
+++ grass/trunk/vector/v.in.lidar/main.c	2015-12-22 02:02:07 UTC (rev 67316)
@@ -27,6 +27,8 @@
 #include <grass/glocale.h>
 #include <liblas/capi/liblas.h>
 
+#include "count_decimation.h"
+
 #ifndef MAX
 #  define MIN(a,b)      ((a<b) ? a : b)
 #  define MAX(a,b)      ((a>b) ? a : b)
@@ -897,32 +899,16 @@
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
-    /* counters used by both but that's ok, the filters are exclusive */
-    int skip_every = 0;
-    int preserve_every = 0;
-    int every_counter = 0;
+    struct CountDecimationControl count_decimation_control;
+
+    count_decimation_init_from_str(&count_decimation_control,
+                                   skip_opt->answer, preserve_opt->answer,
+                                   offset_opt->answer, limit_opt->answer);
+    if (!count_decimation_is_valid(&count_decimation_control))
+        G_fatal_error(_("Settings for count-based decimation are not valid"));
+    /* we don't check if the decimation is noop */
+
 #ifdef HAVE_LONG_LONG_INT
-    unsigned long long n_count_filtered = 0;
-    unsigned long long offset_n = 0;
-    unsigned long long offset_n_counter = 0;
-    unsigned long long limit_n = 0;
-    unsigned long long limit_n_counter = 0;
-#else
-    unsigned long n_count_filtered = 0;
-    unsigned long offset_n = 0;
-    unsigned long offset_n_counter = 0;
-    unsigned long limit_n = 0;
-    unsigned long limit_n_counter = 0;
-#endif
-    if (skip_opt->answer)
-        skip_every = atoi(skip_opt->answer);
-    if (preserve_opt->answer)
-        preserve_every = atoi(preserve_opt->answer);
-    if (offset_opt->answer)
-        offset_n = atoi(offset_opt->answer);
-    if (limit_opt->answer)
-        limit_n = atoi(limit_opt->answer);
-#ifdef HAVE_LONG_LONG_INT
     G_important_message(_("Scanning %llu points..."), n_features);
 #else
     G_important_message(_("Scanning %lu points..."), n_features);
@@ -1010,33 +996,8 @@
                 continue;
             }
         }
-        if (offset_n) {
-            if (offset_n_counter < offset_n) {
-                offset_n_counter++;
-                continue;
-            }
-            else {
-                offset_n = 0;  /* disable offset check */
-            }
-        }
-        if (skip_every) {
-            every_counter++;
-            if (every_counter == skip_every) {
-                n_count_filtered++;
-                every_counter = 0;
-                continue;
-            }
-        }
-        else if (preserve_every) {
-            every_counter++;
-            if (every_counter == preserve_every) {
-                every_counter = 0;
-            }
-            else {
-                n_count_filtered++;
-                continue;
-            }
-        }
+        if (count_decimation_is_out(&count_decimation_control))
+            continue;
 
 	Vect_append_point(Points, x, y, z);
         if (id_layer)
@@ -1148,12 +1109,8 @@
 	    }
 	}
 
-        if (limit_n) {
-            limit_n_counter++;
-            /* this matches the last successfully imported point */
-            if (limit_n_counter == limit_n)
-                break;
-        }
+        if (count_decimation_is_end(&count_decimation_control))
+            break;
         if (id_layer && cat == GV_CAT_MAX) {
             cat_max_reached = TRUE;
             break;
@@ -1183,19 +1140,24 @@
     Vect_close(&Map);
 
     /* can be easily determined only when iterated over all points */
-    if (!limit_n && !cat_max_reached && points_imported != n_features
+    if (!count_decimation_control.limit_n && !cat_max_reached
+            && points_imported != n_features
             - not_valid - n_outside - n_filtered - n_class_filtered
-            - n_outside_mask - offset_n_counter - n_count_filtered
-            - zrange_filtered)
+            - n_outside_mask - count_decimation_control.offset_n_counter
+            - count_decimation_control.n_count_filtered - zrange_filtered)
         G_warning(_("The underlying libLAS library is at its limits."
                     " Previously reported counts might have been distorted."
                     " However, the import itself should be unaffected."));
 
 #ifdef HAVE_LONG_LONG_INT
-    if (limit_n)
-        G_message(_("%llu points imported (limit was %llu)"), limit_n_counter, limit_n);
-    else
+    if (count_decimation_control.limit_n) {
+        G_message(_("%llu points imported (limit was %llu)"),
+                  count_decimation_control.limit_n_counter,
+                  count_decimation_control.limit_n);
+    }
+    else {
         G_message(_("%llu points imported"), points_imported);
+    }
     if (not_valid)
 	G_message(_("%llu input points were not valid"), not_valid);
     if (n_outside)
@@ -1208,10 +1170,12 @@
         G_message(_("%llu input points were filtered out by class number"), n_class_filtered);
     if (zrange_filtered)
         G_message(_("%llu input points were filtered outsite the range for z coordinate"), zrange_filtered);
-    if (offset_n_counter)
-        G_message(_("%llu input points were skipped at the begging using offset"), offset_n_counter);
-    if (n_count_filtered)
-        G_message(_("%llu input points were skipped by count-based decimation"), n_count_filtered);
+    if (count_decimation_control.offset_n_counter)
+        G_message(_("%llu input points were skipped at the begging using offset"),
+                  count_decimation_control.offset_n_counter);
+    if (count_decimation_control.n_count_filtered)
+        G_message(_("%llu input points were skipped by count-based decimation"),
+                  count_decimation_control.n_count_filtered);
 #else
     if (limit_n)
         G_message(_("%lu points imported (limit was %d)"), limit_n_counter, limit_n);
@@ -1235,7 +1199,7 @@
         G_message(_("%lu input points were skipped by count-based decimation"), n_count_filtered);
     G_message(_("Accuracy of the printed point counts might be limited by your computer architecture."));
 #endif
-    if (limit_n)
+    if (count_decimation_control.limit_n)
         G_message(_("The rest of points was ignored"));
 
     if (cat_max_reached)



More information about the grass-commit mailing list