|
@@ -20,6 +20,7 @@
|
|
|
#include "grass/interpf.h"
|
|
|
|
|
|
#define EPSILON 0.000000001
|
|
|
+#define RAND_VALUE_VECTOR_SIZE 1000
|
|
|
|
|
|
static int test_large_file(int depths, int rows, int cols, int tile_size);
|
|
|
static int test_large_file_zeros(int depths, int rows, int cols, int tile_size);
|
|
@@ -35,10 +36,12 @@ int unit_test_put_get_value_large_file(int depths, int rows, int cols, int tile_
|
|
|
|
|
|
G_message(_("\n++ Running g3d put/get value large file unit tests ++"));
|
|
|
|
|
|
- sum += test_large_file(depths, rows, cols, tile_size);
|
|
|
- sum += test_large_file_zeros(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(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)
|
|
@@ -80,7 +83,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Creating 3D raster map");
|
|
|
|
|
|
- map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
+ map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large",
|
|
|
+ RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
|
|
|
/* The window is the same as the map region ... of course */
|
|
|
Rast3d_set_window_map(map, ®ion);
|
|
@@ -105,7 +109,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
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);
|
|
|
+ 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++) {
|
|
@@ -115,7 +120,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
|
|
|
/* Check the counter as cell value */
|
|
|
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
if(fabs(value - (double)(count) > EPSILON)) {
|
|
|
- G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, (double)(count));
|
|
|
+ G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
|
|
|
+ z, y, x, value, (double)(count));
|
|
|
sum++;
|
|
|
}
|
|
|
count++;
|
|
@@ -125,7 +131,7 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
|
|
|
G_percent(1, 1, 1);
|
|
|
Rast3d_close(map);
|
|
|
|
|
|
- //G_remove("grid3", "test_put_get_value_dcell_large");
|
|
|
+ G_remove("grid3", "test_put_get_value_dcell_large");
|
|
|
|
|
|
return sum;
|
|
|
}
|
|
@@ -162,7 +168,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Creating 3D raster map filled with zeros");
|
|
|
|
|
|
- map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_zeros", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
+ map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_zeros",
|
|
|
+ RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
|
|
|
/* The window is the same as the map region ... of course */
|
|
|
Rast3d_set_window_map(map, ®ion);
|
|
@@ -185,7 +192,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Verifying 3D raster map filled with zeros");
|
|
|
|
|
|
- map = Rast3d_open_cell_old("test_put_get_value_dcell_large_zeros", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
|
|
|
+ map = Rast3d_open_cell_old("test_put_get_value_dcell_large_zeros",
|
|
|
+ G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
|
|
|
|
|
|
for(z = 0; z < region.depths; z++) {
|
|
|
G_percent(z, region.depths, 1);
|
|
@@ -194,7 +202,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
|
|
|
/* Check the counter as cell value */
|
|
|
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
if(value > EPSILON) {
|
|
|
- G_message("At: z %i y %i x %i -- value %.14lf != 0.0\n", z, y, x, value);
|
|
|
+ G_message("At: z %i y %i x %i -- value %.14lf != 0.0\n",
|
|
|
+ z, y, x, value);
|
|
|
sum++;
|
|
|
}
|
|
|
}
|
|
@@ -203,7 +212,7 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
|
|
|
G_percent(1, 1, 1);
|
|
|
Rast3d_close(map);
|
|
|
|
|
|
- //G_remove("grid3", "test_put_get_value_dcell_large_zeros");
|
|
|
+ G_remove("grid3", "test_put_get_value_dcell_large_zeros");
|
|
|
|
|
|
return sum;
|
|
|
}
|
|
@@ -213,8 +222,10 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
|
|
|
int test_large_file_random(int depths, int rows, int cols, int tile_size)
|
|
|
{
|
|
|
int sum = 0;
|
|
|
- int x, y, z;
|
|
|
- DCELL value, radnom_value;
|
|
|
+ int x, y, z, i;
|
|
|
+ DCELL value, random_value;
|
|
|
+ DCELL *random_value_vector = G_calloc(RAND_VALUE_VECTOR_SIZE, sizeof(DCELL));
|
|
|
+
|
|
|
|
|
|
G_message("Testing DCELL put function for large files filled with random values");
|
|
|
|
|
@@ -239,20 +250,30 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Creating 3D raster map filled with random values");
|
|
|
|
|
|
- map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_random", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
+ map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_random",
|
|
|
+ RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
|
|
|
/* The window is the same as the map region ... of course */
|
|
|
Rast3d_set_window_map(map, ®ion);
|
|
|
|
|
|
srand(1);
|
|
|
+ /* We fill the random value vector */
|
|
|
+ for(i = 0; i < RAND_VALUE_VECTOR_SIZE; i++) {
|
|
|
+ random_value_vector[i] = (DCELL)rand();
|
|
|
+ }
|
|
|
+
|
|
|
+ i = 0;
|
|
|
|
|
|
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 = (double)rand();
|
|
|
+ value = random_value_vector[i];
|
|
|
Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
+ i++;
|
|
|
+ if(i == RAND_VALUE_VECTOR_SIZE)
|
|
|
+ i = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -264,9 +285,10 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Verifying 3D raster map filled with random values");
|
|
|
|
|
|
- map = Rast3d_open_cell_old("test_put_get_value_dcell_large_random", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
|
|
|
+ map = Rast3d_open_cell_old("test_put_get_value_dcell_large_random",
|
|
|
+ G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
|
|
|
|
|
|
- srand(1);
|
|
|
+ i = 0;
|
|
|
|
|
|
for(z = 0; z < region.depths; z++) {
|
|
|
G_percent(z, region.depths, 1);
|
|
@@ -274,18 +296,24 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
|
|
|
for(x = 0; x < region.cols; x++) {
|
|
|
/* Check the counter as cell value */
|
|
|
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
- radnom_value = (DCELL)rand();
|
|
|
- if(fabs(value - radnom_value) > EPSILON) {
|
|
|
- G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, radnom_value);
|
|
|
+ random_value = random_value_vector[i];
|
|
|
+ if(fabs(value - random_value) > EPSILON) {
|
|
|
+ G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
|
|
|
+ z, y, x, value, random_value);
|
|
|
sum++;
|
|
|
}
|
|
|
+ i++;
|
|
|
+ if(i == RAND_VALUE_VECTOR_SIZE)
|
|
|
+ i = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
G_percent(1, 1, 1);
|
|
|
Rast3d_close(map);
|
|
|
|
|
|
- //G_remove("grid3", "test_put_get_value_dcell_large_random");
|
|
|
+ G_free(random_value_vector);
|
|
|
+
|
|
|
+ G_remove("grid3", "test_put_get_value_dcell_large_random");
|
|
|
|
|
|
return sum;
|
|
|
}
|
|
@@ -295,8 +323,9 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
|
|
|
int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
|
|
|
{
|
|
|
int sum = 0;
|
|
|
- int x, y, z;
|
|
|
- DCELL value, radnom_value;
|
|
|
+ int x, y, z, i;
|
|
|
+ DCELL value, random_value;
|
|
|
+ DCELL *random_value_vector = G_calloc(RAND_VALUE_VECTOR_SIZE, sizeof(DCELL));
|
|
|
|
|
|
G_message("Testing DCELL put function for large files filled with sparse random values");
|
|
|
|
|
@@ -321,31 +350,44 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Creating 3D raster map filled with sparse random values");
|
|
|
|
|
|
- map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_sparse_random", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
+ map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_sparse_random",
|
|
|
+ RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, tile_size);
|
|
|
|
|
|
/* The window is the same as the map region ... of course */
|
|
|
Rast3d_set_window_map(map, ®ion);
|
|
|
|
|
|
srand(1);
|
|
|
|
|
|
+ /* We fill the random value vector */
|
|
|
+ for(i = 0; i < RAND_VALUE_VECTOR_SIZE; i++) {
|
|
|
+ /* Put the counter as cell value */
|
|
|
+ value = (DCELL)rand();
|
|
|
+ value /= RAND_MAX;
|
|
|
+ if(value <= 0.7)
|
|
|
+ value = 0.0;
|
|
|
+ else if(value <= 0.8)
|
|
|
+ value = 1.0;
|
|
|
+ else if(value <= 0.9)
|
|
|
+ value = 2.0;
|
|
|
+ else if(value <= 1.0)
|
|
|
+ value = 3.0;
|
|
|
+ else
|
|
|
+ value = 4.0;
|
|
|
+ random_value_vector[i] = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+
|
|
|
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 = (DCELL)rand();
|
|
|
- value /= RAND_MAX;
|
|
|
- if(value <= 0.7)
|
|
|
- value = 0.0;
|
|
|
- else if(value <= 0.8)
|
|
|
- value = 1.0;
|
|
|
- else if(value <= 0.9)
|
|
|
- value = 2.0;
|
|
|
- else if(value <= 1.0)
|
|
|
- value = 3.0;
|
|
|
- else
|
|
|
- value = 4.0;
|
|
|
- Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
+ /* Put the counter as cell value */
|
|
|
+ value = random_value_vector[i];
|
|
|
+ Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
+ i++;
|
|
|
+ if(i == RAND_VALUE_VECTOR_SIZE)
|
|
|
+ i = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -357,9 +399,10 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
|
|
|
|
|
|
G_message("Verifying 3D raster map filled with sparse random values");
|
|
|
|
|
|
- map = Rast3d_open_cell_old("test_put_get_value_dcell_large_sparse_random", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
|
|
|
+ map = Rast3d_open_cell_old("test_put_get_value_dcell_large_sparse_random",
|
|
|
+ G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
|
|
|
|
|
|
- srand(1);
|
|
|
+ i = 0;
|
|
|
|
|
|
for(z = 0; z < region.depths; z++) {
|
|
|
G_percent(z, region.depths, 1);
|
|
@@ -367,29 +410,23 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
|
|
|
for(x = 0; x < region.cols; x++) {
|
|
|
/* Check the counter as cell value */
|
|
|
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
|
|
|
- radnom_value = (DCELL)rand();
|
|
|
- radnom_value /= RAND_MAX;
|
|
|
- if(radnom_value <= 0.7)
|
|
|
- radnom_value = 0.0;
|
|
|
- else if(radnom_value <= 0.8)
|
|
|
- radnom_value = 1.0;
|
|
|
- else if(radnom_value <= 0.9)
|
|
|
- radnom_value = 2.0;
|
|
|
- else if(radnom_value <= 1.0)
|
|
|
- radnom_value = 3.0;
|
|
|
- else
|
|
|
- radnom_value = 4.0;
|
|
|
- if(fabs(value - radnom_value) > EPSILON) {
|
|
|
- G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, radnom_value);
|
|
|
+ if(fabs(value - random_value_vector[i]) > EPSILON) {
|
|
|
+ G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
|
|
|
+ z, y, x, value, random_value);
|
|
|
sum++;
|
|
|
}
|
|
|
+ i++;
|
|
|
+ if(i == RAND_VALUE_VECTOR_SIZE)
|
|
|
+ i = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
G_percent(1, 1, 1);
|
|
|
Rast3d_close(map);
|
|
|
|
|
|
- //G_remove("grid3", "test_put_get_value_dcell_large_sparse_random");
|
|
|
+ G_free(random_value_vector);
|
|
|
+
|
|
|
+ G_remove("grid3", "test_put_get_value_dcell_large_sparse_random");
|
|
|
|
|
|
return sum;
|
|
|
}
|