Przeglądaj źródła

libraster: Rast_option_to_interp_type() added

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56212 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 lat temu
rodzic
commit
0b3c9c27bb
3 zmienionych plików z 70 dodań i 12 usunięć
  1. 1 0
      include/defs/raster.h
  2. 6 1
      include/raster.h
  3. 63 11
      lib/raster/interp.c

+ 1 - 0
include/defs/raster.h

@@ -393,6 +393,7 @@ DCELL Rast_interp_bicubic_bspline(double, double,
 		       DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL,
 		       DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL,
 		       DCELL);
+int Rast_option_to_interp_type(const struct Option *);
 
 /* mask_info.c */
 char *Rast_mask_info(void);

+ 6 - 1
include/raster.h

@@ -12,7 +12,12 @@
 #define FCELL_TYPE 1
 #define DCELL_TYPE 2
 
-/* for G_get_raster_sample(), INTERP_TYPE */
+/*! \brief Interpolation methods
+
+  For G_get_raster_sample(), INTERP_TYPE
+
+  \todo Rename to use prefix INTERP_
+*/
 #define UNKNOWN	  0
 #define NEAREST   1		/* nearest neighbor interpolation  */
 #define BILINEAR  2		/* bilinear interpolation          */

+ 63 - 11
lib/raster/interp.c

@@ -1,19 +1,22 @@
 /*!
- * \file raster/interp.c
- *
- * \brief Raster Library - Interpolation
- *
- * (C) 2001-2009 GRASS Development Team
- *
- * This program is free software under the GNU General Public License 
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author Original author CERL
- */
+  \file lib/raster/interp.c
+  
+  \brief Raster Library - Interpolation methods
+  
+  (C) 2001-2009,2013 GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Original author CERL
+*/
 
 #include <math.h>
+#include <string.h>
+
 #include <grass/gis.h>
 #include <grass/raster.h>
+#include <grass/glocale.h>
 
 DCELL Rast_interp_linear(double u, DCELL c0, DCELL c1)
 {
@@ -160,3 +163,52 @@ DCELL Rast_interp_bicubic_bspline(double u, double v,
 
     return Rast_interp_cubic_bspline(v, c0, c1, c2, c3);
 }
+
+/*!
+  \brief Get interpolation method from the option.
+
+  Calls G_fatal_error() on unknown interpolation method.
+  
+  Supported methods:
+   - NEAREST
+   - BILINEAR
+   - CUBIC
+
+  \code
+  int interp_method
+  struct Option *opt_method;
+  
+  opt_method = G_define_standard_option(G_OPT_R_INTERP_TYPE);
+  
+  if (G_parser(argc, argv))
+      exit(EXIT_FAILURE);
+      
+  interp_method = G_option_to_interp_type(opt_method);
+  \endcode
+
+  \param option pointer to interpolation option
+  
+  \return interpolation method code
+*/
+int Rast_option_to_interp_type(const struct Option *option)
+{
+    int interp_type;
+    
+    interp_type = UNKNOWN;
+    if (option->answer) {
+        if (strcmp(option->answer, "nearest") == 0) {
+            interp_type = NEAREST;
+        }
+        else if (strcmp(option->answer, "bilinear") == 0) {
+            interp_type = BILINEAR;
+        }
+        else if (strcmp(option->answer, "bicubic") == 0) {
+            interp_type = CUBIC;
+        }
+    }
+
+    if (interp_type == UNKNOWN)
+        G_fatal_error(_("Unknown interpolation method: %s"), option->answer);
+
+    return interp_type;
+}