1 |
– |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Interpolate and extrapolate pictures with different view parameters. |
6 |
|
* |
7 |
|
* Greg Ward 09Dec89 |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "standard.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
|
#include <ctype.h> |
13 |
+ |
#include <string.h> |
14 |
|
|
15 |
+ |
#include "standard.h" |
16 |
+ |
#include "rtprocess.h" /* Windows: must come before color.h */ |
17 |
|
#include "view.h" |
18 |
– |
|
18 |
|
#include "color.h" |
19 |
|
|
21 |
– |
#include "resolu.h" |
22 |
– |
|
20 |
|
#define LOG2 0.69314718055994530942 |
21 |
|
|
22 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
23 |
|
#define sscan(y) (ourspict+(y)*hresolu) |
24 |
|
#define wscan(y) (ourweigh+(y)*hresolu) |
25 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
26 |
+ |
#define bscan(y) (ourbpict+(y)*hresolu) |
27 |
|
#define averaging (ourweigh != NULL) |
28 |
+ |
#define blurring (ourbpict != NULL) |
29 |
|
#define usematrix (hasmatrix & !averaging) |
30 |
|
#define zisnorm (!usematrix | ourview.type != VT_PER) |
31 |
|
|
36 |
|
|
37 |
|
#define PACKSIZ 256 /* max. calculation packet size */ |
38 |
|
|
39 |
< |
#define RTCOM "rtrace -h- -ovl -fff " |
39 |
> |
#define RTCOM "rtrace -h- -ovl -fff -ld- -i- -I- " |
40 |
|
|
41 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
42 |
|
|
58 |
|
COLOR *ourspict; /* output pixel sums (averaging) */ |
59 |
|
float *ourweigh = NULL; /* output pixel weights (averaging) */ |
60 |
|
float *ourzbuf; /* corresponding z-buffer */ |
61 |
+ |
COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ |
62 |
|
|
63 |
+ |
VIEW avgview; /* average view for -B option */ |
64 |
+ |
int nvavg; /* number of views averaged */ |
65 |
+ |
|
66 |
|
char *progname; |
67 |
|
|
68 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
73 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
74 |
|
double backz = 0.0; /* background z value */ |
75 |
|
int normdist = 1; /* i/o normalized distance? */ |
76 |
+ |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
77 |
|
double ourexp = -1; /* original picture exposure */ |
78 |
|
int expadj = 0; /* exposure adjustment (f-stops) */ |
79 |
|
double rexpadj = 1; /* real exposure adjustment */ |
80 |
|
|
81 |
< |
VIEW theirview = STDVIEW; /* input view */ |
81 |
> |
VIEW theirview; /* input view */ |
82 |
|
int gotview; /* got input view? */ |
83 |
|
int wrongformat = 0; /* input in another format? */ |
84 |
|
RESOLU tresolu; /* input resolution */ |
86 |
|
MAT4 theirs2ours; /* transformation matrix */ |
87 |
|
int hasmatrix = 0; /* has transformation matrix */ |
88 |
|
|
89 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
86 |
< |
#define childpid (PDesc[2]) |
89 |
> |
static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ |
90 |
|
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
91 |
|
int packsiz; /* actual packet size */ |
92 |
< |
int queuesiz; /* number of pixels pending */ |
92 |
> |
int queuesiz = 0; /* number of pixels pending */ |
93 |
|
|
94 |
|
extern double movepixel(); |
95 |
|
|
98 |
|
int argc; |
99 |
|
char *argv[]; |
100 |
|
{ |
101 |
< |
#define check(ol,al) if (argv[i][ol] || \ |
102 |
< |
badarg(argc-i-1,argv+i+1,al)) \ |
101 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
102 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
103 |
|
goto badopt |
104 |
|
int gotvfile = 0; |
105 |
|
int doavg = -1; |
106 |
+ |
int doblur = 0; |
107 |
|
char *zfile = NULL; |
108 |
|
char *expcomp = NULL; |
109 |
< |
char *err; |
106 |
< |
int i, rval; |
109 |
> |
int i, an, rval; |
110 |
|
|
111 |
|
progname = argv[0]; |
112 |
|
|
113 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
114 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
113 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
114 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
115 |
|
if (rval >= 0) { |
116 |
< |
i += rval; |
116 |
> |
an += rval; |
117 |
|
continue; |
118 |
|
} |
119 |
< |
switch (argv[i][1]) { |
119 |
> |
switch (argv[an][1]) { |
120 |
|
case 'e': /* exposure */ |
121 |
|
check(2,"f"); |
122 |
< |
expcomp = argv[++i]; |
122 |
> |
expcomp = argv[++an]; |
123 |
|
break; |
124 |
|
case 't': /* threshold */ |
125 |
|
check(2,"f"); |
126 |
< |
zeps = atof(argv[++i]); |
126 |
> |
zeps = atof(argv[++an]); |
127 |
|
break; |
128 |
|
case 'a': /* average */ |
129 |
|
check(2,NULL); |
130 |
|
doavg = 1; |
131 |
|
break; |
132 |
+ |
case 'B': /* blur views */ |
133 |
+ |
check(2,NULL); |
134 |
+ |
doblur = 1; |
135 |
+ |
break; |
136 |
|
case 'q': /* quick (no avg.) */ |
137 |
|
check(2,NULL); |
138 |
|
doavg = 0; |
142 |
|
normdist = !normdist; |
143 |
|
break; |
144 |
|
case 'f': /* fill type */ |
145 |
< |
switch (argv[i][2]) { |
145 |
> |
switch (argv[an][2]) { |
146 |
|
case '0': /* none */ |
147 |
|
check(3,NULL); |
148 |
|
fillo = 0; |
161 |
|
break; |
162 |
|
case 's': /* sample */ |
163 |
|
check(3,"i"); |
164 |
< |
fillsamp = atoi(argv[++i]); |
164 |
> |
fillsamp = atoi(argv[++an]); |
165 |
|
break; |
166 |
|
case 'c': /* color */ |
167 |
|
check(3,"fff"); |
168 |
|
fillfunc = backfill; |
169 |
< |
setcolor(backcolor, atof(argv[i+1]), |
170 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
169 |
> |
setcolor(backcolor, atof(argv[an+1]), |
170 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
171 |
|
setcolr(backcolr, colval(backcolor,RED), |
172 |
|
colval(backcolor,GRN), |
173 |
|
colval(backcolor,BLU)); |
174 |
< |
i += 3; |
174 |
> |
an += 3; |
175 |
|
break; |
176 |
|
case 'z': /* z value */ |
177 |
|
check(3,"f"); |
178 |
|
fillfunc = backfill; |
179 |
< |
backz = atof(argv[++i]); |
179 |
> |
backz = atof(argv[++an]); |
180 |
|
break; |
181 |
|
case 'r': /* rtrace */ |
182 |
|
check(3,"s"); |
183 |
|
fillfunc = rcalfill; |
184 |
< |
calstart(RTCOM, argv[++i]); |
184 |
> |
calstart(RTCOM, argv[++an]); |
185 |
|
break; |
186 |
|
default: |
187 |
|
goto badopt; |
189 |
|
break; |
190 |
|
case 'z': /* z file */ |
191 |
|
check(2,"s"); |
192 |
< |
zfile = argv[++i]; |
192 |
> |
zfile = argv[++an]; |
193 |
|
break; |
194 |
|
case 'x': /* x resolution */ |
195 |
|
check(2,"i"); |
196 |
< |
hresolu = atoi(argv[++i]); |
196 |
> |
hresolu = atoi(argv[++an]); |
197 |
|
break; |
198 |
|
case 'y': /* y resolution */ |
199 |
|
check(2,"i"); |
200 |
< |
vresolu = atoi(argv[++i]); |
200 |
> |
vresolu = atoi(argv[++an]); |
201 |
|
break; |
202 |
|
case 'p': /* pixel aspect */ |
203 |
< |
if (argv[i][2] != 'a') |
203 |
> |
if (argv[an][2] != 'a') |
204 |
|
goto badopt; |
205 |
|
check(3,"f"); |
206 |
< |
pixaspect = atof(argv[++i]); |
206 |
> |
pixaspect = atof(argv[++an]); |
207 |
|
break; |
208 |
|
case 'v': /* view file */ |
209 |
< |
if (argv[i][2] != 'f') |
209 |
> |
if (argv[an][2] != 'f') |
210 |
|
goto badopt; |
211 |
|
check(3,"s"); |
212 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
212 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
213 |
|
if (gotvfile < 0) |
214 |
< |
syserror(argv[i]); |
214 |
> |
syserror(argv[an]); |
215 |
|
else if (gotvfile == 0) { |
216 |
|
fprintf(stderr, "%s: bad view file\n", |
217 |
< |
argv[i]); |
217 |
> |
argv[an]); |
218 |
|
exit(1); |
219 |
|
} |
220 |
|
break; |
221 |
|
default: |
222 |
|
badopt: |
223 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
224 |
< |
progname, argv[i]); |
224 |
> |
progname, argv[an]); |
225 |
|
goto userr; |
226 |
|
} |
227 |
|
} |
228 |
|
/* check arguments */ |
229 |
< |
if ((argc-i)%2) |
229 |
> |
if ((argc-an)%2) |
230 |
|
goto userr; |
231 |
|
if (fillsamp == 1) |
232 |
|
fillo &= ~F_BACK; |
233 |
|
if (doavg < 0) |
234 |
< |
doavg = (argc-i) > 2; |
234 |
> |
doavg = (argc-an) > 2; |
235 |
|
if (expcomp != NULL) |
236 |
|
if (expcomp[0] == '+' | expcomp[0] == '-') { |
237 |
|
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
238 |
< |
if (doavg) |
238 |
> |
if (doavg | doblur) |
239 |
|
rexpadj = pow(2.0, atof(expcomp)); |
240 |
|
else |
241 |
|
rexpadj = pow(2.0, (double)expadj); |
244 |
|
goto userr; |
245 |
|
rexpadj = atof(expcomp); |
246 |
|
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
247 |
< |
if (!doavg) |
247 |
> |
if (!(doavg | doblur)) |
248 |
|
rexpadj = pow(2.0, (double)expadj); |
249 |
|
} |
250 |
|
/* set view */ |
251 |
< |
if ((err = setview(&ourview)) != NULL) { |
252 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
251 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
252 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
253 |
> |
progname); |
254 |
|
exit(1); |
255 |
|
} |
256 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
265 |
|
if (ourpict == NULL) |
266 |
|
syserror(progname); |
267 |
|
} |
268 |
+ |
if (doblur) { |
269 |
+ |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
270 |
+ |
if (ourbpict == NULL) |
271 |
+ |
syserror(progname); |
272 |
+ |
} |
273 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
274 |
|
if (ourzbuf == NULL) |
275 |
|
syserror(progname); |
263 |
– |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
276 |
|
/* new header */ |
277 |
|
newheader("RADIANCE", stdout); |
278 |
< |
/* get input */ |
279 |
< |
for ( ; i < argc; i += 2) |
280 |
< |
addpicture(argv[i], argv[i+1]); |
281 |
< |
/* fill in spaces */ |
282 |
< |
if (fillo&F_BACK) |
283 |
< |
backpicture(fillfunc, fillsamp); |
284 |
< |
else |
285 |
< |
fillpicture(fillfunc); |
278 |
> |
fputnow(stdout); |
279 |
> |
/* run pictures */ |
280 |
> |
do { |
281 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
282 |
> |
for (i = an; i < argc; i += 2) |
283 |
> |
addpicture(argv[i], argv[i+1]); |
284 |
> |
if (fillo&F_BACK) /* fill in spaces */ |
285 |
> |
backpicture(fillfunc, fillsamp); |
286 |
> |
else |
287 |
> |
fillpicture(fillfunc); |
288 |
> |
/* aft clipping */ |
289 |
> |
clipaft(); |
290 |
> |
} while (addblur() && nextview(stdin) != EOF); |
291 |
|
/* close calculation */ |
292 |
|
caldone(); |
276 |
– |
/* aft clipping */ |
277 |
– |
clipaft(); |
293 |
|
/* add to header */ |
294 |
|
printargs(argc, argv, stdout); |
295 |
< |
if (gotvfile) { |
295 |
> |
compavgview(); |
296 |
> |
if (doblur | gotvfile) { |
297 |
|
fputs(VIEWSTR, stdout); |
298 |
< |
fprintview(&ourview, stdout); |
298 |
> |
fprintview(&avgview, stdout); |
299 |
|
putc('\n', stdout); |
300 |
|
} |
301 |
|
if (pixaspect < .99 | pixaspect > 1.01) |
306 |
|
ourexp = rexpadj; |
307 |
|
if (ourexp < .995 | ourexp > 1.005) |
308 |
|
fputexpos(ourexp, stdout); |
309 |
< |
fputformat(COLRFMT, stdout); |
309 |
> |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
310 |
> |
fputformat(ourfmt, stdout); |
311 |
|
putc('\n', stdout); |
312 |
|
/* write picture */ |
313 |
|
writepicture(); |
318 |
|
exit(0); |
319 |
|
userr: |
320 |
|
fprintf(stderr, |
321 |
< |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n", |
321 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
322 |
|
progname); |
323 |
|
exit(1); |
324 |
|
#undef check |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
+ |
int |
329 |
|
headline(s) /* process header string */ |
330 |
|
char *s; |
331 |
|
{ |
332 |
|
char fmt[32]; |
333 |
|
|
334 |
|
if (isheadid(s)) |
335 |
< |
return; |
335 |
> |
return(0); |
336 |
|
if (formatval(fmt, s)) { |
337 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
338 |
< |
return; |
337 |
> |
if (globmatch(ourfmt, fmt)) { |
338 |
> |
wrongformat = 0; |
339 |
> |
strcpy(ourfmt, fmt); |
340 |
> |
} else |
341 |
> |
wrongformat = 1; |
342 |
> |
return(0); |
343 |
|
} |
344 |
< |
putc('\t', stdout); |
345 |
< |
fputs(s, stdout); |
346 |
< |
|
344 |
> |
if (nvavg < 2) { |
345 |
> |
putc('\t', stdout); |
346 |
> |
fputs(s, stdout); |
347 |
> |
} |
348 |
|
if (isexpos(s)) { |
349 |
|
theirexp *= exposval(s); |
350 |
< |
return; |
350 |
> |
return(0); |
351 |
|
} |
352 |
|
if (isview(s) && sscanview(&theirview, s) > 0) |
353 |
|
gotview++; |
354 |
+ |
return(0); |
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
+ |
nextview(fp) /* get and set next view */ |
359 |
+ |
FILE *fp; |
360 |
+ |
{ |
361 |
+ |
char linebuf[256]; |
362 |
+ |
char *err; |
363 |
+ |
register int i; |
364 |
+ |
|
365 |
+ |
if (fp != NULL) { |
366 |
+ |
do /* get new view */ |
367 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
368 |
+ |
return(EOF); |
369 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
370 |
+ |
} |
371 |
+ |
/* set new view */ |
372 |
+ |
if ((err = setview(&ourview)) != NULL) { |
373 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
374 |
+ |
exit(1); |
375 |
+ |
} |
376 |
+ |
if (!nvavg) { /* first view */ |
377 |
+ |
copystruct(&avgview, &ourview); |
378 |
+ |
return(nvavg++); |
379 |
+ |
} |
380 |
+ |
/* add to average view */ |
381 |
+ |
for (i = 0; i < 3; i++) { |
382 |
+ |
avgview.vp[i] += ourview.vp[i]; |
383 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
384 |
+ |
avgview.vup[i] += ourview.vup[i]; |
385 |
+ |
} |
386 |
+ |
avgview.horiz += ourview.horiz; |
387 |
+ |
avgview.vert += ourview.vert; |
388 |
+ |
avgview.hoff += ourview.hoff; |
389 |
+ |
avgview.voff += ourview.voff; |
390 |
+ |
avgview.vfore += ourview.vfore; |
391 |
+ |
avgview.vaft += ourview.vaft; |
392 |
+ |
return(nvavg++); |
393 |
+ |
} |
394 |
+ |
|
395 |
+ |
|
396 |
+ |
compavgview() /* compute average view */ |
397 |
+ |
{ |
398 |
+ |
register int i; |
399 |
+ |
double f; |
400 |
+ |
|
401 |
+ |
if (nvavg < 2) |
402 |
+ |
return; |
403 |
+ |
f = 1.0/nvavg; |
404 |
+ |
for (i = 0; i < 3; i++) { |
405 |
+ |
avgview.vp[i] *= f; |
406 |
+ |
avgview.vdir[i] *= f; |
407 |
+ |
avgview.vup[i] *= f; |
408 |
+ |
} |
409 |
+ |
avgview.horiz *= f; |
410 |
+ |
avgview.vert *= f; |
411 |
+ |
avgview.hoff *= f; |
412 |
+ |
avgview.voff *= f; |
413 |
+ |
avgview.vfore *= f; |
414 |
+ |
avgview.vaft *= f; |
415 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
416 |
+ |
copystruct(&avgview, &ourview); |
417 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
418 |
+ |
} |
419 |
+ |
|
420 |
+ |
|
421 |
|
addpicture(pfile, zspec) /* add picture to output */ |
422 |
|
char *pfile, *zspec; |
423 |
|
{ |
434 |
|
syserror(pfile); |
435 |
|
/* get header with exposure and view */ |
436 |
|
theirexp = 1.0; |
437 |
+ |
copystruct(&theirview, &stdview); |
438 |
|
gotview = 0; |
439 |
< |
printf("%s:\n", pfile); |
439 |
> |
if (nvavg < 2) |
440 |
> |
printf("%s:\n", pfile); |
441 |
|
getheader(pfp, headline, NULL); |
442 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
443 |
|
fprintf(stderr, "%s: picture format error\n", pfile); |
470 |
|
if (xlim == NULL) |
471 |
|
syserror(progname); |
472 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
473 |
< |
free((char *)zin); |
474 |
< |
free((char *)xlim); |
473 |
> |
free((void *)zin); |
474 |
> |
free((void *)xlim); |
475 |
|
if (zfd != -1) |
476 |
|
close(zfd); |
477 |
|
fclose(pfp); |
490 |
|
exit(1); |
491 |
|
} |
492 |
|
if (zfd != -1 && lseek(zfd, |
493 |
< |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
493 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
494 |
|
syserror(zspec); |
495 |
|
/* load image */ |
496 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
505 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
506 |
|
} |
507 |
|
/* clean up */ |
508 |
< |
free((char *)xlim); |
509 |
< |
free((char *)scanin); |
510 |
< |
free((char *)zin); |
511 |
< |
free((char *)plast); |
508 |
> |
free((void *)xlim); |
509 |
> |
free((void *)scanin); |
510 |
> |
free((void *)zin); |
511 |
> |
free((void *)plast); |
512 |
|
fclose(pfp); |
513 |
|
if (zfd != -1) |
514 |
|
close(zfd); |
521 |
|
{ |
522 |
|
double m4t[4][4]; |
523 |
|
|
524 |
< |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
524 |
> |
if (vw1->type != VT_PER & vw1->type != VT_PAR) |
525 |
|
return(0); |
526 |
< |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
526 |
> |
if (vw2->type != VT_PER & vw2->type != VT_PAR) |
527 |
|
return(0); |
528 |
|
setident4(xfmat); |
529 |
|
xfmat[0][0] = vw1->hvec[0]; |
640 |
|
y1 = p0->y + c1*s1y/l1; |
641 |
|
for (c2 = l2; c2-- > 0; ) { |
642 |
|
x = x1 + c2*s2x/l2; |
643 |
< |
if (x < 0 || x >= hresolu) |
643 |
> |
if (x < 0 | x >= hresolu) |
644 |
|
continue; |
645 |
|
y = y1 + c2*s2y/l2; |
646 |
< |
if (y < 0 || y >= vresolu) |
646 |
> |
if (y < 0 | y >= vresolu) |
647 |
|
continue; |
648 |
|
if (averaging) { |
649 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
671 |
|
{ |
672 |
|
FVECT pt, tdir, odir; |
673 |
|
double d; |
585 |
– |
register int i; |
674 |
|
|
675 |
|
if (pos[2] <= 0) /* empty pixel */ |
676 |
|
return(0); |
677 |
|
if (usematrix) { |
678 |
|
pos[0] += theirview.hoff - .5; |
679 |
|
pos[1] += theirview.voff - .5; |
680 |
+ |
if (normdist & theirview.type == VT_PER) |
681 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
682 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
683 |
+ |
else |
684 |
+ |
d = 1.; |
685 |
+ |
pos[2] += d*theirview.vfore; |
686 |
|
if (theirview.type == VT_PER) { |
687 |
< |
if (normdist) /* adjust distance */ |
594 |
< |
pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
595 |
< |
+ pos[1]*pos[1]*theirview.vn2); |
687 |
> |
pos[2] /= d; |
688 |
|
pos[0] *= pos[2]; |
689 |
|
pos[1] *= pos[2]; |
690 |
|
} |
691 |
|
multp3(pos, pos, theirs2ours); |
692 |
< |
if (pos[2] <= 0) |
692 |
> |
if (pos[2] <= ourview.vfore) |
693 |
|
return(0); |
694 |
|
if (ourview.type == VT_PER) { |
695 |
|
pos[0] /= pos[2]; |
697 |
|
} |
698 |
|
pos[0] += .5 - ourview.hoff; |
699 |
|
pos[1] += .5 - ourview.voff; |
700 |
+ |
pos[2] -= ourview.vfore; |
701 |
|
} else { |
702 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
703 |
|
return(0); |
711 |
|
if (pos[2] <= 0) |
712 |
|
return(0); |
713 |
|
} |
714 |
< |
if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY) |
714 |
> |
if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) |
715 |
|
return(0); |
716 |
|
if (!averaging) |
717 |
|
return(1); |
718 |
< |
if (ourview.type == VT_PAR) /* compute our direction */ |
719 |
< |
VCOPY(odir, ourview.vdir); |
720 |
< |
else |
721 |
< |
for (i = 0; i < 3; i++) |
722 |
< |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
723 |
< |
d = DOT(odir,tdir); /* compute pixel weight */ |
724 |
< |
if (d >= 1.-1./MAXWT/MAXWT) |
718 |
> |
/* compute pixel weight */ |
719 |
> |
if (ourview.type == VT_PAR) { |
720 |
> |
d = DOT(ourview.vdir,tdir); |
721 |
> |
d = 1. - d*d; |
722 |
> |
} else { |
723 |
> |
VSUB(odir, pt, ourview.vp); |
724 |
> |
d = DOT(odir,tdir); |
725 |
> |
d = 1. - d*d/DOT(odir,odir); |
726 |
> |
} |
727 |
> |
if (d <= 1./MAXWT/MAXWT) |
728 |
|
return(MAXWT); /* clip to maximum weight */ |
729 |
< |
return(1./sqrt(1.-d)); |
729 |
> |
return(1./sqrt(d)); |
730 |
|
} |
731 |
|
|
732 |
|
|
757 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
758 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
759 |
|
if (zfd != -1) { |
760 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
760 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
761 |
|
0) < 0) |
762 |
|
syserror("lseek"); |
763 |
|
if (read(zfd, (char *)zline, |
918 |
|
xback = -2; |
919 |
|
} |
920 |
|
} |
921 |
< |
free((char *)yback); |
921 |
> |
free((void *)yback); |
922 |
|
} |
923 |
|
|
924 |
|
|
931 |
|
for (x = 0; x < hresolu; x++) |
932 |
|
if (zscan(y)[x] <= 0) |
933 |
|
(*fill)(x,y); |
934 |
+ |
if (fill == rcalfill) |
935 |
+ |
clearqueue(); |
936 |
|
} |
937 |
|
|
938 |
|
|
944 |
|
double yzn2, vx; |
945 |
|
|
946 |
|
if (ourview.vaft <= FTINY) |
947 |
< |
return; |
947 |
> |
return(0); |
948 |
|
tstdist = ourview.vaft - ourview.vfore; |
949 |
|
for (y = 0; y < vresolu; y++) { |
950 |
|
if (adjtest) { /* adjust test */ |
962 |
|
continue; |
963 |
|
} |
964 |
|
if (averaging) |
965 |
< |
bzero(sscan(y)[x], sizeof(COLOR)); |
965 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
966 |
|
else |
967 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
967 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
968 |
|
zscan(y)[x] = 0.0; |
969 |
|
} |
970 |
|
} |
971 |
+ |
return(1); |
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
+ |
addblur() /* add to blurred picture */ |
976 |
+ |
{ |
977 |
+ |
COLOR cval; |
978 |
+ |
double d; |
979 |
+ |
register int i; |
980 |
+ |
|
981 |
+ |
if (!blurring) |
982 |
+ |
return(0); |
983 |
+ |
i = hresolu*vresolu; |
984 |
+ |
if (nvavg < 2) |
985 |
+ |
if (averaging) |
986 |
+ |
while (i--) { |
987 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
988 |
+ |
d = 1.0/ourweigh[i]; |
989 |
+ |
scalecolor(ourbpict[i], d); |
990 |
+ |
} |
991 |
+ |
else |
992 |
+ |
while (i--) |
993 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
994 |
+ |
else |
995 |
+ |
if (averaging) |
996 |
+ |
while (i--) { |
997 |
+ |
copycolor(cval, ourspict[i]); |
998 |
+ |
d = 1.0/ourweigh[i]; |
999 |
+ |
scalecolor(cval, d); |
1000 |
+ |
addcolor(ourbpict[i], cval); |
1001 |
+ |
} |
1002 |
+ |
else |
1003 |
+ |
while (i--) { |
1004 |
+ |
colr_color(cval, ourpict[i]); |
1005 |
+ |
addcolor(ourbpict[i], cval); |
1006 |
+ |
} |
1007 |
+ |
/* print view */ |
1008 |
+ |
printf("VIEW%d:", nvavg); |
1009 |
+ |
fprintview(&ourview, stdout); |
1010 |
+ |
putchar('\n'); |
1011 |
+ |
return(1); |
1012 |
+ |
} |
1013 |
+ |
|
1014 |
+ |
|
1015 |
|
writepicture() /* write out picture (alters buffer) */ |
1016 |
|
{ |
1017 |
|
int y; |
1020 |
|
|
1021 |
|
fprtresolu(hresolu, vresolu, stdout); |
1022 |
|
for (y = vresolu-1; y >= 0; y--) |
1023 |
< |
if (averaging) { |
1023 |
> |
if (blurring) { |
1024 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1025 |
> |
d = rexpadj/nvavg; |
1026 |
> |
scalecolor(bscan(y)[x], d); |
1027 |
> |
} |
1028 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1029 |
> |
syserror(progname); |
1030 |
> |
} else if (averaging) { |
1031 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1032 |
|
d = rexpadj/wscan(y)[x]; |
1033 |
|
scalecolor(sscan(y)[x], d); |
1096 |
|
int rval; |
1097 |
|
register char **wp, *cp; |
1098 |
|
|
1099 |
< |
if (childpid != -1) { |
1099 |
> |
if (PDesc.running) { |
1100 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1101 |
|
exit(1); |
1102 |
|
} |
1115 |
|
} |
1116 |
|
*wp = NULL; |
1117 |
|
/* start process */ |
1118 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1118 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1119 |
|
syserror(progname); |
1120 |
|
if (rval == 0) { |
1121 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1130 |
|
|
1131 |
|
caldone() /* done with calculation */ |
1132 |
|
{ |
1133 |
< |
if (childpid == -1) |
1133 |
> |
if (!PDesc.running) |
1134 |
|
return; |
1135 |
|
clearqueue(); |
1136 |
< |
close_process(PDesc); |
991 |
< |
childpid = -1; |
1136 |
> |
close_process(&PDesc); |
1137 |
|
} |
1138 |
|
|
1139 |
|
|
1168 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1169 |
|
} |
1170 |
|
/* mark end and get results */ |
1171 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1172 |
< |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
1171 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1172 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1173 |
> |
4*sizeof(float)*(queuesiz+1), |
1174 |
|
6*sizeof(float)*(queuesiz+1)) != |
1175 |
< |
4*sizeof(float)*queuesiz) { |
1175 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1176 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1177 |
|
progname); |
1178 |
|
exit(1); |