17 |
|
#define pscan(y) (ourpict+(y)*ourview.hresolu) |
18 |
|
#define zscan(y) (ourzbuf+(y)*ourview.hresolu) |
19 |
|
|
20 |
+ |
#define ABS(x) ((x)>0?(x):-(x)) |
21 |
+ |
|
22 |
|
VIEW ourview = STDVIEW(512); /* desired view */ |
23 |
|
|
24 |
|
double zeps = 0.001; /* allowed z epsilon */ |
31 |
|
VIEW theirview = STDVIEW(512); /* input view */ |
32 |
|
int gotview; /* got input view? */ |
33 |
|
|
34 |
+ |
double theirs2ours[4][4]; /* transformation matrix */ |
35 |
|
|
36 |
+ |
|
37 |
|
main(argc, argv) /* interpolate pictures */ |
38 |
|
int argc; |
39 |
|
char *argv[]; |
193 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
194 |
|
exit(1); |
195 |
|
} |
196 |
+ |
/* compute transformation */ |
197 |
+ |
pixform(theirs2ours, &theirview, &ourview); |
198 |
|
/* allocate scanlines */ |
199 |
|
scanin = (COLR *)malloc(xres*sizeof(COLR)); |
200 |
|
zin = (float *)malloc(xres*sizeof(float)); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
+ |
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
226 |
+ |
register double xfmat[4][4]; |
227 |
+ |
register VIEW *vw1, *vw2; |
228 |
+ |
{ |
229 |
+ |
double m4t[4][4]; |
230 |
+ |
|
231 |
+ |
setident4(xfmat); |
232 |
+ |
xfmat[0][0] = vw1->vhinc[0]; |
233 |
+ |
xfmat[0][1] = vw1->vhinc[1]; |
234 |
+ |
xfmat[0][2] = vw1->vhinc[2]; |
235 |
+ |
xfmat[1][0] = vw1->vvinc[0]; |
236 |
+ |
xfmat[1][1] = vw1->vvinc[1]; |
237 |
+ |
xfmat[1][2] = vw1->vvinc[2]; |
238 |
+ |
xfmat[2][0] = vw1->vdir[0]; |
239 |
+ |
xfmat[2][1] = vw1->vdir[1]; |
240 |
+ |
xfmat[2][2] = vw1->vdir[2]; |
241 |
+ |
xfmat[3][0] = vw1->vp[0]; |
242 |
+ |
xfmat[3][1] = vw1->vp[1]; |
243 |
+ |
xfmat[3][2] = vw1->vp[2]; |
244 |
+ |
setident4(m4t); |
245 |
+ |
m4t[0][0] = vw2->vhinc[0]/vw2->vhn2; |
246 |
+ |
m4t[1][0] = vw2->vhinc[1]/vw2->vhn2; |
247 |
+ |
m4t[2][0] = vw2->vhinc[2]/vw2->vhn2; |
248 |
+ |
m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2; |
249 |
+ |
m4t[0][1] = vw2->vvinc[0]/vw2->vvn2; |
250 |
+ |
m4t[1][1] = vw2->vvinc[1]/vw2->vvn2; |
251 |
+ |
m4t[2][1] = vw2->vvinc[2]/vw2->vvn2; |
252 |
+ |
m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2; |
253 |
+ |
m4t[0][2] = vw2->vdir[0]; |
254 |
+ |
m4t[1][2] = vw2->vdir[1]; |
255 |
+ |
m4t[2][2] = vw2->vdir[2]; |
256 |
+ |
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
257 |
+ |
multmat4(xfmat, xfmat, m4t); |
258 |
+ |
} |
259 |
+ |
|
260 |
+ |
|
261 |
|
addscanline(y, pline, zline) /* add scanline to output */ |
262 |
|
int y; |
263 |
|
COLR *pline; |
264 |
|
float *zline; |
265 |
|
{ |
266 |
< |
FVECT p, dir; |
267 |
< |
double xnew, ynew, znew; |
266 |
> |
extern double sqrt(); |
267 |
> |
double pos[3]; |
268 |
|
register int x; |
269 |
|
register int xpos, ypos; |
270 |
|
|
271 |
|
for (x = 0; x < theirview.hresolu; x++) { |
272 |
< |
rayview(p, dir, &theirview, x+.5, y+.5); |
273 |
< |
p[0] += zline[x]*dir[0]; |
274 |
< |
p[1] += zline[x]*dir[1]; |
275 |
< |
p[2] += zline[x]*dir[2]; |
276 |
< |
pixelview(&xnew, &ynew, &znew, &ourview, p); |
277 |
< |
if (znew <= 0.0 || xnew < 0 || xnew > ourview.hresolu |
278 |
< |
|| ynew < 0 || ynew > ourview.vresolu) |
272 |
> |
pos[0] = x - .5*(theirview.hresolu-1); |
273 |
> |
pos[1] = y - .5*(theirview.vresolu-1); |
274 |
> |
pos[2] = zline[x]; |
275 |
> |
if (theirview.type == VT_PER) { |
276 |
> |
pos[2] /= sqrt( 1. |
277 |
> |
+ pos[0]*pos[0]*theirview.vhn2 |
278 |
> |
+ pos[1]*pos[1]*theirview.vvn2 ); |
279 |
> |
pos[0] *= pos[2]; |
280 |
> |
pos[1] *= pos[2]; |
281 |
> |
} |
282 |
> |
multp3(pos, pos, theirs2ours); |
283 |
> |
if (pos[2] <= 0.0) |
284 |
|
continue; |
285 |
< |
/* check current value at position */ |
286 |
< |
xpos = xnew; |
287 |
< |
ypos = ynew; |
285 |
> |
if (ourview.type == VT_PER) { |
286 |
> |
pos[0] /= pos[2]; |
287 |
> |
pos[1] /= pos[2]; |
288 |
> |
} |
289 |
> |
pos[0] += .5*ourview.hresolu; |
290 |
> |
pos[1] += .5*ourview.vresolu; |
291 |
> |
if (pos[0] < 0 || pos[0] > ourview.hresolu |
292 |
> |
|| pos[1] < 0 || pos[1] > ourview.vresolu) |
293 |
> |
continue; |
294 |
> |
/* check current value at pos */ |
295 |
> |
xpos = pos[0]; |
296 |
> |
ypos = pos[1]; |
297 |
|
if (zscan(ypos)[xpos] <= 0.0 |
298 |
< |
|| zscan(ypos)[xpos] - znew |
298 |
> |
|| zscan(ypos)[xpos] - pos[2] |
299 |
|
> zeps*zscan(ypos)[xpos]) { |
300 |
< |
zscan(ypos)[xpos] = znew; |
300 |
> |
zscan(ypos)[xpos] = pos[2]; |
301 |
|
copycolr(pscan(ypos)[xpos], pline[x]); |
302 |
|
} |
303 |
|
} |
306 |
|
|
307 |
|
fillpicture() /* fill in empty spaces */ |
308 |
|
{ |
309 |
+ |
int *yback, xback; |
310 |
|
int y; |
311 |
< |
COLR cfill; |
312 |
< |
register int x, xblank; |
313 |
< |
|
311 |
> |
COLR pfill; |
312 |
> |
register int x, i; |
313 |
> |
/* get back buffer */ |
314 |
> |
yback = (int *)malloc(ourview.hresolu*sizeof(int)); |
315 |
> |
if (yback == NULL) { |
316 |
> |
perror(progname); |
317 |
> |
return; |
318 |
> |
} |
319 |
> |
for (x = 0; x < ourview.hresolu; x++) |
320 |
> |
yback[x] = -2; |
321 |
> |
/* fill image */ |
322 |
|
for (y = 0; y < ourview.vresolu; y++) { |
323 |
< |
xblank = -1; |
323 |
> |
xback = -2; |
324 |
|
for (x = 0; x < ourview.hresolu; x++) |
325 |
< |
if (zscan(y)[x] <= 0.0) { |
326 |
< |
if (xblank < 0) |
327 |
< |
xblank = x; |
328 |
< |
} else if (xblank >= 0) { |
329 |
< |
if (xblank == 0 || zscan(y)[xblank-1] < zscan(y)[x]) |
330 |
< |
copycolr(cfill, pscan(y)[x]); |
325 |
> |
if (zscan(y)[x] <= 0.0) { /* empty pixel */ |
326 |
> |
if (yback[x] == -2) { |
327 |
> |
for (i = y+1; i < ourview.vresolu; i++) |
328 |
> |
if (zscan(i)[x] > 0.0) |
329 |
> |
break; |
330 |
> |
if (i < ourview.vresolu |
331 |
> |
&& (y <= 0 || zscan(y-1)[x] < zscan(i)[x])) |
332 |
> |
yback[x] = i; |
333 |
> |
else |
334 |
> |
yback[x] = y-1; |
335 |
> |
} |
336 |
> |
if (xback == -2) { |
337 |
> |
for (i = x+1; x < ourview.hresolu; i++) |
338 |
> |
if (zscan(y)[i] > 0.0) |
339 |
> |
break; |
340 |
> |
if (i < ourview.hresolu |
341 |
> |
&& (x <= 0 || zscan(y)[x-1] < zscan(y)[i])) |
342 |
> |
xback = i; |
343 |
> |
else |
344 |
> |
xback = x-1; |
345 |
> |
} |
346 |
> |
if (xback < 0 && yback[x] < 0) |
347 |
> |
continue; |
348 |
> |
if (yback[x] < 0 || ABS(x-xback) <= 1 |
349 |
> |
|| ( ABS(y-yback[x]) > 1 |
350 |
> |
&& zscan(yback[x])[x] < zscan(y)[xback] )) |
351 |
> |
copycolr(pscan(y)[x],pscan(y)[xback]); |
352 |
|
else |
353 |
< |
copycolr(cfill, pscan(y)[xblank-1]); |
354 |
< |
for ( ; xblank < x; xblank++) |
355 |
< |
copycolr(pscan(y)[xblank], cfill); |
356 |
< |
xblank = -1; |
353 |
> |
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
354 |
> |
} else { /* full pixel */ |
355 |
> |
yback[x] = -2; |
356 |
> |
xback = -2; |
357 |
|
} |
272 |
– |
if (xblank > 0) { |
273 |
– |
copycolr(cfill, pscan(y)[xblank-1]); |
274 |
– |
for ( ; xblank < ourview.hresolu; xblank++) |
275 |
– |
copycolr(pscan(y)[xblank], cfill); |
276 |
– |
} |
358 |
|
} |
359 |
+ |
free((char *)yback); |
360 |
|
} |
361 |
|
|
362 |
|
|