2
/*****************************************************************************
4
* MODULE: Grass raster3d Library
5
* AUTHOR(S): Soeren Gebbert, Braunschweig (GER) Jun 2011
6
* soerengebbert <at> googlemail <dot> com
8
* PURPOSE: Unit and Integration tests
10
* COPYRIGHT: (C) 2000 by the GRASS Development Team
12
* This program is free software under the GNU General Public
13
* License (>=v2). Read the file COPYING that comes with GRASS
16
*****************************************************************************/
19
#include "test_raster3d_lib.h"
20
#include "grass/interpf.h"
22
static int test_put_get_value_dcell(void);
23
static int test_put_get_value_fcell(void);
24
static int test_put_get_value_resampling(void);
25
static int test_get_value_region(RASTER3D_Map *map, int cols, int rows, int depths);
26
static int test_resampling_dcell(RASTER3D_Map *map, double north, double east, double
27
top, int col, int row, int depth, int fact);
28
static int test_resampling_fcell(RASTER3D_Map *map, double north, double east, double
29
top, int col, int row, int depth, int fact);
31
/* *************************************************************** */
32
/* Perform the put-get value tests ******************************* */
33
/* *************************************************************** */
34
int unit_test_put_get_value()
38
G_message("\n++ Running raster3d put/get value unit tests ++");
40
sum += test_put_get_value_dcell();
41
sum += test_put_get_value_fcell();
42
sum += test_put_get_value_resampling();
46
G_warning("\n-- raster3d put/get value unit tests failure --");
48
G_message("\n-- raster3d put/get value unit tests finished successfully --");
53
/* *************************************************************** */
55
int test_put_get_value_dcell(void)
62
G_message("Testing DCELL put get value functions");
64
double north, east, top;
67
RASTER3D_Region region;
68
RASTER3D_Map *map = NULL;
70
/* We need to set up a specific region for the new raster3d map.
71
* First we safe the default region. */
72
Rast3d_get_window(®ion);
84
Rast3d_adjust_region(®ion);
86
map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, 32);
88
/* The window is the same as the map region ... of course */
89
Rast3d_set_window_map(map, ®ion);
92
1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 north
93
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
94
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 region
97
5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 east
98
|....|....|....|....|....|....|....|....|....|....|
99
0 1 2 3 4 5 6 7 8 9 10 region
102
0 200 400 600 800 1000 top
103
|....|....|....|....|....|
107
for(z = 0; z < region.depths; z++) {
108
for(y = 0; y < region.rows; y++) { /* From the north to the south */
109
for(x = 0; x < region.cols; x++) {
111
Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
116
for(z = 0; z < region.depths; z++) {
117
for(y = 0; y < region.rows; y++) { /* From the north to the south */
118
for(x = 0; x < region.cols; x++) {
119
/* Add cols, rows and depths and put this in the map */
121
Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
127
/* Reread the new open map and compare the expected results */
129
G_message("Get the value of the upper left corner -> 0");
132
col = row = depth = 0;
133
north = region.north - region.ns_res * row;
134
east = region.west + region.ew_res * col;
135
top = region.bottom + region.tb_res * depth;
137
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
140
G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
142
col = row = depth = 1;
143
north = region.north - region.ns_res * row;
144
east = region.west + region.ew_res * col;
145
top = region.bottom + region.tb_res * depth;
147
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
149
G_message("Get the value of x == 4 y == 3 z == 2 -> x + y + z = 9");
154
north = region.north - region.ns_res * row;
155
east = region.west + region.ew_res * col;
156
top = region.bottom + region.tb_res * depth;
158
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
161
/* Write everything to the disk and reopen the map */
162
Rast3d_flush_all_tiles(map);
164
map = Rast3d_open_cell_old("test_put_get_value_dcell", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
167
G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z = 27");
172
north = region.north - region.ns_res * row;
173
east = region.west + region.ew_res * col;
174
top = region.bottom + region.tb_res * depth;
176
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 1);
178
G_message("Get the value of x == 10 y == 15 z == 5 -> x + y + z = NAN");
183
north = region.north - region.ns_res * row;
184
east = region.west + region.ew_res * col;
185
top = region.bottom + region.tb_res * depth;
187
Rast3d_get_region_value(map, north, east, top, &value, DCELL_TYPE);
188
Rast3d_get_value(map, col, row, depth, &value_ref, DCELL_TYPE);
189
/* Rast3d_get_value_region does not work with coordinates outside the region */
190
printf("Value %g == %g\n", value, value_ref);
192
if(value == 0 || value < 0 || value > 0) {
193
G_message("Error in Rast3d_get_region_value");
196
if(value_ref == 0 || value_ref < 0 || value_ref > 0) {
197
G_message("Error in Rast3d_get_value");
203
G_remove("grid3", "test_put_get_value_dcell");
208
/* *************************************************************** */
210
int test_put_get_value_fcell(void)
217
G_message("Testing FCELL put get value functions");
219
double north, east, top;
222
RASTER3D_Region region;
223
RASTER3D_Map *map = NULL;
225
/* We need to set up a specific region for the new raster3d map.
226
* First we safe the default region. */
227
Rast3d_get_window(®ion);
239
Rast3d_adjust_region(®ion);
241
map = Rast3d_open_new_opt_tile_size("test_put_get_value_fcell", RASTER3D_USE_CACHE_XY, ®ion, FCELL_TYPE, 32);
243
/* The window is the same as the map region ... of course */
244
Rast3d_set_window_map(map, ®ion);
246
for(z = 0; z < region.depths; z++) {
247
for(y = 0; y < region.rows; y++) {
248
for(x = 0; x < region.cols; x++) {
249
/* Add cols, rows and depths and put this in the map */
251
Rast3d_put_value(map, x, y, z, &value, FCELL_TYPE);
256
/* Write everything to the disk */
257
Rast3d_flush_all_tiles(map);
260
map = Rast3d_open_cell_old("test_put_get_value_fcell", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
262
/* Reread the map and compare the expected results */
264
G_message("Get the value of the lower left corner -> 0");
266
col = row = depth = 0;
267
north = region.north - region.ns_res * row;
268
east = region.west + region.ew_res * col;
269
top = region.bottom + region.tb_res * depth;
271
sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
273
G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
275
col = row = depth = 1;
276
north = region.north - region.ns_res * row;
277
east = region.west + region.ew_res * col;
278
top = region.bottom + region.tb_res * depth;
280
sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
282
G_message("Get the value of x == 4 y == 3 z == 2 -> x + y + z = 9");
287
north = region.north - region.ns_res * row;
288
east = region.west + region.ew_res * col;
289
top = region.bottom + region.tb_res * depth;
291
sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
293
G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z = 27");
298
north = region.north - region.ns_res * row;
299
east = region.west + region.ew_res * col;
300
top = region.bottom + region.tb_res * depth;
302
sum += test_resampling_fcell(map, north, east, top, col, row, depth, 1);
304
G_message("Get the value of x == 10 y == 15 z == 5 -> x + y + z = NAN");
309
north = region.north - region.ns_res * row;
310
east = region.west + region.ew_res * col;
311
top = region.bottom + region.tb_res * depth;
313
Rast3d_get_region_value(map, north, east, top, &value, FCELL_TYPE);
314
Rast3d_get_value(map, 10, 15, 5, &value_ref, FCELL_TYPE);
315
/* Rast3d_get_value_region does not work with coordinates outside the region */
316
printf("Value %g == %g\n", value, value_ref);
318
if(value == 0 || value < 0 || value > 0) {
319
G_message("Error in Rast3d_get_region_value");
322
if(value_ref == 0 || value_ref < 0 || value_ref > 0) {
323
G_message("Error in Rast3d_get_value");
329
G_remove("grid3", "test_put_get_value_fcell");
334
/* *************************************************************** */
336
int test_put_get_value_resampling(void)
342
G_message("Testing put get resample value functions");
344
double north, east, top;
347
RASTER3D_Region region;
348
RASTER3D_Region window;
349
RASTER3D_Map *map = NULL;
351
/* We need to set up a specific region for the new raster3d map.
352
* First we safe the default region. */
353
Rast3d_get_window(®ion);
365
Rast3d_adjust_region(®ion);
367
map = Rast3d_open_new_opt_tile_size("test_put_get_value_resample", RASTER3D_USE_CACHE_XY, ®ion, DCELL_TYPE, 32);
370
1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 north
371
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
372
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 region
373
| | | | | | | | | | | | | | | |
374
30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 window
377
5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 east
378
|....|....|....|....|....|....|....|....|....|....|
379
0 1 2 3 4 5 6 7 8 9 10 region
380
| | | | | | | | | | |
381
0 2 4 6 8 10 12 14 16 18 20 window
383
0 200 400 600 800 1000 top
384
|....|....|....|....|....|
390
for(z = 0; z < region.depths; z++) {
391
for(y = 0; y < region.rows; y++) { /* North to south */
392
for(x = 0; x < region.cols; x++) {
393
/* Add cols, rows and depths and put this in the map */
395
Rast3d_put_double(map, x, y, z, value);
400
/* Write everything to the disk */
401
Rast3d_flush_all_tiles(map);
404
/* We modify the window for resampling tests */
405
Rast3d_region_copy(&window, ®ion);
407
/* Double the cols, rows and depths -> 8x resolution window */
412
Rast3d_adjust_region(&window);
414
map = Rast3d_open_cell_old("test_put_get_value_resample", G_mapset(), ®ion, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
416
/* The window has the 8x resolution as the map region */
417
Rast3d_set_window_map(map, &window);
419
/* Reread the map and compare the expected results */
421
G_message("Get the value of the upper left corner -> 0");
423
col = row = depth = 0;
424
north = region.north - region.ns_res * row;
425
east = region.west + region.ew_res * col;
426
top = region.bottom + region.tb_res * depth;
428
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
430
G_message("Get the value of x == y == z == 1 -> x + y + z == 3");
433
col = row = depth = 1;
434
north = region.north - region.ns_res * row;
435
east = region.west + region.ew_res * col;
436
top = region.bottom + region.tb_res * depth;
438
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
440
G_message("Get the value of x == 7 y == 9 z == 3 -> x + y + z == 19");
445
north = region.north - region.ns_res * row;
446
east = region.west + region.ew_res * col;
447
top = region.bottom + region.tb_res * depth;
449
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
451
G_message("Get the value of x == 9 y == 14 z == 4 -> x + y + z == 27");
456
north = region.north - region.ns_res * row;
457
east = region.west + region.ew_res * col;
458
top = region.bottom + region.tb_res * depth;
460
sum += test_resampling_dcell(map, north, east, top, col, row, depth, 2);
462
sum += test_get_value_region(map, region.cols, region.rows, region.depths);
466
G_remove("grid3", "test_put_get_value_resample");
471
/* *************************************************************** */
473
int test_resampling_dcell(RASTER3D_Map *map, double north, double east, double top, int col, int row, int depth, int fact)
481
Rast3d_get_region_value(map, north, east, top, &value, DCELL_TYPE);
482
Rast3d_get_window_value(map, north, east, top, &value_win, DCELL_TYPE);
483
Rast3d_get_value(map, col * fact, row * fact, depth * fact, &value_ref, DCELL_TYPE);
484
Rast3d_get_value_region(map, col, row, depth, &value_reg, DCELL_TYPE);
485
printf("Value %g == %g == %g == %g\n", value, value_win, value_ref, value_reg);
487
if(value != col + row + depth) {
488
G_message("Error in Rast3d_get_region_value");
491
if(value_win != col + row + depth) {
492
G_message("Error in Rast3d_get_window_value");
495
if(value_ref != col + row + depth) {
496
G_message("Error in Rast3d_get_value");
499
if(value_reg != col + row + depth) {
500
G_message("Error in Rast3d_get_value_region");
507
/* *************************************************************** */
509
int test_resampling_fcell(RASTER3D_Map *map, double north, double east, double top, int col, int row, int depth, int fact)
517
Rast3d_get_region_value(map, north, east, top, &value, FCELL_TYPE);
518
Rast3d_get_window_value(map, north, east, top, &value_win, FCELL_TYPE);
519
Rast3d_get_value(map, col * fact, row * fact, depth * fact, &value_ref, FCELL_TYPE);
520
Rast3d_get_value_region(map, col, row, depth, &value_reg, FCELL_TYPE);
521
printf("Value %g == %g == %g == %g\n", value, value_win, value_ref, value_reg);
523
if(value != col + row + depth) {
524
G_message("Error in Rast3d_get_region_value");
527
if(value_win != col + row + depth) {
528
G_message("Error in Rast3d_get_window_value");
531
if(value_ref != col + row + depth) {
532
G_message("Error in Rast3d_get_value");
535
if(value_reg != col + row + depth) {
536
G_message("Error in Rast3d_get_value_region");
543
/* *************************************************************** */
545
int test_get_value_region(RASTER3D_Map *map, int cols, int rows, int depths)
553
/* Test for correct Null value */
554
Rast3d_get_value_region(map, -1, -1, -1, &fvalue1, FCELL_TYPE);
555
Rast3d_get_value_region(map, cols, rows, depths, &fvalue2, FCELL_TYPE);
556
Rast3d_get_value_region(map, -1, -1, -1, &dvalue1, DCELL_TYPE);
557
Rast3d_get_value_region(map, cols, rows, depths, &dvalue2, DCELL_TYPE);
558
printf("Value %g == %g == %g == %g\n", fvalue1, fvalue2, dvalue1, dvalue2);
560
if(!Rast_is_f_null_value(&fvalue1)) {
561
G_message("Error in Rast3d_get_value_region");
564
if(!Rast_is_f_null_value(&fvalue2)) {
565
G_message("Error in Rast3d_get_value_region");
568
if(!Rast_is_d_null_value(&dvalue1)) {
569
G_message("Error in Rast3d_get_value_region");
572
if(!Rast_is_d_null_value(&dvalue2)) {
573
G_message("Error in Rast3d_get_value_region");