| 1 |
+ |
/* Copyright (c) 1991 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 <fcntl.h> |
| 16 |
+ |
|
| 17 |
+ |
#include <ctype.h> |
| 18 |
+ |
|
| 19 |
|
#include "view.h" |
| 20 |
|
|
| 21 |
|
#include "color.h" |
| 22 |
|
|
| 23 |
< |
#define pscan(y) (ourpict+(y)*ourview.hresolu) |
| 18 |
< |
#define zscan(y) (ourzbuf+(y)*ourview.hresolu) |
| 23 |
> |
#include "resolu.h" |
| 24 |
|
|
| 25 |
< |
#define F_FORE 1 /* fill foreground */ |
| 26 |
< |
#define F_BACK 2 /* fill background */ |
| 25 |
> |
#ifndef BSD |
| 26 |
> |
#define vfork fork |
| 27 |
> |
#endif |
| 28 |
|
|
| 29 |
+ |
#define pscan(y) (ourpict+(y)*hresolu) |
| 30 |
+ |
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 31 |
+ |
|
| 32 |
+ |
#define F_FORE 1 /* fill foreground */ |
| 33 |
+ |
#define F_BACK 2 /* fill background */ |
| 34 |
+ |
|
| 35 |
+ |
#define PACKSIZ 256 /* max. calculation packet size */ |
| 36 |
+ |
|
| 37 |
+ |
#define RTCOM "rtrace -h- -ovl -fff " |
| 38 |
+ |
|
| 39 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
| 40 |
|
|
| 41 |
< |
VIEW ourview = STDVIEW(512); /* desired view */ |
| 41 |
> |
struct position {int x,y; float z;}; |
| 42 |
|
|
| 43 |
+ |
VIEW ourview = STDVIEW; /* desired view */ |
| 44 |
+ |
int hresolu = 512; /* horizontal resolution */ |
| 45 |
+ |
int vresolu = 512; /* vertical resolution */ |
| 46 |
+ |
double pixaspect = 1.0; /* pixel aspect ratio */ |
| 47 |
+ |
|
| 48 |
|
double zeps = .02; /* allowed z epsilon */ |
| 49 |
|
|
| 50 |
|
COLR *ourpict; /* output picture */ |
| 52 |
|
|
| 53 |
|
char *progname; |
| 54 |
|
|
| 55 |
< |
VIEW theirview = STDVIEW(512); /* input view */ |
| 56 |
< |
int gotview; /* got input view? */ |
| 57 |
< |
|
| 58 |
< |
int fill = F_FORE|F_BACK; /* fill level */ |
| 55 |
> |
int fillo = F_FORE|F_BACK; /* selected fill options */ |
| 56 |
> |
int fillsamp = 0; /* sample separation (0 == inf) */ |
| 57 |
> |
extern int backfill(), rcalfill(); /* fill functions */ |
| 58 |
> |
int (*fillfunc)() = backfill; /* selected fill function */ |
| 59 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 60 |
+ |
double backz = 0.0; /* background z value */ |
| 61 |
+ |
int normdist = 1; /* normalized distance? */ |
| 62 |
+ |
double ourexp = -1; /* output picture exposure */ |
| 63 |
|
|
| 64 |
+ |
VIEW theirview = STDVIEW; /* input view */ |
| 65 |
+ |
int gotview; /* got input view? */ |
| 66 |
+ |
int wrongformat = 0; /* input in another format? */ |
| 67 |
+ |
RESOLU tresolu; /* input resolution */ |
| 68 |
+ |
double theirexp; /* input picture exposure */ |
| 69 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 70 |
< |
int normdist = 1; /* normalized distance? */ |
| 70 |
> |
int hasmatrix = 0; /* has transformation matrix */ |
| 71 |
|
|
| 72 |
+ |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
| 73 |
+ |
#define childpid (PDesc[2]) |
| 74 |
+ |
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
| 75 |
+ |
int packsiz; /* actual packet size */ |
| 76 |
+ |
int queuesiz; /* number of pixels pending */ |
| 77 |
|
|
| 78 |
+ |
|
| 79 |
|
main(argc, argv) /* interpolate pictures */ |
| 80 |
|
int argc; |
| 81 |
|
char *argv[]; |
| 82 |
|
{ |
| 83 |
< |
#define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt |
| 84 |
< |
extern double atof(); |
| 83 |
> |
#define check(ol,al) if (argv[i][ol] || \ |
| 84 |
> |
badarg(argc-i-1,argv+i+1,al)) \ |
| 85 |
> |
goto badopt |
| 86 |
|
int gotvfile = 0; |
| 87 |
|
char *zfile = NULL; |
| 88 |
|
char *err; |
| 89 |
< |
int i; |
| 89 |
> |
int i, rval; |
| 90 |
|
|
| 91 |
|
progname = argv[0]; |
| 92 |
|
|
| 93 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 93 |
> |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 94 |
> |
rval = getviewopt(&ourview, argc-i, argv+i); |
| 95 |
> |
if (rval >= 0) { |
| 96 |
> |
i += rval; |
| 97 |
> |
continue; |
| 98 |
> |
} |
| 99 |
|
switch (argv[i][1]) { |
| 100 |
|
case 't': /* threshold */ |
| 101 |
< |
check(2,1); |
| 101 |
> |
check(2,"f"); |
| 102 |
|
zeps = atof(argv[++i]); |
| 103 |
|
break; |
| 104 |
|
case 'n': /* dist. normalized? */ |
| 105 |
< |
check(2,0); |
| 105 |
> |
check(2,NULL); |
| 106 |
|
normdist = !normdist; |
| 107 |
|
break; |
| 108 |
|
case 'f': /* fill type */ |
| 109 |
|
switch (argv[i][2]) { |
| 110 |
|
case '0': /* none */ |
| 111 |
< |
check(3,0); |
| 112 |
< |
fill = 0; |
| 111 |
> |
check(3,NULL); |
| 112 |
> |
fillo = 0; |
| 113 |
|
break; |
| 114 |
|
case 'f': /* foreground */ |
| 115 |
< |
check(3,0); |
| 116 |
< |
fill = F_FORE; |
| 115 |
> |
check(3,NULL); |
| 116 |
> |
fillo = F_FORE; |
| 117 |
|
break; |
| 118 |
|
case 'b': /* background */ |
| 119 |
< |
check(3,0); |
| 120 |
< |
fill = F_BACK; |
| 119 |
> |
check(3,NULL); |
| 120 |
> |
fillo = F_BACK; |
| 121 |
|
break; |
| 122 |
|
case 'a': /* all */ |
| 123 |
< |
check(3,0); |
| 124 |
< |
fill = F_FORE|F_BACK; |
| 123 |
> |
check(3,NULL); |
| 124 |
> |
fillo = F_FORE|F_BACK; |
| 125 |
|
break; |
| 126 |
+ |
case 's': /* sample */ |
| 127 |
+ |
check(3,"i"); |
| 128 |
+ |
fillsamp = atoi(argv[++i]); |
| 129 |
+ |
break; |
| 130 |
|
case 'c': /* color */ |
| 131 |
< |
check(3,3); |
| 131 |
> |
check(3,"fff"); |
| 132 |
> |
fillfunc = backfill; |
| 133 |
|
setcolr(backcolr, atof(argv[i+1]), |
| 134 |
|
atof(argv[i+2]), atof(argv[i+3])); |
| 135 |
|
i += 3; |
| 136 |
|
break; |
| 137 |
+ |
case 'z': /* z value */ |
| 138 |
+ |
check(3,"f"); |
| 139 |
+ |
fillfunc = backfill; |
| 140 |
+ |
backz = atof(argv[++i]); |
| 141 |
+ |
break; |
| 142 |
+ |
case 'r': /* rtrace */ |
| 143 |
+ |
check(3,"s"); |
| 144 |
+ |
fillfunc = rcalfill; |
| 145 |
+ |
calstart(RTCOM, argv[++i]); |
| 146 |
+ |
break; |
| 147 |
|
default: |
| 148 |
|
goto badopt; |
| 149 |
|
} |
| 150 |
|
break; |
| 151 |
|
case 'z': /* z file */ |
| 152 |
< |
check(2,1); |
| 152 |
> |
check(2,"s"); |
| 153 |
|
zfile = argv[++i]; |
| 154 |
|
break; |
| 155 |
|
case 'x': /* x resolution */ |
| 156 |
< |
check(2,1); |
| 157 |
< |
ourview.hresolu = atoi(argv[++i]); |
| 156 |
> |
check(2,"i"); |
| 157 |
> |
hresolu = atoi(argv[++i]); |
| 158 |
|
break; |
| 159 |
|
case 'y': /* y resolution */ |
| 160 |
< |
check(2,1); |
| 161 |
< |
ourview.vresolu = atoi(argv[++i]); |
| 160 |
> |
check(2,"i"); |
| 161 |
> |
vresolu = atoi(argv[++i]); |
| 162 |
|
break; |
| 163 |
< |
case 'v': /* view */ |
| 164 |
< |
switch (argv[i][2]) { |
| 109 |
< |
case 't': /* type */ |
| 110 |
< |
check(4,0); |
| 111 |
< |
ourview.type = argv[i][3]; |
| 112 |
< |
break; |
| 113 |
< |
case 'p': /* point */ |
| 114 |
< |
check(3,3); |
| 115 |
< |
ourview.vp[0] = atof(argv[++i]); |
| 116 |
< |
ourview.vp[1] = atof(argv[++i]); |
| 117 |
< |
ourview.vp[2] = atof(argv[++i]); |
| 118 |
< |
break; |
| 119 |
< |
case 'd': /* direction */ |
| 120 |
< |
check(3,3); |
| 121 |
< |
ourview.vdir[0] = atof(argv[++i]); |
| 122 |
< |
ourview.vdir[1] = atof(argv[++i]); |
| 123 |
< |
ourview.vdir[2] = atof(argv[++i]); |
| 124 |
< |
break; |
| 125 |
< |
case 'u': /* up */ |
| 126 |
< |
check(3,3); |
| 127 |
< |
ourview.vup[0] = atof(argv[++i]); |
| 128 |
< |
ourview.vup[1] = atof(argv[++i]); |
| 129 |
< |
ourview.vup[2] = atof(argv[++i]); |
| 130 |
< |
break; |
| 131 |
< |
case 'h': /* horizontal */ |
| 132 |
< |
check(3,1); |
| 133 |
< |
ourview.horiz = atof(argv[++i]); |
| 134 |
< |
break; |
| 135 |
< |
case 'v': /* vertical */ |
| 136 |
< |
check(3,1); |
| 137 |
< |
ourview.vert = atof(argv[++i]); |
| 138 |
< |
break; |
| 139 |
< |
case 'f': /* file */ |
| 140 |
< |
check(3,1); |
| 141 |
< |
gotvfile = viewfile(argv[++i], &ourview); |
| 142 |
< |
if (gotvfile < 0) { |
| 143 |
< |
perror(argv[i]); |
| 144 |
< |
exit(1); |
| 145 |
< |
} else if (gotvfile == 0) { |
| 146 |
< |
fprintf(stderr, "%s: bad view file\n", |
| 147 |
< |
argv[i]); |
| 148 |
< |
exit(1); |
| 149 |
< |
} |
| 150 |
< |
break; |
| 151 |
< |
default: |
| 163 |
> |
case 'p': /* pixel aspect */ |
| 164 |
> |
if (argv[i][2] != 'a') |
| 165 |
|
goto badopt; |
| 166 |
+ |
check(3,"f"); |
| 167 |
+ |
pixaspect = atof(argv[++i]); |
| 168 |
+ |
break; |
| 169 |
+ |
case 'v': /* view file */ |
| 170 |
+ |
if (argv[i][2] != 'f') |
| 171 |
+ |
goto badopt; |
| 172 |
+ |
check(3,"s"); |
| 173 |
+ |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
| 174 |
+ |
if (gotvfile < 0) { |
| 175 |
+ |
perror(argv[i]); |
| 176 |
+ |
exit(1); |
| 177 |
+ |
} else if (gotvfile == 0) { |
| 178 |
+ |
fprintf(stderr, "%s: bad view file\n", |
| 179 |
+ |
argv[i]); |
| 180 |
+ |
exit(1); |
| 181 |
|
} |
| 182 |
|
break; |
| 183 |
|
default: |
| 186 |
|
progname, argv[i]); |
| 187 |
|
goto userr; |
| 188 |
|
} |
| 189 |
+ |
} |
| 190 |
|
/* check arguments */ |
| 191 |
< |
if (argc-i < 2 || (argc-i)%2) |
| 191 |
> |
if ((argc-i)%2) |
| 192 |
|
goto userr; |
| 193 |
+ |
if (fillsamp == 1) |
| 194 |
+ |
fillo &= ~F_BACK; |
| 195 |
|
/* set view */ |
| 196 |
|
if (err = setview(&ourview)) { |
| 197 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 198 |
|
exit(1); |
| 199 |
|
} |
| 200 |
+ |
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
| 201 |
|
/* allocate frame */ |
| 202 |
< |
ourpict = (COLR *)calloc(ourview.hresolu*ourview.vresolu,sizeof(COLR)); |
| 203 |
< |
ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float)); |
| 204 |
< |
if (ourpict == NULL || ourzbuf == NULL) { |
| 205 |
< |
perror(progname); |
| 206 |
< |
exit(1); |
| 175 |
< |
} |
| 202 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
| 203 |
> |
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 204 |
> |
if (ourpict == NULL || ourzbuf == NULL) |
| 205 |
> |
syserror(); |
| 206 |
> |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
| 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 |
< |
fillpicture(); |
| 211 |
> |
if (fillo&F_BACK) |
| 212 |
> |
backpicture(fillfunc, fillsamp); |
| 213 |
|
else |
| 214 |
< |
backpicture(); |
| 214 |
> |
fillpicture(fillfunc); |
| 215 |
> |
/* close calculation */ |
| 216 |
> |
caldone(); |
| 217 |
|
/* add to header */ |
| 218 |
|
printargs(argc, argv, stdout); |
| 219 |
|
if (gotvfile) { |
| 220 |
< |
printf(VIEWSTR); |
| 220 |
> |
fputs(VIEWSTR, stdout); |
| 221 |
|
fprintview(&ourview, stdout); |
| 222 |
< |
printf("\n"); |
| 222 |
> |
putc('\n', stdout); |
| 223 |
|
} |
| 224 |
< |
printf("\n"); |
| 224 |
> |
if (pixaspect < .99 || pixaspect > 1.01) |
| 225 |
> |
fputaspect(pixaspect, stdout); |
| 226 |
> |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 227 |
> |
fputexpos(ourexp, stdout); |
| 228 |
> |
fputformat(COLRFMT, stdout); |
| 229 |
> |
putc('\n', stdout); |
| 230 |
|
/* write picture */ |
| 231 |
|
writepicture(); |
| 232 |
|
/* write z file */ |
| 236 |
|
exit(0); |
| 237 |
|
userr: |
| 238 |
|
fprintf(stderr, |
| 239 |
< |
"Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n", |
| 239 |
> |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
| 240 |
|
progname); |
| 241 |
|
exit(1); |
| 242 |
|
#undef check |
| 246 |
|
headline(s) /* process header string */ |
| 247 |
|
char *s; |
| 248 |
|
{ |
| 249 |
< |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
| 212 |
< |
register char **an; |
| 249 |
> |
char fmt[32]; |
| 250 |
|
|
| 251 |
< |
printf("\t%s", s); |
| 251 |
> |
if (isformat(s)) { |
| 252 |
> |
formatval(fmt, s); |
| 253 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
| 254 |
> |
return; |
| 255 |
> |
} |
| 256 |
> |
putc('\t', stdout); |
| 257 |
> |
fputs(s, stdout); |
| 258 |
|
|
| 259 |
< |
for (an = altname; *an != NULL; an++) |
| 260 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
| 261 |
< |
if (sscanview(&theirview, s+strlen(*an)) == 0) |
| 262 |
< |
gotview++; |
| 263 |
< |
break; |
| 264 |
< |
} |
| 259 |
> |
if (isexpos(s)) { |
| 260 |
> |
theirexp *= exposval(s); |
| 261 |
> |
return; |
| 262 |
> |
} |
| 263 |
> |
if (isview(s) && sscanview(&theirview, s) > 0) |
| 264 |
> |
gotview++; |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 268 |
|
addpicture(pfile, zspec) /* add picture to output */ |
| 269 |
|
char *pfile, *zspec; |
| 270 |
|
{ |
| 271 |
< |
extern double atof(); |
| 272 |
< |
FILE *pfp, *zfp; |
| 271 |
> |
FILE *pfp; |
| 272 |
> |
int zfd; |
| 273 |
|
char *err; |
| 274 |
|
COLR *scanin; |
| 275 |
< |
float *zin, *zlast; |
| 276 |
< |
int *plast; |
| 275 |
> |
float *zin; |
| 276 |
> |
struct position *plast; |
| 277 |
|
int y; |
| 278 |
|
/* open picture file */ |
| 279 |
|
if ((pfp = fopen(pfile, "r")) == NULL) { |
| 280 |
|
perror(pfile); |
| 281 |
|
exit(1); |
| 282 |
|
} |
| 283 |
< |
/* get header and view */ |
| 284 |
< |
printf("%s:\n", pfile); |
| 283 |
> |
/* get header with exposure and view */ |
| 284 |
> |
theirexp = 1.0; |
| 285 |
|
gotview = 0; |
| 286 |
< |
getheader(pfp, headline); |
| 287 |
< |
if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp) |
| 288 |
< |
!= (YMAJOR|YDECR)) { |
| 289 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
| 286 |
> |
printf("%s:\n", pfile); |
| 287 |
> |
getheader(pfp, headline, NULL); |
| 288 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
| 289 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
| 290 |
|
exit(1); |
| 291 |
|
} |
| 292 |
+ |
if (ourexp <= 0) |
| 293 |
+ |
ourexp = theirexp; |
| 294 |
+ |
else if (ABS(theirexp-ourexp) > .01*ourexp) |
| 295 |
+ |
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
| 296 |
|
if (err = setview(&theirview)) { |
| 297 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
| 298 |
|
exit(1); |
| 299 |
|
} |
| 300 |
|
/* compute transformation */ |
| 301 |
< |
pixform(theirs2ours, &theirview, &ourview); |
| 301 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
| 302 |
|
/* allocate scanlines */ |
| 303 |
< |
scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR)); |
| 304 |
< |
zin = (float *)malloc(theirview.hresolu*sizeof(float)); |
| 305 |
< |
plast = (int *)calloc(theirview.hresolu, sizeof(int)); |
| 306 |
< |
zlast = (float *)calloc(theirview.hresolu, sizeof(float)); |
| 307 |
< |
if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) { |
| 308 |
< |
perror(progname); |
| 262 |
< |
exit(1); |
| 263 |
< |
} |
| 303 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
| 304 |
> |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
| 305 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
| 306 |
> |
sizeof(struct position)); |
| 307 |
> |
if (scanin == NULL || zin == NULL || plast == NULL) |
| 308 |
> |
syserror(); |
| 309 |
|
/* get z specification or file */ |
| 310 |
< |
if ((zfp = fopen(zspec, "r")) == NULL) { |
| 310 |
> |
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 311 |
|
double zvalue; |
| 312 |
|
register int x; |
| 313 |
|
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 314 |
|
perror(zspec); |
| 315 |
|
exit(1); |
| 316 |
|
} |
| 317 |
< |
for (x = 0; x < theirview.hresolu; x++) |
| 317 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
| 318 |
|
zin[x] = zvalue; |
| 319 |
|
} |
| 320 |
|
/* load image */ |
| 321 |
< |
for (y = theirview.vresolu-1; y >= 0; y--) { |
| 322 |
< |
if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) { |
| 321 |
> |
for (y = 0; y < numscans(&tresolu); y++) { |
| 322 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 323 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 324 |
|
exit(1); |
| 325 |
|
} |
| 326 |
< |
if (zfp != NULL |
| 327 |
< |
&& fread(zin,sizeof(float),theirview.hresolu,zfp) |
| 328 |
< |
< theirview.hresolu) { |
| 326 |
> |
if (zfd != -1 && read(zfd,(char *)zin, |
| 327 |
> |
scanlen(&tresolu)*sizeof(float)) |
| 328 |
> |
< scanlen(&tresolu)*sizeof(float)) { |
| 329 |
|
fprintf(stderr, "%s: read error\n", zspec); |
| 330 |
|
exit(1); |
| 331 |
|
} |
| 332 |
< |
addscanline(y, scanin, zin, plast, zlast); |
| 332 |
> |
addscanline(y, scanin, zin, plast); |
| 333 |
|
} |
| 334 |
|
/* clean up */ |
| 335 |
|
free((char *)scanin); |
| 336 |
|
free((char *)zin); |
| 337 |
|
free((char *)plast); |
| 293 |
– |
free((char *)zlast); |
| 338 |
|
fclose(pfp); |
| 339 |
< |
if (zfp != NULL) |
| 340 |
< |
fclose(zfp); |
| 339 |
> |
if (zfd != -1) |
| 340 |
> |
close(zfd); |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
|
| 347 |
|
{ |
| 348 |
|
double m4t[4][4]; |
| 349 |
|
|
| 350 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
| 351 |
+ |
return(0); |
| 352 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
| 353 |
+ |
return(0); |
| 354 |
|
setident4(xfmat); |
| 355 |
< |
xfmat[0][0] = vw1->vhinc[0]; |
| 356 |
< |
xfmat[0][1] = vw1->vhinc[1]; |
| 357 |
< |
xfmat[0][2] = vw1->vhinc[2]; |
| 358 |
< |
xfmat[1][0] = vw1->vvinc[0]; |
| 359 |
< |
xfmat[1][1] = vw1->vvinc[1]; |
| 360 |
< |
xfmat[1][2] = vw1->vvinc[2]; |
| 355 |
> |
xfmat[0][0] = vw1->hvec[0]; |
| 356 |
> |
xfmat[0][1] = vw1->hvec[1]; |
| 357 |
> |
xfmat[0][2] = vw1->hvec[2]; |
| 358 |
> |
xfmat[1][0] = vw1->vvec[0]; |
| 359 |
> |
xfmat[1][1] = vw1->vvec[1]; |
| 360 |
> |
xfmat[1][2] = vw1->vvec[2]; |
| 361 |
|
xfmat[2][0] = vw1->vdir[0]; |
| 362 |
|
xfmat[2][1] = vw1->vdir[1]; |
| 363 |
|
xfmat[2][2] = vw1->vdir[2]; |
| 365 |
|
xfmat[3][1] = vw1->vp[1]; |
| 366 |
|
xfmat[3][2] = vw1->vp[2]; |
| 367 |
|
setident4(m4t); |
| 368 |
< |
m4t[0][0] = vw2->vhinc[0]/vw2->vhn2; |
| 369 |
< |
m4t[1][0] = vw2->vhinc[1]/vw2->vhn2; |
| 370 |
< |
m4t[2][0] = vw2->vhinc[2]/vw2->vhn2; |
| 371 |
< |
m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2; |
| 372 |
< |
m4t[0][1] = vw2->vvinc[0]/vw2->vvn2; |
| 373 |
< |
m4t[1][1] = vw2->vvinc[1]/vw2->vvn2; |
| 374 |
< |
m4t[2][1] = vw2->vvinc[2]/vw2->vvn2; |
| 375 |
< |
m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2; |
| 368 |
> |
m4t[0][0] = vw2->hvec[0]/vw2->hn2; |
| 369 |
> |
m4t[1][0] = vw2->hvec[1]/vw2->hn2; |
| 370 |
> |
m4t[2][0] = vw2->hvec[2]/vw2->hn2; |
| 371 |
> |
m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2; |
| 372 |
> |
m4t[0][1] = vw2->vvec[0]/vw2->vn2; |
| 373 |
> |
m4t[1][1] = vw2->vvec[1]/vw2->vn2; |
| 374 |
> |
m4t[2][1] = vw2->vvec[2]/vw2->vn2; |
| 375 |
> |
m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2; |
| 376 |
|
m4t[0][2] = vw2->vdir[0]; |
| 377 |
|
m4t[1][2] = vw2->vdir[1]; |
| 378 |
|
m4t[2][2] = vw2->vdir[2]; |
| 379 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
| 380 |
|
multmat4(xfmat, xfmat, m4t); |
| 381 |
+ |
return(1); |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
|
| 385 |
< |
addscanline(y, pline, zline, lasty, lastyz) /* add scanline to output */ |
| 385 |
> |
addscanline(y, pline, zline, lasty) /* add scanline to output */ |
| 386 |
|
int y; |
| 387 |
|
COLR *pline; |
| 388 |
|
float *zline; |
| 389 |
< |
int *lasty; /* input/output */ |
| 341 |
< |
float *lastyz; /* input/output */ |
| 389 |
> |
struct position *lasty; /* input/output */ |
| 390 |
|
{ |
| 391 |
|
extern double sqrt(); |
| 392 |
< |
double pos[3]; |
| 393 |
< |
int lastx = 0; |
| 346 |
< |
double lastxz = 0; |
| 347 |
< |
double zt; |
| 348 |
< |
int xpos, ypos; |
| 392 |
> |
FVECT pos; |
| 393 |
> |
struct position lastx, newpos; |
| 394 |
|
register int x; |
| 395 |
|
|
| 396 |
< |
for (x = theirview.hresolu-1; x >= 0; x--) { |
| 397 |
< |
pos[0] = x - .5*(theirview.hresolu-1); |
| 398 |
< |
pos[1] = y - .5*(theirview.vresolu-1); |
| 396 |
> |
lastx.z = 0; |
| 397 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) { |
| 398 |
> |
pix2loc(pos, &tresolu, x, y); |
| 399 |
|
pos[2] = zline[x]; |
| 400 |
< |
if (theirview.type == VT_PER) { |
| 401 |
< |
if (normdist) /* adjust for eye-ray distance */ |
| 357 |
< |
pos[2] /= sqrt( 1. |
| 358 |
< |
+ pos[0]*pos[0]*theirview.vhn2 |
| 359 |
< |
+ pos[1]*pos[1]*theirview.vvn2 ); |
| 360 |
< |
pos[0] *= pos[2]; |
| 361 |
< |
pos[1] *= pos[2]; |
| 362 |
< |
} |
| 363 |
< |
multp3(pos, pos, theirs2ours); |
| 364 |
< |
if (pos[2] <= 0) |
| 400 |
> |
if (movepixel(pos) < 0) { |
| 401 |
> |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 402 |
|
continue; |
| 366 |
– |
if (ourview.type == VT_PER) { |
| 367 |
– |
pos[0] /= pos[2]; |
| 368 |
– |
pos[1] /= pos[2]; |
| 403 |
|
} |
| 404 |
< |
pos[0] += .5*ourview.hresolu; |
| 405 |
< |
pos[1] += .5*ourview.vresolu; |
| 406 |
< |
if (pos[0] < 0 || (xpos = pos[0]) >= ourview.hresolu |
| 373 |
< |
|| pos[1] < 0 || (ypos = pos[1]) >= ourview.vresolu) |
| 374 |
< |
continue; |
| 404 |
> |
newpos.x = pos[0] * hresolu; |
| 405 |
> |
newpos.y = pos[1] * vresolu; |
| 406 |
> |
newpos.z = zline[x]; |
| 407 |
|
/* add pixel to our image */ |
| 408 |
< |
zt = 2.*zeps*zline[x]; |
| 409 |
< |
addpixel(xpos, ypos, |
| 410 |
< |
(fill&F_FORE && ABS(zline[x]-lastxz) <= zt) |
| 411 |
< |
? lastx - xpos : 1, |
| 412 |
< |
(fill&F_FORE && ABS(zline[x]-lastyz[x]) <= zt) |
| 413 |
< |
? lasty[x] - ypos : 1, |
| 414 |
< |
pline[x], pos[2]); |
| 415 |
< |
lastx = xpos; |
| 384 |
< |
lasty[x] = ypos; |
| 385 |
< |
lastxz = lastyz[x] = zline[x]; |
| 408 |
> |
if (pos[0] >= 0 && newpos.x < hresolu |
| 409 |
> |
&& pos[1] >= 0 && newpos.y < vresolu) { |
| 410 |
> |
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
| 411 |
> |
lasty[x].x = lastx.x = newpos.x; |
| 412 |
> |
lasty[x].y = lastx.y = newpos.y; |
| 413 |
> |
lasty[x].z = lastx.z = newpos.z; |
| 414 |
> |
} else |
| 415 |
> |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 416 |
|
} |
| 417 |
|
} |
| 418 |
|
|
| 419 |
|
|
| 420 |
< |
addpixel(xstart, ystart, width, height, pix, z) /* fill in area for pixel */ |
| 421 |
< |
int xstart, ystart; |
| 392 |
< |
int width, height; |
| 420 |
> |
addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */ |
| 421 |
> |
struct position *p0, *p1, *p2; |
| 422 |
|
COLR pix; |
| 423 |
|
double z; |
| 424 |
|
{ |
| 425 |
< |
register int x, y; |
| 426 |
< |
/* make width and height positive */ |
| 427 |
< |
if (width < 0) { |
| 428 |
< |
width = -width; |
| 429 |
< |
xstart = xstart-width+1; |
| 430 |
< |
} else if (width == 0) |
| 431 |
< |
width = 1; |
| 432 |
< |
if (height < 0) { |
| 433 |
< |
height = -height; |
| 434 |
< |
ystart = ystart-height+1; |
| 435 |
< |
} else if (height == 0) |
| 436 |
< |
height = 1; |
| 437 |
< |
/* fill pixel(s) within rectangle */ |
| 438 |
< |
for (y = ystart; y < ystart+height; y++) |
| 439 |
< |
for (x = xstart; x < xstart+width; x++) |
| 440 |
< |
if (zscan(y)[x] <= 0 |
| 441 |
< |
|| zscan(y)[x]-z > zeps*zscan(y)[x]) { |
| 425 |
> |
double zt = 2.*zeps*p0->z; /* threshold */ |
| 426 |
> |
int s1x, s1y, s2x, s2y; /* step sizes */ |
| 427 |
> |
int l1, l2, c1, c2; /* side lengths and counters */ |
| 428 |
> |
int p1isy; /* p0p1 along y? */ |
| 429 |
> |
int x1, y1; /* p1 position */ |
| 430 |
> |
register int x, y; /* final position */ |
| 431 |
> |
|
| 432 |
> |
/* compute vector p0p1 */ |
| 433 |
> |
if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 434 |
> |
s1x = p1->x - p0->x; |
| 435 |
> |
s1y = p1->y - p0->y; |
| 436 |
> |
l1 = ABS(s1x); |
| 437 |
> |
if (p1isy = (ABS(s1y) > l1)) |
| 438 |
> |
l1 = ABS(s1y); |
| 439 |
> |
} else { |
| 440 |
> |
l1 = s1x = s1y = 1; |
| 441 |
> |
p1isy = -1; |
| 442 |
> |
} |
| 443 |
> |
/* compute vector p0p2 */ |
| 444 |
> |
if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) { |
| 445 |
> |
s2x = p2->x - p0->x; |
| 446 |
> |
s2y = p2->y - p0->y; |
| 447 |
> |
if (p1isy == 1) |
| 448 |
> |
l2 = ABS(s2x); |
| 449 |
> |
else { |
| 450 |
> |
l2 = ABS(s2y); |
| 451 |
> |
if (p1isy != 0 && ABS(s2x) > l2) |
| 452 |
> |
l2 = ABS(s2x); |
| 453 |
> |
} |
| 454 |
> |
} else |
| 455 |
> |
l2 = s2x = s2y = 1; |
| 456 |
> |
/* fill the parallelogram */ |
| 457 |
> |
for (c1 = l1; c1-- > 0; ) { |
| 458 |
> |
x1 = p0->x + c1*s1x/l1; |
| 459 |
> |
y1 = p0->y + c1*s1y/l1; |
| 460 |
> |
for (c2 = l2; c2-- > 0; ) { |
| 461 |
> |
x = x1 + c2*s2x/l2; |
| 462 |
> |
if (x < 0 || x >= hresolu) |
| 463 |
> |
continue; |
| 464 |
> |
y = y1 + c2*s2y/l2; |
| 465 |
> |
if (y < 0 || y >= vresolu) |
| 466 |
> |
continue; |
| 467 |
> |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 468 |
> |
> zeps*zscan(y)[x]) { |
| 469 |
|
zscan(y)[x] = z; |
| 470 |
|
copycolr(pscan(y)[x], pix); |
| 471 |
|
} |
| 472 |
+ |
} |
| 473 |
+ |
} |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
|
| 477 |
< |
fillpicture() /* fill in empty spaces */ |
| 477 |
> |
movepixel(pos) /* reposition image point */ |
| 478 |
> |
FVECT pos; |
| 479 |
|
{ |
| 480 |
+ |
FVECT pt, direc; |
| 481 |
+ |
|
| 482 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
| 483 |
+ |
return(-1); |
| 484 |
+ |
if (hasmatrix) { |
| 485 |
+ |
pos[0] += theirview.hoff - .5; |
| 486 |
+ |
pos[1] += theirview.voff - .5; |
| 487 |
+ |
if (theirview.type == VT_PER) { |
| 488 |
+ |
if (normdist) /* adjust for eye-ray distance */ |
| 489 |
+ |
pos[2] /= sqrt( 1. |
| 490 |
+ |
+ pos[0]*pos[0]*theirview.hn2 |
| 491 |
+ |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 492 |
+ |
pos[0] *= pos[2]; |
| 493 |
+ |
pos[1] *= pos[2]; |
| 494 |
+ |
} |
| 495 |
+ |
multp3(pos, pos, theirs2ours); |
| 496 |
+ |
if (pos[2] <= 0) |
| 497 |
+ |
return(-1); |
| 498 |
+ |
if (ourview.type == VT_PER) { |
| 499 |
+ |
pos[0] /= pos[2]; |
| 500 |
+ |
pos[1] /= pos[2]; |
| 501 |
+ |
} |
| 502 |
+ |
pos[0] += .5 - ourview.hoff; |
| 503 |
+ |
pos[1] += .5 - ourview.voff; |
| 504 |
+ |
return(0); |
| 505 |
+ |
} |
| 506 |
+ |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
| 507 |
+ |
return(-1); |
| 508 |
+ |
pt[0] += direc[0]*pos[2]; |
| 509 |
+ |
pt[1] += direc[1]*pos[2]; |
| 510 |
+ |
pt[2] += direc[2]*pos[2]; |
| 511 |
+ |
viewloc(pos, &ourview, pt); |
| 512 |
+ |
if (pos[2] <= 0) |
| 513 |
+ |
return(-1); |
| 514 |
+ |
return(0); |
| 515 |
+ |
} |
| 516 |
+ |
|
| 517 |
+ |
|
| 518 |
+ |
backpicture(fill, samp) /* background fill algorithm */ |
| 519 |
+ |
int (*fill)(); |
| 520 |
+ |
int samp; |
| 521 |
+ |
{ |
| 522 |
|
int *yback, xback; |
| 523 |
|
int y; |
| 423 |
– |
COLR pfill; |
| 524 |
|
register int x, i; |
| 525 |
|
/* get back buffer */ |
| 526 |
< |
yback = (int *)malloc(ourview.hresolu*sizeof(int)); |
| 527 |
< |
if (yback == NULL) { |
| 528 |
< |
perror(progname); |
| 529 |
< |
return; |
| 430 |
< |
} |
| 431 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 526 |
> |
yback = (int *)malloc(hresolu*sizeof(int)); |
| 527 |
> |
if (yback == NULL) |
| 528 |
> |
syserror(); |
| 529 |
> |
for (x = 0; x < hresolu; x++) |
| 530 |
|
yback[x] = -2; |
| 531 |
|
/* |
| 532 |
|
* Xback and yback are the pixel locations of suitable |
| 535 |
|
* that there is no suitable background in this direction. |
| 536 |
|
*/ |
| 537 |
|
/* fill image */ |
| 538 |
< |
for (y = 0; y < ourview.vresolu; y++) { |
| 538 |
> |
for (y = 0; y < vresolu; y++) { |
| 539 |
|
xback = -2; |
| 540 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 540 |
> |
for (x = 0; x < hresolu; x++) |
| 541 |
|
if (zscan(y)[x] <= 0) { /* empty pixel */ |
| 542 |
|
/* |
| 543 |
|
* First, find background from above or below. |
| 544 |
|
* (farthest assigned pixel) |
| 545 |
|
*/ |
| 546 |
|
if (yback[x] == -2) { |
| 547 |
< |
for (i = y+1; i < ourview.vresolu; i++) |
| 547 |
> |
for (i = y+1; i < vresolu; i++) |
| 548 |
|
if (zscan(i)[x] > 0) |
| 549 |
|
break; |
| 550 |
< |
if (i < ourview.vresolu |
| 550 |
> |
if (i < vresolu |
| 551 |
|
&& (y <= 0 || zscan(y-1)[x] < zscan(i)[x])) |
| 552 |
|
yback[x] = i; |
| 553 |
|
else |
| 557 |
|
* Next, find background from left or right. |
| 558 |
|
*/ |
| 559 |
|
if (xback == -2) { |
| 560 |
< |
for (i = x+1; i < ourview.hresolu; i++) |
| 560 |
> |
for (i = x+1; i < hresolu; i++) |
| 561 |
|
if (zscan(y)[i] > 0) |
| 562 |
|
break; |
| 563 |
< |
if (i < ourview.hresolu |
| 563 |
> |
if (i < hresolu |
| 564 |
|
&& (x <= 0 || zscan(y)[x-1] < zscan(y)[i])) |
| 565 |
|
xback = i; |
| 566 |
|
else |
| 567 |
|
xback = x-1; |
| 568 |
|
} |
| 569 |
|
/* |
| 570 |
< |
* Check to see if we have no background for |
| 571 |
< |
* this pixel. If not, use background color. |
| 570 |
> |
* If we have no background for this pixel, |
| 571 |
> |
* use the given fill function. |
| 572 |
|
*/ |
| 573 |
< |
if (xback < 0 && yback[x] < 0) { |
| 574 |
< |
copycolr(pscan(y)[x], backcolr); |
| 477 |
< |
continue; |
| 478 |
< |
} |
| 573 |
> |
if (xback < 0 && yback[x] < 0) |
| 574 |
> |
goto fillit; |
| 575 |
|
/* |
| 576 |
|
* Compare, and use the background that is |
| 577 |
|
* farther, unless one of them is next to us. |
| 578 |
+ |
* If the background is too distant, call |
| 579 |
+ |
* the fill function. |
| 580 |
|
*/ |
| 581 |
|
if ( yback[x] < 0 |
| 582 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
| 583 |
|
|| ( ABS(y-yback[x]) > 1 |
| 584 |
|
&& zscan(yback[x])[x] |
| 585 |
< |
< zscan(y)[xback] ) ) |
| 585 |
> |
< zscan(y)[xback] ) ) { |
| 586 |
> |
if (samp > 0 && ABS(x-xback) >= samp) |
| 587 |
> |
goto fillit; |
| 588 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 589 |
< |
else |
| 589 |
> |
zscan(y)[x] = zscan(y)[xback]; |
| 590 |
> |
} else { |
| 591 |
> |
if (samp > 0 && ABS(y-yback[x]) > samp) |
| 592 |
> |
goto fillit; |
| 593 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 594 |
+ |
zscan(y)[x] = zscan(yback[x])[x]; |
| 595 |
+ |
} |
| 596 |
+ |
continue; |
| 597 |
+ |
fillit: |
| 598 |
+ |
(*fill)(x,y); |
| 599 |
+ |
if (fill == rcalfill) { /* use it */ |
| 600 |
+ |
clearqueue(); |
| 601 |
+ |
xback = x; |
| 602 |
+ |
yback[x] = y; |
| 603 |
+ |
} |
| 604 |
|
} else { /* full pixel */ |
| 605 |
|
yback[x] = -2; |
| 606 |
|
xback = -2; |
| 610 |
|
} |
| 611 |
|
|
| 612 |
|
|
| 613 |
< |
backpicture() /* paint in empty pixels */ |
| 613 |
> |
fillpicture(fill) /* paint in empty pixels using fill */ |
| 614 |
> |
int (*fill)(); |
| 615 |
|
{ |
| 616 |
|
register int x, y; |
| 617 |
|
|
| 618 |
< |
for (y = 0; y < ourview.vresolu; y++) |
| 619 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 618 |
> |
for (y = 0; y < vresolu; y++) |
| 619 |
> |
for (x = 0; x < hresolu; x++) |
| 620 |
|
if (zscan(y)[x] <= 0) |
| 621 |
< |
copycolr(pscan(y)[x], backcolr); |
| 621 |
> |
(*fill)(x,y); |
| 622 |
|
} |
| 623 |
|
|
| 624 |
|
|
| 626 |
|
{ |
| 627 |
|
int y; |
| 628 |
|
|
| 629 |
< |
fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout); |
| 630 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) |
| 631 |
< |
if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0) { |
| 632 |
< |
perror(progname); |
| 519 |
< |
exit(1); |
| 520 |
< |
} |
| 629 |
> |
fprtresolu(hresolu, vresolu, stdout); |
| 630 |
> |
for (y = vresolu-1; y >= 0; y--) |
| 631 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 632 |
> |
syserror(); |
| 633 |
|
} |
| 634 |
|
|
| 635 |
|
|
| 638 |
|
{ |
| 639 |
|
extern double sqrt(); |
| 640 |
|
int donorm = normdist && ourview.type == VT_PER; |
| 641 |
< |
FILE *fp; |
| 641 |
> |
int fd; |
| 642 |
|
int y; |
| 643 |
|
float *zout; |
| 644 |
|
|
| 645 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
| 645 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
| 646 |
|
perror(fname); |
| 647 |
|
exit(1); |
| 648 |
|
} |
| 649 |
|
if (donorm |
| 650 |
< |
&& (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) { |
| 651 |
< |
perror(progname); |
| 652 |
< |
exit(1); |
| 541 |
< |
} |
| 542 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) { |
| 650 |
> |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 651 |
> |
syserror(); |
| 652 |
> |
for (y = vresolu-1; y >= 0; y--) { |
| 653 |
|
if (donorm) { |
| 654 |
|
double vx, yzn2; |
| 655 |
|
register int x; |
| 656 |
< |
yzn2 = y - .5*(ourview.vresolu-1); |
| 657 |
< |
yzn2 = 1. + yzn2*yzn2*ourview.vvn2; |
| 658 |
< |
for (x = 0; x < ourview.hresolu; x++) { |
| 659 |
< |
vx = x - .5*(ourview.hresolu-1); |
| 656 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 657 |
> |
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 658 |
> |
for (x = 0; x < hresolu; x++) { |
| 659 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 660 |
|
zout[x] = zscan(y)[x] |
| 661 |
< |
* sqrt(vx*vx*ourview.vhn2 + yzn2); |
| 661 |
> |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 662 |
|
} |
| 663 |
|
} else |
| 664 |
|
zout = zscan(y); |
| 665 |
< |
if (fwrite(zout, sizeof(float), ourview.hresolu, fp) |
| 666 |
< |
< ourview.hresolu) { |
| 665 |
> |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
| 666 |
> |
< hresolu*sizeof(float)) { |
| 667 |
|
perror(fname); |
| 668 |
|
exit(1); |
| 669 |
|
} |
| 670 |
|
} |
| 671 |
|
if (donorm) |
| 672 |
|
free((char *)zout); |
| 673 |
< |
fclose(fp); |
| 673 |
> |
close(fd); |
| 674 |
|
} |
| 675 |
|
|
| 676 |
|
|
| 682 |
|
&& *s != 'e' && *s != 'E' && *s != '+') |
| 683 |
|
return(0); |
| 684 |
|
return(1); |
| 685 |
+ |
} |
| 686 |
+ |
|
| 687 |
+ |
|
| 688 |
+ |
backfill(x, y) /* fill pixel with background */ |
| 689 |
+ |
int x, y; |
| 690 |
+ |
{ |
| 691 |
+ |
register BYTE *dest = pscan(y)[x]; |
| 692 |
+ |
|
| 693 |
+ |
copycolr(dest, backcolr); |
| 694 |
+ |
zscan(y)[x] = backz; |
| 695 |
+ |
} |
| 696 |
+ |
|
| 697 |
+ |
|
| 698 |
+ |
calstart(prog, args) /* start fill calculation */ |
| 699 |
+ |
char *prog, *args; |
| 700 |
+ |
{ |
| 701 |
+ |
char combuf[512]; |
| 702 |
+ |
char *argv[64]; |
| 703 |
+ |
int rval; |
| 704 |
+ |
register char **wp, *cp; |
| 705 |
+ |
|
| 706 |
+ |
if (childpid != -1) { |
| 707 |
+ |
fprintf(stderr, "%s: too many calculations\n", progname); |
| 708 |
+ |
exit(1); |
| 709 |
+ |
} |
| 710 |
+ |
strcpy(combuf, prog); |
| 711 |
+ |
strcat(combuf, args); |
| 712 |
+ |
cp = combuf; |
| 713 |
+ |
wp = argv; |
| 714 |
+ |
for ( ; ; ) { |
| 715 |
+ |
while (isspace(*cp)) cp++; |
| 716 |
+ |
if (!*cp) break; |
| 717 |
+ |
*wp++ = cp; |
| 718 |
+ |
while (!isspace(*cp)) |
| 719 |
+ |
if (!*cp++) goto done; |
| 720 |
+ |
*cp++ = '\0'; |
| 721 |
+ |
} |
| 722 |
+ |
done: |
| 723 |
+ |
*wp = NULL; |
| 724 |
+ |
/* start process */ |
| 725 |
+ |
if ((rval = open_process(PDesc, argv)) < 0) |
| 726 |
+ |
syserror(); |
| 727 |
+ |
if (rval == 0) { |
| 728 |
+ |
fprintf(stderr, "%s: command not found\n", argv[0]); |
| 729 |
+ |
exit(1); |
| 730 |
+ |
} |
| 731 |
+ |
packsiz = rval/(6*sizeof(float)) - 1; |
| 732 |
+ |
if (packsiz > PACKSIZ) |
| 733 |
+ |
packsiz = PACKSIZ; |
| 734 |
+ |
queuesiz = 0; |
| 735 |
+ |
} |
| 736 |
+ |
|
| 737 |
+ |
|
| 738 |
+ |
caldone() /* done with calculation */ |
| 739 |
+ |
{ |
| 740 |
+ |
if (childpid == -1) |
| 741 |
+ |
return; |
| 742 |
+ |
clearqueue(); |
| 743 |
+ |
close_process(PDesc); |
| 744 |
+ |
childpid = -1; |
| 745 |
+ |
} |
| 746 |
+ |
|
| 747 |
+ |
|
| 748 |
+ |
rcalfill(x, y) /* fill with ray-calculated pixel */ |
| 749 |
+ |
int x, y; |
| 750 |
+ |
{ |
| 751 |
+ |
if (queuesiz >= packsiz) /* flush queue if needed */ |
| 752 |
+ |
clearqueue(); |
| 753 |
+ |
/* add position to queue */ |
| 754 |
+ |
queue[queuesiz][0] = x; |
| 755 |
+ |
queue[queuesiz][1] = y; |
| 756 |
+ |
queuesiz++; |
| 757 |
+ |
} |
| 758 |
+ |
|
| 759 |
+ |
|
| 760 |
+ |
clearqueue() /* process queue */ |
| 761 |
+ |
{ |
| 762 |
+ |
FVECT orig, dir; |
| 763 |
+ |
float fbuf[6*(PACKSIZ+1)]; |
| 764 |
+ |
register float *fbp; |
| 765 |
+ |
register int i; |
| 766 |
+ |
|
| 767 |
+ |
fbp = fbuf; |
| 768 |
+ |
for (i = 0; i < queuesiz; i++) { |
| 769 |
+ |
viewray(orig, dir, &ourview, |
| 770 |
+ |
(queue[i][0]+.5)/hresolu, |
| 771 |
+ |
(queue[i][1]+.5)/vresolu); |
| 772 |
+ |
*fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2]; |
| 773 |
+ |
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
| 774 |
+ |
} |
| 775 |
+ |
/* mark end and get results */ |
| 776 |
+ |
bzero((char *)fbp, 6*sizeof(float)); |
| 777 |
+ |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
| 778 |
+ |
6*sizeof(float)*(queuesiz+1)) != |
| 779 |
+ |
4*sizeof(float)*queuesiz) { |
| 780 |
+ |
fprintf(stderr, "%s: error reading from rtrace process\n", |
| 781 |
+ |
progname); |
| 782 |
+ |
exit(1); |
| 783 |
+ |
} |
| 784 |
+ |
fbp = fbuf; |
| 785 |
+ |
for (i = 0; i < queuesiz; i++) { |
| 786 |
+ |
if (ourexp > 0 && ourexp != 1.0) { |
| 787 |
+ |
fbp[0] *= ourexp; |
| 788 |
+ |
fbp[1] *= ourexp; |
| 789 |
+ |
fbp[2] *= ourexp; |
| 790 |
+ |
} |
| 791 |
+ |
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 792 |
+ |
fbp[0], fbp[1], fbp[2]); |
| 793 |
+ |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
| 794 |
+ |
fbp += 4; |
| 795 |
+ |
} |
| 796 |
+ |
queuesiz = 0; |
| 797 |
+ |
} |
| 798 |
+ |
|
| 799 |
+ |
|
| 800 |
+ |
syserror() /* report error and exit */ |
| 801 |
+ |
{ |
| 802 |
+ |
perror(progname); |
| 803 |
+ |
exit(1); |
| 804 |
|
} |