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

Comparing ray/src/hd/rhoptimize.c (file contents):
Revision 3.5 by gwlarson, Thu Nov 12 15:07:49 1998 UTC vs.
Revision 3.6 by gwlarson, Sat Jan 9 09:23:49 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ SGI";
20  
21   char    *progname;
22   char    tempfile[128];
23 + int     dupchecking = 0;
24  
25   extern char     *rindex();
26   extern int      quit();
# Line 35 | Line 36 | char   *argv[];
36          long    nextipos, lastopos, thisopos;
37  
38          progname = argv[0];
39 <        if (argc < 2 | argc > 3) {
40 <                fprintf(stderr, "Usage: %s input.hdk [output.hdk]\n", progname);
39 >        argv++; argc--;                 /* duplicate checking flag? */
40 >        if (argc > 1 && !strcmp(argv[0], "-u")) {
41 >                dupchecking++;
42 >                argv++; argc--;
43 >        }
44 >        if (argc < 1 | argc > 2) {
45 >                fprintf(stderr, "Usage: %s [-u] input.hdk [output.hdk]\n",
46 >                                progname);
47                  exit(1);
48          }
49 <        inpname = argv[1];
50 <        if (argc == 3)                  /* use given output file */
51 <                outname = argv[2];
49 >        inpname = argv[0];              /* get input file */
50 >        argv++; argc--;
51 >        if (argc == 1)                  /* use given output file */
52 >                outname = argv[0];
53          else {                          /* else use temporary file */
54                  if (access(inpname, R_OK|W_OK) < 0) {   /* check permissions */
55                          sprintf(errmsg, "cannot access \"%s\"", inpname);
# Line 133 | Line 141 | char   *infn, *outfn;
141   }
142  
143  
144 + int
145 + nuniq(rva, n)                   /* sort unique rays to front of beam list */
146 + register RAYVAL *rva;
147 + int     n;
148 + {
149 +        register int    i, j;
150 +        RAYVAL  rtmp;
151 +
152 +        for (j = 0; j < n; j++)
153 +                for (i = j+1; i < n; i++)
154 +                        if ( rva[i].d == rva[j].d &&
155 +                                        rva[i].r[0][0]==rva[j].r[0][0] &&
156 +                                        rva[i].r[0][1]==rva[j].r[0][1] &&
157 +                                        rva[i].r[1][0]==rva[j].r[1][0] &&
158 +                                        rva[i].r[1][1]==rva[j].r[1][1] ) {
159 +                                n--;            /* swap duplicate with end */
160 +                                copystruct(&rtmp, rva+n);
161 +                                copystruct(rva+n, rva+i);
162 +                                copystruct(rva+i, &rtmp);
163 +                                i--;            /* recheck one we swapped */
164 +                        }
165 +        return(n);
166 + }
167 +
168 +
169   static BEAMI    *beamdir;
170  
171   static int
# Line 141 | Line 174 | int    *b1p, *b2p;
174   {
175          register long   pdif = beamdir[*b1p].fo - beamdir[*b2p].fo;
176  
144        if (pdif > 0L) return(1);
177          if (pdif < 0L) return(-1);
178 <        return(0);
178 >        return(pdif > 0L);
179   }
180  
181   static HOLO     *hout;
# Line 155 | Line 187 | int    *bq, nb;
187   {
188          register int    i;
189          register BEAM   *bp;
190 +        int     n;
191  
192          beamdir = hp->bi;               /* sort based on file position */
193          qsort((char *)bq, nb, sizeof(*bq), bpcmp);
194                                          /* transfer and free each beam */
195          for (i = 0; i < nb; i++) {
196                  bp = hdgetbeam(hp, bq[i]);
197 <                bcopy((char *)hdbray(bp), (char *)hdnewrays(hout,bq[i],bp->nrm),
198 <                                bp->nrm*sizeof(RAYVAL));
197 >                DCHECK(bp==NULL, CONSISTENCY, "empty beam in xferclump");
198 >                n = dupchecking ? nuniq(hdbray(bp),bp->nrm) : bp->nrm;
199 >                bcopy((char *)hdbray(bp), (char *)hdnewrays(hout,bq[i],n),
200 >                                n*sizeof(RAYVAL));
201                  hdfreebeam(hp, bq[i]);
202          }
203          hdflush(hout);                  /* write & free clump */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines