| 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 */ |
| 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) |
| 301 |
|
} |
| 302 |
|
/* compute transformation */ |
| 303 |
|
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
| 304 |
< |
/* allocate scanlines */ |
| 299 |
< |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
| 304 |
> |
/* get z specification or file */ |
| 305 |
|
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
| 306 |
< |
plast = (struct position *)calloc(scanlen(&tresolu), |
| 302 |
< |
sizeof(struct position)); |
| 303 |
< |
if (scanin == NULL || zin == NULL || plast == NULL) |
| 306 |
> |
if (zin == NULL) |
| 307 |
|
syserror(progname); |
| 305 |
– |
/* get z specification or file */ |
| 308 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 309 |
|
double zvalue; |
| 310 |
|
register int x; |
| 313 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
| 314 |
|
zin[x] = zvalue; |
| 315 |
|
} |
| 316 |
< |
/* load image */ |
| 317 |
< |
for (y = 0; y < numscans(&tresolu); y++) { |
| 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 (zfd != -1 && read(zfd,(char *)zin, |
| 341 |
< |
scanlen(&tresolu)*sizeof(float)) |
| 342 |
< |
< scanlen(&tresolu)*sizeof(float)) { |
| 343 |
< |
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); |
| 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; |
| 416 |
|
register int x; |
| 417 |
|
|
| 418 |
|
lastx.z = 0; |
| 419 |
< |
for (x = scanlen(&tresolu); x-- > 0; ) { |
| 419 |
> |
for (x = xl->max; x >= xl->min; x--) { |
| 420 |
|
pix2loc(pos, &tresolu, x, y); |
| 421 |
|
pos[2] = zline[x]; |
| 422 |
|
if (movepixel(pos) < 0) { |
| 493 |
|
} |
| 494 |
|
} |
| 495 |
|
} |
| 496 |
+ |
} |
| 497 |
+ |
|
| 498 |
+ |
|
| 499 |
+ |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
| 500 |
+ |
register struct bound *xl; |
| 501 |
+ |
struct bound *yl; |
| 502 |
+ |
float *zline; |
| 503 |
+ |
int zfd; |
| 504 |
+ |
{ |
| 505 |
+ |
int step; |
| 506 |
+ |
FVECT pos; |
| 507 |
+ |
register int x, y; |
| 508 |
+ |
/* set up step size */ |
| 509 |
+ |
if (scanlen(&tresolu) < numscans(&tresolu)) |
| 510 |
+ |
step = scanlen(&tresolu)/NSTEPS; |
| 511 |
+ |
else |
| 512 |
+ |
step = numscans(&tresolu)/NSTEPS; |
| 513 |
+ |
if (step < MINSTEP) { /* not worth cropping? */ |
| 514 |
+ |
yl->min = 0; |
| 515 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 516 |
+ |
x = scanlen(&tresolu) - 1; |
| 517 |
+ |
for (y = numscans(&tresolu); y--; ) { |
| 518 |
+ |
xl[y].min = 0; |
| 519 |
+ |
xl[y].max = x; |
| 520 |
+ |
} |
| 521 |
+ |
return(1); |
| 522 |
+ |
} |
| 523 |
+ |
yl->min = 32000; yl->max = 0; /* search for points on image */ |
| 524 |
+ |
for (y = step - 1; y < numscans(&tresolu); y += step) { |
| 525 |
+ |
if (zfd != -1) { |
| 526 |
+ |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
| 527 |
+ |
0) < 0) |
| 528 |
+ |
syserror("lseek"); |
| 529 |
+ |
if (read(zfd, (char *)zline, |
| 530 |
+ |
scanlen(&tresolu)*sizeof(float)) |
| 531 |
+ |
< scanlen(&tresolu)*sizeof(float)) |
| 532 |
+ |
syserror("read"); |
| 533 |
+ |
} |
| 534 |
+ |
xl[y].min = 32000; xl[y].max = 0; /* x max */ |
| 535 |
+ |
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
| 536 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 537 |
+ |
pos[2] = zline[x]; |
| 538 |
+ |
if (movepixel(pos) == 0 && pos[0] >= 0 && |
| 539 |
+ |
pos[0] < 1 && pos[1] >= 0 && |
| 540 |
+ |
pos[1] < 1) { |
| 541 |
+ |
xl[y].max = x + step - 1; |
| 542 |
+ |
xl[y].min = x - step + 1; /* x min */ |
| 543 |
+ |
if (xl[y].min < 0) |
| 544 |
+ |
xl[y].min = 0; |
| 545 |
+ |
for (x = step - 1; x < xl[y].max; x += step) { |
| 546 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 547 |
+ |
pos[2] = zline[x]; |
| 548 |
+ |
if (movepixel(pos) == 0 && |
| 549 |
+ |
pos[0] >= 0 && |
| 550 |
+ |
pos[0] < 1 && |
| 551 |
+ |
pos[1] >= 0 && |
| 552 |
+ |
pos[1] < 1) { |
| 553 |
+ |
xl[y].min = x - step + 1; |
| 554 |
+ |
break; |
| 555 |
+ |
} |
| 556 |
+ |
} |
| 557 |
+ |
if (y < yl->min) /* y limits */ |
| 558 |
+ |
yl->min = y - step + 1; |
| 559 |
+ |
yl->max = y + step - 1; |
| 560 |
+ |
break; |
| 561 |
+ |
} |
| 562 |
+ |
} |
| 563 |
+ |
/* fill in between */ |
| 564 |
+ |
if (xl[y].min < xl[y-step].min) |
| 565 |
+ |
xl[y-1].min = xl[y].min; |
| 566 |
+ |
else |
| 567 |
+ |
xl[y-1].min = xl[y-step].min; |
| 568 |
+ |
if (xl[y].max > xl[y-step].max) |
| 569 |
+ |
xl[y-1].max = xl[y].max; |
| 570 |
+ |
else |
| 571 |
+ |
xl[y-1].max = xl[y-step].max; |
| 572 |
+ |
for (x = 2; x < step; x++) |
| 573 |
+ |
copystruct(xl+y-x, xl+y-1); |
| 574 |
+ |
} |
| 575 |
+ |
if (yl->max >= numscans(&tresolu)) |
| 576 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 577 |
+ |
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
| 578 |
+ |
copystruct(xl+x, xl+y); |
| 579 |
+ |
return(yl->max >= yl->min); |
| 580 |
|
} |
| 581 |
|
|
| 582 |
|
|