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.18 by greg, Sat Dec 1 21:09:53 2018 UTC vs.
Revision 2.19 by greg, Wed Aug 14 04:18:12 2019 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 45 | Line 47 | const char     *file_type[] = {
47                          "ascii",
48                          COLRFMT,
49                          CIEFMT,
50 +                        DEPTH16FMT,
51 +                        NORMAL32FMT,
52                          "float",
53                          "double",
54                          "BSDF_RBFmesh",
55                          "Radiance_octree",
56                          "Radiance_tmesh",
57 +                        "8-bit_indexed_name",
58 +                        "16-bit_indexed_name",
59 +                        "24-bit_indexed_name",
60                          "BINARY_unknown",
61                          NULL    /* terminator */
62                  };
63                                  /* keep consistent with above */
64 < enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT,
65 <                TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY};
64 > enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE,
65 >                TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE,
66 >                TYP_RBFMESH, TYP_OCTREE, TYP_TMESH,
67 >                TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY};
68                  
69   #define has_header(t)   (!( 1L<<(t) & (1L<<TYP_TEXT | 1L<<TYP_BINARY) ))
70  
# Line 210 | Line 219 | color_check(COLOR c1, COLOR c2)
219          return(real_check(colval(c1,p), colval(c2,p)));
220   }
221  
222 + /* Compare two normal directions for equivalence */
223 + static int
224 + norm_check(FVECT nv1, FVECT nv2)
225 + {
226 +        double  max2 = nv1[2]*nv1[2];
227 +        int     imax = 2;
228 +        int     i = 2;
229 +                                        /* identify largest component */
230 +        while (i--) {
231 +                double  tm2 = nv1[i]*nv1[i];
232 +                if (tm2 > max2) {
233 +                        imax = i;
234 +                        max2 = tm2;
235 +                }
236 +        }
237 +        i = 3;                          /* compare smaller components */
238 +        while (i--) {
239 +                if (i == imax)
240 +                        continue;
241 +                if (!real_check(nv1[i], nv2[i]))
242 +                        return(0);
243 +        }
244 +        return(1);
245 + }
246 +
247   /* Compare two strings for equivalence */
248   static int
249   equiv_string(char *s1, char *s2)
# Line 565 | Line 599 | compare_text()
599          return(good_RMS());                     /* final check for reals */
600   }
601  
602 + /* Check image/map resolutions */
603 + static int
604 + check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
605 + {
606 +        if (r1p->rt != r2p->rt) {
607 +                if (report != REP_QUIET)
608 +                        printf(
609 +                        "%s: %ss '%s' and '%s' have different pixel ordering\n",
610 +                                        progname, class, f1name, f2name);
611 +                return(0);
612 +        }
613 +        if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) {
614 +                if (report != REP_QUIET)
615 +                        printf(
616 +                        "%s: %ss '%s' and '%s' are different sizes\n",
617 +                                        progname, class, f1name, f2name);
618 +                return(0);
619 +        }
620 +        return(1);
621 + }
622 +
623   /* Compare two inputs that are known to be RGBE or XYZE images */
624   static int
625   compare_hdr()
# Line 579 | Line 634 | compare_hdr()
634          }
635          fgetsresolu(&rs1, f1in);
636          fgetsresolu(&rs2, f2in);
637 <        if (rs1.rt != rs2.rt) {
583 <                if (report != REP_QUIET)
584 <                        printf(
585 <                        "%s: Images '%s' and '%s' have different pixel ordering\n",
586 <                                        progname, f1name, f2name);
637 >        if (!check_resolu("HDR image", &rs1, &rs2))
638                  return(0);
588        }
589        if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
590                if (report != REP_QUIET)
591                        printf(
592                        "%s: Images '%s' and '%s' are different sizes\n",
593                                        progname, f1name, f2name);
594                return(0);
595        }
639          scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR));
640          scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR));
641          if (!scan1 | !scan2) {
# Line 637 | Line 680 | compare_hdr()
680          return(good_RMS());                     /* final check of RMS */
681   }
682  
683 + /* Set reference depth based on header variable */
684 + static int
685 + set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
686 + {
687 +        static char     depthvar[] = DEPTHSTR;
688 +        const char      *drval;
689 +
690 +        depthvar[LDEPTHSTR] = '\0';
691 +        drval = (const char *)lu_find(htp, depthvar)->data;
692 +        if (!drval)
693 +                return(0);
694 +        dcp->refdepth = atof(drval);
695 +        if (dcp->refdepth <= 0) {
696 +                if (report != REP_QUIET) {
697 +                        fputs(dcp->inpname, stderr);
698 +                        fputs(": bad reference depth '", stderr);
699 +                        fputs(drval, stderr);
700 +                        fputs("'\n", stderr);
701 +                }
702 +                return(-1);
703 +        }
704 +        return(1);
705 + }
706 +
707 + /* Compare two encoded depth maps */
708 + static int
709 + compare_depth()
710 + {
711 +        long            nread = 0;
712 +        DEPTHCODEC      dc1, dc2;
713 +
714 +        if (report >= REP_VERBOSE) {
715 +                fputs(progname, stdout);
716 +                fputs(": comparing inputs as depth maps\n", stdout);
717 +        }
718 +        set_dc_defaults(&dc1);
719 +        dc1.hdrflags = HF_RESIN;
720 +        dc1.finp = f1in;
721 +        dc1.inpname = f1name;
722 +        set_dc_defaults(&dc2);
723 +        dc2.hdrflags = HF_RESIN;
724 +        dc2.finp = f2in;
725 +        dc2.inpname = f2name;
726 +        if (report != REP_QUIET) {
727 +                dc1.hdrflags |= HF_STDERR;
728 +                dc2.hdrflags |= HF_STDERR;
729 +        }
730 +        if (!process_dc_header(&dc1, 0, NULL))
731 +                return(0);
732 +        if (!process_dc_header(&dc2, 0, NULL))
733 +                return(0);
734 +        if (!check_resolu("Depth map", &dc1.res, &dc2.res))
735 +                return(0);
736 +        if (set_refdepth(&dc1, &hdr1) < 0)
737 +                return(0);
738 +        if (set_refdepth(&dc2, &hdr2) < 0)
739 +                return(0);
740 +        while (nread < dc1.res.xr*dc1.res.yr) {
741 +                double  d1 = decode_depth_next(&dc1);
742 +                double  d2 = decode_depth_next(&dc2);
743 +                if ((d1 < 0) | (d2 < 0)) {
744 +                        if (report != REP_QUIET)
745 +                                printf("%s: unexpected end-of-file\n",
746 +                                                progname);
747 +                        return(0);
748 +                }
749 +                ++nread;
750 +                if (real_check(d1, d2))
751 +                        continue;
752 +                if (report != REP_QUIET)
753 +                        printf("%s: %ld%s depth values differ\n",
754 +                                        progname, nread, num_sfx(nread));
755 +                return(0);
756 +        }
757 +        return(good_RMS());             /* final check of RMS */
758 + }
759 +
760 + /* Compare two encoded normal maps */
761 + static int
762 + compare_norm()
763 + {
764 +        long            nread = 0;
765 +        NORMCODEC       nc1, nc2;
766 +
767 +        if (report >= REP_VERBOSE) {
768 +                fputs(progname, stdout);
769 +                fputs(": comparing inputs as normal maps\n", stdout);
770 +        }
771 +        set_nc_defaults(&nc1);
772 +        nc1.hdrflags = HF_RESIN;
773 +        nc1.finp = f1in;
774 +        nc1.inpname = f1name;
775 +        set_nc_defaults(&nc2);
776 +        nc2.hdrflags = HF_RESIN;
777 +        nc2.finp = f2in;
778 +        nc2.inpname = f2name;
779 +        if (report != REP_QUIET) {
780 +                nc1.hdrflags |= HF_STDERR;
781 +                nc2.hdrflags |= HF_STDERR;
782 +        }
783 +        if (!process_nc_header(&nc1, 0, NULL))
784 +                return(0);
785 +        if (!process_nc_header(&nc2, 0, NULL))
786 +                return(0);
787 +        if (!check_resolu("Normal map", &nc1.res, &nc2.res))
788 +                return(0);
789 +        while (nread < nc1.res.xr*nc1.res.yr) {
790 +                FVECT   nv1, nv2;
791 +                int     rv1 = decode_normal_next(nv1, &nc1);
792 +                int     rv2 = decode_normal_next(nv2, &nc2);
793 +                if ((rv1 < 0) | (rv2 < 0)) {
794 +                        if (report != REP_QUIET)
795 +                                printf("%s: unexpected end-of-file\n",
796 +                                                progname);
797 +                        return(0);
798 +                }
799 +                ++nread;
800 +                if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2)))
801 +                        continue;
802 +                if (report != REP_QUIET)
803 +                        printf("%s: %ld%s normal vectors differ\n",
804 +                                        progname, nread, num_sfx(nread));
805 +                return(0);
806 +        }
807 +        return(good_RMS());             /* final check of RMS */
808 + }
809 +
810   /* Compare two inputs that are known to be 32-bit floating-point data */
811   static int
812   compare_float()
# Line 778 | Line 948 | main(int argc, char *argv[])
948          ign_header |= !has_header(typ1);        /* check headers if indicated */
949          if (!ign_header && !headers_match())
950                  return(1);
781        lu_done(&hdr1); lu_done(&hdr2);         /* done with header info. */
951          if (!ign_header & (report >= REP_WARN)) {
952                  if (lin1cnt != lin2cnt)
953                          printf("%s: warning - headers are different lengths\n",
# Line 796 | Line 965 | main(int argc, char *argv[])
965          case TYP_TMESH:
966          case TYP_OCTREE:
967          case TYP_RBFMESH:
968 +        case TYP_ID8:
969 +        case TYP_ID16:
970 +        case TYP_ID24:
971          case TYP_UNKNOWN:
972                  return( !compare_binary() );
973          case TYP_TEXT:
# Line 804 | Line 976 | main(int argc, char *argv[])
976          case TYP_RGBE:
977          case TYP_XYZE:
978                  return( !compare_hdr() );
979 +        case TYP_DEPTH:
980 +                return( !compare_depth() );
981 +        case TYP_NORM:
982 +                return( !compare_norm() );
983          case TYP_FLOAT:
984                  return( !compare_float() );
985          case TYP_DOUBLE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines