60 |
|
int thresolu, tvresolu; /* input resolution */ |
61 |
|
double theirexp; /* input picture exposure */ |
62 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
63 |
+ |
int hasmatrix = 0; /* has transformation matrix */ |
64 |
|
|
65 |
|
int childpid = -1; /* id of fill process */ |
66 |
|
FILE *psend, *precv; /* pipes to/from fill calculation */ |
285 |
|
exit(1); |
286 |
|
} |
287 |
|
/* compute transformation */ |
288 |
< |
pixform(theirs2ours, &theirview, &ourview); |
288 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
289 |
|
/* allocate scanlines */ |
290 |
|
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
291 |
|
zin = (float *)malloc(thresolu*sizeof(float)); |
332 |
|
{ |
333 |
|
double m4t[4][4]; |
334 |
|
|
335 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
336 |
+ |
return(0); |
337 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
338 |
+ |
return(0); |
339 |
|
setident4(xfmat); |
340 |
|
xfmat[0][0] = vw1->hvec[0]; |
341 |
|
xfmat[0][1] = vw1->hvec[1]; |
363 |
|
m4t[2][2] = vw2->vdir[2]; |
364 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
365 |
|
multmat4(xfmat, xfmat, m4t); |
366 |
+ |
return(1); |
367 |
|
} |
368 |
|
|
369 |
|
|
374 |
|
struct position *lasty; /* input/output */ |
375 |
|
{ |
376 |
|
extern double sqrt(); |
377 |
< |
double pos[3]; |
377 |
> |
FVECT pos; |
378 |
|
struct position lastx, newpos; |
379 |
|
register int x; |
380 |
|
|
381 |
|
lastx.z = 0; |
382 |
|
for (x = thresolu-1; x >= 0; x--) { |
383 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
384 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
383 |
> |
pos[0] = (x+.5)/thresolu; |
384 |
> |
pos[1] = (y+.5)/tvresolu; |
385 |
|
pos[2] = zline[x]; |
386 |
< |
if (theirview.type == VT_PER) { |
381 |
< |
if (normdist) /* adjust for eye-ray distance */ |
382 |
< |
pos[2] /= sqrt( 1. |
383 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
384 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
385 |
< |
pos[0] *= pos[2]; |
386 |
< |
pos[1] *= pos[2]; |
387 |
< |
} |
388 |
< |
multp3(pos, pos, theirs2ours); |
389 |
< |
if (pos[2] <= 0) { |
386 |
> |
if (movepixel(pos) < 0) { |
387 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
388 |
|
continue; |
389 |
|
} |
393 |
– |
if (ourview.type == VT_PER) { |
394 |
– |
pos[0] /= pos[2]; |
395 |
– |
pos[1] /= pos[2]; |
396 |
– |
} |
397 |
– |
pos[0] += .5 - ourview.hoff; |
398 |
– |
pos[1] += .5 - ourview.voff; |
390 |
|
newpos.x = pos[0] * hresolu; |
391 |
|
newpos.y = pos[1] * vresolu; |
392 |
|
newpos.z = zline[x]; |
445 |
|
y1 = p0->y + c1*s1y/l1; |
446 |
|
for (c2 = l2; c2-- > 0; ) { |
447 |
|
x = x1 + c2*s2x/l2; |
448 |
+ |
if (x < 0 || x >= hresolu) |
449 |
+ |
continue; |
450 |
|
y = y1 + c2*s2y/l2; |
451 |
+ |
if (y < 0 || y >= vresolu) |
452 |
+ |
continue; |
453 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
454 |
|
> zeps*zscan(y)[x]) { |
455 |
|
zscan(y)[x] = z; |
460 |
|
} |
461 |
|
|
462 |
|
|
463 |
+ |
movepixel(pos) /* reposition image point */ |
464 |
+ |
FVECT pos; |
465 |
+ |
{ |
466 |
+ |
FVECT pt, direc; |
467 |
+ |
|
468 |
+ |
if (hasmatrix) { |
469 |
+ |
pos[0] += theirview.hoff - .5; |
470 |
+ |
pos[1] += theirview.voff - .5; |
471 |
+ |
if (theirview.type == VT_PER) { |
472 |
+ |
if (normdist) /* adjust for eye-ray distance */ |
473 |
+ |
pos[2] /= sqrt( 1. |
474 |
+ |
+ pos[0]*pos[0]*theirview.hn2 |
475 |
+ |
+ pos[1]*pos[1]*theirview.vn2 ); |
476 |
+ |
pos[0] *= pos[2]; |
477 |
+ |
pos[1] *= pos[2]; |
478 |
+ |
} |
479 |
+ |
multp3(pos, pos, theirs2ours); |
480 |
+ |
if (pos[2] <= 0) |
481 |
+ |
return(-1); |
482 |
+ |
if (ourview.type == VT_PER) { |
483 |
+ |
pos[0] /= pos[2]; |
484 |
+ |
pos[1] /= pos[2]; |
485 |
+ |
} |
486 |
+ |
pos[0] += .5 - ourview.hoff; |
487 |
+ |
pos[1] += .5 - ourview.voff; |
488 |
+ |
return(0); |
489 |
+ |
} |
490 |
+ |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
491 |
+ |
return(-1); |
492 |
+ |
pt[0] += direc[0]*pos[2]; |
493 |
+ |
pt[1] += direc[1]*pos[2]; |
494 |
+ |
pt[2] += direc[2]*pos[2]; |
495 |
+ |
viewpixel(&pos[0], &pos[1], &pos[2], &ourview, pt); |
496 |
+ |
if (pos[2] <= 0) |
497 |
+ |
return(-1); |
498 |
+ |
return(0); |
499 |
+ |
} |
500 |
+ |
|
501 |
+ |
|
502 |
|
backpicture(fill, samp) /* background fill algorithm */ |
503 |
|
int (*fill)(); |
504 |
|
int samp; |
505 |
|
{ |
506 |
|
int *yback, xback; |
507 |
|
int y; |
474 |
– |
COLR pfill; |
508 |
|
register int x, i; |
509 |
|
/* get back buffer */ |
510 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
552 |
|
} |
553 |
|
/* |
554 |
|
* If we have no background for this pixel, |
522 |
– |
* or if the background is too distant, |
555 |
|
* use the given fill function. |
556 |
|
*/ |
557 |
< |
if ((xback < 0 && yback[x] < 0) |
558 |
< |
|| (samp > 0 |
527 |
< |
&& ABS(x-xback) >= samp |
528 |
< |
&& ABS(y-yback[y]) >= samp)) { |
529 |
< |
(*fill)(x,y); |
530 |
< |
if (fill != backfill) { /* reuse */ |
531 |
< |
yback[x] = -2; |
532 |
< |
xback = -2; |
533 |
< |
} |
534 |
< |
continue; |
535 |
< |
} |
557 |
> |
if (xback < 0 && yback[x] < 0) |
558 |
> |
goto fillit; |
559 |
|
/* |
560 |
|
* Compare, and use the background that is |
561 |
|
* farther, unless one of them is next to us. |
562 |
+ |
* If the background is too distant, call |
563 |
+ |
* the fill function. |
564 |
|
*/ |
565 |
|
if ( yback[x] < 0 |
566 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
567 |
|
|| ( ABS(y-yback[x]) > 1 |
568 |
|
&& zscan(yback[x])[x] |
569 |
|
< zscan(y)[xback] ) ) { |
570 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
571 |
+ |
goto fillit; |
572 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
573 |
|
zscan(y)[x] = zscan(y)[xback]; |
574 |
|
} else { |
575 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
576 |
+ |
goto fillit; |
577 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
578 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
579 |
|
} |
580 |
+ |
continue; |
581 |
+ |
fillit: |
582 |
+ |
(*fill)(x,y); |
583 |
+ |
if (fill == rcalfill) { /* use it */ |
584 |
+ |
clearqueue(); |
585 |
+ |
xback = x; |
586 |
+ |
yback[x] = y; |
587 |
+ |
} |
588 |
|
} else { /* full pixel */ |
589 |
|
yback[x] = -2; |
590 |
|
xback = -2; |
637 |
|
if (donorm) { |
638 |
|
double vx, yzn2; |
639 |
|
register int x; |
640 |
< |
yzn2 = y - .5*(vresolu-1); |
640 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
641 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
642 |
|
for (x = 0; x < hresolu; x++) { |
643 |
< |
vx = x - .5*(hresolu-1); |
643 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
644 |
|
zout[x] = zscan(y)[x] |
645 |
|
* sqrt(vx*vx*ourview.hn2 + yzn2); |
646 |
|
} |