PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_pixel_set_to_array()

static void test_pixel_set_to_array ( )
static

Definition at line 370 of file cu_band_misc.c.

370  {
371  rt_raster rast;
372  rt_band band;
373  rt_mask mask = NULL;
374  int x, y;
375  int rtn;
376  const int maxX = 10;
377  const int maxY = 10;
378  int maskX = 3;
379  int maskY = 3;
380  rt_pixel npixels = NULL;
381  int i;
382  double **value;
383  double val;
384  int nod;
385  int **nodata;
386  int dimx;
387  int dimy;
388 
389  rast = rt_raster_new(maxX, maxY);
390  CU_ASSERT(rast != NULL);
391 
392  band = cu_add_band(rast, PT_32BF, 1, 0);
393  CU_ASSERT(band != NULL);
394 
395  for (x = 0; x < maxX; x++) {
396  for (y = 0; y < maxY; y++) {
397  rtn = rt_band_set_pixel(band, x, y, 1, NULL);
398  }
399  }
400 
401 
402  rtn = rt_band_get_pixel(band,4,4,&val,&nod);
403  CU_ASSERT_EQUAL(nod,0);
404  CU_ASSERT_DOUBLE_EQUAL(val,1,.01);
405 
406  /* set up mask */
407 
408  mask = (rt_mask) rtalloc(sizeof(struct rt_mask_t) );
409  CU_ASSERT(mask != NULL);
410  mask->values = rtalloc(sizeof(double*)*maskY);
411  mask->nodata = rtalloc(sizeof(int*)*maskY);
412 
413  for( i = 0; i < maskY; i++) {
414  mask->values[i] = rtalloc(sizeof(double) *maskX);
415  mask->nodata[i] = rtalloc(sizeof(int) *maskX);
416  }
417 
418  CU_ASSERT(mask->values != NULL);
419  CU_ASSERT(mask->nodata != NULL);
420 
421  /* set mask to nodata */
422 
423  for(y = 0; y < maskY; y++) {
424  for(x = 0; x < maskX; x++){
425  mask->values[y][x]= 0;
426  mask->nodata[y][x]= 1;
427  }
428  }
429 
430  mask->dimx = maskX;
431  mask->dimy = maskY;
432  mask->weighted = 0;
433 
435  band,
436  4,4,
437  1, 1,
438  1,
439  &npixels
440  );
441 
442  CU_ASSERT_EQUAL(rtn,8);
443 
444  rtn = rt_pixel_set_to_array(
445  npixels, rtn, mask,
446  4,4,
447  1, 1,
448  &value,
449  &nodata,
450  &dimx, &dimy
451  );
452 
453 
454  rtdealloc(npixels);
455  CU_ASSERT_EQUAL(rtn, ES_NONE);
456  CU_ASSERT_EQUAL(dimx, 3);
457  CU_ASSERT_EQUAL(dimy, 3);
458  CU_ASSERT_EQUAL(nodata[1][1],1);
459 
460  for (x = 0; x < dimx; x++) {
461  rtdealloc(nodata[x]);
462  rtdealloc(value[x]);
463  }
464 
465  rtdealloc(nodata);
466  rtdealloc(value);
467 
468  /* set mask to 1 */
469 
470  for(y = 0; y < maskY; y++) {
471  for(x = 0; x < maskX; x++){
472  mask->values[y][x]= 1;
473  mask->nodata[y][x]= 0;
474  }
475  }
476 
477  mask->dimx = maskX;
478  mask->dimy = maskY;
479  mask->weighted = 0;
480 
481 
483  band,
484  4,4,
485  1, 1,
486  1,
487  &npixels
488  );
489 
490  CU_ASSERT_EQUAL(rtn,8);
491 
492  rtn = rt_pixel_set_to_array(
493  npixels, rtn, mask,
494  4,4,
495  1, 1,
496  &value,
497  &nodata,
498  &dimx, &dimy
499  );
500 
501 
502  rtdealloc(npixels);
503  CU_ASSERT_EQUAL(rtn, ES_NONE);
504  CU_ASSERT_EQUAL(dimx, 3);
505  CU_ASSERT_EQUAL(dimy, 3);
506  CU_ASSERT_NOT_EQUAL(nodata[0][0],1);
507  CU_ASSERT_DOUBLE_EQUAL(value[0][0],1,.01);
508 
509  for (x = 0; x < dimx; x++) {
510  rtdealloc(nodata[x]);
511  rtdealloc(value[x]);
512  }
513 
514  rtdealloc(nodata);
515  rtdealloc(value);
516 
517  /* set mask to 0.5 */
518 
519  for(y = 0; y < maskY; y++) {
520  for(x = 0; x < maskX; x++){
521  mask->values[y][x]= 0.5;
522  mask->nodata[y][x]= 0;
523  }
524  }
525 
526  mask->dimx = maskX;
527  mask->dimy = maskY;
528  mask->weighted = 1;
529 
531  band,
532  4,4,
533  1, 1,
534  1,
535  &npixels
536  );
537 
538  CU_ASSERT_EQUAL(rtn,8);
539 
540  rtn = rt_pixel_set_to_array(
541  npixels, rtn, mask,
542  4,4,
543  1, 1,
544  &value,
545  &nodata,
546  &dimx, &dimy
547  );
548 
549 
550  rtdealloc(npixels);
551  CU_ASSERT_EQUAL(rtn, ES_NONE);
552  CU_ASSERT_EQUAL(dimx, 3);
553  CU_ASSERT_EQUAL(dimy, 3);
554  CU_ASSERT_NOT_EQUAL(nodata[0][0],1);
555  CU_ASSERT_DOUBLE_EQUAL(value[0][0],0.5,0.1);
556 
557  for (x = 0; x < dimx; x++) {
558  rtdealloc(nodata[x]);
559  rtdealloc(value[x]);
560  }
561 
562  rtdealloc(nodata);
563  rtdealloc(value);
564 
565  for( i = 0; i < maskY; i++) {
566  rtdealloc(mask->values[i]);
567  rtdealloc(mask->nodata[i]);
568  }
569 
570  rtdealloc(mask->values);
571  rtdealloc(mask->nodata);
572  rtdealloc(mask);
573 
574  if (rtn)
575  rtdealloc(npixels);
576 
578 
579 }
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1221
struct rt_mask_t * rt_mask
Definition: librtcore.h:148
@ PT_32BF
Definition: librtcore.h:195
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:974
@ ES_NONE
Definition: librtcore.h:180
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_pixel.c:286
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition: rt_band.c:1374
void rtdealloc(void *mem)
Definition: rt_context.c:186
int value
Definition: genraster.py:61
band
Definition: ovdump.py:57
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)
double ** values
Definition: librtcore.h:2346
uint16_t dimy
Definition: librtcore.h:2345
uint16_t dimx
Definition: librtcore.h:2344
int ** nodata
Definition: librtcore.h:2347
int weighted
Definition: librtcore.h:2348

References ovdump::band, cu_add_band(), cu_free_raster(), rt_mask_t::dimx, rt_mask_t::dimy, ES_NONE, rt_mask_t::nodata, PT_32BF, rtpixdump::rast, rt_band_get_nearest_pixel(), rt_band_get_pixel(), rt_band_set_pixel(), rt_pixel_set_to_array(), rt_raster_new(), rtalloc(), rtdealloc(), genraster::value, rt_mask_t::values, rt_mask_t::weighted, pixval::x, and pixval::y.

Referenced by band_misc_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: