ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/radcompare.c
(Generate patch)

Comparing ray/src/util/radcompare.c (file contents):
Revision 2.17 by greg, Sat Nov 17 20:22:17 2018 UTC vs.
Revision 2.26 by greg, Mon Jul 27 16:49:56 2020 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #include <stdlib.h>
11 #include <math.h>
11   #include <ctype.h>
12 + #include "rtmath.h"
13   #include "platform.h"
14   #include "rtio.h"
15   #include "resolu.h"
16   #include "color.h"
17 + #include "depthcodec.h"
18 + #include "normcodec.h"
19   #include "lookup.h"
20                          /* Reporting levels */
21   #define REP_QUIET       0       /* no reporting */
# Line 33 | Line 35 | double max_lim = 0.25;         /* difference limit if non-neg
35  
36   int     lin1cnt=0, lin2cnt=0;   /* file line position */
37  
38 + int     comment_c = '\0';       /* comment delimiter for text files */
39 +
40   const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
41                          "th","st","nd","rd","th","th","th","th","th","th"
42                  };
# Line 45 | Line 49 | const char     *file_type[] = {
49                          "ascii",
50                          COLRFMT,
51                          CIEFMT,
52 +                        DEPTH16FMT,
53 +                        NORMAL32FMT,
54                          "float",
55                          "double",
56                          "BSDF_RBFmesh",
57                          "Radiance_octree",
58                          "Radiance_tmesh",
59 +                        "8-bit_indexed_name",
60 +                        "16-bit_indexed_name",
61 +                        "24-bit_indexed_name",
62                          "BINARY_unknown",
63                          NULL    /* terminator */
64                  };
65                                  /* keep consistent with above */
66 < enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT,
67 <                TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY};
66 > enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE,
67 >                TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE,
68 >                TYP_RBFMESH, TYP_OCTREE, TYP_TMESH,
69 >                TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY};
70                  
71   #define has_header(t)   (!( 1L<<(t) & (1L<<TYP_TEXT | 1L<<TYP_BINARY) ))
72  
# Line 64 | Line 75 | const char     *hdr_ignkey[] = {
75                          "SOFTWARE",
76                          "CAPDATE",
77                          "GMT",
78 +                        "FRAME",
79                          NULL    /* terminator */
80                  };
81                                  /* header variable settings */
# Line 89 | Line 101 | char           *progname = NULL;
101   const char      stdin_name[] = "<stdin>";
102   const char      *f1name=NULL, *f2name=NULL;
103   FILE            *f1in=NULL, *f2in=NULL;
104 + int             f1swap=0, f2swap=0;
105  
106                                  /* running real differences */
107   double  diff2sum = 0;
# Line 100 | Line 113 | usage()
113   {
114          fputs("Usage: ", stderr);
115          fputs(progname, stderr);
116 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
116 >        fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
117                          stderr);
118          exit(2);
119   }
# Line 138 | Line 151 | read_line(LINEBUF *bp, FILE *fp)
151                  if (!bp->str)
152                          goto memerr;
153          }
154 +        if (comment_c) {                /* elide comment? */
155 +                char    *cp = sskip2(bp->str,0);
156 +                if (*cp == comment_c) {
157 +                        *cp++ = '\n';
158 +                        *cp = '\0';
159 +                        bp->len = cp - bp->str;
160 +                }
161 +        }
162          return(bp->len);
163   memerr:
164          fprintf(stderr,
# Line 209 | Line 230 | color_check(COLOR c1, COLOR c2)
230          return(real_check(colval(c1,p), colval(c2,p)));
231   }
232  
233 + /* Compare two normal directions for equivalence */
234 + static int
235 + norm_check(FVECT nv1, FVECT nv2)
236 + {
237 +        double  max2 = nv1[2]*nv2[2];
238 +        int     imax = 2;
239 +        int     i = 2;
240 +                                        /* identify largest component */
241 +        while (i--) {
242 +                double  tm2 = nv1[i]*nv2[i];
243 +                if (tm2 > max2) {
244 +                        imax = i;
245 +                        max2 = tm2;
246 +                }
247 +        }
248 +        i = 3;                          /* compare smaller components */
249 +        while (i--) {
250 +                if (i == imax)
251 +                        continue;
252 +                if (!real_check(nv1[i], nv2[i]))
253 +                        return(0);
254 +        }
255 +        return(1);
256 + }
257 +
258   /* Compare two strings for equivalence */
259   static int
260   equiv_string(char *s1, char *s2)
# Line 281 | Line 327 | equiv_string(char *s1, char *s2)
327   static int
328   setheadvar(char *val, void *p)
329   {
330 +        char    newval[128];
331          LUTAB   *htp = (LUTAB *)p;
332          LUENT   *tep;
333          char    *key;
# Line 290 | Line 337 | setheadvar(char *val, void *p)
337          adv_linecnt(htp);       /* side-effect is to count lines */
338          if (!isalpha(*val))     /* key must start line */
339                  return(0);
340 +                                /* check if we need to swap binary data */
341 +        if ((n = isbigendian(val)) >= 0) {
342 +                if (nativebigendian() == n)
343 +                        return(0);
344 +                f1swap += (htp == &hdr1);
345 +                f2swap += (htp == &hdr2);
346 +                return(0);
347 +        }
348          key = val++;
349          while (*val && !isspace(*val) & (*val != '='))
350                  val++;
# Line 315 | Line 370 | setheadvar(char *val, void *p)
370                  return(-1);     /* memory allocation error */
371          if (!tep->key)
372                  tep->key = strcpy(malloc(kln+1), key);
373 <        if (tep->data)
373 >        if (tep->data) {        /* check for special cases */
374 >                if (!strcmp(key, "EXPOSURE")) {
375 >                        sprintf(newval, "%f", atof(tep->data)*atof(val));
376 >                        vln = strlen(val = newval);
377 >                }
378                  free(tep->data);
379 +        }
380          tep->data = strcpy(malloc(vln+1), val);
381          return(1);
382   }
# Line 425 | Line 485 | identify_type(const char *name, FILE *fin, LUTAB *htp)
485          }
486          if (c)
487                  return(TYP_BINARY);
428        SET_FILE_TEXT(fin);                     /* originally set to binary */
488          return(TYP_TEXT);
489   badeof:
490          if (report != REP_QUIET) {
# Line 508 | Line 567 | compare_text()
567  
568          if (report >= REP_VERBOSE) {
569                  fputs(progname, stdout);
570 <                fputs(": comparing inputs as ASCII text\n", stdout);
570 >                fputs(": comparing inputs as ASCII text", stdout);
571 >                if (comment_c) {
572 >                        fputs(", ignoring comments starting with '", stdout);
573 >                        fputc(comment_c, stdout);
574 >                        fputc('\'', stdout);
575 >                }
576 >                fputc('\n', stdout);
577          }
578 +        SET_FILE_TEXT(f1in);                    /* originally set to binary */
579 +        SET_FILE_TEXT(f2in);
580          init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
581          while (read_line(&l1buf, f1in)) {
582                  lin1cnt++;
# Line 564 | Line 631 | compare_text()
631          return(good_RMS());                     /* final check for reals */
632   }
633  
634 + /* Check image/map resolutions */
635 + static int
636 + check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
637 + {
638 +        if (r1p->rt != r2p->rt) {
639 +                if (report != REP_QUIET)
640 +                        printf(
641 +                        "%s: %ss '%s' and '%s' have different pixel ordering\n",
642 +                                        progname, class, f1name, f2name);
643 +                return(0);
644 +        }
645 +        if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) {
646 +                if (report != REP_QUIET)
647 +                        printf(
648 +                        "%s: %ss '%s' and '%s' are different sizes\n",
649 +                                        progname, class, f1name, f2name);
650 +                return(0);
651 +        }
652 +        return(1);
653 + }
654 +
655   /* Compare two inputs that are known to be RGBE or XYZE images */
656   static int
657   compare_hdr()
# Line 578 | Line 666 | compare_hdr()
666          }
667          fgetsresolu(&rs1, f1in);
668          fgetsresolu(&rs2, f2in);
669 <        if (rs1.rt != rs2.rt) {
582 <                if (report != REP_QUIET)
583 <                        printf(
584 <                        "%s: Images '%s' and '%s' have different pixel ordering\n",
585 <                                        progname, f1name, f2name);
669 >        if (!check_resolu("HDR image", &rs1, &rs2))
670                  return(0);
587        }
588        if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
589                if (report != REP_QUIET)
590                        printf(
591                        "%s: Images '%s' and '%s' are different sizes\n",
592                                        progname, f1name, f2name);
593                return(0);
594        }
671          scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR));
672          scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR));
673          if (!scan1 | !scan2) {
# Line 636 | Line 712 | compare_hdr()
712          return(good_RMS());                     /* final check of RMS */
713   }
714  
715 + /* Set reference depth based on header variable */
716 + static int
717 + set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
718 + {
719 +        static char     depthvar[] = DEPTHSTR;
720 +        const char      *drval;
721 +
722 +        depthvar[LDEPTHSTR-1] = '\0';
723 +        drval = (const char *)lu_find(htp, depthvar)->data;
724 +        if (!drval)
725 +                return(0);
726 +        dcp->refdepth = atof(drval);
727 +        if (dcp->refdepth <= 0) {
728 +                if (report != REP_QUIET) {
729 +                        fputs(dcp->inpname, stderr);
730 +                        fputs(": bad reference depth '", stderr);
731 +                        fputs(drval, stderr);
732 +                        fputs("'\n", stderr);
733 +                }
734 +                return(-1);
735 +        }
736 +        return(1);
737 + }
738 +
739 + /* Compare two encoded depth maps */
740 + static int
741 + compare_depth()
742 + {
743 +        long            nread = 0;
744 +        DEPTHCODEC      dc1, dc2;
745 +
746 +        if (report >= REP_VERBOSE) {
747 +                fputs(progname, stdout);
748 +                fputs(": comparing inputs as depth maps\n", stdout);
749 +        }
750 +        set_dc_defaults(&dc1);
751 +        dc1.hdrflags = HF_RESIN;
752 +        dc1.finp = f1in;
753 +        dc1.inpname = f1name;
754 +        set_dc_defaults(&dc2);
755 +        dc2.hdrflags = HF_RESIN;
756 +        dc2.finp = f2in;
757 +        dc2.inpname = f2name;
758 +        if (report != REP_QUIET) {
759 +                dc1.hdrflags |= HF_STDERR;
760 +                dc2.hdrflags |= HF_STDERR;
761 +        }
762 +        if (!process_dc_header(&dc1, 0, NULL))
763 +                return(0);
764 +        if (!process_dc_header(&dc2, 0, NULL))
765 +                return(0);
766 +        if (!check_resolu("Depth map", &dc1.res, &dc2.res))
767 +                return(0);
768 +        if (set_refdepth(&dc1, &hdr1) < 0)
769 +                return(0);
770 +        if (set_refdepth(&dc2, &hdr2) < 0)
771 +                return(0);
772 +        while (nread < dc1.res.xr*dc1.res.yr) {
773 +                double  d1 = decode_depth_next(&dc1);
774 +                double  d2 = decode_depth_next(&dc2);
775 +                if ((d1 < 0) | (d2 < 0)) {
776 +                        if (report != REP_QUIET)
777 +                                printf("%s: unexpected end-of-file\n",
778 +                                                progname);
779 +                        return(0);
780 +                }
781 +                ++nread;
782 +                if (real_check(d1, d2))
783 +                        continue;
784 +                if (report != REP_QUIET)
785 +                        printf("%s: %ld%s depth values differ\n",
786 +                                        progname, nread, num_sfx(nread));
787 +                return(0);
788 +        }
789 +        return(good_RMS());             /* final check of RMS */
790 + }
791 +
792 + /* Compare two encoded normal maps */
793 + static int
794 + compare_norm()
795 + {
796 +        long            nread = 0;
797 +        NORMCODEC       nc1, nc2;
798 +
799 +        if (report >= REP_VERBOSE) {
800 +                fputs(progname, stdout);
801 +                fputs(": comparing inputs as normal maps\n", stdout);
802 +        }
803 +        set_nc_defaults(&nc1);
804 +        nc1.hdrflags = HF_RESIN;
805 +        nc1.finp = f1in;
806 +        nc1.inpname = f1name;
807 +        set_nc_defaults(&nc2);
808 +        nc2.hdrflags = HF_RESIN;
809 +        nc2.finp = f2in;
810 +        nc2.inpname = f2name;
811 +        if (report != REP_QUIET) {
812 +                nc1.hdrflags |= HF_STDERR;
813 +                nc2.hdrflags |= HF_STDERR;
814 +        }
815 +        if (!process_nc_header(&nc1, 0, NULL))
816 +                return(0);
817 +        if (!process_nc_header(&nc2, 0, NULL))
818 +                return(0);
819 +        if (!check_resolu("Normal map", &nc1.res, &nc2.res))
820 +                return(0);
821 +        while (nread < nc1.res.xr*nc1.res.yr) {
822 +                FVECT   nv1, nv2;
823 +                int     rv1 = decode_normal_next(nv1, &nc1);
824 +                int     rv2 = decode_normal_next(nv2, &nc2);
825 +                if ((rv1 < 0) | (rv2 < 0)) {
826 +                        if (report != REP_QUIET)
827 +                                printf("%s: unexpected end-of-file\n",
828 +                                                progname);
829 +                        return(0);
830 +                }
831 +                ++nread;
832 +                if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2)))
833 +                        continue;
834 +                if (report != REP_QUIET)
835 +                        printf("%s: %ld%s normal vectors differ\n",
836 +                                        progname, nread, num_sfx(nread));
837 +                return(0);
838 +        }
839 +        return(good_RMS());             /* final check of RMS */
840 + }
841 +
842   /* Compare two inputs that are known to be 32-bit floating-point data */
843   static int
844   compare_float()
# Line 651 | Line 854 | compare_float()
854                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
855                          goto badeof;
856                  ++nread;
857 +                if (f1swap) swap32((char *)&f1, 1);
858 +                if (f2swap) swap32((char *)&f2, 1);
859                  if (real_check(f1, f2))
860                          continue;
861                  if (report != REP_QUIET)
# Line 681 | Line 886 | compare_double()
886                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
887                          goto badeof;
888                  ++nread;
889 +                if (f1swap) swap64((char *)&f1, 1);
890 +                if (f2swap) swap64((char *)&f2, 1);
891                  if (real_check(f1, f2))
892                          continue;
893                  if (report != REP_QUIET)
# Line 709 | Line 916 | main(int argc, char *argv[])
916                  case 'h':                       /* ignore header info. */
917                          ign_header = !ign_header;
918                          continue;
919 +                case 'c':                       /* ignore comments */
920 +                        comment_c = argv[a][2];
921 +                        continue;
922                  case 's':                       /* silent operation */
923                          report = REP_QUIET;
924                          continue;
# Line 769 | Line 979 | main(int argc, char *argv[])
979                  return(2);
980          if (typ1 != typ2) {
981                  if (report != REP_QUIET)
982 <                        printf("%s: '%s' is %s and '%s' is %s\n",
982 >                        printf("%s: '%s' format is %s and '%s' is %s\n",
983                                          progname, f1name, file_type[typ1],
984                                          f2name, file_type[typ2]);
985                  return(1);
# Line 777 | Line 987 | main(int argc, char *argv[])
987          ign_header |= !has_header(typ1);        /* check headers if indicated */
988          if (!ign_header && !headers_match())
989                  return(1);
780        lu_done(&hdr1); lu_done(&hdr2);         /* done with header info. */
990          if (!ign_header & (report >= REP_WARN)) {
991                  if (lin1cnt != lin2cnt)
992                          printf("%s: warning - headers are different lengths\n",
# Line 786 | Line 995 | main(int argc, char *argv[])
995                          printf("%s: warning - unrecognized format\n",
996                                          progname);
997          }
998 <        if (report >= REP_VERBOSE)
999 <                printf("%s: input file type is %s\n",
1000 <                                progname, file_type[typ1]);
1001 <
998 >        if (report >= REP_VERBOSE) {
999 >                printf("%s: data format is %s\n", progname, file_type[typ1]);
1000 >                if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) {
1001 >                        if (f1swap)
1002 >                                printf("%s: input '%s' is byte-swapped\n",
1003 >                                                progname, f1name);
1004 >                        if (f2swap)
1005 >                                printf("%s: input '%s' is byte-swapped\n",
1006 >                                                progname, f2name);
1007 >                }
1008 >        }
1009          switch (typ1) {                         /* compare based on type */
1010          case TYP_BINARY:
1011          case TYP_TMESH:
1012          case TYP_OCTREE:
1013          case TYP_RBFMESH:
1014 +        case TYP_ID8:
1015 +        case TYP_ID16:
1016 +        case TYP_ID24:
1017          case TYP_UNKNOWN:
1018                  return( !compare_binary() );
1019          case TYP_TEXT:
# Line 803 | Line 1022 | main(int argc, char *argv[])
1022          case TYP_RGBE:
1023          case TYP_XYZE:
1024                  return( !compare_hdr() );
1025 +        case TYP_DEPTH:
1026 +                return( !compare_depth() );
1027 +        case TYP_NORM:
1028 +                return( !compare_norm() );
1029          case TYP_FLOAT:
1030                  return( !compare_float() );
1031          case TYP_DOUBLE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines