--- ray/src/hd/rhpict2.c 1999/03/09 14:23:51 3.6 +++ ray/src/hd/rhpict2.c 1999/03/09 15:08:22 3.8 @@ -205,12 +205,13 @@ int n; int -random_samp(h, v, nl, n) /* grow sample point noisily */ +random_samp(h, v, nl, n, rf) /* grow sample point noisily */ int h, v; register short nl[NNEIGH][2]; int n; +double *rf; { - float nwt[NNEIGH]; + double tv = *rf * (1.-1./NNEIGH); int4 maxr2; register int4 p, r2; register int i; @@ -223,11 +224,6 @@ int n; maxr2 = (h-nl[n-1][0])*(h-nl[n-1][0]) + (v-nl[n-1][1])*(v-nl[n-1][1]); DCHECK(maxr2>=MAXRAD2, CONSISTENCY, "out of range neighbor"); maxr = isqrt(maxr2); - /* compute neighbor weights */ - for (i = n; i--; ) { - r2 = (nl[i][0]-h)*(nl[i][0]-h) + (nl[i][1]-v)*(nl[i][1]-v); - nwt[i] = pixWeight[r2]; - } /* sample kernel */ for (v2 = v-maxr; v2 <= v+maxr; v2++) { if (v2 < 0) v2 = 0; @@ -239,18 +235,25 @@ int n; if (r2 > maxr2) continue; if (CHK4(pixFlags, v2*hres+h2)) continue; /* occupied */ - if (frandom() > pixWeight[r2]) { - /* pick neighbor instead */ + if (frandom() < tv) { /* use neighbor instead? */ i = random() % n; r2 = nl[i][1]*hres + nl[i][0]; copycolor(ctmp, mypixel[r2]); - scalecolor(ctmp, nwt[i]); - addcolor(mypixel[v2*hres+h2], ctmp); - myweight[v2*hres+h2] += nwt[i] * myweight[r2]; - continue; + r2 = (h2-nl[i][0])*(h2-nl[i][0]) + + (v2-nl[i][1])*(v2-nl[i][1]); + if (r2 < MAXRAD2) { + scalecolor(ctmp, pixWeight[r2]); + addcolor(mypixel[v2*hres+h2], ctmp); + myweight[v2*hres+h2] += pixWeight[r2] * + myweight[nl[i][1]*hres+nl[i][0]]; + continue; + } } - addcolor(mypixel[v2*hres+h2], mypixel[p]); - myweight[v2*hres+h2] += myweight[p]; + /* use central sample */ + copycolor(ctmp, mypixel[p]); + scalecolor(ctmp, pixWeight[r2]); + addcolor(mypixel[v2*hres+h2], ctmp); + myweight[v2*hres+h2] += pixWeight[r2] * myweight[p]; } } return(1); @@ -258,17 +261,17 @@ int n; pixFinish(ransamp) /* done with beams -- compute pixel values */ -int ransamp; +double ransamp; { if (pixWeight[0] <= FTINY) init_wfunc(); /* initialize weighting function */ reset_flags(); /* set occupancy flags */ - meet_neighbors(kill_occl); /* eliminate occlusion errors */ + meet_neighbors(kill_occl,NULL); /* eliminate occlusion errors */ reset_flags(); /* reset occupancy flags */ - if (ransamp) /* spread samples over image */ - meet_neighbors(random_samp); + if (ransamp >= 0.) /* spread samples over image */ + meet_neighbors(random_samp,&ransamp); else - meet_neighbors(smooth_samp); + meet_neighbors(smooth_samp,NULL); free((char *)pixFlags); /* free pixel flags */ pixFlags = NULL; } @@ -345,8 +348,9 @@ register short (*rnl)[NNEIGH]; } -meet_neighbors(nf) /* run through samples and their neighbors */ +meet_neighbors(nf, dp) /* run through samples and their neighbors */ int (*nf)(); +char *dp; { short ln[NNEIGH][2]; int h, v, n, v2; @@ -370,7 +374,7 @@ int (*nf)(); if (!CHK4(pixFlags, v*hres+h)) continue; /* no one home */ n = findneigh(ln, h, v, rnl); - (*nf)(h, v, ln, n); /* call on neighbors */ + (*nf)(h, v, ln, n, dp); /* call on neighbors */ } if (++v >= vres) /* reinitialize row list */ break;