| 1 |
+ |
/* Copyright (c) 1994 Regents of the University of California */ |
| 2 |
+ |
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
#endif |
| 12 |
|
|
| 13 |
|
#include "standard.h" |
| 14 |
|
|
| 15 |
+ |
#include <ctype.h> |
| 16 |
+ |
|
| 17 |
|
#include "view.h" |
| 18 |
|
|
| 19 |
|
#include "color.h" |
| 20 |
|
|
| 21 |
+ |
#include "resolu.h" |
| 22 |
+ |
|
| 23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
| 24 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 25 |
|
|
| 26 |
|
#define F_FORE 1 /* fill foreground */ |
| 27 |
|
#define F_BACK 2 /* fill background */ |
| 28 |
|
|
| 29 |
< |
#define PACKSIZ 42 /* calculation packet size */ |
| 29 |
> |
#define PACKSIZ 256 /* max. calculation packet size */ |
| 30 |
|
|
| 31 |
< |
#define RTCOM "rtrace -h -ovl -fff -x %d %s" |
| 31 |
> |
#define RTCOM "rtrace -h- -ovl -fff " |
| 32 |
|
|
| 33 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
| 34 |
|
|
| 35 |
|
struct position {int x,y; float z;}; |
| 36 |
|
|
| 37 |
+ |
#define NSTEPS 64 /* number steps in overlap prescan */ |
| 38 |
+ |
#define MINSTEP 4 /* minimum worthwhile preview step */ |
| 39 |
+ |
|
| 40 |
+ |
struct bound {int min,max;}; |
| 41 |
+ |
|
| 42 |
|
VIEW ourview = STDVIEW; /* desired view */ |
| 43 |
|
int hresolu = 512; /* horizontal resolution */ |
| 44 |
|
int vresolu = 512; /* vertical resolution */ |
| 45 |
+ |
double pixaspect = 1.0; /* pixel aspect ratio */ |
| 46 |
|
|
| 47 |
|
double zeps = .02; /* allowed z epsilon */ |
| 48 |
|
|
| 51 |
|
|
| 52 |
|
char *progname; |
| 53 |
|
|
| 54 |
< |
int fill = F_FORE|F_BACK; /* selected fill algorithm */ |
| 54 |
> |
int fillo = F_FORE|F_BACK; /* selected fill options */ |
| 55 |
> |
int fillsamp = 0; /* sample separation (0 == inf) */ |
| 56 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
| 57 |
< |
int (*deffill)() = backfill; /* selected fill function */ |
| 57 |
> |
int (*fillfunc)() = backfill; /* selected fill function */ |
| 58 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 59 |
|
double backz = 0.0; /* background z value */ |
| 60 |
|
int normdist = 1; /* normalized distance? */ |
| 62 |
|
|
| 63 |
|
VIEW theirview = STDVIEW; /* input view */ |
| 64 |
|
int gotview; /* got input view? */ |
| 65 |
< |
int thresolu, tvresolu; /* input resolution */ |
| 65 |
> |
int wrongformat = 0; /* input in another format? */ |
| 66 |
> |
RESOLU tresolu; /* input resolution */ |
| 67 |
|
double theirexp; /* input picture exposure */ |
| 68 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 69 |
+ |
int hasmatrix = 0; /* has transformation matrix */ |
| 70 |
|
|
| 71 |
< |
int childpid = -1; /* id of fill process */ |
| 72 |
< |
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 73 |
< |
int queue[PACKSIZ][2]; /* pending pixels */ |
| 71 |
> |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
| 72 |
> |
#define childpid (PDesc[2]) |
| 73 |
> |
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
| 74 |
> |
int packsiz; /* actual packet size */ |
| 75 |
|
int queuesiz; /* number of pixels pending */ |
| 76 |
|
|
| 77 |
|
|
| 79 |
|
int argc; |
| 80 |
|
char *argv[]; |
| 81 |
|
{ |
| 82 |
< |
#define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt |
| 83 |
< |
extern double atof(); |
| 82 |
> |
#define check(ol,al) if (argv[i][ol] || \ |
| 83 |
> |
badarg(argc-i-1,argv+i+1,al)) \ |
| 84 |
> |
goto badopt |
| 85 |
|
int gotvfile = 0; |
| 86 |
|
char *zfile = NULL; |
| 87 |
|
char *err; |
| 97 |
|
} |
| 98 |
|
switch (argv[i][1]) { |
| 99 |
|
case 't': /* threshold */ |
| 100 |
< |
check(2,1); |
| 100 |
> |
check(2,"f"); |
| 101 |
|
zeps = atof(argv[++i]); |
| 102 |
|
break; |
| 103 |
|
case 'n': /* dist. normalized? */ |
| 104 |
< |
check(2,0); |
| 104 |
> |
check(2,NULL); |
| 105 |
|
normdist = !normdist; |
| 106 |
|
break; |
| 107 |
|
case 'f': /* fill type */ |
| 108 |
|
switch (argv[i][2]) { |
| 109 |
|
case '0': /* none */ |
| 110 |
< |
check(3,0); |
| 111 |
< |
fill = 0; |
| 110 |
> |
check(3,NULL); |
| 111 |
> |
fillo = 0; |
| 112 |
|
break; |
| 113 |
|
case 'f': /* foreground */ |
| 114 |
< |
check(3,0); |
| 115 |
< |
fill = F_FORE; |
| 114 |
> |
check(3,NULL); |
| 115 |
> |
fillo = F_FORE; |
| 116 |
|
break; |
| 117 |
|
case 'b': /* background */ |
| 118 |
< |
check(3,0); |
| 119 |
< |
fill = F_BACK; |
| 118 |
> |
check(3,NULL); |
| 119 |
> |
fillo = F_BACK; |
| 120 |
|
break; |
| 121 |
|
case 'a': /* all */ |
| 122 |
< |
check(3,0); |
| 123 |
< |
fill = F_FORE|F_BACK; |
| 122 |
> |
check(3,NULL); |
| 123 |
> |
fillo = F_FORE|F_BACK; |
| 124 |
|
break; |
| 125 |
+ |
case 's': /* sample */ |
| 126 |
+ |
check(3,"i"); |
| 127 |
+ |
fillsamp = atoi(argv[++i]); |
| 128 |
+ |
break; |
| 129 |
|
case 'c': /* color */ |
| 130 |
< |
check(3,3); |
| 131 |
< |
deffill = backfill; |
| 130 |
> |
check(3,"fff"); |
| 131 |
> |
fillfunc = backfill; |
| 132 |
|
setcolr(backcolr, atof(argv[i+1]), |
| 133 |
|
atof(argv[i+2]), atof(argv[i+3])); |
| 134 |
|
i += 3; |
| 135 |
|
break; |
| 136 |
|
case 'z': /* z value */ |
| 137 |
< |
check(3,1); |
| 138 |
< |
deffill = backfill; |
| 137 |
> |
check(3,"f"); |
| 138 |
> |
fillfunc = backfill; |
| 139 |
|
backz = atof(argv[++i]); |
| 140 |
|
break; |
| 141 |
|
case 'r': /* rtrace */ |
| 142 |
< |
check(3,1); |
| 143 |
< |
deffill = rcalfill; |
| 142 |
> |
check(3,"s"); |
| 143 |
> |
fillfunc = rcalfill; |
| 144 |
|
calstart(RTCOM, argv[++i]); |
| 145 |
|
break; |
| 146 |
|
default: |
| 148 |
|
} |
| 149 |
|
break; |
| 150 |
|
case 'z': /* z file */ |
| 151 |
< |
check(2,1); |
| 151 |
> |
check(2,"s"); |
| 152 |
|
zfile = argv[++i]; |
| 153 |
|
break; |
| 154 |
|
case 'x': /* x resolution */ |
| 155 |
< |
check(2,1); |
| 155 |
> |
check(2,"i"); |
| 156 |
|
hresolu = atoi(argv[++i]); |
| 157 |
|
break; |
| 158 |
|
case 'y': /* y resolution */ |
| 159 |
< |
check(2,1); |
| 159 |
> |
check(2,"i"); |
| 160 |
|
vresolu = atoi(argv[++i]); |
| 161 |
|
break; |
| 162 |
+ |
case 'p': /* pixel aspect */ |
| 163 |
+ |
if (argv[i][2] != 'a') |
| 164 |
+ |
goto badopt; |
| 165 |
+ |
check(3,"f"); |
| 166 |
+ |
pixaspect = atof(argv[++i]); |
| 167 |
+ |
break; |
| 168 |
|
case 'v': /* view file */ |
| 169 |
|
if (argv[i][2] != 'f') |
| 170 |
|
goto badopt; |
| 171 |
< |
check(3,1); |
| 172 |
< |
gotvfile = viewfile(argv[++i], &ourview); |
| 173 |
< |
if (gotvfile < 0) { |
| 174 |
< |
perror(argv[i]); |
| 175 |
< |
exit(1); |
| 149 |
< |
} else if (gotvfile == 0) { |
| 171 |
> |
check(3,"s"); |
| 172 |
> |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
| 173 |
> |
if (gotvfile < 0) |
| 174 |
> |
syserror(argv[i]); |
| 175 |
> |
else if (gotvfile == 0) { |
| 176 |
|
fprintf(stderr, "%s: bad view file\n", |
| 177 |
|
argv[i]); |
| 178 |
|
exit(1); |
| 188 |
|
/* check arguments */ |
| 189 |
|
if ((argc-i)%2) |
| 190 |
|
goto userr; |
| 191 |
+ |
if (fillsamp == 1) |
| 192 |
+ |
fillo &= ~F_BACK; |
| 193 |
|
/* set view */ |
| 194 |
< |
if (err = setview(&ourview)) { |
| 194 |
> |
if ((err = setview(&ourview)) != NULL) { |
| 195 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 196 |
|
exit(1); |
| 197 |
|
} |
| 198 |
+ |
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
| 199 |
|
/* allocate frame */ |
| 200 |
< |
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
| 201 |
< |
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
| 200 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
| 201 |
> |
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 202 |
|
if (ourpict == NULL || ourzbuf == NULL) |
| 203 |
< |
syserror(); |
| 203 |
> |
syserror(progname); |
| 204 |
> |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
| 205 |
> |
/* new header */ |
| 206 |
> |
newheader("RADIANCE", stdout); |
| 207 |
|
/* get input */ |
| 208 |
|
for ( ; i < argc; i += 2) |
| 209 |
|
addpicture(argv[i], argv[i+1]); |
| 210 |
|
/* fill in spaces */ |
| 211 |
< |
if (fill&F_BACK) |
| 212 |
< |
backpicture(); |
| 211 |
> |
if (fillo&F_BACK) |
| 212 |
> |
backpicture(fillfunc, fillsamp); |
| 213 |
|
else |
| 214 |
< |
fillpicture(); |
| 214 |
> |
fillpicture(fillfunc); |
| 215 |
|
/* close calculation */ |
| 216 |
|
caldone(); |
| 217 |
+ |
/* aft clipping */ |
| 218 |
+ |
clipaft(); |
| 219 |
|
/* add to header */ |
| 220 |
|
printargs(argc, argv, stdout); |
| 221 |
|
if (gotvfile) { |
| 222 |
< |
printf(VIEWSTR); |
| 222 |
> |
fputs(VIEWSTR, stdout); |
| 223 |
|
fprintview(&ourview, stdout); |
| 224 |
< |
printf("\n"); |
| 224 |
> |
putc('\n', stdout); |
| 225 |
|
} |
| 226 |
< |
if (ourexp > 0 && ourexp != 1.0) |
| 226 |
> |
if (pixaspect < .99 || pixaspect > 1.01) |
| 227 |
> |
fputaspect(pixaspect, stdout); |
| 228 |
> |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 229 |
|
fputexpos(ourexp, stdout); |
| 230 |
< |
printf("\n"); |
| 230 |
> |
fputformat(COLRFMT, stdout); |
| 231 |
> |
putc('\n', stdout); |
| 232 |
|
/* write picture */ |
| 233 |
|
writepicture(); |
| 234 |
|
/* write z file */ |
| 248 |
|
headline(s) /* process header string */ |
| 249 |
|
char *s; |
| 250 |
|
{ |
| 251 |
< |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
| 215 |
< |
register char **an; |
| 251 |
> |
char fmt[32]; |
| 252 |
|
|
| 253 |
< |
printf("\t%s", s); |
| 253 |
> |
if (isheadid(s)) |
| 254 |
> |
return; |
| 255 |
> |
if (formatval(fmt, s)) { |
| 256 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
| 257 |
> |
return; |
| 258 |
> |
} |
| 259 |
> |
putc('\t', stdout); |
| 260 |
> |
fputs(s, stdout); |
| 261 |
|
|
| 262 |
|
if (isexpos(s)) { |
| 263 |
|
theirexp *= exposval(s); |
| 264 |
|
return; |
| 265 |
|
} |
| 266 |
< |
for (an = altname; *an != NULL; an++) |
| 267 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
| 225 |
< |
if (sscanview(&theirview, s+strlen(*an)) > 0) |
| 226 |
< |
gotview++; |
| 227 |
< |
break; |
| 228 |
< |
} |
| 266 |
> |
if (isview(s) && sscanview(&theirview, s) > 0) |
| 267 |
> |
gotview++; |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
|
addpicture(pfile, zspec) /* add picture to output */ |
| 272 |
|
char *pfile, *zspec; |
| 273 |
|
{ |
| 274 |
< |
extern double atof(); |
| 275 |
< |
FILE *pfp, *zfp; |
| 274 |
> |
FILE *pfp; |
| 275 |
> |
int zfd; |
| 276 |
|
char *err; |
| 277 |
|
COLR *scanin; |
| 278 |
|
float *zin; |
| 279 |
|
struct position *plast; |
| 280 |
+ |
struct bound *xlim, ylim; |
| 281 |
|
int y; |
| 282 |
|
/* open picture file */ |
| 283 |
< |
if ((pfp = fopen(pfile, "r")) == NULL) { |
| 284 |
< |
perror(pfile); |
| 245 |
< |
exit(1); |
| 246 |
< |
} |
| 283 |
> |
if ((pfp = fopen(pfile, "r")) == NULL) |
| 284 |
> |
syserror(pfile); |
| 285 |
|
/* get header with exposure and view */ |
| 286 |
|
theirexp = 1.0; |
| 287 |
|
gotview = 0; |
| 288 |
|
printf("%s:\n", pfile); |
| 289 |
< |
getheader(pfp, headline); |
| 290 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
| 291 |
< |
!= (YMAJOR|YDECR)) { |
| 254 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
| 289 |
> |
getheader(pfp, headline, NULL); |
| 290 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
| 291 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
| 292 |
|
exit(1); |
| 293 |
|
} |
| 294 |
|
if (ourexp <= 0) |
| 300 |
|
exit(1); |
| 301 |
|
} |
| 302 |
|
/* compute transformation */ |
| 303 |
< |
pixform(theirs2ours, &theirview, &ourview); |
| 267 |
< |
/* allocate scanlines */ |
| 268 |
< |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
| 269 |
< |
zin = (float *)malloc(thresolu*sizeof(float)); |
| 270 |
< |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
| 271 |
< |
if (scanin == NULL || zin == NULL || plast == NULL) |
| 272 |
< |
syserror(); |
| 303 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
| 304 |
|
/* get z specification or file */ |
| 305 |
< |
if ((zfp = fopen(zspec, "r")) == NULL) { |
| 305 |
> |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
| 306 |
> |
if (zin == NULL) |
| 307 |
> |
syserror(progname); |
| 308 |
> |
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 309 |
|
double zvalue; |
| 310 |
|
register int x; |
| 311 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 312 |
< |
perror(zspec); |
| 313 |
< |
exit(1); |
| 280 |
< |
} |
| 281 |
< |
for (x = 0; x < thresolu; x++) |
| 311 |
> |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) |
| 312 |
> |
syserror(zspec); |
| 313 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
| 314 |
|
zin[x] = zvalue; |
| 315 |
|
} |
| 316 |
< |
/* load image */ |
| 317 |
< |
for (y = tvresolu-1; y >= 0; y--) { |
| 318 |
< |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
| 316 |
> |
/* compute transferrable perimeter */ |
| 317 |
> |
xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); |
| 318 |
> |
if (xlim == NULL) |
| 319 |
> |
syserror(progname); |
| 320 |
> |
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
| 321 |
> |
free((char *)zin); |
| 322 |
> |
free((char *)xlim); |
| 323 |
> |
if (zfd != -1) |
| 324 |
> |
close(zfd); |
| 325 |
> |
fclose(pfp); |
| 326 |
> |
return; |
| 327 |
> |
} |
| 328 |
> |
/* allocate scanlines */ |
| 329 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
| 330 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
| 331 |
> |
sizeof(struct position)); |
| 332 |
> |
if (scanin == NULL | plast == NULL) |
| 333 |
> |
syserror(progname); |
| 334 |
> |
/* skip to starting point */ |
| 335 |
> |
for (y = 0; y < ylim.min; y++) |
| 336 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 337 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 338 |
|
exit(1); |
| 339 |
|
} |
| 340 |
< |
if (zfp != NULL |
| 341 |
< |
&& fread(zin,sizeof(float),thresolu,zfp) < thresolu) { |
| 342 |
< |
fprintf(stderr, "%s: read error\n", zspec); |
| 340 |
> |
if (zfd != -1 && lseek(zfd, |
| 341 |
> |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
| 342 |
> |
syserror(zspec); |
| 343 |
> |
/* load image */ |
| 344 |
> |
for (y = ylim.min; y <= ylim.max; y++) { |
| 345 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 346 |
> |
fprintf(stderr, "%s: read error\n", pfile); |
| 347 |
|
exit(1); |
| 348 |
|
} |
| 349 |
< |
addscanline(y, scanin, zin, plast); |
| 349 |
> |
if (zfd != -1 && read(zfd, (char *)zin, |
| 350 |
> |
scanlen(&tresolu)*sizeof(float)) |
| 351 |
> |
< scanlen(&tresolu)*sizeof(float)) |
| 352 |
> |
syserror(zspec); |
| 353 |
> |
addscanline(xlim+y, y, scanin, zin, plast); |
| 354 |
|
} |
| 355 |
|
/* clean up */ |
| 356 |
+ |
free((char *)xlim); |
| 357 |
|
free((char *)scanin); |
| 358 |
|
free((char *)zin); |
| 359 |
|
free((char *)plast); |
| 360 |
|
fclose(pfp); |
| 361 |
< |
if (zfp != NULL) |
| 362 |
< |
fclose(zfp); |
| 361 |
> |
if (zfd != -1) |
| 362 |
> |
close(zfd); |
| 363 |
|
} |
| 364 |
|
|
| 365 |
|
|
| 369 |
|
{ |
| 370 |
|
double m4t[4][4]; |
| 371 |
|
|
| 372 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
| 373 |
+ |
return(0); |
| 374 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
| 375 |
+ |
return(0); |
| 376 |
|
setident4(xfmat); |
| 377 |
|
xfmat[0][0] = vw1->hvec[0]; |
| 378 |
|
xfmat[0][1] = vw1->hvec[1]; |
| 400 |
|
m4t[2][2] = vw2->vdir[2]; |
| 401 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
| 402 |
|
multmat4(xfmat, xfmat, m4t); |
| 403 |
+ |
return(1); |
| 404 |
|
} |
| 405 |
|
|
| 406 |
|
|
| 407 |
< |
addscanline(y, pline, zline, lasty) /* add scanline to output */ |
| 407 |
> |
addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ |
| 408 |
> |
struct bound *xl; |
| 409 |
|
int y; |
| 410 |
|
COLR *pline; |
| 411 |
|
float *zline; |
| 412 |
|
struct position *lasty; /* input/output */ |
| 413 |
|
{ |
| 414 |
< |
extern double sqrt(); |
| 350 |
< |
double pos[3]; |
| 414 |
> |
FVECT pos; |
| 415 |
|
struct position lastx, newpos; |
| 416 |
|
register int x; |
| 417 |
|
|
| 418 |
< |
for (x = thresolu-1; x >= 0; x--) { |
| 419 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
| 420 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
| 418 |
> |
lastx.z = 0; |
| 419 |
> |
for (x = xl->max; x >= xl->min; x--) { |
| 420 |
> |
pix2loc(pos, &tresolu, x, y); |
| 421 |
|
pos[2] = zline[x]; |
| 422 |
< |
if (theirview.type == VT_PER) { |
| 359 |
< |
if (normdist) /* adjust for eye-ray distance */ |
| 360 |
< |
pos[2] /= sqrt( 1. |
| 361 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
| 362 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 363 |
< |
pos[0] *= pos[2]; |
| 364 |
< |
pos[1] *= pos[2]; |
| 365 |
< |
} |
| 366 |
< |
multp3(pos, pos, theirs2ours); |
| 367 |
< |
if (pos[2] <= 0) { |
| 422 |
> |
if (movepixel(pos) < 0) { |
| 423 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 424 |
|
continue; |
| 425 |
|
} |
| 371 |
– |
if (ourview.type == VT_PER) { |
| 372 |
– |
pos[0] /= pos[2]; |
| 373 |
– |
pos[1] /= pos[2]; |
| 374 |
– |
} |
| 375 |
– |
pos[0] += .5 - ourview.hoff; |
| 376 |
– |
pos[1] += .5 - ourview.voff; |
| 426 |
|
newpos.x = pos[0] * hresolu; |
| 427 |
|
newpos.y = pos[1] * vresolu; |
| 428 |
|
newpos.z = zline[x]; |
| 452 |
|
register int x, y; /* final position */ |
| 453 |
|
|
| 454 |
|
/* compute vector p0p1 */ |
| 455 |
< |
if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 455 |
> |
if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 456 |
|
s1x = p1->x - p0->x; |
| 457 |
|
s1y = p1->y - p0->y; |
| 458 |
|
l1 = ABS(s1x); |
| 463 |
|
p1isy = -1; |
| 464 |
|
} |
| 465 |
|
/* compute vector p0p2 */ |
| 466 |
< |
if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) { |
| 466 |
> |
if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) { |
| 467 |
|
s2x = p2->x - p0->x; |
| 468 |
|
s2y = p2->y - p0->y; |
| 469 |
|
if (p1isy == 1) |
| 481 |
|
y1 = p0->y + c1*s1y/l1; |
| 482 |
|
for (c2 = l2; c2-- > 0; ) { |
| 483 |
|
x = x1 + c2*s2x/l2; |
| 484 |
+ |
if (x < 0 || x >= hresolu) |
| 485 |
+ |
continue; |
| 486 |
|
y = y1 + c2*s2y/l2; |
| 487 |
+ |
if (y < 0 || y >= vresolu) |
| 488 |
+ |
continue; |
| 489 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 490 |
|
> zeps*zscan(y)[x]) { |
| 491 |
|
zscan(y)[x] = z; |
| 496 |
|
} |
| 497 |
|
|
| 498 |
|
|
| 499 |
< |
backpicture() /* background fill algorithm */ |
| 499 |
> |
movepixel(pos) /* reposition image point */ |
| 500 |
> |
FVECT pos; |
| 501 |
|
{ |
| 502 |
+ |
double d0, d1; |
| 503 |
+ |
FVECT pt, direc; |
| 504 |
+ |
|
| 505 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
| 506 |
+ |
return(-1); |
| 507 |
+ |
if (normdist && theirview.type == VT_PER) { /* adjust distance */ |
| 508 |
+ |
d0 = pos[0] + theirview.hoff - .5; |
| 509 |
+ |
d1 = pos[1] + theirview.voff - .5; |
| 510 |
+ |
pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); |
| 511 |
+ |
} |
| 512 |
+ |
if (hasmatrix) { |
| 513 |
+ |
pos[0] += theirview.hoff - .5; |
| 514 |
+ |
pos[1] += theirview.voff - .5; |
| 515 |
+ |
if (theirview.type == VT_PER) { |
| 516 |
+ |
pos[0] *= pos[2]; |
| 517 |
+ |
pos[1] *= pos[2]; |
| 518 |
+ |
} |
| 519 |
+ |
multp3(pos, pos, theirs2ours); |
| 520 |
+ |
if (pos[2] <= 0) |
| 521 |
+ |
return(-1); |
| 522 |
+ |
if (ourview.type == VT_PER) { |
| 523 |
+ |
pos[0] /= pos[2]; |
| 524 |
+ |
pos[1] /= pos[2]; |
| 525 |
+ |
} |
| 526 |
+ |
pos[0] += .5 - ourview.hoff; |
| 527 |
+ |
pos[1] += .5 - ourview.voff; |
| 528 |
+ |
return(0); |
| 529 |
+ |
} |
| 530 |
+ |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY) |
| 531 |
+ |
return(-1); |
| 532 |
+ |
pt[0] += direc[0]*pos[2]; |
| 533 |
+ |
pt[1] += direc[1]*pos[2]; |
| 534 |
+ |
pt[2] += direc[2]*pos[2]; |
| 535 |
+ |
viewloc(pos, &ourview, pt); |
| 536 |
+ |
if (pos[2] <= 0) |
| 537 |
+ |
return(-1); |
| 538 |
+ |
return(0); |
| 539 |
+ |
} |
| 540 |
+ |
|
| 541 |
+ |
|
| 542 |
+ |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
| 543 |
+ |
register struct bound *xl; |
| 544 |
+ |
struct bound *yl; |
| 545 |
+ |
float *zline; |
| 546 |
+ |
int zfd; |
| 547 |
+ |
{ |
| 548 |
+ |
int step; |
| 549 |
+ |
FVECT pos; |
| 550 |
+ |
register int x, y; |
| 551 |
+ |
/* set up step size */ |
| 552 |
+ |
if (scanlen(&tresolu) < numscans(&tresolu)) |
| 553 |
+ |
step = scanlen(&tresolu)/NSTEPS; |
| 554 |
+ |
else |
| 555 |
+ |
step = numscans(&tresolu)/NSTEPS; |
| 556 |
+ |
if (step < MINSTEP) { /* not worth cropping? */ |
| 557 |
+ |
yl->min = 0; |
| 558 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 559 |
+ |
x = scanlen(&tresolu) - 1; |
| 560 |
+ |
for (y = numscans(&tresolu); y--; ) { |
| 561 |
+ |
xl[y].min = 0; |
| 562 |
+ |
xl[y].max = x; |
| 563 |
+ |
} |
| 564 |
+ |
return(1); |
| 565 |
+ |
} |
| 566 |
+ |
yl->min = 32000; yl->max = 0; /* search for points on image */ |
| 567 |
+ |
for (y = step - 1; y < numscans(&tresolu); y += step) { |
| 568 |
+ |
if (zfd != -1) { |
| 569 |
+ |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
| 570 |
+ |
0) < 0) |
| 571 |
+ |
syserror("lseek"); |
| 572 |
+ |
if (read(zfd, (char *)zline, |
| 573 |
+ |
scanlen(&tresolu)*sizeof(float)) |
| 574 |
+ |
< scanlen(&tresolu)*sizeof(float)) |
| 575 |
+ |
syserror("read"); |
| 576 |
+ |
} |
| 577 |
+ |
xl[y].min = 32000; xl[y].max = 0; /* x max */ |
| 578 |
+ |
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
| 579 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 580 |
+ |
pos[2] = zline[x]; |
| 581 |
+ |
if (movepixel(pos) == 0 && pos[0] >= 0 && |
| 582 |
+ |
pos[0] < 1 && pos[1] >= 0 && |
| 583 |
+ |
pos[1] < 1) { |
| 584 |
+ |
xl[y].max = x + step - 1; |
| 585 |
+ |
xl[y].min = x - step + 1; /* x min */ |
| 586 |
+ |
if (xl[y].min < 0) |
| 587 |
+ |
xl[y].min = 0; |
| 588 |
+ |
for (x = step - 1; x < xl[y].max; x += step) { |
| 589 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 590 |
+ |
pos[2] = zline[x]; |
| 591 |
+ |
if (movepixel(pos) == 0 && |
| 592 |
+ |
pos[0] >= 0 && |
| 593 |
+ |
pos[0] < 1 && |
| 594 |
+ |
pos[1] >= 0 && |
| 595 |
+ |
pos[1] < 1) { |
| 596 |
+ |
xl[y].min = x - step + 1; |
| 597 |
+ |
break; |
| 598 |
+ |
} |
| 599 |
+ |
} |
| 600 |
+ |
if (y < yl->min) /* y limits */ |
| 601 |
+ |
yl->min = y - step + 1; |
| 602 |
+ |
yl->max = y + step - 1; |
| 603 |
+ |
break; |
| 604 |
+ |
} |
| 605 |
+ |
} |
| 606 |
+ |
/* fill in between */ |
| 607 |
+ |
if (y < step) { |
| 608 |
+ |
xl[y-1].min = xl[y].min; |
| 609 |
+ |
xl[y-1].max = xl[y].max; |
| 610 |
+ |
} else { |
| 611 |
+ |
if (xl[y].min < xl[y-step].min) |
| 612 |
+ |
xl[y-1].min = xl[y].min; |
| 613 |
+ |
else |
| 614 |
+ |
xl[y-1].min = xl[y-step].min; |
| 615 |
+ |
if (xl[y].max > xl[y-step].max) |
| 616 |
+ |
xl[y-1].max = xl[y].max; |
| 617 |
+ |
else |
| 618 |
+ |
xl[y-1].max = xl[y-step].max; |
| 619 |
+ |
} |
| 620 |
+ |
for (x = 2; x < step; x++) |
| 621 |
+ |
copystruct(xl+y-x, xl+y-1); |
| 622 |
+ |
} |
| 623 |
+ |
if (yl->max >= numscans(&tresolu)) |
| 624 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 625 |
+ |
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
| 626 |
+ |
copystruct(xl+x, xl+y); |
| 627 |
+ |
return(yl->max >= yl->min); |
| 628 |
+ |
} |
| 629 |
+ |
|
| 630 |
+ |
|
| 631 |
+ |
backpicture(fill, samp) /* background fill algorithm */ |
| 632 |
+ |
int (*fill)(); |
| 633 |
+ |
int samp; |
| 634 |
+ |
{ |
| 635 |
|
int *yback, xback; |
| 636 |
|
int y; |
| 450 |
– |
COLR pfill; |
| 637 |
|
register int x, i; |
| 638 |
|
/* get back buffer */ |
| 639 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
| 640 |
|
if (yback == NULL) |
| 641 |
< |
syserror(); |
| 641 |
> |
syserror(progname); |
| 642 |
|
for (x = 0; x < hresolu; x++) |
| 643 |
|
yback[x] = -2; |
| 644 |
|
/* |
| 680 |
|
xback = x-1; |
| 681 |
|
} |
| 682 |
|
/* |
| 683 |
< |
* Check to see if we have no background for |
| 684 |
< |
* this pixel. If not, use background color. |
| 683 |
> |
* If we have no background for this pixel, |
| 684 |
> |
* use the given fill function. |
| 685 |
|
*/ |
| 686 |
< |
if (xback < 0 && yback[x] < 0) { |
| 687 |
< |
(*deffill)(x,y); |
| 502 |
< |
continue; |
| 503 |
< |
} |
| 686 |
> |
if (xback < 0 && yback[x] < 0) |
| 687 |
> |
goto fillit; |
| 688 |
|
/* |
| 689 |
|
* Compare, and use the background that is |
| 690 |
|
* farther, unless one of them is next to us. |
| 691 |
+ |
* If the background is too distant, call |
| 692 |
+ |
* the fill function. |
| 693 |
|
*/ |
| 694 |
|
if ( yback[x] < 0 |
| 695 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
| 696 |
|
|| ( ABS(y-yback[x]) > 1 |
| 697 |
|
&& zscan(yback[x])[x] |
| 698 |
|
< zscan(y)[xback] ) ) { |
| 699 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
| 700 |
+ |
goto fillit; |
| 701 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 702 |
|
zscan(y)[x] = zscan(y)[xback]; |
| 703 |
|
} else { |
| 704 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
| 705 |
+ |
goto fillit; |
| 706 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 707 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
| 708 |
|
} |
| 709 |
+ |
continue; |
| 710 |
+ |
fillit: |
| 711 |
+ |
(*fill)(x,y); |
| 712 |
+ |
if (fill == rcalfill) { /* use it */ |
| 713 |
+ |
clearqueue(); |
| 714 |
+ |
xback = x; |
| 715 |
+ |
yback[x] = y; |
| 716 |
+ |
} |
| 717 |
|
} else { /* full pixel */ |
| 718 |
|
yback[x] = -2; |
| 719 |
|
xback = -2; |
| 723 |
|
} |
| 724 |
|
|
| 725 |
|
|
| 726 |
< |
fillpicture() /* paint in empty pixels with default */ |
| 726 |
> |
fillpicture(fill) /* paint in empty pixels using fill */ |
| 727 |
> |
int (*fill)(); |
| 728 |
|
{ |
| 729 |
|
register int x, y; |
| 730 |
|
|
| 731 |
|
for (y = 0; y < vresolu; y++) |
| 732 |
|
for (x = 0; x < hresolu; x++) |
| 733 |
|
if (zscan(y)[x] <= 0) |
| 734 |
< |
(*deffill)(x,y); |
| 734 |
> |
(*fill)(x,y); |
| 735 |
|
} |
| 736 |
|
|
| 737 |
|
|
| 738 |
+ |
clipaft() /* perform aft clipping as indicated */ |
| 739 |
+ |
{ |
| 740 |
+ |
register int x, y; |
| 741 |
+ |
double tstdist; |
| 742 |
+ |
double yzn2, vx; |
| 743 |
+ |
|
| 744 |
+ |
if (ourview.vaft <= FTINY) |
| 745 |
+ |
return; |
| 746 |
+ |
tstdist = ourview.vaft - ourview.vfore; |
| 747 |
+ |
for (y = 0; y < vresolu; y++) { |
| 748 |
+ |
if (ourview.type == VT_PER) { /* adjust distance */ |
| 749 |
+ |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 750 |
+ |
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 751 |
+ |
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
| 752 |
+ |
} |
| 753 |
+ |
for (x = 0; x < hresolu; x++) |
| 754 |
+ |
if (zscan(y)[x] > tstdist) { |
| 755 |
+ |
if (ourview.type == VT_PER) { |
| 756 |
+ |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 757 |
+ |
if (zscan(y)[x] <= (ourview.vaft - |
| 758 |
+ |
ourview.vfore) * |
| 759 |
+ |
sqrt(vx*vx*ourview.hn2 + yzn2)) |
| 760 |
+ |
continue; |
| 761 |
+ |
} |
| 762 |
+ |
bzero(pscan(y)[x], sizeof(COLR)); |
| 763 |
+ |
zscan(y)[x] = 0.0; |
| 764 |
+ |
} |
| 765 |
+ |
} |
| 766 |
+ |
} |
| 767 |
+ |
|
| 768 |
+ |
|
| 769 |
|
writepicture() /* write out picture */ |
| 770 |
|
{ |
| 771 |
|
int y; |
| 772 |
|
|
| 773 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
| 773 |
> |
fprtresolu(hresolu, vresolu, stdout); |
| 774 |
|
for (y = vresolu-1; y >= 0; y--) |
| 775 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 776 |
< |
syserror(); |
| 776 |
> |
syserror(progname); |
| 777 |
|
} |
| 778 |
|
|
| 779 |
|
|
| 780 |
|
writedistance(fname) /* write out z file */ |
| 781 |
|
char *fname; |
| 782 |
|
{ |
| 553 |
– |
extern double sqrt(); |
| 783 |
|
int donorm = normdist && ourview.type == VT_PER; |
| 784 |
< |
FILE *fp; |
| 784 |
> |
int fd; |
| 785 |
|
int y; |
| 786 |
|
float *zout; |
| 787 |
|
|
| 788 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
| 789 |
< |
perror(fname); |
| 561 |
< |
exit(1); |
| 562 |
< |
} |
| 788 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
| 789 |
> |
syserror(fname); |
| 790 |
|
if (donorm |
| 791 |
|
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 792 |
< |
syserror(); |
| 792 |
> |
syserror(progname); |
| 793 |
|
for (y = vresolu-1; y >= 0; y--) { |
| 794 |
|
if (donorm) { |
| 795 |
|
double vx, yzn2; |
| 796 |
|
register int x; |
| 797 |
< |
yzn2 = y - .5*(vresolu-1); |
| 797 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 798 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 799 |
|
for (x = 0; x < hresolu; x++) { |
| 800 |
< |
vx = x - .5*(hresolu-1); |
| 800 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 801 |
|
zout[x] = zscan(y)[x] |
| 802 |
|
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 803 |
|
} |
| 804 |
|
} else |
| 805 |
|
zout = zscan(y); |
| 806 |
< |
if (fwrite(zout, sizeof(float), hresolu, fp) < hresolu) { |
| 807 |
< |
perror(fname); |
| 808 |
< |
exit(1); |
| 582 |
< |
} |
| 806 |
> |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
| 807 |
> |
< hresolu*sizeof(float)) |
| 808 |
> |
syserror(fname); |
| 809 |
|
} |
| 810 |
|
if (donorm) |
| 811 |
|
free((char *)zout); |
| 812 |
< |
fclose(fp); |
| 812 |
> |
close(fd); |
| 813 |
|
} |
| 814 |
|
|
| 815 |
|
|
| 834 |
|
} |
| 835 |
|
|
| 836 |
|
|
| 837 |
< |
calstart(prog, args) /* start fill calculation */ |
| 837 |
> |
calstart(prog, args) /* start fill calculation */ |
| 838 |
|
char *prog, *args; |
| 839 |
|
{ |
| 840 |
|
char combuf[512]; |
| 841 |
< |
int p0[2], p1[2]; |
| 841 |
> |
char *argv[64]; |
| 842 |
> |
int rval; |
| 843 |
> |
register char **wp, *cp; |
| 844 |
|
|
| 845 |
|
if (childpid != -1) { |
| 846 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
| 847 |
|
exit(1); |
| 848 |
|
} |
| 849 |
< |
sprintf(combuf, prog, PACKSIZ, args); |
| 850 |
< |
if (pipe(p0) < 0 || pipe(p1) < 0) |
| 851 |
< |
syserror(); |
| 852 |
< |
if ((childpid = vfork()) == 0) { /* fork calculation */ |
| 853 |
< |
close(p0[1]); |
| 854 |
< |
close(p1[0]); |
| 855 |
< |
if (p0[0] != 0) { |
| 856 |
< |
dup2(p0[0], 0); |
| 857 |
< |
close(p0[0]); |
| 858 |
< |
} |
| 859 |
< |
if (p1[1] != 1) { |
| 860 |
< |
dup2(p1[1], 1); |
| 633 |
< |
close(p1[1]); |
| 634 |
< |
} |
| 635 |
< |
execl("/bin/sh", "sh", "-c", combuf, 0); |
| 636 |
< |
perror("/bin/sh"); |
| 637 |
< |
_exit(127); |
| 849 |
> |
strcpy(combuf, prog); |
| 850 |
> |
strcat(combuf, args); |
| 851 |
> |
cp = combuf; |
| 852 |
> |
wp = argv; |
| 853 |
> |
for ( ; ; ) { |
| 854 |
> |
while (isspace(*cp)) /* nullify spaces */ |
| 855 |
> |
*cp++ = '\0'; |
| 856 |
> |
if (!*cp) /* all done? */ |
| 857 |
> |
break; |
| 858 |
> |
*wp++ = cp; /* add argument to list */ |
| 859 |
> |
while (*++cp && !isspace(*cp)) |
| 860 |
> |
; |
| 861 |
|
} |
| 862 |
< |
if (childpid == -1) |
| 863 |
< |
syserror(); |
| 864 |
< |
close(p0[0]); |
| 865 |
< |
close(p1[1]); |
| 866 |
< |
if ((psend = fdopen(p0[1], "w")) == NULL) |
| 867 |
< |
syserror(); |
| 868 |
< |
if ((precv = fdopen(p1[0], "r")) == NULL) |
| 869 |
< |
syserror(); |
| 862 |
> |
*wp = NULL; |
| 863 |
> |
/* start process */ |
| 864 |
> |
if ((rval = open_process(PDesc, argv)) < 0) |
| 865 |
> |
syserror(progname); |
| 866 |
> |
if (rval == 0) { |
| 867 |
> |
fprintf(stderr, "%s: command not found\n", argv[0]); |
| 868 |
> |
exit(1); |
| 869 |
> |
} |
| 870 |
> |
packsiz = rval/(6*sizeof(float)) - 1; |
| 871 |
> |
if (packsiz > PACKSIZ) |
| 872 |
> |
packsiz = PACKSIZ; |
| 873 |
|
queuesiz = 0; |
| 874 |
|
} |
| 875 |
|
|
| 876 |
|
|
| 877 |
< |
caldone() /* done with calculation */ |
| 877 |
> |
caldone() /* done with calculation */ |
| 878 |
|
{ |
| 653 |
– |
int pid; |
| 654 |
– |
|
| 879 |
|
if (childpid == -1) |
| 880 |
|
return; |
| 657 |
– |
if (fclose(psend) == EOF) |
| 658 |
– |
syserror(); |
| 881 |
|
clearqueue(); |
| 882 |
< |
fclose(precv); |
| 661 |
< |
while ((pid = wait(0)) != -1 && pid != childpid) |
| 662 |
< |
; |
| 882 |
> |
close_process(PDesc); |
| 883 |
|
childpid = -1; |
| 884 |
|
} |
| 885 |
|
|
| 887 |
|
rcalfill(x, y) /* fill with ray-calculated pixel */ |
| 888 |
|
int x, y; |
| 889 |
|
{ |
| 890 |
< |
FVECT orig, dir; |
| 671 |
< |
float outbuf[6]; |
| 672 |
< |
|
| 673 |
< |
if (queuesiz >= PACKSIZ) { /* flush queue */ |
| 674 |
< |
if (fflush(psend) == EOF) |
| 675 |
< |
syserror(); |
| 890 |
> |
if (queuesiz >= packsiz) /* flush queue if needed */ |
| 891 |
|
clearqueue(); |
| 892 |
< |
} |
| 678 |
< |
/* send new ray */ |
| 679 |
< |
viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu); |
| 680 |
< |
outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2]; |
| 681 |
< |
outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2]; |
| 682 |
< |
if (fwrite(outbuf, sizeof(float), 6, psend) < 6) |
| 683 |
< |
syserror(); |
| 684 |
< |
/* remember it */ |
| 892 |
> |
/* add position to queue */ |
| 893 |
|
queue[queuesiz][0] = x; |
| 894 |
|
queue[queuesiz][1] = y; |
| 895 |
|
queuesiz++; |
| 896 |
|
} |
| 897 |
|
|
| 898 |
|
|
| 899 |
< |
clearqueue() /* get results from queue */ |
| 899 |
> |
clearqueue() /* process queue */ |
| 900 |
|
{ |
| 901 |
< |
float inbuf[4]; |
| 901 |
> |
FVECT orig, dir; |
| 902 |
> |
float fbuf[6*(PACKSIZ+1)]; |
| 903 |
> |
register float *fbp; |
| 904 |
|
register int i; |
| 905 |
|
|
| 906 |
+ |
if (queuesiz == 0) |
| 907 |
+ |
return; |
| 908 |
+ |
fbp = fbuf; |
| 909 |
|
for (i = 0; i < queuesiz; i++) { |
| 910 |
< |
if (fread(inbuf, sizeof(float), 4, precv) < 4) { |
| 911 |
< |
fprintf(stderr, "%s: read error in clearqueue\n", |
| 912 |
< |
progname); |
| 913 |
< |
exit(1); |
| 914 |
< |
} |
| 910 |
> |
viewray(orig, dir, &ourview, |
| 911 |
> |
(queue[i][0]+.5)/hresolu, |
| 912 |
> |
(queue[i][1]+.5)/vresolu); |
| 913 |
> |
*fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2]; |
| 914 |
> |
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
| 915 |
> |
} |
| 916 |
> |
/* mark end and get results */ |
| 917 |
> |
bzero((char *)fbp, 6*sizeof(float)); |
| 918 |
> |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
| 919 |
> |
6*sizeof(float)*(queuesiz+1)) != |
| 920 |
> |
4*sizeof(float)*queuesiz) { |
| 921 |
> |
fprintf(stderr, "%s: error reading from rtrace process\n", |
| 922 |
> |
progname); |
| 923 |
> |
exit(1); |
| 924 |
> |
} |
| 925 |
> |
fbp = fbuf; |
| 926 |
> |
for (i = 0; i < queuesiz; i++) { |
| 927 |
|
if (ourexp > 0 && ourexp != 1.0) { |
| 928 |
< |
inbuf[0] *= ourexp; |
| 929 |
< |
inbuf[1] *= ourexp; |
| 930 |
< |
inbuf[2] *= ourexp; |
| 928 |
> |
fbp[0] *= ourexp; |
| 929 |
> |
fbp[1] *= ourexp; |
| 930 |
> |
fbp[2] *= ourexp; |
| 931 |
|
} |
| 932 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 933 |
< |
inbuf[0], inbuf[1], inbuf[2]); |
| 934 |
< |
zscan(queue[i][1])[queue[i][0]] = inbuf[3]; |
| 933 |
> |
fbp[0], fbp[1], fbp[2]); |
| 934 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
| 935 |
> |
fbp += 4; |
| 936 |
|
} |
| 937 |
|
queuesiz = 0; |
| 938 |
|
} |
| 939 |
|
|
| 940 |
|
|
| 941 |
< |
syserror() /* report error and exit */ |
| 941 |
> |
syserror(s) /* report error and exit */ |
| 942 |
> |
char *s; |
| 943 |
|
{ |
| 944 |
< |
perror(progname); |
| 944 |
> |
perror(s); |
| 945 |
|
exit(1); |
| 946 |
|
} |