[GRASS-SVN] r61282 - in grass/trunk: include/defs lib/raster3d lib/raster3d/test

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 19 17:02:05 PDT 2014


Author: huhabla
Date: 2014-07-19 17:02:05 -0700 (Sat, 19 Jul 2014)
New Revision: 61282

Modified:
   grass/trunk/include/defs/raster3d.h
   grass/trunk/lib/raster3d/region.c
   grass/trunk/lib/raster3d/test/test_coordinate_transform.c
   grass/trunk/lib/raster3d/test/test_put_get_value.c
   grass/trunk/lib/raster3d/window.c
Log:
raster3dlib: Fixed wrong northern coordinates to row conversion resulting from wrong 
index scheme for rows in the raster3d library unittest. Updated the tests accordingly.
Added Rast3d_location2coord_double() to receive col, 
row and depth indices as double values. 

Unfortunately changed the editor that i use the indention and converted 
all tabs into spaces at save time. Hence, 
the commit contains 95% tab to space conversion noise.

The important changes are in region.c in Rast3d_location2coord()
and in test_coordinate_transform.c and test_put_get_value.c in the test directory. 


Modified: grass/trunk/include/defs/raster3d.h
===================================================================
--- grass/trunk/include/defs/raster3d.h	2014-07-19 22:09:49 UTC (rev 61281)
+++ grass/trunk/include/defs/raster3d.h	2014-07-20 00:02:05 UTC (rev 61282)
@@ -125,12 +125,12 @@
 int Rast3d_key_get_double(struct Key_Value *, const char *, double *);
 int Rast3d_key_get_string(struct Key_Value *, const char *, char **);
 int Rast3d_key_get_value(struct Key_Value *, const char *, char *, char *, int,
-		    int, int *);
+            int, int *);
 int Rast3d_key_set_int(struct Key_Value *, const char *, const int *);
 int Rast3d_key_set_double(struct Key_Value *, const char *, const double *);
 int Rast3d_key_set_string(struct Key_Value *, const char *, char *const *);
 int Rast3d_key_set_value(struct Key_Value *, const char *, const char *,
-		    const char *, int, int, const int *);
+            const char *, int, int, const int *);
 /* long.c */
 int Rast3d_long_encode(long *, unsigned char *, int);
 void Rast3d_long_decode(unsigned char *, long *, int, int);
@@ -183,13 +183,13 @@
 /* param.c */
 void Rast3d_set_standard3d_input_params(void);
 int Rast3d_get_standard3d_params(int *, int *, int *, int *, int *,
-			    int *, int *, int *, int *, int *);
+                int *, int *, int *, int *, int *);
 void Rast3d_set_window_params(void);
 char *Rast3d_get_window_params(void);
 
 /* range.c */
 void Rast3d_range_update_from_tile(RASTER3D_Map *, const void *, int, int, int, int,
-			      int, int, int, int);
+                  int, int, int, int);
 int Rast3d_read_range(const char *, const char *, struct FPRange *);
 int Rast3d_range_load(RASTER3D_Map *);
 void Rast3d_range_min_max(RASTER3D_Map *, double *, double *);
@@ -208,6 +208,7 @@
 int Rast3d_read_region_map(const char *, const char *, RASTER3D_Region *);
 int Rast3d_is_valid_location(RASTER3D_Region *, double, double, double);
 void Rast3d_location2coord(RASTER3D_Region *, double, double, double, int *, int *, int *);
+void Rast3d_location2coord_double(RASTER3D_Region *, double, double, double, double *, double *, double *);
 void Rast3d_location2coord2(RASTER3D_Region *, double, double, double, int *, int *, int *);
 void Rast3d_coord2location(RASTER3D_Region *, double, double, double, double *, double *, double *);
 /* resample.c */
@@ -219,12 +220,12 @@
 /* volume.c */
 void Rast3d_get_volume_a(void *, double[2][2][2][3], int, int, int, void *, int);
 void Rast3d_get_volume(void *, double, double, double, double, double, double,
-		   double, double, double, double, double, double, int, int,
-		   int, void *, int);
+           double, double, double, double, double, double, int, int,
+           int, void *, int);
 void Rast3d_get_aligned_volume(void *, double, double, double, double, double,
-			  double, int, int, int, void *, int);
+              double, int, int, int, void *, int);
 void Rast3d_make_aligned_volume_file(void *, const char *, double, double, double,
-			       double, double, double, int, int, int);
+                   double, double, double, int, int, int);
 /* window.c */
 void Rast3d_get_value(RASTER3D_Map *, int, int, int, void *, int);
 float Rast3d_get_float(RASTER3D_Map *, int, int, int);
@@ -244,33 +245,33 @@
 /* int Rast3d_writeWindow (RASTER3D_Region *, char *); */
 /* getblock.c */
 void Rast3d_get_block_nocache(RASTER3D_Map *, int, int, int, int, int, int, void *,
-			 int);
+             int);
 void Rast3d_get_block(RASTER3D_Map *, int, int, int, int, int, int, void *, int);
 
 /* header.c */
 int Rast3d_read_header(RASTER3D_Map *, int *, int *, double *, double *, double *,
-		   double *, double *, double *, int *, int *, int *,
-		   double *, double *, double *, int *, int *, int *, int *,
-		   int *, int *, int *, int *, int *, int *, int *, char **, int *, int *);
+           double *, double *, double *, int *, int *, int *,
+           double *, double *, double *, int *, int *, int *, int *,
+           int *, int *, int *, int *, int *, int *, int *, char **, int *, int *);
 int Rast3d_write_header(RASTER3D_Map *, int, int, double, double, double, double,
-		    double, double, int, int, int, double, double, double,
-		    int, int, int, int, int, int, int, int, int, int, int,
-		    char *, int, int);
+            double, double, int, int, int, double, double, double,
+            int, int, int, int, int, int, int, int, int, int, int,
+            char *, int, int);
 int Rast3d_rewrite_header(RASTER3D_Map * map);
 int Rast3d_cache_size_encode(int, int);
 int Rast3d__compute_cache_size(RASTER3D_Map *, int);
 int Rast3d_fill_header(RASTER3D_Map *, int, int, int, int, int, int, int, int, int,
-		   int, int, int, int, int, int, int, double, double, double,
-		   double, double, double, int, int, int, double, double,
-		   double, char *, int, int);
+           int, int, int, int, int, int, int, double, double, double,
+           double, double, double, int, int, int, double, double,
+           double, char *, int, int);
 /* headerinfo.c */
 void Rast3d_get_coords_map(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_coords_map_window(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_nof_tiles_map(RASTER3D_Map *, int *, int *, int *);
 void Rast3d_get_region_map(RASTER3D_Map *, double *, double *, double *, double *,
-		      double *, double *);
+              double *, double *);
 void Rast3d_get_window_map(RASTER3D_Map *, double *, double *, double *, double *,
-		      double *, double *);
+              double *, double *);
 void Rast3d_get_tile_dimensions_map(RASTER3D_Map *, int *, int *, int *);
 int Rast3d_tile_type_map(RASTER3D_Map *);
 int Rast3d_file_type_map(RASTER3D_Map *);
@@ -317,13 +318,13 @@
 void Rast3d_tile_coord_origin(RASTER3D_Map *, int, int, int, int *, int *, int *);
 void Rast3d_tile_index_origin(RASTER3D_Map *, int, int *, int *, int *);
 void Rast3d_coord2tile_coord(RASTER3D_Map *, int, int, int, int *, int *, int *, int *,
-			 int *, int *);
+             int *, int *);
 void Rast3d_coord2tile_index(RASTER3D_Map *, int, int, int, int *, int *);
 int Rast3d_coord_in_range(RASTER3D_Map *, int, int, int);
 int Rast3d_tile_index_in_range(RASTER3D_Map *, int);
 int Rast3d_tile_in_range(RASTER3D_Map *, int, int, int);
 int Rast3d_compute_clipped_tile_dimensions(RASTER3D_Map *, int, int *, int *, int *,
-				     int *, int *, int *);
+                     int *, int *, int *);
 
 /* tilenull.c */
 void Rast3d_set_null_tile_type(RASTER3D_Map *, void *, int);

Modified: grass/trunk/lib/raster3d/region.c
===================================================================
--- grass/trunk/lib/raster3d/region.c	2014-07-19 22:09:49 UTC (rev 61281)
+++ grass/trunk/lib/raster3d/region.c	2014-07-20 00:02:05 UTC (rev 61282)
@@ -10,7 +10,7 @@
 
 
 /*!
- * \brief 
+ * \brief
  *
  *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
  *
@@ -37,7 +37,7 @@
 }
 
 /*!
- * \brief 
+ * \brief
  *
  *  Returns in <em>region2d</em> the <em>2d</em> portion of <em>region3d</em>.
  *
@@ -75,7 +75,7 @@
 
 
 /*!
- * \brief 
+ * \brief
  *
  * Replaces the <em>2d</em> portion of <em>region3d</em> with the
  * values stored in <em>region2d</em>.
@@ -104,7 +104,7 @@
 }
 
 /*!
- * \brief 
+ * \brief
  *
  * Replaces the <em>2d</em> portion of <em>region3d</em> with the
  * values stored in <em>region2d</em>.
@@ -140,7 +140,7 @@
 
 
 /*!
- * \brief 
+ * \brief
  *
  * Computes an adjusts the resolutions in the region structure from the region
  * boundaries and number of cells per dimension.
@@ -158,7 +158,7 @@
     Rast3d_region_from_to_cell_head(&region2d, region);
 
     if (region->depths <= 0)
-	Rast3d_fatal_error("Rast3d_adjust_region: depths <= 0");
+    Rast3d_fatal_error("Rast3d_adjust_region: depths <= 0");
     region->tb_res = (region->top - region->bottom) / region->depths;
 }
 
@@ -166,7 +166,7 @@
 
 
 /*!
- * \brief 
+ * \brief
  *
  * Computes an adjusts the number of cells per dimension in the region
  * structure from the region boundaries and resolutions.
@@ -184,19 +184,19 @@
     Rast3d_region_from_to_cell_head(&region2d, region);
 
     if (region->tb_res <= 0)
-	Rast3d_fatal_error("Rast3d_adjust_region_res: tb_res <= 0");
+    Rast3d_fatal_error("Rast3d_adjust_region_res: tb_res <= 0");
 
     region->depths = (region->top - region->bottom + region->tb_res / 2.0) /
-	region->tb_res;
+    region->tb_res;
     if (region->depths == 0)
-	region->depths = 1;
+    region->depths = 1;
 }
 
 /*---------------------------------------------------------------------------*/
 
 
 /*!
- * \brief 
+ * \brief
  *
  * Copies the values of <em>regionSrc</em> into <em>regionDst</em>.
  *
@@ -207,23 +207,23 @@
 
 void Rast3d_region_copy(RASTER3D_Region * regionDest, RASTER3D_Region * regionSrc)
 {
-	regionDest->proj = regionSrc->proj;
-	regionDest->zone = regionSrc->zone;
+    regionDest->proj = regionSrc->proj;
+    regionDest->zone = regionSrc->zone;
 
-	regionDest->north = regionSrc->north;
-	regionDest->south = regionSrc->south;
-	regionDest->east = regionSrc->east;
-	regionDest->west = regionSrc->west;
-	regionDest->top = regionSrc->top;
-	regionDest->bottom = regionSrc->bottom;
+    regionDest->north = regionSrc->north;
+    regionDest->south = regionSrc->south;
+    regionDest->east = regionSrc->east;
+    regionDest->west = regionSrc->west;
+    regionDest->top = regionSrc->top;
+    regionDest->bottom = regionSrc->bottom;
 
-	regionDest->rows = regionSrc->rows;
-	regionDest->cols = regionSrc->cols;
-	regionDest->depths = regionSrc->depths;
+    regionDest->rows = regionSrc->rows;
+    regionDest->cols = regionSrc->cols;
+    regionDest->depths = regionSrc->depths;
 
-	regionDest->ns_res = regionSrc->ns_res;
-	regionDest->ew_res = regionSrc->ew_res;
-	regionDest->tb_res = regionSrc->tb_res;
+    regionDest->ns_res = regionSrc->ns_res;
+    regionDest->ew_res = regionSrc->ew_res;
+    regionDest->tb_res = regionSrc->tb_res;
 }
 
 
@@ -236,11 +236,11 @@
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
 
     if (G_name_is_fully_qualified(name, xname, xmapset))
-	Rast3d_filename(fullName, RASTER3D_HEADER_ELEMENT, xname, xmapset);
+    Rast3d_filename(fullName, RASTER3D_HEADER_ELEMENT, xname, xmapset);
     else {
-	if (!mapset || !*mapset)
-	    mapset = G_find_raster3d(name, "");
-	Rast3d_filename(fullName, RASTER3D_HEADER_ELEMENT, name, mapset);
+    if (!mapset || !*mapset)
+        mapset = G_find_raster3d(name, "");
+    Rast3d_filename(fullName, RASTER3D_HEADER_ELEMENT, name, mapset);
     }
     return Rast3d_read_window(region, fullName);
 }
@@ -249,9 +249,9 @@
 
 
 /*!
- * \brief 
+ * \brief
  *
- *  Returns 1 if region-coordinates <em>(north, west, bottom)</em> are
+ *  Returns 1 if region-coordinates <em>(north, east, top)</em> are
  * inside the region of <em>map</em>. Returns 0 otherwise.
  *
  *  \param REgion
@@ -264,15 +264,15 @@
 int Rast3d_is_valid_location(RASTER3D_Region *region, double north, double east, double top)
 {
     return ((north >= region->south) && (north <= region->north) &&
-	    (east >= region->west) && (east <= region->east) &&
-	    (((top >= region->bottom) && (top <= region->top)) ||
-	     ((top <= region->bottom) && (top >= region->top))));
+        (east >= region->west) && (east <= region->east) &&
+        (((top >= region->bottom) && (top <= region->top)) ||
+         ((top <= region->bottom) && (top >= region->top))));
 }
 
 /*---------------------------------------------------------------------------*/
 
 /*!
- * \brief 
+ * \brief
  *
  *  Converts region-coordinates <em>(north, east,
  *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
@@ -289,28 +289,51 @@
 
 void
 Rast3d_location2coord(RASTER3D_Region *region, double north, double east, double top,
-		   int *x, int *y, int *z)
+           int *x, int *y, int *z)
 {
     double col, row, depth;
-    
-    col = (east - region->west) / (region->east -
-				      region->west) * (double)(region->cols);
-    row = (north - region->south) / (region->north -
-					region->south) * (double)(region->rows);
-    depth = (top - region->bottom) / (region->top -
-				       region->bottom) * (double)(region->depths);
-    
+
+    Rast3d_location2coord_double(region, north, east, top, &col, &row, &depth);
+
     *x = (int)col;
-    /* Adjust row to start at the northern edge*/
-    *y = region->rows - (int)row - 1;
+    *y = (int)row;
     *z = (int)depth;
-        
-    G_debug(4, "Rast3d_location2coord x %i y %i z %i\n", *x, *y, *z);
 }
 
+/*!
+ * \brief
+ *
+ *  Converts region-coordinates <em>(north, east,
+ *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
+ *
+ * <b>Note:</b> The results are <i>double</i> numbers. Casting them to
+ * <i>int</i> will give the column, row and depth number.
+ *
+ *  \param map
+ *  \param north
+ *  \param east
+ *  \param top
+ *  \param x
+ *  \param y
+ *  \param z
+ *  \return void
+ */
 
+void
+Rast3d_location2coord_double(RASTER3D_Region *region, double north, double east, double top,
+           double *x, double *y, double *z)
+{
+    double row;
+
+    *x = (east - region->west) / (region->ew_res);
+    *y = (region->north - north) / (region->ns_res);
+    *z = (top - region->bottom) / (region->tb_res);
+
+    G_debug(4, "Rast3d_location2coord_double x %f y %f z %f\n", *x, *y, *z);
+}
+
 /*!
- * \brief 
+ * \brief
  *
  *  Converts region-coordinates <em>(north, east,
  *  top)</em> into cell-coordinates <em>(x, y, z)</em>.
@@ -328,37 +351,35 @@
 
 void
 Rast3d_location2coord2(RASTER3D_Region *region, double north, double east, double top,
-		   int *x, int *y, int *z)
+           int *x, int *y, int *z)
 {
     if (!Rast3d_is_valid_location(region, north, east, top))
-	Rast3d_fatal_error("Rast3d_location2coord2: location not in region");
+    Rast3d_fatal_error("Rast3d_location2coord2: location not in region");
 
     Rast3d_location2coord(region, north, east, top, x, y, z);
 }
 
 /*!
- * \brief 
+ * \brief
  *
- *  Converts cell-coordinates <em>(x, y, z)</em> into region-coordinates 
- * <em>(north, east, top)</em>. 
+ *  Converts cell-coordinates <em>(x, y, z)</em> into region-coordinates
+ * <em>(north, east, top)</em>.
  *
  *  * <b>Note:</b> x, y and z is a double:
  *  - x+0.0 will return the easting for the western edge of the column.
  *  - x+0.5 will return the easting for the center of the column.
  *  - x+1.0 will return the easting for the eastern edge of the column.
- * 
+ *
  *  - y+0.0 will return the northing for the northern edge of the row.
  *  - y+0.5 will return the northing for the center of the row.
  *  - y+1.0 will return the northing for the southern edge of the row.
- * 
+ *
  *  - z+0.0 will return the top for the lower edge of the depth.
  *  - z+0.5 will return the top for the center of the depth.
  *  - z+1.0 will return the top for the upper edge of the column.
  *
- * <b>Note:</b> The result is a <i>double</i>. Casting it to an
- * <i>int</i> will give the column, row and depth number.
- * 
- * 
+*
+ *
  *  \param map
  *  \param x
  *  \param y
@@ -374,7 +395,7 @@
 {
     *north = region->north - y * region->ns_res;
     *east = region->west + x * region->ew_res;
-    *top = region->bottom + z * region->tb_res; 
-        
+    *top = region->bottom + z * region->tb_res;
+
     G_debug(4, "Rast3d_coord2location north %g east %g top %g\n", *north, *east, *top);
 }

Modified: grass/trunk/lib/raster3d/test/test_coordinate_transform.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_coordinate_transform.c	2014-07-19 22:09:49 UTC (rev 61281)
+++ grass/trunk/lib/raster3d/test/test_coordinate_transform.c	2014-07-20 00:02:05 UTC (rev 61282)
@@ -20,9 +20,9 @@
     sum += test_region();
 
     if (sum > 0)
-	G_warning("\n-- raster3d coordinate transform unit tests failure --");
+    G_warning("\n-- raster3d coordinate transform unit tests failure --");
     else
-	G_message("\n-- raster3d coordinate transform unit tests finished successfully --");
+    G_message("\n-- raster3d coordinate transform unit tests finished successfully --");
 
     return sum;
 }
@@ -31,19 +31,19 @@
 
 int test_coordinate_transform(void)
 {
-    int sum = 0; 
-    
+    int sum = 0;
+
     double north, east, top;
     int col = 0, row = 0, depth = 0;
-    
+
     RASTER3D_Region region, default_region;
     RASTER3D_Map *map = NULL;
-    
+
     /* We need to set up a specific region for the new raster3d map.
      * First we safe the default region. */
     Rast3d_get_window(&default_region);
     Rast3d_region_copy(&region, &default_region);
-    
+
     region.bottom = 0.0;
     region.top = 1000;
     region.south = 1000;
@@ -53,100 +53,100 @@
     region.rows = 15;
     region.cols = 10;
     region.depths = 5;
-        
+
     Rast3d_adjust_region(&region);
-    
+
     map = Rast3d_open_new_opt_tile_size("test_coordinate_transform", RASTER3D_USE_CACHE_XYZ, &region, FCELL_TYPE, 32);
-        
+
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
-    
+
     G_message("Test the upper right corner, coordinates must be col = 9, row = 0, depth = 4");
-    
+
     /*
      ROWS
-  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6500 7000 7500 8000 8500 9000
-    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|                         
+  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500
+    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
    15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
-          
+
     COLS
   5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000
-    |....|....|....|....|....|....|....|....|....|....|                         
+    |....|....|....|....|....|....|....|....|....|....|
     0    1    2    3    4    5    6    7    8    9   10
-      
+
     DEPTHS
     0   200  400  600  800  1000
-    |....|....|....|....|....|                         
-    0    1    2    3    4    5                          
+    |....|....|....|....|....|
+    0    1    2    3    4    5
     */
     north = 8499.9;
     east=  9999.9;
     top =  999.9;
-        
-    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);    
+
+    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
     printf("Rast3d_location2coord col %i row %i depth %i\n", col, row, depth);
     if(region.cols - 1 != col || 0 != row || region.depths - 1 != depth) {
         G_message("Error in Rast3d_location2coord");
         sum++;
     }
-    
-    G_message("Test the lower left corner, coordinates must be col = 0 row = 14 depth = 0");
-    
+
+    G_message("Test the lower left corner, coordinates must be col = 0 row = 15 depth = 0");
+
     north = 1000.0;
     east= 5000.0;
     top = 0.0;
-        
-    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);    
+
+    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
     printf("Rast3d_location2coord col %i row %i depth %i\n", col, row, depth);
-    if(0 != col || 14 != row || 0 != depth) {
+    if(0 != col || 15 != row || 0 != depth) {
         G_message("Error in Rast3d_location2coord");
         sum++;
     }
-    
+
     G_message("Test the center, coordinates must be col = 4 row = 7 depth = 2");
-    
-    
+
+
     north = 4750.0;
     east= 7499.9;
     top = 500.0;
-        
-    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);    
+
+    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
     printf("Rast3d_location2coord col %i row %i depth %i\n", col, row, depth);
     if((region.cols - 1)/2 != col || (region.rows - 1)/2 != row || (region.depths - 1)/2 != depth) {
         G_message("Error in Rast3d_location2coord");
         sum++;
     }
-    
+
     G_message("Test the n=3000.1, e=7000.1 and t=800.1, coordinates must be col = 4 row = 10 depth = 4");
-    
+
     north = 3000.1;
     east= 7000.1;
     top = 800.1;
-        
-    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);    
+
+    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
     printf("Rast3d_location2coord col %i row %i depth %i\n", col, row, depth);
     if(4 != col || map->region.rows - 5 != row || 4 != depth) {
         G_message("Error in Rast3d_location2coord");
         sum++;
     }
-    
+
     G_message("Test the n=2999.9, e=6999.9 and t=799.9, coordinates must be col = 3 row = 11 depth = 3");
-    
+
     north = 2999.9;
     east= 6999.9;
     top = 799.9;
-        
-    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);    
+
+    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
     printf("Rast3d_location2coord col %i row %i depth %i\n", col, row, depth);
     if(3 != col || map->region.rows - 4 != row || 3 != depth) {
         G_message("Error in Rast3d_location2coord");
         sum++;
     }
-    
+
     Rast3d_close(map);
-    
+
     G_remove("grid3", "test_coordinate_transform");
-    
+
     return sum;
 }
 
@@ -156,7 +156,7 @@
 {
     int sum = 0;
     RASTER3D_Region region, new_region;
-    
+
     Rast3d_get_window(&region);
     region.bottom = 0.0;
     region.top = 1000;
@@ -170,97 +170,97 @@
     region.ew_res = 0;
     region.ns_res = 0;
     region.tb_res = 0;
-        
+
     /* Test region adjustment */
     Rast3d_adjust_region(&region);
-    
+
     if(region.ew_res != 500) {
         G_message("Error in Rast3d_adjust_region: region.ew_res != 500");
         sum++;
     }
-    
+
     if(region.ns_res != 500) {
         G_message("Error in Rast3d_adjust_region: region.ew_res != 500");
         sum++;
     }
-    
+
     if(region.tb_res != 200) {
         G_message("Error in Rast3d_adjust_region: region.ew_res != 500");
         sum++;
     }
-    
+
     /* Test the region copy */
     Rast3d_region_copy(&new_region, &region);
-        
+
     if(region.bottom != new_region.bottom) {
         G_message("Error in Rast3d_region_copy: region.bottom != new_region.bottom");
         sum++;
     }
-    
+
     if(region.cols != new_region.cols) {
         G_message("Error in Rast3d_region_copy: region.cols != new_region.cols");
         sum++;
     }
-    
+
     if(region.depths != new_region.depths) {
         G_message("Error in Rast3d_region_copy: region.depths != new_region.depths");
         sum++;
     }
-    
+
     if(region.east != new_region.east) {
         G_message("Error in Rast3d_region_copy: region.east != new_region.east");
         sum++;
     }
-    
+
     if(region.ew_res != new_region.ew_res) {
         G_message("Error in Rast3d_region_copy: region.ew_res != new_region.ew_res");
         sum++;
     }
-    
+
     if(region.north != new_region.north) {
         G_message("Error in Rast3d_region_copy: region.north != new_region.north");
         sum++;
     }
-    
+
     if(region.ns_res != new_region.ns_res) {
         G_message("Error in Rast3d_region_copy: region.ns_res != new_region.ns_res");
         sum++;
     }
-    
+
     if(region.proj != new_region.proj) {
         G_message("Error in Rast3d_region_copy: region.proj != new_region.proj");
         sum++;
     }
-    
+
     if(region.rows != new_region.rows) {
         G_message("Error in Rast3d_region_copy: region.rows != new_region.rows");
         sum++;
     }
-    
+
     if(region.south != new_region.south) {
         G_message("Error in Rast3d_region_copy: region.south != new_region.south");
         sum++;
     }
-    
+
     if(region.tb_res != new_region.tb_res) {
         G_message("Error in Rast3d_region_copy: region.tb_res != new_region.tb_res");
         sum++;
     }
-    
+
     if(region.top != new_region.top) {
         G_message("Error in Rast3d_region_copy: region.top != new_region.top");
         sum++;
     }
-    
+
     if(region.west != new_region.west) {
         G_message("Error in Rast3d_region_copy: region.west != new_region.west");
         sum++;
     }
-    
+
     if(region.zone != new_region.zone) {
         G_message("Error in Rast3d_region_copy: region.zone != new_region.zone");
         sum++;
-    }    
-    
+    }
+
     return sum;
 }

Modified: grass/trunk/lib/raster3d/test/test_put_get_value.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_put_get_value.c	2014-07-19 22:09:49 UTC (rev 61281)
+++ grass/trunk/lib/raster3d/test/test_put_get_value.c	2014-07-20 00:02:05 UTC (rev 61282)
@@ -4,7 +4,7 @@
 * MODULE:       Grass raster3d Library
 * AUTHOR(S):    Soeren Gebbert, Braunschweig (GER) Jun 2011
 * 		        soerengebbert <at> googlemail <dot> com
-*               
+*
 * PURPOSE:	Unit and Integration tests
 *
 * COPYRIGHT:    (C) 2000 by the GRASS Development Team
@@ -23,13 +23,13 @@
 static int test_put_get_value_fcell(void);
 static int test_put_get_value_resampling(void);
 static int test_get_value_region(RASTER3D_Map *map, int cols, int rows, int depths);
-static int test_resampling_dcell(RASTER3D_Map *map, double north, double east, double 
+static int test_resampling_dcell(RASTER3D_Map *map, double north, double east, double
                                  top, int col, int row, int depth, int fact);
-static int test_resampling_fcell(RASTER3D_Map *map, double north, double east, double 
+static int test_resampling_fcell(RASTER3D_Map *map, double north, double east, double
                                  top, int col, int row, int depth, int fact);
 
 /* *************************************************************** */
-/* Perform the coordinate transformation tests ******************* */
+/* Perform the put-get value tests ******************************* */
 /* *************************************************************** */
 int unit_test_put_get_value()
 {
@@ -43,9 +43,9 @@
 
 
     if (sum > 0)
-	G_warning("\n-- raster3d put/get value unit tests failure --");
+    G_warning("\n-- raster3d put/get value unit tests failure --");
     else
-	G_message("\n-- raster3d put/get value unit tests finished successfully --");
+    G_message("\n-- raster3d put/get value unit tests finished successfully --");
 
     return sum;
 }
@@ -54,23 +54,23 @@
 
 int test_put_get_value_dcell(void)
 {
-    int sum = 0; 
+    int sum = 0;
     int x, y, z;
     DCELL value;
     DCELL value_ref;
-    
+
     G_message("Testing DCELL put get value functions");
-    
+
     double north, east, top;
     int col, row, depth;
-    
+
     RASTER3D_Region region;
     RASTER3D_Map *map = NULL;
-    
+
     /* We need to set up a specific region for the new raster3d map.
      * First we safe the default region. */
     Rast3d_get_window(&region);
-    
+
     region.bottom = 0.0;
     region.top = 1000;
     region.south = 1000;
@@ -80,30 +80,30 @@
     region.rows = 15;
     region.cols = 10;
     region.depths = 5;
-        
+
     Rast3d_adjust_region(&region);
-        
+
     map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, 32);
-    
+
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
     /*
      ROWS
-  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6500 7000 7500 8000 8500 9000 north
-    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|                         
+  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 north
+    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
    15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0 region
-          
+
     COLS
   5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 east
-    |....|....|....|....|....|....|....|....|....|....|                         
+    |....|....|....|....|....|....|....|....|....|....|
     0    1    2    3    4    5    6    7    8    9   10 region
-      
+
     DEPTHS
     0   200  400  600  800  1000  top
-    |....|....|....|....|....|                         
-    0    1    2    3    4    5 region                   
+    |....|....|....|....|....|
+    0    1    2    3    4    5 region
     */
-    
+
     for(z = 0; z < region.depths; z++) {
         for(y = 0; y < region.rows; y++) { /* From the north to the south */
             for(x = 0; x < region.cols; x++) {
@@ -119,65 +119,65 @@
     Rast3d_close(map);
 
     map = Rast3d_open_cell_old("test_put_get_value_dcell", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
-    
+
     /* Reread the map and compare the expected results */
-    
+
     G_message("Get the value of the upper left corner -> 0");
-    
-    
+
+
     col = row = depth = 0;
     north = region.north - 0.1; /* north would be out of bounds therefor -0.1 */
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
-    
-    
+
+
     G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
-    
+
     col = row = depth = 1;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
-    
+
     G_message("Get the value of x == 4 y == 3 z == 2 -> x + y + z = 9");
-    
+
     col = 4;
     row = 3;
     depth = 2;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
-    
+
     G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z = 27");
-    
+
     col = 9;
     row = 14;
     depth = 4;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
-        
+
     G_message("Get the value of x == 10 y == 15 z == 5 -> x + y + z = NAN");
-        
+
     col = 10;
     row = 15;
     depth = 5;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     Rast3d_get_region_value(map, north, east, top, &value, DCELL_TYPE);
     Rast3d_get_value(map, col, row, depth, &value_ref, DCELL_TYPE);
     /* Rast3d_get_value_region does not work with coordinates outside the region */
     printf("Value %g == %g\n", value, value_ref);
-    
+
     if(value == 0 || value < 0 || value > 0) {
         G_message("Error in Rast3d_get_region_value");
         sum++;
@@ -186,11 +186,11 @@
         G_message("Error in Rast3d_get_value");
         sum++;
     }
-    
+
     Rast3d_close(map);
-    
+
     G_remove("grid3", "test_put_get_value_dcell");
-    
+
     return sum;
 }
 
@@ -198,23 +198,23 @@
 
 int test_put_get_value_fcell(void)
 {
-     int sum = 0; 
+     int sum = 0;
     int x, y, z;
     FCELL value;
     FCELL value_ref;
-    
+
     G_message("Testing FCELL put get value functions");
-    
+
     double north, east, top;
     int col, row, depth;
-    
+
     RASTER3D_Region region;
     RASTER3D_Map *map = NULL;
-    
+
     /* We need to set up a specific region for the new raster3d map.
      * First we safe the default region. */
     Rast3d_get_window(&region);
-    
+
     region.bottom = 0.0;
     region.top = 1000;
     region.south = 1000;
@@ -224,14 +224,14 @@
     region.rows = 15;
     region.cols = 10;
     region.depths = 5;
-        
+
     Rast3d_adjust_region(&region);
-        
+
     map = Rast3d_open_new_opt_tile_size("test_put_get_value_fcell", RASTER3D_USE_CACHE_XY, &region, FCELL_TYPE, 32);
-    
+
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
-    
+
     for(z = 0; z < region.depths; z++) {
         for(y = 0; y < region.rows; y++) {
             for(x = 0; x < region.cols; x++) {
@@ -247,63 +247,63 @@
     Rast3d_close(map);
 
     map = Rast3d_open_cell_old("test_put_get_value_fcell", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
-    
+
        /* Reread the map and compare the expected results */
-    
+
     G_message("Get the value of the lower left corner -> 0");
-    
+
     col = row = depth = 0;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
-    
+
     G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
-    
+
     col = row = depth = 1;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
-    
+
     G_message("Get the value of x == 4 y == 3 z == 2 -> x + y + z = 9");
-    
+
     col = 4;
     row = 3;
     depth = 2;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
-    
+
     G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z = 27");
-    
+
     col = 9;
     row = 14;
     depth = 4;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
-        
+
     G_message("Get the value of x == 10 y == 15 z == 5 -> x + y + z = NAN");
-    
+
     col = 10;
     row = 15;
     depth = 5;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     Rast3d_get_region_value(map, north, east, top, &value, FCELL_TYPE);
     Rast3d_get_value(map, 10, 15, 5, &value_ref, FCELL_TYPE);
     /* Rast3d_get_value_region does not work with coordinates outside the region */
     printf("Value %g == %g\n", value, value_ref);
-    
+
     if(value == 0 || value < 0 || value > 0) {
         G_message("Error in Rast3d_get_region_value");
         sum++;
@@ -312,11 +312,11 @@
         G_message("Error in Rast3d_get_value");
         sum++;
     }
-    
+
     Rast3d_close(map);
-    
+
     G_remove("grid3", "test_put_get_value_fcell");
-    
+
     return sum;
 }
 
@@ -324,23 +324,23 @@
 
 int test_put_get_value_resampling(void)
 {
-    int sum = 0; 
+    int sum = 0;
     int x, y, z;
     DCELL value;
-    
+
     G_message("Testing put get resample value functions");
-    
+
     double north, east, top;
     int col, row, depth;
-    
+
     RASTER3D_Region region;
     RASTER3D_Region window;
     RASTER3D_Map *map = NULL;
-    
+
     /* We need to set up a specific region for the new raster3d map.
      * First we safe the default region. */
     Rast3d_get_window(&region);
-    
+
     region.bottom = 0.0;
     region.top = 1000;
     region.south = 1000;
@@ -350,32 +350,32 @@
     region.rows = 15;
     region.cols = 10;
     region.depths = 5;
-        
+
     Rast3d_adjust_region(&region);
-    
+
     map = Rast3d_open_new_opt_tile_size("test_put_get_value_resample", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, 32);
     /*
      ROWS
-  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6500 7000 7500 8000 8500 9000 north
-    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|                         
+  1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 north
+    |....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
    15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0 region
     |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
    30   28   26   24   22   20   18   16   14   12   10    8    6    4    2    0 window
-          
+
     COLS
   5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 east
-    |....|....|....|....|....|....|....|....|....|....|                         
+    |....|....|....|....|....|....|....|....|....|....|
     0    1    2    3    4    5    6    7    8    9   10 region
     |    |    |    |    |    |    |    |    |    |    |
     0    2    4    6    8   10   12   14   16   18   20 window
     DEPTHS
     0   200  400  600  800  1000 top
-    |....|....|....|....|....|                         
-    0    1    2    3    4    5 region  
+    |....|....|....|....|....|
+    0    1    2    3    4    5 region
     |    |    |    |    |    |
-    0    2    4    6    8   10 window                   
+    0    2    4    6    8   10 window
     */
-    
+
     for(z = 0; z < region.depths; z++) {
         for(y = 0; y < region.rows; y++) {  /* North to south */
             for(x = 0; x < region.cols; x++) {
@@ -404,56 +404,56 @@
 
     /* The window has the 8x resolution as the map region */
     Rast3d_set_window_map(map, &window);
-    
+
     /* Reread the map and compare the expected results */
-    
+
     G_message("Get the value of the upper left corner -> 0");
-    
+
     col = row = depth = 0;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
-    
+
     G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
-    
-    
+
+
     col = row = depth = 1;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
-    
+
     G_message("Get the value of x == 7 y == 9 z == 3 -> x + y + z == 19");
-        
+
     col = 7;
     row = 9;
     depth = 3;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
-    
+
     G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z == 27");
-        
+
     col = 9;
     row = 14;
     depth = 4;
-    north = region.north - region.ns_res * (row + 1);
+    north = region.north - region.ns_res * row;
     east = region.west + region.ew_res * col;
     top = region.bottom + region.tb_res * depth;
-    
+
     sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
-    
+
     sum += test_get_value_region(map, region.cols, region.rows, region.depths);
-    
+
     Rast3d_close(map);
-    
+
     G_remove("grid3", "test_put_get_value_resample");
-    
+
     return sum;
 }
 
@@ -466,13 +466,13 @@
     DCELL value_ref;
     DCELL value_reg;
     DCELL value_win;
-    
+
     Rast3d_get_region_value(map, north, east, top, &value, DCELL_TYPE);
     Rast3d_get_window_value(map, north, east, top, &value_win, DCELL_TYPE);
     Rast3d_get_value(map, col * fact, row * fact, depth * fact, &value_ref, DCELL_TYPE);
     Rast3d_get_value_region(map, col, row, depth, &value_reg, DCELL_TYPE);
     printf("Value %g == %g == %g == %g\n", value, value_win, value_ref, value_reg);
-    
+
     if(value != col + row + depth) {
         G_message("Error in Rast3d_get_region_value");
         sum++;
@@ -489,7 +489,7 @@
         G_message("Error in Rast3d_get_value_region");
         sum++;
     }
-    
+
     return sum;
 }
 
@@ -502,13 +502,13 @@
     FCELL value_ref;
     FCELL value_reg;
     FCELL value_win;
-    
+
     Rast3d_get_region_value(map, north, east, top, &value, FCELL_TYPE);
     Rast3d_get_window_value(map, north, east, top, &value_win, FCELL_TYPE);
     Rast3d_get_value(map, col * fact, row * fact, depth * fact, &value_ref, FCELL_TYPE);
     Rast3d_get_value_region(map, col, row, depth, &value_reg, FCELL_TYPE);
     printf("Value %g == %g == %g == %g\n", value, value_win, value_ref, value_reg);
-    
+
     if(value != col + row + depth) {
         G_message("Error in Rast3d_get_region_value");
         sum++;
@@ -525,7 +525,7 @@
         G_message("Error in Rast3d_get_value_region");
         sum++;
     }
-    
+
     return sum;
 }
 
@@ -538,14 +538,14 @@
     FCELL fvalue2 = 0.0;
     DCELL dvalue1 = 0.0;
     DCELL dvalue2 = 0.0;
-    
+
     /* Test for correct Null value */
     Rast3d_get_value_region(map, -1, -1, -1, &fvalue1, FCELL_TYPE);
     Rast3d_get_value_region(map, cols, rows, depths, &fvalue2, FCELL_TYPE);
     Rast3d_get_value_region(map, -1, -1, -1, &dvalue1, DCELL_TYPE);
     Rast3d_get_value_region(map, cols, rows, depths, &dvalue2, DCELL_TYPE);
     printf("Value %g == %g == %g == %g\n", fvalue1, fvalue2, dvalue1, dvalue2);
-    
+
     if(!Rast_is_f_null_value(&fvalue1)) {
         G_message("Error in Rast3d_get_value_region");
         sum++;
@@ -562,6 +562,6 @@
         G_message("Error in Rast3d_get_value_region");
         sum++;
     }
-    
+
     return sum;
 }

Modified: grass/trunk/lib/raster3d/window.c
===================================================================
--- grass/trunk/lib/raster3d/window.c	2014-07-19 22:09:49 UTC (rev 61281)
+++ grass/trunk/lib/raster3d/window.c	2014-07-20 00:02:05 UTC (rev 61282)
@@ -77,7 +77,7 @@
 /*!
  * \brief 
  *
- *  Returns 1 if window-coordinates <em>(north, west, bottom)</em> are
+ *  Returns 1 if window-coordinates <em>(north, east and top)</em> are
  * inside the window of <em>map</em>. Returns 0 otherwise.
  *
  *  \param map



More information about the grass-commit mailing list