Debian Codegraph @

src/tests/utest_cdrizzle.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #include <math.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <Python.h>
6 #ifndef NPY_NO_DEPRECATED_API
7 #define NPY_NO_DEPRECATED_API NPY_1_21_API_VERSION
8 #endif
9
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wpedantic"
12 #include <numpy/arrayobject.h>
13 #include <numpy/npy_math.h>
14
15 #if !defined(__clang__) && defined(__GNUC__)
16 #pragma GCC diagnostic ignored "-Wstringop-truncation"
17 // too much work to check whether this is critical (Wmaybe-uninitialized).
18 // TODO: consider replacing fct.h with another test framework
19 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
20 #endif
21
22 #pragma GCC diagnostic ignored "-Wunused-function"
23
24 #ifdef WIN32
25 #include "cextern/fct.h"
26 #else
27 #include "pandokia_fct.h"
28 #endif
29
30 #pragma GCC diagnostic pop
31
32 #include "cdrizzlebox.h"
33 #include "cdrizzleblot.h"
34 #include "cdrizzlemap.h"
35 #include "cdrizzleutil.h"
36 #include "drizzletest.h"
37
38 FILE *logptr = NULL;
39 static integer_t image_size[2];
40 static PyArrayObject *test_data;
41 static PyArrayObject *test_weights;
42 static PyArrayObject *test_pixmap;
43 static PyArrayObject *test_output_data;
44 static PyArrayObject *test_output_counts;
45 static PyArrayObject *test_context;
46
47 static char log_file[] = "";
48
49 void
50 set_test_arrays(
51 PyArrayObject *dat, PyArrayObject *wei, PyArrayObject *map, PyArrayObject *odat,
52 PyArrayObject *ocnt, PyArrayObject *ocon)
53 {
54 test_data = dat;
55 test_weights = wei;
56 test_pixmap = map;
57 test_output_data = odat;
58 test_output_counts = ocnt;
59 test_context = ocon;
60
61 get_dimensions(test_data, image_size);
62 return;
63 }
64
65 void
66 set_pixmap(struct driz_param_t *p, int xmin, int xmax, int ymin, int ymax)
67 {
68 int i, j;
69 double xpix, ypix;
70
71 ypix = ymin;
72 for (j = ymin; j < ymax; j++) {
73 xpix = xmin;
74 for (i = xmin; i < xmax; i++) {
75 get_pixmap(p->pixmap, i, j)[0] = xpix;
76 get_pixmap(p->pixmap, i, j)[1] = ypix;
77 xpix += 1.0;
78 }
79 ypix += 1.0;
80 }
81
82 return;
83 }
84
85 void
86 init_pixmap(struct driz_param_t *p)
87 {
88 set_pixmap(p, 0, image_size[0], 0, image_size[1]);
89 return;
90 }
91
92 void
93 stretch_pixmap(struct driz_param_t *p, double sx, double sy)
94 {
95 int i, j;
96 double xpix, ypix;
97
98 ypix = 0.0;
99 for (j = 0; j < image_size[1]; j++) {
100 xpix = 0.0;
101 for (i = 0; i < image_size[0]; i++) {
102 get_pixmap(p->pixmap, i, j)[0] = sx * xpix;
103 get_pixmap(p->pixmap, i, j)[1] = sy * ypix;
104 xpix += 1.0;
105 }
106 ypix += 1.0;
107 }
108
109 return;
110 }
111
112 void
113 nan_pixmap(struct driz_param_t *p)
114 {
115 int i, j;
116
117 for (j = 0; j < image_size[1]; j++) {
118 for (i = 0; i < image_size[0]; i++) {
119 get_pixmap(p->pixmap, i, j)[0] = NPY_NAN;
120 get_pixmap(p->pixmap, i, j)[1] = NPY_NAN;
121 }
122 }
123
124 return;
125 }
126
127 void
128 nan_pixel(struct driz_param_t *p, int xpix, int ypix)
129 {
130 int idim;
131 for (idim = 0; idim < 2; ++idim) {
132 get_pixmap(p->pixmap, xpix, ypix)[idim] = NPY_NAN;
133 }
134 }
135
136 void
137 offset_pixmap(struct driz_param_t *p, double x_offset, double y_offset)
138 {
139 int i, j;
140 double xpix, ypix;
141
142 ypix = y_offset;
143 for (j = 0; j < image_size[1]; j++) {
144 xpix = x_offset;
145 for (i = 0; i < image_size[0]; i++) {
146 get_pixmap(p->pixmap, i, j)[0] = xpix;
147 get_pixmap(p->pixmap, i, j)[1] = ypix;
148 xpix += 1.0;
149 }
150 ypix += 1.0;
151 }
152
153 return;
154 }
155
156 void
157 fill_image(PyArrayObject *image, double value)
158 {
159 npy_intp *ndim = PyArray_DIMS(image);
160 int ypix, xpix;
161
162 for (ypix = 0; ypix < ndim[0]; ++ypix) {
163 for (xpix = 0; xpix < ndim[1]; ++xpix) {
164 set_pixel(image, xpix, ypix, value);
165 }
166 }
167
168 return;
169 }
170
171 void
172 fill_image_block(PyArrayObject *image, double value, int lo, int hi)
173 {
174 int ypix, xpix;
175
176 for (ypix = lo; ypix < hi; ++ypix) {
177 for (xpix = lo; xpix < hi; ++xpix) {
178 set_pixel(image, xpix, ypix, value);
179 }
180 }
181
182 return;
183 }
184 void
185 unset_context(PyArrayObject *context)
186 {
187 npy_intp *ndim = PyArray_DIMS(context);
188 int ypix, xpix;
189
190 for (ypix = 0; ypix < ndim[0]; ++ypix) {
191 for (xpix = 0; xpix < ndim[1]; ++xpix) {
192 unset_bit(context, xpix, ypix);
193 }
194 }
195
196 return;
197 }
198
199 void
200 print_image(char *title, PyArrayObject *image, int lo, int hi)
201 {
202 int j, i;
203
204 if (logptr) {
205 fprintf(logptr, "\n%s\n", title);
206 for (j = lo; j < hi; ++j) {
207 for (i = lo; i < hi; ++i) {
208 fprintf(logptr, "%10.2f", get_pixel(image, i, j));
209 }
210 fprintf(logptr, "\n");
211 }
212 }
213
214 return;
215 }
216
217 void
218 print_status(char *title)
219 {
220 if (logptr) {
221 fprintf(logptr, "%s\n", title);
222 }
223 }
224
225 void
226 print_context(char *title, struct driz_param_t *p, int lo, int hi)
227 {
228 int j, i;
229 integer_t bv;
230 if (!p->output_context) {
231 return;
232 }
233
234 if (logptr) {
235 bv = 1;
236 fprintf(logptr, "\n%s\n", title);
237
238 for (j = lo; j < hi; ++j) {
239 for (i = lo; i < hi; ++i) {
240 fprintf(logptr, "%4d", get_bit(p->output_context, i, j, bv));
241 }
242 fprintf(logptr, "\n");
243 }
244 }
245
246 return;
247 }
248
249 void
250 print_pixmap(char *title, struct driz_param_t *p, int lo, int hi)
251 {
252 int i, j, k;
253 char *axis[2] = {"x", "y"};
254
255 if (logptr) {
256 for (k = 0; k < 2; k++) {
257 fprintf(logptr, "\n%s %s axis\n", title, axis[k]);
258
259 for (j = 0; j < image_size[1]; j++) {
260 for (i = 0; i < image_size[0]; i++) {
261 if (i >= lo && i < hi && j >= lo && j < hi) {
262 fprintf(logptr, "%10.2f", get_pixmap(p->pixmap, i, j)[k]);
263 }
264 }
265
266 if (j >= lo && j < hi) {
267 fprintf(logptr, "\n");
268 }
269 }
270 }
271 }
272
273 return;
274 }
275
276 struct driz_param_t *
277 setup_parameters(void)
278 {
279 struct driz_error_t *error;
280
281 /* Initialize the parameter struct with vanilla defaults */
282
283 struct driz_param_t *p;
284 p = (struct driz_param_t *) malloc(sizeof(struct driz_param_t));
285
286 driz_param_init(p);
287
288 p->uuid = 1;
289 p->xmin = 0;
290 p->xmax = image_size[0] - 1;
291 p->ymin = 0;
292 p->ymax = image_size[1] - 1;
293 p->iscale = 1.0f;
294 p->pscale_ratio = 1.0f;
295 p->pixel_fraction = 1.0;
296 p->exposure_time = 1.0;
297 p->ef = p->exposure_time;
298 p->kernel = kernel_square;
299 p->interpolation = interp_poly5;
300 p->weight_scale = 1.0;
301
302 p->data = test_data;
303 p->weights = test_weights;
304 p->pixmap = test_pixmap;
305 p->output_data = test_output_data;
306 p->output_counts = test_output_counts;
307 p->output_context = test_context;
308 p->nmiss = 0;
309 p->nskip = 0;
310
311 error = (struct driz_error_t *) malloc(sizeof(struct driz_error_t));
312 driz_error_init(error);
313 p->error = error;
314 init_pixmap(p);
315
316 fill_image(p->data, 0.0);
317 fill_image(p->weights, 1.0);
318 fill_image(p->output_data, 0.0);
319 fill_image(p->output_counts, 0.0);
320 unset_context(p->output_context);
321
322 if (strlen(log_file)) {
323 logptr = fopen(log_file, "a");
324 setbuf(logptr, NULL);
325 } else {
326 logptr = NULL;
327 }
328 return p;
329 }
330
331 void
332 teardown_parameters(struct driz_param_t *p)
333 {
334 if (logptr) {
335 fclose(logptr);
336 logptr = NULL;
337 }
338
339 free(p->error);
340 free(p);
341 }
342
343 FCT_BGN_FN(utest_cdrizzle)
344 {
345 FCT_FIXTURE_SUITE_BGN("unit tests for drizzle")
346 {
347 FCT_SETUP_BGN() {}
348 FCT_SETUP_END();
349
350 FCT_TEARDOWN_BGN() {}
351 FCT_TEARDOWN_END();
352
353 FCT_TEST_BGN(utest_shrink_bbox)
354 {
355 int xmin, xmax, ymin, ymax;
356 struct driz_param_t *p; /* parameter structure */
357
358 p = setup_parameters();
359 nan_pixmap(p);
360
361 get_pixmap(p->pixmap, 16, 50)[0] = 16;
362 get_pixmap(p->pixmap, 16, 50)[1] = 50;
363 get_pixmap(p->pixmap, 85, 51)[0] = 85;
364 get_pixmap(p->pixmap, 85, 51)[1] = 51;
365 get_pixmap(p->pixmap, 57, 18)[0] = 57;
366 get_pixmap(p->pixmap, 57, 18)[1] = 18;
367 get_pixmap(p->pixmap, 47, 68)[0] = 47;
368 get_pixmap(p->pixmap, 47, 68)[1] = 68;
369
370 xmin = 11;
371 xmax = 98;
372 ymin = 7;
373 ymax = 88;
374
375 shrink_image_section(p->pixmap, &xmin, &xmax, &ymin, &ymax);
376
377 fct_chk_eq_int(xmin, 16);
378 fct_chk_eq_int(xmax, 85);
379 fct_chk_eq_int(ymin, 18);
380 fct_chk_eq_int(ymax, 68);
381
382 teardown_parameters(p);
383 }
384 FCT_TEST_END();
385
386 FCT_TEST_BGN(utest_map_lookup_01)
387 {
388 struct driz_param_t *p;
389 p = setup_parameters();
390 stretch_pixmap(p, 1.0, 1000.0);
391
392 double x = get_pixmap(p->pixmap, 1, 1)[0];
393 double y = get_pixmap(p->pixmap, 1, 1)[1];
394
395 fct_chk_eq_dbl(x, 1.0);
396 fct_chk_eq_dbl(y, 1000.0);
397
398 teardown_parameters(p);
399 }
400 FCT_TEST_END();
401
402 FCT_TEST_BGN(utest_map_lookup_02)
403 {
404 struct driz_param_t *p;
405 p = setup_parameters();
406 stretch_pixmap(p, 1.0, 1000.0);
407
408 double x = get_pixmap(p->pixmap, 3, 0)[0];
409 double y = get_pixmap(p->pixmap, 3, 0)[1];
410
411 fct_chk_eq_dbl(x, 3.0);
412 fct_chk_eq_dbl(y, 0.0);
413
414 teardown_parameters(p);
415 }
416 FCT_TEST_END();
417
418 FCT_TEST_BGN(utest_map_lookup_03)
419 {
420 struct driz_param_t *p;
421 p = setup_parameters();
422 stretch_pixmap(p, 1.0, 1000.0);
423
424 double x = get_pixmap(p->pixmap, 0, 1)[0];
425 double y = get_pixmap(p->pixmap, 0, 1)[1];
426 fct_chk_eq_dbl(x, 0.0);
427 fct_chk_eq_dbl(y, 1000.0);
428
429 teardown_parameters(p);
430 }
431 FCT_TEST_END();
432
433 FCT_TEST_BGN(utest_map_lookup_04)
434 {
435 struct driz_param_t *p;
436 p = setup_parameters();
437 stretch_pixmap(p, 1.0, 1000.0);
438
439 double x = get_pixmap(p->pixmap, 3, 1)[0];
440 double y = get_pixmap(p->pixmap, 3, 1)[1];
441 fct_chk_eq_dbl(x, 3.0);
442 fct_chk_eq_dbl(y, 1000.0);
443
444 teardown_parameters(p);
445 }
446 FCT_TEST_END();
447
448 FCT_TEST_BGN(utest_compute_pscale_ratio)
449 {
450 struct driz_param_t *p;
451 struct polygon bp;
452 float pscale_ratio;
453 const float pscale_ratio_truth = sqrtf(1.2f * 1.7f);
454
455 p = setup_parameters();
456 stretch_pixmap(p, 1.2, 1.7);
457 bp.npv = 4;
458 bp.v[0].x = 0.0;
459 bp.v[0].y = 0.0;
460 bp.v[1].x = (double) p->xmax;
461 bp.v[1].y = 0.0;
462 bp.v[2].x = (double) p->xmax;
463 bp.v[2].y = (double) p->ymax;
464 bp.v[2].x = 0.0;
465 bp.v[2].y = (double) p->ymax;
466
467 compute_pscale_ratio(p, &bp, &pscale_ratio);
468
469 fct_xchk(
470 (int) (fabs(pscale_ratio - pscale_ratio_truth) < 5.0f * FLT_EPSILON),
471 "chk_eq_flt: %f != %f", pscale_ratio, pscale_ratio_truth);
472
473 teardown_parameters(p);
474 }
475 FCT_TEST_END();
476
477 FCT_TEST_BGN(utest_map_point_01)
478 {
479 double ix, iy, ox, oy;
480 struct driz_param_t *p;
481
482 p = setup_parameters();
483 stretch_pixmap(p, 1.0, 1000.0);
484
485 ix = 2.5;
486 iy = 1.5;
487
488 map_point(p, ix, iy, &ox, &oy);
489
490 fct_chk_eq_dbl(ox, 2.5);
491 fct_chk_eq_dbl(oy, 1500.0);
492
493 teardown_parameters(p);
494 }
495 FCT_TEST_END();
496
497 FCT_TEST_BGN(utest_map_point_02)
498 {
499 double ix, iy, ox, oy;
500 struct driz_param_t *p;
501
502 p = setup_parameters();
503 stretch_pixmap(p, 1.0, 1000.0);
504
505 ix = -1.0;
506 iy = 0.5;
507
508 map_point(p, ix, iy, &ox, &oy);
509
510 fct_chk_eq_dbl(ox, -1.0);
511 fct_chk_eq_dbl(oy, 500.0);
512
513 teardown_parameters(p);
514 }
515 FCT_TEST_END();
516
517 FCT_TEST_BGN(utest_map_point_03)
518 {
519 double ix, iy, ox, oy;
520 int status;
521 struct driz_param_t *p;
522
523 p = setup_parameters();
524 stretch_pixmap(p, 1.0, 1000.0);
525
526 ix = 3.25;
527 iy = 5.0;
528
529 status = map_point(p, ix, iy, &ox, &oy);
530
531 fct_chk_int_return_status(status, 0);
532 fct_chk_eq_dbl(ox, 3.25);
533 fct_chk_eq_dbl(oy, 5000.0);
534
535 nan_pixel(p, 3, 5);
536 status = map_point(p, ix, iy, &ox, &oy);
537
538 fct_chk_int_return_status(status, 1);
539 fct_chk_neq_int(ox, ox);
540 fct_chk_neq_int(oy, oy);
541
542 teardown_parameters(p);
543 }
544 FCT_TEST_END();
545
546 FCT_TEST_BGN(utest_map_point_04)
547 {
548 double ix, iy, ox, oy;
549 int status;
550 struct driz_param_t *p;
551
552 p = setup_parameters();
553
554 stretch_pixmap(p, 1.0, 1000.0);
555
556 ix = 0.25;
557 iy = 5.0;
558
559 status = map_point(p, ix, iy, &ox, &oy);
560
561 fct_chk_int_return_status(status, 0);
562 fct_chk_eq_dbl(ox, 0.25);
563 fct_chk_eq_dbl(oy, 5000.0);
564
565 nan_pixel(p, 0, 5);
566 status = map_point(p, ix, iy, &ox, &oy);
567
568 fct_chk_int_return_status(status, 1);
569 fct_chk_neq_int(ox, ox);
570 fct_chk_neq_int(oy, oy);
571
572 teardown_parameters(p);
573 }
574 FCT_TEST_END();
575
576 FCT_TEST_BGN(utest_check_line_overlap_01)
577 {
578 struct scanner s;
579 int ymin, ymax, shift, status;
580
581 /* Test for complete overlap */
582
583 const integer_t j = 0; /* which image line to check ? */
584 integer_t xbounds[2]; /* start of in-bounds */
585 struct driz_param_t *p; /* parameter structure */
586
587 p = setup_parameters();
588 shift = 0;
589 offset_pixmap(p, (double) shift, 0.0);
590
591 init_image_scanner(p, &s, &ymin, &ymax);
592 status = get_scanline_limits(&s, j, &xbounds[0], &xbounds[1]);
593
594 fct_chk_eq_int(status, 0);
595 fct_chk_eq_int(ymin, 0);
596 fct_chk_eq_int(ymax, image_size[1] - 1);
597 fct_chk_eq_int(xbounds[0], MIN(MAX(0, -shift), image_size[0] - 1));
598 fct_chk_eq_int(xbounds[1], MAX(0, MIN(image_size[0] - 1 - shift, image_size[0] - 1)));
599
600 teardown_parameters(p);
601 }
602 FCT_TEST_END();
603
604 FCT_TEST_BGN(utest_check_line_overlap_02)
605 {
606 struct scanner s;
607 int ymin, ymax, shift, status;
608
609 /* Test for half overlap */
610
611 const integer_t j = 0; /* which image line to check ? */
612 integer_t xbounds[2]; /* start of in-bounds */
613 struct driz_param_t *p; /* parameter structure */
614
615 p = setup_parameters();
616 shift = 70;
617 offset_pixmap(p, (double) shift, 0.0);
618
619 init_image_scanner(p, &s, &ymin, &ymax);
620 status = get_scanline_limits(&s, j, &xbounds[0], &xbounds[1]);
621
622 fct_chk_eq_int(status, 0);
623 fct_chk_eq_int(ymin, 0);
624 fct_chk_eq_int(ymax, image_size[1] - 1);
625 fct_chk_eq_int(xbounds[0], MIN(MAX(0, -shift), image_size[0] - 1));
626 fct_chk_eq_int(xbounds[1], MAX(0, MIN(image_size[0] - 1 - shift, image_size[0] - 1)));
627
628 teardown_parameters(p);
629 }
630 FCT_TEST_END();
631
632 FCT_TEST_BGN(utest_check_line_overlap_03)
633 {
634 struct scanner s;
635 int ymin, ymax, shift, status;
636
637 /* Test for negative half overlap */
638
639 const integer_t j = 0; /* which image line to check ? */
640 integer_t xbounds[2]; /* start of in-bounds */
641 struct driz_param_t *p; /* parameter structure */
642
643 p = setup_parameters();
644 shift = -70;
645 offset_pixmap(p, (double) shift, 0.0);
646
647 init_image_scanner(p, &s, &ymin, &ymax);
648 status = get_scanline_limits(&s, j, &xbounds[0], &xbounds[1]);
649
650 fct_chk_eq_int(status, 0);
651 fct_chk_eq_int(ymin, 0);
652 fct_chk_eq_int(ymax, image_size[1] - 1);
653 fct_chk_eq_int(xbounds[0], MIN(MAX(0, -shift), image_size[0] - 1));
654 fct_chk_eq_int(xbounds[1], MAX(0, MIN(image_size[0] - 1 - shift, image_size[0] - 1)));
655
656 teardown_parameters(p);
657 }
658 FCT_TEST_END();
659
660 FCT_TEST_BGN(utest_check_image_overlap_02)
661 {
662 struct scanner s;
663 int ymin, ymax, shift;
664
665 /* Test for half overlap */
666
667 struct driz_param_t *p; /* parameter structure */
668
669 p = setup_parameters();
670 shift = 70;
671 offset_pixmap(p, 0.0, (double) shift);
672
673 init_image_scanner(p, &s, &ymin, &ymax);
674
675 fct_chk_eq_int(ymin, MIN(MAX(0, -shift), image_size[1] - 1));
676 fct_chk_eq_int(ymax, MAX(0, MIN(image_size[1] - 1 - shift, image_size[1] - 1)));
677
678 teardown_parameters(p);
679 }
680 FCT_TEST_END();
681
682 FCT_TEST_BGN(utest_check_image_overlap_03)
683 {
684 struct scanner s;
685 int ymin, ymax, shift;
686
687 /* Test for negative half overlap */
688
689 struct driz_param_t *p; /* parameter structure */
690
691 p = setup_parameters();
692 shift = -70;
693 offset_pixmap(p, 0.0, (double) shift);
694
695 init_image_scanner(p, &s, &ymin, &ymax);
696
697 fct_chk_eq_int(ymin, MIN(MAX(0, -shift), image_size[1] - 1));
698 fct_chk_eq_int(ymax, MAX(0, MIN(image_size[1] - 1 - shift, image_size[1] - 1)));
699
700 teardown_parameters(p);
701 }
702 FCT_TEST_END();
703
704 FCT_TEST_BGN(utest_compute_area_01)
705 {
706 /* Test compute area with aligned square entirely inside */
707 double area;
708 double is, js, x[4], y[4];
709
710 is = 1.0;
711 js = 1.0;
712
713 x[0] = 0.75;
714 y[0] = 1.25;
715 x[1] = 0.75;
716 y[1] = 0.75;
717 x[2] = 1.25;
718 y[2] = 0.75;
719 x[3] = 1.25;
720 y[3] = 1.25;
721
722 area = compute_area(is, js, x, y);
723 fct_chk_eq_dbl(area, 0.25);
724 }
725 FCT_TEST_END();
726
727 FCT_TEST_BGN(utest_compute_area_02)
728 {
729 /* Test compute area with diagonal square entirely inside */
730 double area;
731 double is, js, x[4], y[4];
732
733 is = 1.0;
734 js = 1.0;
735
736 x[0] = 1.0;
737 y[0] = 1.25;
738 x[1] = 0.75;
739 y[1] = 1.0;
740 x[2] = 1.0;
741 y[2] = 0.75;
742 x[3] = 1.25;
743 y[3] = 1.0;
744
745 area = compute_area(is, js, x, y);
746 fct_chk_eq_dbl(area, 0.125);
747 }
748 FCT_TEST_END();
749
750 FCT_TEST_BGN(utest_compute_area_03)
751 {
752 /* Test compute area with aligned square with overlap */
753 double area;
754 double is, js, x[4], y[4];
755
756 is = 1.0;
757 js = 1.0;
758
759 x[0] = 0.0;
760 y[0] = 0.0;
761 x[1] = 1.0;
762 y[1] = 0.0;
763 x[2] = 1.0;
764 y[2] = 1.0;
765 x[3] = 0.0;
766 y[3] = 1.0;
767
768 area = compute_area(is, js, x, y);
769 fct_chk_eq_dbl(area, 0.25);
770 }
771 FCT_TEST_END();
772
773 FCT_TEST_BGN(utest_compute_area_04)
774 {
775 /* Test compute area with diagonal square with overlap */
776 double area;
777 double is, js, x[4], y[4];
778
779 is = 1.0;
780 js = 1.0;
781
782 x[0] = 1.0;
783 y[0] = 1.75;
784 x[1] = 0.75;
785 y[1] = 1.5;
786 x[2] = 1.0;
787 y[2] = 1.25;
788 x[3] = 1.25;
789 y[3] = 1.5;
790
791 area = compute_area(is, js, x, y);
792 fct_chk_eq_dbl(area, 0.0625);
793 }
794 FCT_TEST_END();
795
796 FCT_TEST_BGN(utest_compute_area_05)
797 {
798 /* Test compute area with marching diagonal square */
799 int i, j;
800 double is, js, x[4], y[4], area;
801 double area_ok[7][7] = {
802 {0.125000, 0.218750, 0.250000, 0.218750, 0.125000, 0.031250, 0.000000},
803 {0.218750, 0.375000, 0.437500, 0.375000, 0.218750, 0.062500, 0.000000},
804 {0.250000, 0.437500, 0.500000, 0.437500, 0.250000, 0.062500, 0.000000},
805 {0.218750, 0.375000, 0.437500, 0.375000, 0.218750, 0.062500, 0.000000},
806 {0.125000, 0.218750, 0.250000, 0.218750, 0.125000, 0.031250, 0.000000},
807 {0.031250, 0.062500, 0.062500, 0.062500, 0.031250, 0.000000, 0.000000},
808 {0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000}};
809
810 is = 1.0;
811 js = 1.0;
812
813 for (i = 0; i <= 6; ++i) {
814 for (j = 0; j <= 6; ++j) {
815 x[0] = 0.25 * (double) i;
816 y[0] = 0.25 * (double) j + 0.5;
817 x[1] = 0.25 * (double) i + 0.5;
818 y[1] = 0.25 * (double) j;
819 x[2] = 0.25 * (double) i + 1.0;
820 y[2] = 0.25 * (double) j + 0.5;
821 x[3] = 0.25 * (double) i + 0.5;
822 y[3] = 0.25 * (double) j + 1.0;
823
824 area = compute_area(is, js, x, y);
825
826 /* DBG */
827 fct_chk_eq_dbl(area, area_ok[i][j]);
828 }
829 }
830 }
831 FCT_TEST_END();
832
833 FCT_TEST_BGN(utest_do_kernel_square_01)
834 {
835 /* Simplest case */
836
837 integer_t x1; /* start of in-bounds */
838 integer_t j, x2; /* end of in-bounds */
839 struct driz_param_t *p; /* parameter structure */
840 int n, status;
841
842 n = 100;
843 p = setup_parameters();
844 offset_pixmap(p, 0.0, 0.0);
845 fill_image(p->data, 5.0);
846
847 status = do_kernel_square(p);
848
849 j = 3;
850 x1 = 0;
851 x2 = n;
852
853 fct_chk_eq_int(status, 0);
854 fct_chk_eq_dbl(get_pixel(p->output_data, x1, j), get_pixel(p->data, x1, j));
855 fct_chk_eq_dbl(get_pixel(p->output_data, x2 - 1, j), get_pixel(p->data, x2 - 1, j));
856
857 teardown_parameters(p);
858 }
859 FCT_TEST_END();
860
861 FCT_TEST_BGN(utest_do_kernel_square_02)
862 {
863 /* Offset image */
864
865 struct driz_param_t *p; /* parameter structure */
866 integer_t j;
867 int k, n, status;
868 double offset;
869
870 n = 100;
871 offset = 2.0;
872 p = setup_parameters();
873 offset_pixmap(p, offset, 0.0);
874 fill_image(p->data, 5.0);
875
876 j = 3;
877 status = do_kernel_square(p);
878
879 fct_chk_eq_int(status, 0);
880 for (k = 1; k < n - 2; k++) {
881 fct_chk_eq_dbl(get_pixel(p->output_data, (k + 1), j), get_pixel(p->data, k, j));
882 }
883
884 teardown_parameters(p);
885 }
886 FCT_TEST_END();
887
888 FCT_TEST_BGN(utest_do_kernel_square_03)
889 {
890 /* Single pixel set */
891
892 struct driz_param_t *p; /* parameter structure */
893 integer_t j;
894 int k, n;
895 double offset, value;
896
897 n = 100;
898 offset = 2.0;
899 value = 5.0;
900 p = setup_parameters();
901 offset_pixmap(p, offset, 0.0);
902
903 for (j = 0; j < n; ++j) {
904 set_pixel(p->data, j, j, value);
905 }
906
907 k = 3;
908 do_kernel_square(p);
909
910 fct_chk_eq_dbl(get_pixel(p->output_data, (k + 2), k), get_pixel(p->data, k, k));
911
912 teardown_parameters(p);
913 }
914 FCT_TEST_END();
915
916 FCT_TEST_BGN(utest_do_kernel_square_04)
917 {
918 /* Single pixel, fractional pixel offset */
919
920 struct driz_param_t *p; /* parameter structure */
921 integer_t i, j, k;
922 double offset, value;
923
924 offset = 2.5;
925 value = 4.0;
926 p = setup_parameters();
927 offset_pixmap(p, offset, offset);
928
929 k = 1;
930 set_pixel(p->data, k, k, value);
931
932 do_kernel_square(p);
933
934 for (i = 2; i <= 3; ++i) {
935 for (j = 2; j <= 3; ++j) {
936 fct_chk_eq_dbl(get_pixel(p->output_data, (i + k), (j + k)), value / 4.0);
937 }
938 }
939
940 teardown_parameters(p);
941 }
942 FCT_TEST_END();
943
944 FCT_TEST_BGN(utest_do_kernel_square_05)
945 {
946 /* Diagonal line, fractional pixel offset */
947
948 struct driz_param_t *p; /* parameter structure */
949 integer_t i, j;
950 int n;
951 double offset, value;
952
953 n = 100;
954 offset = 2.5;
955 value = 4.0;
956 p = setup_parameters();
957 offset_pixmap(p, offset, offset);
958
959 for (j = 1; j < n - 1; ++j) {
960 set_pixel(p->data, j, j, value);
961 }
962
963 do_kernel_square(p);
964
965 for (i = 4; i < n - 2; ++i) {
966 fct_chk_eq_dbl(get_pixel(p->output_data, i, i), value / 2.0);
967 fct_chk_eq_dbl(get_pixel(p->output_data, i - 1, i), value / 4.0);
968 fct_chk_eq_dbl(get_pixel(p->output_data, i, i - 1), value / 4.0);
969 }
970
971 teardown_parameters(p);
972 }
973 FCT_TEST_END();
974
975 FCT_TEST_BGN(utest_do_kernel_square_06)
976 {
977 /* Block of pixels, whole number offset */
978
979 struct driz_param_t *p; /* parameter structure */
980 integer_t i, j;
981 int k;
982 double offset, value;
983
984 k = 2;
985 offset = 2.0;
986 value = 4.0;
987 p = setup_parameters();
988 offset_pixmap(p, offset, offset);
989
990 for (i = 0; i < k; ++i) {
991 for (j = 0; j < k; ++j) {
992 set_pixel(p->data, i, j, value);
993 }
994 }
995
996 do_kernel_square(p);
997
998 for (i = 0; i < k; ++i) {
999 for (j = 0; j < k; ++j) {
1000 fct_chk_eq_dbl(get_pixel(p->output_data, (i + 2), (j + 2)), value);
1001 }
1002 }
1003
1004 teardown_parameters(p);
1005 }
1006 FCT_TEST_END();
1007
1008 FCT_TEST_BGN(utest_do_kernel_square_07)
1009 {
1010 /* Block of pixels, fractional offset */
1011
1012 struct driz_param_t *p; /* parameter structure */
1013 integer_t i, j;
1014 int k;
1015 double offset, value;
1016
1017 k = 2;
1018 offset = 2.5;
1019 value = 4.0;
1020 p = setup_parameters();
1021 offset_pixmap(p, offset, offset);
1022
1023 for (i = 1; i < k + 1; ++i) {
1024 for (j = 1; j < k + 1; ++j) {
1025 set_pixel(p->data, i, j, value);
1026 }
1027 }
1028
1029 do_kernel_square(p);
1030
1031 fct_chk_eq_dbl(get_pixel(p->output_data, 3, 3), 1.0);
1032 fct_chk_eq_dbl(get_pixel(p->output_data, 3, 5), 1.0);
1033 fct_chk_eq_dbl(get_pixel(p->output_data, 5, 3), 1.0);
1034 fct_chk_eq_dbl(get_pixel(p->output_data, 5, 5), 1.0);
1035 fct_chk_eq_dbl(get_pixel(p->output_data, 3, 4), 2.0);
1036 fct_chk_eq_dbl(get_pixel(p->output_data, 4, 3), 2.0);
1037 fct_chk_eq_dbl(get_pixel(p->output_data, 4, 5), 2.0);
1038 fct_chk_eq_dbl(get_pixel(p->output_data, 5, 4), 2.0);
1039 fct_chk_eq_dbl(get_pixel(p->output_data, 4, 4), 4.0);
1040
1041 teardown_parameters(p);
1042 }
1043 FCT_TEST_END();
1044
1045 FCT_TEST_BGN(utest_dobox_01)
1046 {
1047 /* Single pixel set, whole number offset */
1048
1049 struct driz_param_t *p; /* parameter structure */
1050 int k;
1051 double offset, value;
1052
1053 k = 2;
1054 offset = 2.0;
1055 value = 44.0;
1056
1057 p = setup_parameters();
1058 offset_pixmap(p, offset, offset);
1059 p->kernel = kernel_turbo;
1060
1061 set_pixel(p->data, k, k, value);
1062 dobox(p);
1063
1064 fct_chk_eq_dbl(get_pixel(p->output_data, (k + 2), (k + 2)), get_pixel(p->data, k, k));
1065 fct_chk_eq_int(p->nskip, 2);
1066 }
1067 FCT_TEST_END();
1068
1069 FCT_TEST_BGN(utest_dobox_02)
1070 {
1071 /* Single pixel, fractional pixel offset */
1072
1073 struct driz_param_t *p; /* parameter structure */
1074 int i, j, k;
1075 double offset, value;
1076
1077 k = 2;
1078 offset = 2.5;
1079 value = 44.0;
1080
1081 p = setup_parameters();
1082 offset_pixmap(p, offset, offset);
1083 p->kernel = kernel_turbo;
1084
1085 set_pixel(p->data, k, k, value);
1086 dobox(p);
1087
1088 for (i = 2; i <= 3; ++i) {
1089 for (j = 2; j <= 3; ++j) {
1090 fct_chk_eq_dbl(get_pixel(p->output_data, (i + k), (j + k)), value / 4.0);
1091 }
1092 }
1093 }
1094 FCT_TEST_END();
1095
1096 FCT_TEST_BGN(utest_dobox_03)
1097 {
1098 /* Turbo mode kernel, diagonal line of pixels set */
1099
1100 struct driz_param_t *p; /* parameter structure */
1101 int i, j, n;
1102 double offset, value;
1103
1104 n = 100;
1105 offset = 2.5;
1106 value = 4.0;
1107
1108 p = setup_parameters();
1109 offset_pixmap(p, offset, offset);
1110 p->kernel = kernel_turbo;
1111
1112 for (j = 1; j < n - 1; ++j) {
1113 set_pixel(p->data, j, j, value);
1114 }
1115
1116 dobox(p);
1117
1118 for (i = 4; i < n; ++i) {
1119 fct_chk_eq_dbl(get_pixel(p->output_data, i, i), value / 2.0);
1120 fct_chk_eq_dbl(get_pixel(p->output_data, i - 1, i), value / 4.0);
1121 fct_chk_eq_dbl(get_pixel(p->output_data, i, i - 1), value / 4.0);
1122 }
1123
1124 teardown_parameters(p);
1125 }
1126 FCT_TEST_END();
1127
1128 FCT_TEST_BGN(utest_dobox_04)
1129 {
1130 /* Check that context map is set for the affected pixels */
1131
1132 struct driz_param_t *p; /* parameter structure */
1133 int i, j, n;
1134 double offset, value;
1135 integer_t bv;
1136
1137 n = 100;
1138 offset = 2.5;
1139 value = 4.0;
1140
1141 p = setup_parameters();
1142 offset_pixmap(p, offset, offset);
1143 // DBG p->kernel = kernel_turbo;
1144
1145 for (j = 1; j < n - 1; ++j) {
1146 set_pixel(p->data, j, j, value);
1147 }
1148
1149 dobox(p);
1150 bv = compute_bit_value(p->uuid);
1151 for (i = 4; i < 100; ++i) {
1152 fct_chk_eq_int(get_bit(p->output_context, i, i, bv), 1);
1153 }
1154
1155 teardown_parameters(p);
1156 }
1157 FCT_TEST_END();
1158
1159 FCT_TEST_BGN(utest_doblot_01)
1160 {
1161 /* Single pixel set blinear interpolation */
1162
1163 struct driz_param_t *p; /* parameter structure */
1164 int k;
1165 double offset, value;
1166
1167 k = 2;
1168 offset = -2.0;
1169 value = 5.0;
1170
1171 p = setup_parameters();
1172 p->interpolation = interp_bilinear;
1173
1174 offset_pixmap(p, offset, offset);
1175
1176 set_pixel(p->data, k, k, value);
1177 doblot(p);
1178
1179 fct_chk_eq_dbl(get_pixel(p->output_data, (k + 2), (k + 2)), get_pixel(p->data, k, k));
1180 }
1181 FCT_TEST_END();
1182
1183 FCT_TEST_BGN(utest_doblot_02)
1184 {
1185 /* Single pixel set quintic interpolation*/
1186
1187 struct driz_param_t *p; /* parameter structure */
1188 int k;
1189 double offset, value;
1190
1191 k = 2;
1192 offset = -2.0;
1193 value = 5.0;
1194
1195 p = setup_parameters();
1196 p->interpolation = interp_bilinear;
1197
1198 offset_pixmap(p, offset, offset);
1199
1200 set_pixel(p->data, k, k, value);
1201 doblot(p);
1202
1203 fct_chk_eq_dbl(get_pixel(p->output_data, (k + 2), (k + 2)), get_pixel(p->data, k, k));
1204 }
1205 FCT_TEST_END();
1206 }
1207 FCT_FIXTURE_SUITE_END();
1208 }
1209 {
1210 FCT_END_FN();
1211 }