[GRASS-SVN] r61287 - in grass/trunk/lib/raster3d: . test testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jul 20 09:03:02 PDT 2014
Author: huhabla
Date: 2014-07-20 09:03:02 -0700 (Sun, 20 Jul 2014)
New Revision: 61287
Modified:
grass/trunk/lib/raster3d/raster3d_intern.h
grass/trunk/lib/raster3d/region.c
grass/trunk/lib/raster3d/test/test_main.c
grass/trunk/lib/raster3d/test/test_put_get_value.c
grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c
grass/trunk/lib/raster3d/testsuite/raster3d_lib_test.py
Log:
raster3dlib: Using Macros to reduce function nesting in coordinate to index conversion.
Updated the testsuite.
Modified: grass/trunk/lib/raster3d/raster3d_intern.h
===================================================================
--- grass/trunk/lib/raster3d/raster3d_intern.h 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/raster3d_intern.h 2014-07-20 16:03:02 UTC (rev 61287)
@@ -1,3 +1,6 @@
+#ifndef RASTER3D_INTERN_H
+#define RASTER3D_INTERN_H
+
#include <grass/raster3d.h>
#include <grass/gis.h>
@@ -77,3 +80,43 @@
#define RASTER3D_REGION_EWRES "e-w resol"
#define RASTER3D_REGION_NSRES "n-s resol"
#define RASTER3D_REGION_TBRES "t-b resol"
+
+/* Coordinates to index conversion will return double.
+ * Use floor() and integer casting to receive col,row and depth
+ *
+ * double cold = EASTERN_TO_COL(east, region)
+ * int col = (int)floor(cold)
+ *
+ */
+#define EASTERN_TO_COL(east, region) (east - region->west) / (region->ew_res);
+#define NORTHERN_TO_ROW(north, region) (region->north - north) / (region->ns_res);
+#define TOP_TO_DEPTH(top, region) (top - region->bottom) / (region->tb_res);
+/* Location coordinates to index coordinates
+ * region is a pointer to the RASTER3D_Region structure
+ * north, east and top are double values
+ * x, y, and z are pointer to double values
+ */
+#define LOCATION_TO_COORD(region, north, east, top, x, y, z) \
+ { \
+ *x = EASTERN_TO_COL(east, region) \
+ *y = NORTHERN_TO_ROW(north, region) \
+ *z = TOP_TO_DEPTH(top, region) \
+ }
+
+/* Row to north, col to east and depth to top macros
+ * region is a pointer to the RASTER3D_Region structure
+ * north, east and top are pointer to double values,
+ * x, y and z are double values
+ */
+#define COL_TO_EASTERN(region, x) region->west + x * region->ew_res;
+#define ROW_TO_NORTHERN(region, y) region->north - y * region->ns_res;
+#define DEPTH_TO_TOP(region, z) region->bottom + z * region->tb_res;
+#define COORD_TO_LOCATION(region, x, y, z, north, east, top) \
+ { \
+ *east = COL_TO_EASTERN(region, x) \
+ *north = ROW_TO_NORTHERN(region, y) \
+ *top = DEPTH_TO_TOP(region, z) \
+ }
+
+
+#endif
Modified: grass/trunk/lib/raster3d/region.c
===================================================================
--- grass/trunk/lib/raster3d/region.c 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/region.c 2014-07-20 16:03:02 UTC (rev 61287)
@@ -1,11 +1,10 @@
#include <stdio.h>
+#include <math.h>
-#include <grass/gis.h>
#include <grass/raster.h>
-#include <grass/raster3d.h>
-
#include "raster3d_intern.h"
+
/*---------------------------------------------------------------------------*/
@@ -254,7 +253,7 @@
* Returns 1 if region-coordinates <em>(north, east, top)</em> are
* inside the region of <em>map</em>. Returns 0 otherwise.
*
- * \param REgion
+ * \param region
* \param north
* \param east
* \param top
@@ -277,7 +276,7 @@
* Converts region-coordinates <em>(north, east,
* top)</em> into cell-coordinates <em>(x, y, z)</em>.
*
- * \param map
+ * \param region
* \param north
* \param east
* \param top
@@ -292,12 +291,11 @@
int *x, int *y, int *z)
{
double col, row, depth;
+ LOCATION_TO_COORD(region, north, east, top, &col, &row, &depth);
- Rast3d_location2coord_double(region, north, east, top, &col, &row, &depth);
-
- *x = (int)col;
- *y = (int)row;
- *z = (int)depth;
+ *x = (int)floor(col);
+ *y = (int)floor(row);
+ *z = (int)floor(depth);
}
/*!
@@ -309,7 +307,7 @@
* <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 region
* \param north
* \param east
* \param top
@@ -323,12 +321,8 @@
Rast3d_location2coord_double(RASTER3D_Region *region, double north, double east, double top,
double *x, double *y, double *z)
{
- double row;
+ LOCATION_TO_COORD(region, north, east, top, x, y, z);
- *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);
}
@@ -339,7 +333,7 @@
* top)</em> into cell-coordinates <em>(x, y, z)</em>.
* This function calls Rast3d_fatal_error in case location is not in window.
*
- * \param map
+ * \param region
* \param north
* \param east
* \param top
@@ -356,7 +350,12 @@
if (!Rast3d_is_valid_location(region, north, east, top))
Rast3d_fatal_error("Rast3d_location2coord2: location not in region");
- Rast3d_location2coord(region, north, east, top, x, y, z);
+ double col, row, depth;
+ LOCATION_TO_COORD(region, north, east, top, &col, &row, &depth);
+
+ *x = (int)floor(col);
+ *y = (int)floor(row);
+ *z = (int)floor(depth);
}
/*!
@@ -379,8 +378,7 @@
* - z+1.0 will return the top for the upper edge of the column.
*
*
- *
- * \param map
+ * \param region
* \param x
* \param y
* \param z
@@ -393,9 +391,7 @@
void
Rast3d_coord2location(RASTER3D_Region * region, double x, double y, double z, double *north, double *east, double *top)
{
- *north = region->north - y * region->ns_res;
- *east = region->west + x * region->ew_res;
- *top = region->bottom + z * region->tb_res;
+ COORD_TO_LOCATION(region, x, y, z, north, east, top);
G_debug(4, "Rast3d_coord2location north %g east %g top %g\n", *north, *east, *top);
}
Modified: grass/trunk/lib/raster3d/test/test_main.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_main.c 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/test/test_main.c 2014-07-20 16:03:02 UTC (rev 61287)
@@ -42,14 +42,6 @@
param.unit->options = "coord,putget,large";
param.unit->description = "Choose the unit tests to run";
-/* No integration test for now
- param.integration = G_define_option();
- param.integration->key = "integration";
- param.integration->type = TYPE_STRING;
- param.integration->required = NO;
- param.integration->options = "";
- param.integration->description = "Choose the integration tests to run";
-*/
param.depths = G_define_option();
param.depths->key = "depths";
param.depths->type = TYPE_INTEGER;
@@ -103,6 +95,7 @@
module = G_define_module();
module->description
= "Performs unit and integration tests for the raster3d library";
+ G_add_keyword(_("raster3d"));
G_add_keyword(_("test"));
Modified: grass/trunk/lib/raster3d/test/test_put_get_value.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_put_get_value.c 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/test/test_put_get_value.c 2014-07-20 16:03:02 UTC (rev 61287)
@@ -37,8 +37,8 @@
G_message("\n++ Running raster3d put/get value unit tests ++");
- //sum += test_put_get_value_dcell();
- //sum += test_put_get_value_fcell();
+ sum += test_put_get_value_dcell();
+ sum += test_put_get_value_fcell();
sum += test_put_get_value_resampling();
@@ -107,6 +107,15 @@
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++) {
+ value = -1;
+ Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+ }
+ }
+ }
+
+ 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++) {
/* Add cols, rows and depths and put this in the map */
value = x + y + z;
Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
@@ -114,19 +123,14 @@
}
}
- /* Write everything to the disk */
- Rast3d_flush_all_tiles(map);
- Rast3d_close(map);
- map = Rast3d_open_cell_old("test_put_get_value_dcell", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
+ /* Reread the new open map and compare the expected results */
- /* 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 */
+ north = region.north - region.ns_res * row;
east = region.west + region.ew_res * col;
top = region.bottom + region.tb_res * depth;
@@ -153,6 +157,13 @@
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
+
+ /* Write everything to the disk and reopen the map */
+ Rast3d_flush_all_tiles(map);
+ Rast3d_close(map);
+ map = Rast3d_open_cell_old("test_put_get_value_dcell", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
+
+
G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z = 27");
col = 9;
Modified: grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c 2014-07-20 16:03:02 UTC (rev 61287)
@@ -36,12 +36,12 @@
G_message("\n++ Running raster3d put/get value large file unit tests ++");
+ sum += test_large_file(depths, rows, cols, tile_size);
sum += test_large_file_random(depths, rows, cols, tile_size);
sum += test_large_file_sparse_random(depths, rows, cols, tile_size);
sum += test_large_file(depths, rows, cols, tile_size);
+ sum += test_large_file_zeros(depths, rows, cols, tile_size);
sum += test_large_file(depths, rows, cols, tile_size);
- sum += test_large_file(depths, rows, cols, tile_size);
- sum += test_large_file_zeros(depths, rows, cols, tile_size);
if (sum > 0)
@@ -57,7 +57,7 @@
int test_large_file(int depths, int rows, int cols, int tile_size)
{
int sum = 0;
- int x, y, z;
+ int x, y, z, count;
DCELL value;
G_message("Testing DCELL put function for large files");
@@ -89,12 +89,28 @@
/* The window is the same as the map region ... of course */
Rast3d_set_window_map(map, ®ion);
- int count = 1;
+ /*Write -1 first to see if the tile handling works correctly */
for(z = 0; z < region.depths; z++) {
G_percent(z, region.depths, 1);
for(y = 0; y < region.rows; y++) {
for(x = 0; x < region.cols; x++) {
/* Put the counter as cell value */
+ value = -1;
+ Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+ }
+ }
+ }
+
+ G_percent(1, 1, 1);
+ G_message("Rewriting the values");
+
+ /* Now write the values to be evaluated */
+ count = 1;
+ for(z = 0; z < region.depths; z++) {
+ G_percent(z, region.depths, 1);
+ for(y = 0; y < region.rows; y++) {
+ for(x = 0; x < region.cols; x++) {
+ /* Put the counter as cell value */
value = count;
Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
count++;
@@ -103,15 +119,9 @@
}
G_percent(1, 1, 1);
- /* Write everything to the disk */
- Rast3d_flush_all_tiles(map);
- Rast3d_close(map);
G_message("Verifying 3D raster map");
- map = Rast3d_open_cell_old("test_put_get_value_dcell_large",
- G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
-
count = 1;
for(z = 0; z < region.depths; z++) {
G_percent(z, region.depths, 1);
Modified: grass/trunk/lib/raster3d/testsuite/raster3d_lib_test.py
===================================================================
--- grass/trunk/lib/raster3d/testsuite/raster3d_lib_test.py 2014-07-20 15:59:12 UTC (rev 61286)
+++ grass/trunk/lib/raster3d/testsuite/raster3d_lib_test.py 2014-07-20 16:03:02 UTC (rev 61287)
@@ -26,6 +26,7 @@
self.assertModule("test.raster3d.lib", unit="large", depths=91, rows=89, cols=87, tile_size=1024)
self.assertModule("test.raster3d.lib", unit="large", depths=91, rows=89, cols=87, tile_size=32768)
+ # Enable zlib compression
self.assertModule("test.raster3d.lib", flags="l", unit="large", depths=91, rows=89, cols=87)
self.assertModule("test.raster3d.lib", flags="l", unit="large", depths=91, rows=89, cols=87, tile_size=8)
self.assertModule("test.raster3d.lib", flags="l", unit="large", depths=91, rows=89, cols=87, tile_size=512)
More information about the grass-commit
mailing list