| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
– |
|
| 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 <fcntl.h> |
| 12 |
> |
#include <ctype.h> |
| 13 |
> |
#include <string.h> |
| 14 |
|
|
| 15 |
+ |
#include "platform.h" |
| 16 |
+ |
#include "standard.h" |
| 17 |
+ |
#include "rtprocess.h" /* Windows: must come before color.h */ |
| 18 |
|
#include "view.h" |
| 16 |
– |
|
| 19 |
|
#include "color.h" |
| 20 |
|
|
| 21 |
< |
#ifndef BSD |
| 20 |
< |
#define vfork fork |
| 21 |
< |
#endif |
| 21 |
> |
#define LOG2 0.69314718055994530942 |
| 22 |
|
|
| 23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
| 24 |
+ |
#define sscan(y) (ourspict+(y)*hresolu) |
| 25 |
+ |
#define wscan(y) (ourweigh+(y)*hresolu) |
| 26 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 27 |
+ |
#define bscan(y) (ourbpict+(y)*hresolu) |
| 28 |
+ |
#define averaging (ourweigh != NULL) |
| 29 |
+ |
#define blurring (ourbpict != NULL) |
| 30 |
+ |
#define usematrix (hasmatrix & !averaging) |
| 31 |
+ |
#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) |
| 32 |
|
|
| 33 |
+ |
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
| 34 |
+ |
|
| 35 |
|
#define F_FORE 1 /* fill foreground */ |
| 36 |
|
#define F_BACK 2 /* fill background */ |
| 37 |
|
|
| 38 |
< |
#define PACKSIZ 42 /* calculation packet size */ |
| 38 |
> |
#define PACKSIZ 256 /* max. calculation packet size */ |
| 39 |
|
|
| 40 |
< |
#define RTCOM "rtrace -h -ovl -fff %s" |
| 40 |
> |
#define RTCOM "rtrace -h- -ovl -fff -ld- -i- -I- " |
| 41 |
|
|
| 42 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
| 43 |
|
|
| 44 |
|
struct position {int x,y; float z;}; |
| 45 |
|
|
| 46 |
+ |
#define NSTEPS 64 /* number steps in overlap prescan */ |
| 47 |
+ |
#define MINSTEP 4 /* minimum worthwhile preview step */ |
| 48 |
+ |
|
| 49 |
+ |
struct bound {int min,max;}; |
| 50 |
+ |
|
| 51 |
|
VIEW ourview = STDVIEW; /* desired view */ |
| 52 |
|
int hresolu = 512; /* horizontal resolution */ |
| 53 |
|
int vresolu = 512; /* vertical resolution */ |
| 55 |
|
|
| 56 |
|
double zeps = .02; /* allowed z epsilon */ |
| 57 |
|
|
| 58 |
< |
COLR *ourpict; /* output picture */ |
| 58 |
> |
COLR *ourpict; /* output picture (COLR's) */ |
| 59 |
> |
COLOR *ourspict; /* output pixel sums (averaging) */ |
| 60 |
> |
float *ourweigh = NULL; /* output pixel weights (averaging) */ |
| 61 |
|
float *ourzbuf; /* corresponding z-buffer */ |
| 62 |
+ |
COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ |
| 63 |
|
|
| 64 |
+ |
VIEW avgview; /* average view for -B option */ |
| 65 |
+ |
int nvavg; /* number of views averaged */ |
| 66 |
+ |
|
| 67 |
|
char *progname; |
| 68 |
|
|
| 69 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
| 70 |
|
int fillsamp = 0; /* sample separation (0 == inf) */ |
| 51 |
– |
extern int backfill(), rcalfill(); /* fill functions */ |
| 52 |
– |
int (*fillfunc)() = backfill; /* selected fill function */ |
| 71 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 72 |
+ |
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
| 73 |
|
double backz = 0.0; /* background z value */ |
| 74 |
< |
int normdist = 1; /* normalized distance? */ |
| 75 |
< |
double ourexp = -1; /* output picture exposure */ |
| 74 |
> |
int normdist = 1; /* i/o normalized distance? */ |
| 75 |
> |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
| 76 |
> |
double ourexp = -1; /* original picture exposure */ |
| 77 |
> |
int expadj = 0; /* exposure adjustment (f-stops) */ |
| 78 |
> |
double rexpadj = 1; /* real exposure adjustment */ |
| 79 |
|
|
| 80 |
< |
VIEW theirview = STDVIEW; /* input view */ |
| 80 |
> |
VIEW theirview; /* input view */ |
| 81 |
|
int gotview; /* got input view? */ |
| 82 |
< |
int thresolu, tvresolu; /* input resolution */ |
| 82 |
> |
int wrongformat = 0; /* input in another format? */ |
| 83 |
> |
RESOLU tresolu; /* input resolution */ |
| 84 |
|
double theirexp; /* input picture exposure */ |
| 85 |
< |
double theirs2ours[4][4]; /* transformation matrix */ |
| 85 |
> |
MAT4 theirs2ours; /* transformation matrix */ |
| 86 |
> |
int hasmatrix = 0; /* has transformation matrix */ |
| 87 |
|
|
| 88 |
< |
int childpid = -1; /* id of fill process */ |
| 89 |
< |
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 90 |
< |
int queue[PACKSIZ][2]; /* pending pixels */ |
| 91 |
< |
int queuesiz; /* number of pixels pending */ |
| 88 |
> |
static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ |
| 89 |
> |
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
| 90 |
> |
int packsiz; /* actual packet size */ |
| 91 |
> |
int queuesiz = 0; /* number of pixels pending */ |
| 92 |
|
|
| 93 |
+ |
typedef void fillfunc_t(int x, int y); |
| 94 |
|
|
| 95 |
< |
main(argc, argv) /* interpolate pictures */ |
| 96 |
< |
int argc; |
| 97 |
< |
char *argv[]; |
| 95 |
> |
static gethfunc headline; |
| 96 |
> |
static int nextview(FILE *fp); |
| 97 |
> |
static void compavgview(void); |
| 98 |
> |
static void addpicture(char *pfile, char *zspec); |
| 99 |
> |
static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2); |
| 100 |
> |
static void addscanline(struct bound *xl, int y, |
| 101 |
> |
COLR *pline, float *zline, struct position *lasty); |
| 102 |
> |
static void addpixel(struct position *p0, struct position *p1, |
| 103 |
> |
struct position *p2, COLR pix, double w, double z); |
| 104 |
> |
static double movepixel(FVECT pos); |
| 105 |
> |
static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd); |
| 106 |
> |
static void backpicture(fillfunc_t *fill, int samp); |
| 107 |
> |
static void fillpicture(fillfunc_t *fill); |
| 108 |
> |
static int clipaft(void); |
| 109 |
> |
static int addblur(void); |
| 110 |
> |
static void writepicture(void); |
| 111 |
> |
static void writedistance(char *fname); |
| 112 |
> |
static fillfunc_t backfill; |
| 113 |
> |
static fillfunc_t rcalfill; |
| 114 |
> |
static void calstart(char *prog, char *args); |
| 115 |
> |
static void caldone(void); |
| 116 |
> |
static void clearqueue(void); |
| 117 |
> |
static void syserror(char *s); |
| 118 |
> |
|
| 119 |
> |
fillfunc_t *fillfunc = backfill; /* selected fill function */ |
| 120 |
> |
|
| 121 |
> |
int |
| 122 |
> |
main( /* interpolate pictures */ |
| 123 |
> |
int argc, |
| 124 |
> |
char *argv[] |
| 125 |
> |
) |
| 126 |
|
{ |
| 127 |
< |
#define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt |
| 128 |
< |
extern double atof(); |
| 127 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
| 128 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
| 129 |
> |
goto badopt |
| 130 |
|
int gotvfile = 0; |
| 131 |
+ |
int doavg = -1; |
| 132 |
+ |
int doblur = 0; |
| 133 |
|
char *zfile = NULL; |
| 134 |
< |
char *err; |
| 135 |
< |
int i, rval; |
| 134 |
> |
char *expcomp = NULL; |
| 135 |
> |
int i, an, rval; |
| 136 |
|
|
| 137 |
+ |
SET_DEFAULT_BINARY(); |
| 138 |
+ |
SET_FILE_BINARY(stdout); |
| 139 |
+ |
|
| 140 |
|
progname = argv[0]; |
| 141 |
|
|
| 142 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 143 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
| 142 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
| 143 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
| 144 |
|
if (rval >= 0) { |
| 145 |
< |
i += rval; |
| 145 |
> |
an += rval; |
| 146 |
|
continue; |
| 147 |
|
} |
| 148 |
< |
switch (argv[i][1]) { |
| 148 |
> |
switch (argv[an][1]) { |
| 149 |
> |
case 'e': /* exposure */ |
| 150 |
> |
check(2,"f"); |
| 151 |
> |
expcomp = argv[++an]; |
| 152 |
> |
break; |
| 153 |
|
case 't': /* threshold */ |
| 154 |
< |
check(2,1); |
| 155 |
< |
zeps = atof(argv[++i]); |
| 154 |
> |
check(2,"f"); |
| 155 |
> |
zeps = atof(argv[++an]); |
| 156 |
|
break; |
| 157 |
+ |
case 'a': /* average */ |
| 158 |
+ |
check(2,NULL); |
| 159 |
+ |
doavg = 1; |
| 160 |
+ |
break; |
| 161 |
+ |
case 'B': /* blur views */ |
| 162 |
+ |
check(2,NULL); |
| 163 |
+ |
doblur = 1; |
| 164 |
+ |
break; |
| 165 |
+ |
case 'q': /* quick (no avg.) */ |
| 166 |
+ |
check(2,NULL); |
| 167 |
+ |
doavg = 0; |
| 168 |
+ |
break; |
| 169 |
|
case 'n': /* dist. normalized? */ |
| 170 |
< |
check(2,0); |
| 170 |
> |
check(2,NULL); |
| 171 |
|
normdist = !normdist; |
| 172 |
|
break; |
| 173 |
|
case 'f': /* fill type */ |
| 174 |
< |
switch (argv[i][2]) { |
| 174 |
> |
switch (argv[an][2]) { |
| 175 |
|
case '0': /* none */ |
| 176 |
< |
check(3,0); |
| 176 |
> |
check(3,NULL); |
| 177 |
|
fillo = 0; |
| 178 |
|
break; |
| 179 |
|
case 'f': /* foreground */ |
| 180 |
< |
check(3,0); |
| 180 |
> |
check(3,NULL); |
| 181 |
|
fillo = F_FORE; |
| 182 |
|
break; |
| 183 |
|
case 'b': /* background */ |
| 184 |
< |
check(3,0); |
| 184 |
> |
check(3,NULL); |
| 185 |
|
fillo = F_BACK; |
| 186 |
|
break; |
| 187 |
|
case 'a': /* all */ |
| 188 |
< |
check(3,0); |
| 188 |
> |
check(3,NULL); |
| 189 |
|
fillo = F_FORE|F_BACK; |
| 190 |
|
break; |
| 191 |
|
case 's': /* sample */ |
| 192 |
< |
check(3,1); |
| 193 |
< |
fillsamp = atoi(argv[++i]); |
| 192 |
> |
check(3,"i"); |
| 193 |
> |
fillsamp = atoi(argv[++an]); |
| 194 |
|
break; |
| 195 |
|
case 'c': /* color */ |
| 196 |
< |
check(3,3); |
| 196 |
> |
check(3,"fff"); |
| 197 |
|
fillfunc = backfill; |
| 198 |
< |
setcolr(backcolr, atof(argv[i+1]), |
| 199 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
| 200 |
< |
i += 3; |
| 198 |
> |
setcolor(backcolor, atof(argv[an+1]), |
| 199 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
| 200 |
> |
setcolr(backcolr, colval(backcolor,RED), |
| 201 |
> |
colval(backcolor,GRN), |
| 202 |
> |
colval(backcolor,BLU)); |
| 203 |
> |
an += 3; |
| 204 |
|
break; |
| 205 |
|
case 'z': /* z value */ |
| 206 |
< |
check(3,1); |
| 206 |
> |
check(3,"f"); |
| 207 |
|
fillfunc = backfill; |
| 208 |
< |
backz = atof(argv[++i]); |
| 208 |
> |
backz = atof(argv[++an]); |
| 209 |
|
break; |
| 210 |
|
case 'r': /* rtrace */ |
| 211 |
< |
check(3,1); |
| 211 |
> |
check(3,"s"); |
| 212 |
|
fillfunc = rcalfill; |
| 213 |
< |
calstart(RTCOM, argv[++i]); |
| 213 |
> |
calstart(RTCOM, argv[++an]); |
| 214 |
|
break; |
| 215 |
|
default: |
| 216 |
|
goto badopt; |
| 217 |
|
} |
| 218 |
|
break; |
| 219 |
|
case 'z': /* z file */ |
| 220 |
< |
check(2,1); |
| 221 |
< |
zfile = argv[++i]; |
| 220 |
> |
check(2,"s"); |
| 221 |
> |
zfile = argv[++an]; |
| 222 |
|
break; |
| 223 |
|
case 'x': /* x resolution */ |
| 224 |
< |
check(2,1); |
| 225 |
< |
hresolu = atoi(argv[++i]); |
| 224 |
> |
check(2,"i"); |
| 225 |
> |
hresolu = atoi(argv[++an]); |
| 226 |
|
break; |
| 227 |
|
case 'y': /* y resolution */ |
| 228 |
< |
check(2,1); |
| 229 |
< |
vresolu = atoi(argv[++i]); |
| 228 |
> |
check(2,"i"); |
| 229 |
> |
vresolu = atoi(argv[++an]); |
| 230 |
|
break; |
| 231 |
|
case 'p': /* pixel aspect */ |
| 232 |
< |
check(2,1); |
| 233 |
< |
pixaspect = atof(argv[++i]); |
| 232 |
> |
if (argv[an][2] != 'a') |
| 233 |
> |
goto badopt; |
| 234 |
> |
check(3,"f"); |
| 235 |
> |
pixaspect = atof(argv[++an]); |
| 236 |
|
break; |
| 237 |
|
case 'v': /* view file */ |
| 238 |
< |
if (argv[i][2] != 'f') |
| 238 |
> |
if (argv[an][2] != 'f') |
| 239 |
|
goto badopt; |
| 240 |
< |
check(3,1); |
| 241 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
| 242 |
< |
if (gotvfile < 0) { |
| 243 |
< |
perror(argv[i]); |
| 244 |
< |
exit(1); |
| 165 |
< |
} else if (gotvfile == 0) { |
| 240 |
> |
check(3,"s"); |
| 241 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
| 242 |
> |
if (gotvfile < 0) |
| 243 |
> |
syserror(argv[an]); |
| 244 |
> |
else if (gotvfile == 0) { |
| 245 |
|
fprintf(stderr, "%s: bad view file\n", |
| 246 |
< |
argv[i]); |
| 246 |
> |
argv[an]); |
| 247 |
|
exit(1); |
| 248 |
|
} |
| 249 |
|
break; |
| 250 |
|
default: |
| 251 |
|
badopt: |
| 252 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
| 253 |
< |
progname, argv[i]); |
| 253 |
> |
progname, argv[an]); |
| 254 |
|
goto userr; |
| 255 |
|
} |
| 256 |
|
} |
| 257 |
|
/* check arguments */ |
| 258 |
< |
if ((argc-i)%2) |
| 258 |
> |
if ((argc-an)%2) |
| 259 |
|
goto userr; |
| 260 |
+ |
if (fillsamp == 1) |
| 261 |
+ |
fillo &= ~F_BACK; |
| 262 |
+ |
if (doavg < 0) |
| 263 |
+ |
doavg = (argc-an) > 2; |
| 264 |
+ |
if (expcomp != NULL) { |
| 265 |
+ |
if ((expcomp[0] == '+') | (expcomp[0] == '-')) { |
| 266 |
+ |
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
| 267 |
+ |
if (doavg | doblur) |
| 268 |
+ |
rexpadj = pow(2.0, atof(expcomp)); |
| 269 |
+ |
else |
| 270 |
+ |
rexpadj = pow(2.0, (double)expadj); |
| 271 |
+ |
} else { |
| 272 |
+ |
if (!isflt(expcomp)) |
| 273 |
+ |
goto userr; |
| 274 |
+ |
rexpadj = atof(expcomp); |
| 275 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
| 276 |
+ |
if (!(doavg | doblur)) |
| 277 |
+ |
rexpadj = pow(2.0, (double)expadj); |
| 278 |
+ |
} |
| 279 |
+ |
} |
| 280 |
|
/* set view */ |
| 281 |
< |
if (err = setview(&ourview)) { |
| 282 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
| 281 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
| 282 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
| 283 |
> |
progname); |
| 284 |
|
exit(1); |
| 285 |
|
} |
| 286 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
| 287 |
|
/* allocate frame */ |
| 288 |
< |
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
| 289 |
< |
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
| 290 |
< |
if (ourpict == NULL || ourzbuf == NULL) |
| 291 |
< |
syserror(); |
| 292 |
< |
/* get input */ |
| 293 |
< |
for ( ; i < argc; i += 2) |
| 294 |
< |
addpicture(argv[i], argv[i+1]); |
| 295 |
< |
/* fill in spaces */ |
| 296 |
< |
if (fillo&F_BACK) |
| 297 |
< |
backpicture(fillfunc, fillsamp); |
| 298 |
< |
else |
| 299 |
< |
fillpicture(fillfunc); |
| 288 |
> |
if (doavg) { |
| 289 |
> |
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
| 290 |
> |
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 291 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
| 292 |
> |
syserror(progname); |
| 293 |
> |
} else { |
| 294 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
| 295 |
> |
if (ourpict == NULL) |
| 296 |
> |
syserror(progname); |
| 297 |
> |
} |
| 298 |
> |
if (doblur) { |
| 299 |
> |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
| 300 |
> |
if (ourbpict == NULL) |
| 301 |
> |
syserror(progname); |
| 302 |
> |
} |
| 303 |
> |
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 304 |
> |
if (ourzbuf == NULL) |
| 305 |
> |
syserror(progname); |
| 306 |
> |
/* new header */ |
| 307 |
> |
newheader("RADIANCE", stdout); |
| 308 |
> |
fputnow(stdout); |
| 309 |
> |
/* run pictures */ |
| 310 |
> |
do { |
| 311 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
| 312 |
> |
for (i = an; i < argc; i += 2) |
| 313 |
> |
addpicture(argv[i], argv[i+1]); |
| 314 |
> |
if (fillo&F_BACK) /* fill in spaces */ |
| 315 |
> |
backpicture(fillfunc, fillsamp); |
| 316 |
> |
else |
| 317 |
> |
fillpicture(fillfunc); |
| 318 |
> |
/* aft clipping */ |
| 319 |
> |
clipaft(); |
| 320 |
> |
} while (addblur() && nextview(stdin) != EOF); |
| 321 |
|
/* close calculation */ |
| 322 |
|
caldone(); |
| 323 |
|
/* add to header */ |
| 324 |
|
printargs(argc, argv, stdout); |
| 325 |
< |
if (gotvfile) { |
| 325 |
> |
compavgview(); |
| 326 |
> |
if (doblur | gotvfile) { |
| 327 |
|
fputs(VIEWSTR, stdout); |
| 328 |
< |
fprintview(&ourview, stdout); |
| 328 |
> |
fprintview(&avgview, stdout); |
| 329 |
|
putc('\n', stdout); |
| 330 |
|
} |
| 331 |
< |
if (pixaspect < .99 || pixaspect > 1.01) |
| 331 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
| 332 |
|
fputaspect(pixaspect, stdout); |
| 333 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 333 |
> |
if (ourexp > 0) |
| 334 |
> |
ourexp *= rexpadj; |
| 335 |
> |
else |
| 336 |
> |
ourexp = rexpadj; |
| 337 |
> |
if ((ourexp < .995) | (ourexp > 1.005)) |
| 338 |
|
fputexpos(ourexp, stdout); |
| 339 |
+ |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
| 340 |
+ |
fputformat(ourfmt, stdout); |
| 341 |
|
putc('\n', stdout); |
| 342 |
|
/* write picture */ |
| 343 |
|
writepicture(); |
| 348 |
|
exit(0); |
| 349 |
|
userr: |
| 350 |
|
fprintf(stderr, |
| 351 |
< |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
| 351 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
| 352 |
|
progname); |
| 353 |
|
exit(1); |
| 354 |
|
#undef check |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
< |
headline(s) /* process header string */ |
| 359 |
< |
char *s; |
| 358 |
> |
static int |
| 359 |
> |
headline( /* process header string */ |
| 360 |
> |
char *s, |
| 361 |
> |
void *p |
| 362 |
> |
) |
| 363 |
|
{ |
| 364 |
< |
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
| 234 |
< |
register char **an; |
| 364 |
> |
char fmt[32]; |
| 365 |
|
|
| 366 |
< |
putc('\t', stdout); |
| 367 |
< |
fputs(s, stdout); |
| 368 |
< |
|
| 366 |
> |
if (isheadid(s)) |
| 367 |
> |
return(0); |
| 368 |
> |
if (formatval(fmt, s)) { |
| 369 |
> |
if (globmatch(ourfmt, fmt)) { |
| 370 |
> |
wrongformat = 0; |
| 371 |
> |
strcpy(ourfmt, fmt); |
| 372 |
> |
} else |
| 373 |
> |
wrongformat = 1; |
| 374 |
> |
return(0); |
| 375 |
> |
} |
| 376 |
> |
if (nvavg < 2) { |
| 377 |
> |
putc('\t', stdout); |
| 378 |
> |
fputs(s, stdout); |
| 379 |
> |
} |
| 380 |
|
if (isexpos(s)) { |
| 381 |
|
theirexp *= exposval(s); |
| 382 |
+ |
return(0); |
| 383 |
+ |
} |
| 384 |
+ |
if (isview(s) && sscanview(&theirview, s) > 0) |
| 385 |
+ |
gotview++; |
| 386 |
+ |
return(0); |
| 387 |
+ |
} |
| 388 |
+ |
|
| 389 |
+ |
|
| 390 |
+ |
static int |
| 391 |
+ |
nextview( /* get and set next view */ |
| 392 |
+ |
FILE *fp |
| 393 |
+ |
) |
| 394 |
+ |
{ |
| 395 |
+ |
char linebuf[256]; |
| 396 |
+ |
char *err; |
| 397 |
+ |
int i; |
| 398 |
+ |
|
| 399 |
+ |
if (fp != NULL) { |
| 400 |
+ |
do /* get new view */ |
| 401 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
| 402 |
+ |
return(EOF); |
| 403 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
| 404 |
+ |
} |
| 405 |
+ |
/* set new view */ |
| 406 |
+ |
if ((err = setview(&ourview)) != NULL) { |
| 407 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
| 408 |
+ |
exit(1); |
| 409 |
+ |
} |
| 410 |
+ |
if (!nvavg) { /* first view */ |
| 411 |
+ |
avgview = ourview; |
| 412 |
+ |
return(nvavg++); |
| 413 |
+ |
} |
| 414 |
+ |
/* add to average view */ |
| 415 |
+ |
for (i = 0; i < 3; i++) { |
| 416 |
+ |
avgview.vp[i] += ourview.vp[i]; |
| 417 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
| 418 |
+ |
avgview.vup[i] += ourview.vup[i]; |
| 419 |
+ |
} |
| 420 |
+ |
avgview.vdist += ourview.vdist; |
| 421 |
+ |
avgview.horiz += ourview.horiz; |
| 422 |
+ |
avgview.vert += ourview.vert; |
| 423 |
+ |
avgview.hoff += ourview.hoff; |
| 424 |
+ |
avgview.voff += ourview.voff; |
| 425 |
+ |
avgview.vfore += ourview.vfore; |
| 426 |
+ |
avgview.vaft += ourview.vaft; |
| 427 |
+ |
return(nvavg++); |
| 428 |
+ |
} |
| 429 |
+ |
|
| 430 |
+ |
|
| 431 |
+ |
static void |
| 432 |
+ |
compavgview(void) /* compute average view */ |
| 433 |
+ |
{ |
| 434 |
+ |
int i; |
| 435 |
+ |
double f; |
| 436 |
+ |
|
| 437 |
+ |
if (nvavg < 2) |
| 438 |
|
return; |
| 439 |
+ |
f = 1.0/nvavg; |
| 440 |
+ |
for (i = 0; i < 3; i++) { |
| 441 |
+ |
avgview.vp[i] *= f; |
| 442 |
+ |
avgview.vdir[i] *= f; |
| 443 |
+ |
avgview.vup[i] *= f; |
| 444 |
|
} |
| 445 |
< |
for (an = altname; *an != NULL; an++) |
| 446 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
| 447 |
< |
if (sscanview(&theirview, s+strlen(*an)) > 0) |
| 448 |
< |
gotview++; |
| 449 |
< |
break; |
| 450 |
< |
} |
| 445 |
> |
avgview.vdist *= f; |
| 446 |
> |
avgview.horiz *= f; |
| 447 |
> |
avgview.vert *= f; |
| 448 |
> |
avgview.hoff *= f; |
| 449 |
> |
avgview.voff *= f; |
| 450 |
> |
avgview.vfore *= f; |
| 451 |
> |
avgview.vaft *= f; |
| 452 |
> |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
| 453 |
> |
avgview = ourview; |
| 454 |
> |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
| 455 |
|
} |
| 456 |
|
|
| 457 |
|
|
| 458 |
< |
addpicture(pfile, zspec) /* add picture to output */ |
| 459 |
< |
char *pfile, *zspec; |
| 458 |
> |
static void |
| 459 |
> |
addpicture( /* add picture to output */ |
| 460 |
> |
char *pfile, |
| 461 |
> |
char *zspec |
| 462 |
> |
) |
| 463 |
|
{ |
| 255 |
– |
extern double atof(); |
| 464 |
|
FILE *pfp; |
| 465 |
|
int zfd; |
| 466 |
|
char *err; |
| 467 |
|
COLR *scanin; |
| 468 |
|
float *zin; |
| 469 |
|
struct position *plast; |
| 470 |
+ |
struct bound *xlim, ylim; |
| 471 |
|
int y; |
| 472 |
|
/* open picture file */ |
| 473 |
< |
if ((pfp = fopen(pfile, "r")) == NULL) { |
| 474 |
< |
perror(pfile); |
| 266 |
< |
exit(1); |
| 267 |
< |
} |
| 473 |
> |
if ((pfp = fopen(pfile, "r")) == NULL) |
| 474 |
> |
syserror(pfile); |
| 475 |
|
/* get header with exposure and view */ |
| 476 |
|
theirexp = 1.0; |
| 477 |
+ |
theirview = stdview; |
| 478 |
|
gotview = 0; |
| 479 |
< |
printf("%s:\n", pfile); |
| 480 |
< |
getheader(pfp, headline); |
| 481 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
| 482 |
< |
!= (YMAJOR|YDECR)) { |
| 483 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
| 479 |
> |
if (nvavg < 2) |
| 480 |
> |
printf("%s:\n", pfile); |
| 481 |
> |
getheader(pfp, headline, NULL); |
| 482 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
| 483 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
| 484 |
|
exit(1); |
| 485 |
|
} |
| 486 |
|
if (ourexp <= 0) |
| 487 |
|
ourexp = theirexp; |
| 488 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
| 489 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
| 490 |
< |
if (err = setview(&theirview)) { |
| 490 |
> |
if ( (err = setview(&theirview)) ) { |
| 491 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
| 492 |
|
exit(1); |
| 493 |
|
} |
| 494 |
|
/* compute transformation */ |
| 495 |
< |
pixform(theirs2ours, &theirview, &ourview); |
| 288 |
< |
/* allocate scanlines */ |
| 289 |
< |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
| 290 |
< |
zin = (float *)malloc(thresolu*sizeof(float)); |
| 291 |
< |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
| 292 |
< |
if (scanin == NULL || zin == NULL || plast == NULL) |
| 293 |
< |
syserror(); |
| 495 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
| 496 |
|
/* get z specification or file */ |
| 497 |
+ |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
| 498 |
+ |
if (zin == NULL) |
| 499 |
+ |
syserror(progname); |
| 500 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 501 |
|
double zvalue; |
| 502 |
< |
register int x; |
| 503 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 504 |
< |
perror(zspec); |
| 505 |
< |
exit(1); |
| 301 |
< |
} |
| 302 |
< |
for (x = 0; x < thresolu; x++) |
| 502 |
> |
int x; |
| 503 |
> |
if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) |
| 504 |
> |
syserror(zspec); |
| 505 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
| 506 |
|
zin[x] = zvalue; |
| 507 |
|
} |
| 508 |
< |
/* load image */ |
| 509 |
< |
for (y = tvresolu-1; y >= 0; y--) { |
| 510 |
< |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
| 508 |
> |
/* compute transferrable perimeter */ |
| 509 |
> |
xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); |
| 510 |
> |
if (xlim == NULL) |
| 511 |
> |
syserror(progname); |
| 512 |
> |
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
| 513 |
> |
free((void *)zin); |
| 514 |
> |
free((void *)xlim); |
| 515 |
> |
if (zfd != -1) |
| 516 |
> |
close(zfd); |
| 517 |
> |
fclose(pfp); |
| 518 |
> |
return; |
| 519 |
> |
} |
| 520 |
> |
/* allocate scanlines */ |
| 521 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
| 522 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
| 523 |
> |
sizeof(struct position)); |
| 524 |
> |
if ((scanin == NULL) | (plast == NULL)) |
| 525 |
> |
syserror(progname); |
| 526 |
> |
/* skip to starting point */ |
| 527 |
> |
for (y = 0; y < ylim.min; y++) |
| 528 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 529 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 530 |
|
exit(1); |
| 531 |
|
} |
| 532 |
< |
if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float)) |
| 533 |
< |
< thresolu*sizeof(float)) { |
| 534 |
< |
fprintf(stderr, "%s: read error\n", zspec); |
| 532 |
> |
if (zfd != -1 && lseek(zfd, |
| 533 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), |
| 534 |
> |
SEEK_SET) < 0) |
| 535 |
> |
syserror(zspec); |
| 536 |
> |
/* load image */ |
| 537 |
> |
for (y = ylim.min; y <= ylim.max; y++) { |
| 538 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 539 |
> |
fprintf(stderr, "%s: read error\n", pfile); |
| 540 |
|
exit(1); |
| 541 |
|
} |
| 542 |
< |
addscanline(y, scanin, zin, plast); |
| 542 |
> |
if (zfd != -1 && read(zfd, (char *)zin, |
| 543 |
> |
scanlen(&tresolu)*sizeof(float)) |
| 544 |
> |
< scanlen(&tresolu)*sizeof(float)) |
| 545 |
> |
syserror(zspec); |
| 546 |
> |
addscanline(xlim+y, y, scanin, zin, plast); |
| 547 |
|
} |
| 548 |
|
/* clean up */ |
| 549 |
< |
free((char *)scanin); |
| 550 |
< |
free((char *)zin); |
| 551 |
< |
free((char *)plast); |
| 549 |
> |
free((void *)xlim); |
| 550 |
> |
free((void *)scanin); |
| 551 |
> |
free((void *)zin); |
| 552 |
> |
free((void *)plast); |
| 553 |
|
fclose(pfp); |
| 554 |
|
if (zfd != -1) |
| 555 |
|
close(zfd); |
| 556 |
|
} |
| 557 |
|
|
| 558 |
|
|
| 559 |
< |
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
| 560 |
< |
register double xfmat[4][4]; |
| 561 |
< |
register VIEW *vw1, *vw2; |
| 559 |
> |
static int |
| 560 |
> |
pixform( /* compute view1 to view2 matrix */ |
| 561 |
> |
MAT4 xfmat, |
| 562 |
> |
VIEW *vw1, |
| 563 |
> |
VIEW *vw2 |
| 564 |
> |
) |
| 565 |
|
{ |
| 566 |
< |
double m4t[4][4]; |
| 566 |
> |
MAT4 m4t; |
| 567 |
|
|
| 568 |
+ |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
| 569 |
+ |
return(0); |
| 570 |
+ |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
| 571 |
+ |
return(0); |
| 572 |
|
setident4(xfmat); |
| 573 |
|
xfmat[0][0] = vw1->hvec[0]; |
| 574 |
|
xfmat[0][1] = vw1->hvec[1]; |
| 596 |
|
m4t[2][2] = vw2->vdir[2]; |
| 597 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
| 598 |
|
multmat4(xfmat, xfmat, m4t); |
| 599 |
+ |
return(1); |
| 600 |
|
} |
| 601 |
|
|
| 602 |
|
|
| 603 |
< |
addscanline(y, pline, zline, lasty) /* add scanline to output */ |
| 604 |
< |
int y; |
| 605 |
< |
COLR *pline; |
| 606 |
< |
float *zline; |
| 607 |
< |
struct position *lasty; /* input/output */ |
| 603 |
> |
static void |
| 604 |
> |
addscanline( /* add scanline to output */ |
| 605 |
> |
struct bound *xl, |
| 606 |
> |
int y, |
| 607 |
> |
COLR *pline, |
| 608 |
> |
float *zline, |
| 609 |
> |
struct position *lasty /* input/output */ |
| 610 |
> |
) |
| 611 |
|
{ |
| 612 |
< |
extern double sqrt(); |
| 371 |
< |
double pos[3]; |
| 612 |
> |
FVECT pos; |
| 613 |
|
struct position lastx, newpos; |
| 614 |
< |
register int x; |
| 614 |
> |
double wt; |
| 615 |
> |
int x; |
| 616 |
|
|
| 617 |
|
lastx.z = 0; |
| 618 |
< |
for (x = thresolu-1; x >= 0; x--) { |
| 619 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
| 378 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
| 618 |
> |
for (x = xl->max; x >= xl->min; x--) { |
| 619 |
> |
pix2loc(pos, &tresolu, x, y); |
| 620 |
|
pos[2] = zline[x]; |
| 621 |
< |
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) { |
| 621 |
> |
if ((wt = movepixel(pos)) <= FTINY) { |
| 622 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 623 |
|
continue; |
| 624 |
|
} |
| 625 |
< |
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; |
| 625 |
> |
/* add pixel to our image */ |
| 626 |
|
newpos.x = pos[0] * hresolu; |
| 627 |
|
newpos.y = pos[1] * vresolu; |
| 628 |
|
newpos.z = zline[x]; |
| 629 |
< |
/* add pixel to our image */ |
| 630 |
< |
if (pos[0] >= 0 && newpos.x < hresolu |
| 631 |
< |
&& pos[1] >= 0 && newpos.y < vresolu) { |
| 632 |
< |
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
| 406 |
< |
lasty[x].x = lastx.x = newpos.x; |
| 407 |
< |
lasty[x].y = lastx.y = newpos.y; |
| 408 |
< |
lasty[x].z = lastx.z = newpos.z; |
| 409 |
< |
} else |
| 410 |
< |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 629 |
> |
addpixel(&newpos, &lastx, &lasty[x], pline[x], wt, pos[2]); |
| 630 |
> |
lasty[x].x = lastx.x = newpos.x; |
| 631 |
> |
lasty[x].y = lastx.y = newpos.y; |
| 632 |
> |
lasty[x].z = lastx.z = newpos.z; |
| 633 |
|
} |
| 634 |
|
} |
| 635 |
|
|
| 636 |
|
|
| 637 |
< |
addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */ |
| 638 |
< |
struct position *p0, *p1, *p2; |
| 639 |
< |
COLR pix; |
| 640 |
< |
double z; |
| 637 |
> |
static void |
| 638 |
> |
addpixel( /* fill in pixel parallelogram */ |
| 639 |
> |
struct position *p0, |
| 640 |
> |
struct position *p1, |
| 641 |
> |
struct position *p2, |
| 642 |
> |
COLR pix, |
| 643 |
> |
double w, |
| 644 |
> |
double z |
| 645 |
> |
) |
| 646 |
|
{ |
| 647 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
| 648 |
+ |
COLOR pval; /* converted+weighted pixel */ |
| 649 |
|
int s1x, s1y, s2x, s2y; /* step sizes */ |
| 650 |
|
int l1, l2, c1, c2; /* side lengths and counters */ |
| 651 |
|
int p1isy; /* p0p1 along y? */ |
| 652 |
|
int x1, y1; /* p1 position */ |
| 653 |
< |
register int x, y; /* final position */ |
| 653 |
> |
int x, y; /* final position */ |
| 654 |
|
|
| 655 |
|
/* compute vector p0p1 */ |
| 656 |
|
if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 657 |
|
s1x = p1->x - p0->x; |
| 658 |
|
s1y = p1->y - p0->y; |
| 659 |
|
l1 = ABS(s1x); |
| 660 |
< |
if (p1isy = (ABS(s1y) > l1)) |
| 660 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
| 661 |
|
l1 = ABS(s1y); |
| 662 |
+ |
else if (l1 < 1) |
| 663 |
+ |
l1 = 1; |
| 664 |
|
} else { |
| 665 |
|
l1 = s1x = s1y = 1; |
| 666 |
|
p1isy = -1; |
| 676 |
|
if (p1isy != 0 && ABS(s2x) > l2) |
| 677 |
|
l2 = ABS(s2x); |
| 678 |
|
} |
| 679 |
+ |
if (l2 < 1) |
| 680 |
+ |
l2 = 1; |
| 681 |
|
} else |
| 682 |
|
l2 = s2x = s2y = 1; |
| 683 |
|
/* fill the parallelogram */ |
| 684 |
+ |
if (averaging) { |
| 685 |
+ |
colr_color(pval, pix); |
| 686 |
+ |
scalecolor(pval, w); |
| 687 |
+ |
} |
| 688 |
|
for (c1 = l1; c1-- > 0; ) { |
| 689 |
|
x1 = p0->x + c1*s1x/l1; |
| 690 |
|
y1 = p0->y + c1*s1y/l1; |
| 691 |
|
for (c2 = l2; c2-- > 0; ) { |
| 692 |
|
x = x1 + c2*s2x/l2; |
| 693 |
< |
if (x < 0 || x >= hresolu) |
| 693 |
> |
if ((x < 0) | (x >= hresolu)) |
| 694 |
|
continue; |
| 695 |
|
y = y1 + c2*s2y/l2; |
| 696 |
< |
if (y < 0 || y >= vresolu) |
| 696 |
> |
if ((y < 0) | (y >= vresolu)) |
| 697 |
|
continue; |
| 698 |
< |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 698 |
> |
if (averaging) { |
| 699 |
> |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 700 |
|
> zeps*zscan(y)[x]) { |
| 701 |
< |
zscan(y)[x] = z; |
| 701 |
> |
copycolor(sscan(y)[x], pval); |
| 702 |
> |
wscan(y)[x] = w; |
| 703 |
> |
zscan(y)[x] = z; |
| 704 |
> |
} else if (z-zscan(y)[x] <= zeps*zscan(y)[x]) { |
| 705 |
> |
addcolor(sscan(y)[x], pval); |
| 706 |
> |
wscan(y)[x] += w; |
| 707 |
> |
} |
| 708 |
> |
} else if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 709 |
> |
> zeps*zscan(y)[x]) { |
| 710 |
|
copycolr(pscan(y)[x], pix); |
| 711 |
+ |
zscan(y)[x] = z; |
| 712 |
|
} |
| 713 |
|
} |
| 714 |
|
} |
| 715 |
|
} |
| 716 |
|
|
| 717 |
|
|
| 718 |
< |
backpicture(fill, samp) /* background fill algorithm */ |
| 719 |
< |
int (*fill)(); |
| 720 |
< |
int samp; |
| 718 |
> |
static double |
| 719 |
> |
movepixel( /* reposition image point */ |
| 720 |
> |
FVECT pos |
| 721 |
> |
) |
| 722 |
|
{ |
| 723 |
+ |
FVECT pt, tdir, odir; |
| 724 |
+ |
double d; |
| 725 |
+ |
|
| 726 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
| 727 |
+ |
return(0); |
| 728 |
+ |
if (usematrix) { |
| 729 |
+ |
pos[0] += theirview.hoff - .5; |
| 730 |
+ |
pos[1] += theirview.voff - .5; |
| 731 |
+ |
if (normdist & (theirview.type == VT_PER)) |
| 732 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
| 733 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
| 734 |
+ |
else |
| 735 |
+ |
d = 1.; |
| 736 |
+ |
pos[2] += d*theirview.vfore; |
| 737 |
+ |
if (theirview.type == VT_PER) { |
| 738 |
+ |
pos[2] /= d; |
| 739 |
+ |
pos[0] *= pos[2]; |
| 740 |
+ |
pos[1] *= pos[2]; |
| 741 |
+ |
} |
| 742 |
+ |
multp3(pos, pos, theirs2ours); |
| 743 |
+ |
if (pos[2] <= ourview.vfore) |
| 744 |
+ |
return(0); |
| 745 |
+ |
if (ourview.type == VT_PER) { |
| 746 |
+ |
pos[0] /= pos[2]; |
| 747 |
+ |
pos[1] /= pos[2]; |
| 748 |
+ |
} |
| 749 |
+ |
pos[0] += .5 - ourview.hoff; |
| 750 |
+ |
pos[1] += .5 - ourview.voff; |
| 751 |
+ |
pos[2] -= ourview.vfore; |
| 752 |
+ |
} else { |
| 753 |
+ |
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
| 754 |
+ |
return(0); |
| 755 |
+ |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
| 756 |
+ |
pos[2] /= DOT(theirview.vdir, tdir); |
| 757 |
+ |
pt[0] += tdir[0]*pos[2]; |
| 758 |
+ |
pt[1] += tdir[1]*pos[2]; |
| 759 |
+ |
pt[2] += tdir[2]*pos[2]; |
| 760 |
+ |
if (viewloc(pos, &ourview, pt) <= 0) |
| 761 |
+ |
return(0); |
| 762 |
+ |
} |
| 763 |
+ |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
| 764 |
+ |
return(0); |
| 765 |
+ |
if (!averaging) |
| 766 |
+ |
return(1); |
| 767 |
+ |
/* compute pixel weight */ |
| 768 |
+ |
if (ourview.type == VT_PAR) { |
| 769 |
+ |
d = DOT(ourview.vdir,tdir); |
| 770 |
+ |
d = 1. - d*d; |
| 771 |
+ |
} else { |
| 772 |
+ |
VSUB(odir, pt, ourview.vp); |
| 773 |
+ |
d = DOT(odir,tdir); |
| 774 |
+ |
d = 1. - d*d/DOT(odir,odir); |
| 775 |
+ |
} |
| 776 |
+ |
if (d <= 1./MAXWT/MAXWT) |
| 777 |
+ |
return(MAXWT); /* clip to maximum weight */ |
| 778 |
+ |
return(1./sqrt(d)); |
| 779 |
+ |
} |
| 780 |
+ |
|
| 781 |
+ |
|
| 782 |
+ |
static int |
| 783 |
+ |
getperim( /* compute overlapping image area */ |
| 784 |
+ |
struct bound *xl, |
| 785 |
+ |
struct bound *yl, |
| 786 |
+ |
float *zline, |
| 787 |
+ |
int zfd |
| 788 |
+ |
) |
| 789 |
+ |
{ |
| 790 |
+ |
int step; |
| 791 |
+ |
FVECT pos; |
| 792 |
+ |
int x, y; |
| 793 |
+ |
/* set up step size */ |
| 794 |
+ |
if (scanlen(&tresolu) < numscans(&tresolu)) |
| 795 |
+ |
step = scanlen(&tresolu)/NSTEPS; |
| 796 |
+ |
else |
| 797 |
+ |
step = numscans(&tresolu)/NSTEPS; |
| 798 |
+ |
if (step < MINSTEP) { /* not worth cropping? */ |
| 799 |
+ |
yl->min = 0; |
| 800 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 801 |
+ |
x = scanlen(&tresolu) - 1; |
| 802 |
+ |
for (y = numscans(&tresolu); y--; ) { |
| 803 |
+ |
xl[y].min = 0; |
| 804 |
+ |
xl[y].max = x; |
| 805 |
+ |
} |
| 806 |
+ |
return(1); |
| 807 |
+ |
} |
| 808 |
+ |
yl->min = 32000; yl->max = 0; /* search for points on image */ |
| 809 |
+ |
for (y = step - 1; y < numscans(&tresolu); y += step) { |
| 810 |
+ |
if (zfd != -1) { |
| 811 |
+ |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
| 812 |
+ |
SEEK_SET) < 0) |
| 813 |
+ |
syserror("lseek"); |
| 814 |
+ |
if (read(zfd, (char *)zline, |
| 815 |
+ |
scanlen(&tresolu)*sizeof(float)) |
| 816 |
+ |
< scanlen(&tresolu)*sizeof(float)) |
| 817 |
+ |
syserror("read"); |
| 818 |
+ |
} |
| 819 |
+ |
xl[y].min = 32000; xl[y].max = 0; /* x max */ |
| 820 |
+ |
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
| 821 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 822 |
+ |
pos[2] = zline[x]; |
| 823 |
+ |
if (movepixel(pos) > FTINY) { |
| 824 |
+ |
xl[y].max = x + step - 1; |
| 825 |
+ |
xl[y].min = x - step + 1; /* x min */ |
| 826 |
+ |
if (xl[y].min < 0) |
| 827 |
+ |
xl[y].min = 0; |
| 828 |
+ |
for (x = step - 1; x < xl[y].max; x += step) { |
| 829 |
+ |
pix2loc(pos, &tresolu, x, y); |
| 830 |
+ |
pos[2] = zline[x]; |
| 831 |
+ |
if (movepixel(pos) > FTINY) { |
| 832 |
+ |
xl[y].min = x - step + 1; |
| 833 |
+ |
break; |
| 834 |
+ |
} |
| 835 |
+ |
} |
| 836 |
+ |
if (y < yl->min) /* y limits */ |
| 837 |
+ |
yl->min = y - step + 1; |
| 838 |
+ |
yl->max = y + step - 1; |
| 839 |
+ |
break; |
| 840 |
+ |
} |
| 841 |
+ |
} |
| 842 |
+ |
/* fill in between */ |
| 843 |
+ |
if (y < step) { |
| 844 |
+ |
xl[y-1].min = xl[y].min; |
| 845 |
+ |
xl[y-1].max = xl[y].max; |
| 846 |
+ |
} else { |
| 847 |
+ |
if (xl[y].min < xl[y-step].min) |
| 848 |
+ |
xl[y-1].min = xl[y].min; |
| 849 |
+ |
else |
| 850 |
+ |
xl[y-1].min = xl[y-step].min; |
| 851 |
+ |
if (xl[y].max > xl[y-step].max) |
| 852 |
+ |
xl[y-1].max = xl[y].max; |
| 853 |
+ |
else |
| 854 |
+ |
xl[y-1].max = xl[y-step].max; |
| 855 |
+ |
} |
| 856 |
+ |
for (x = 2; x < step; x++) |
| 857 |
+ |
*(xl+y-x) = *(xl+y-1); |
| 858 |
+ |
} |
| 859 |
+ |
if (yl->max >= numscans(&tresolu)) |
| 860 |
+ |
yl->max = numscans(&tresolu) - 1; |
| 861 |
+ |
y -= step; |
| 862 |
+ |
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
| 863 |
+ |
*(xl+x) = *(xl+y); |
| 864 |
+ |
return(yl->max >= yl->min); |
| 865 |
+ |
} |
| 866 |
+ |
|
| 867 |
+ |
|
| 868 |
+ |
static void |
| 869 |
+ |
backpicture( /* background fill algorithm */ |
| 870 |
+ |
fillfunc_t *fill, |
| 871 |
+ |
int samp |
| 872 |
+ |
) |
| 873 |
+ |
{ |
| 874 |
|
int *yback, xback; |
| 875 |
|
int y; |
| 876 |
< |
COLR pfill; |
| 479 |
< |
register int x, i; |
| 876 |
> |
int x, i; |
| 877 |
|
/* get back buffer */ |
| 878 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
| 879 |
|
if (yback == NULL) |
| 880 |
< |
syserror(); |
| 880 |
> |
syserror(progname); |
| 881 |
|
for (x = 0; x < hresolu; x++) |
| 882 |
|
yback[x] = -2; |
| 883 |
|
/* |
| 937 |
|
< zscan(y)[xback] ) ) { |
| 938 |
|
if (samp > 0 && ABS(x-xback) >= samp) |
| 939 |
|
goto fillit; |
| 940 |
< |
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 940 |
> |
if (averaging) { |
| 941 |
> |
copycolor(sscan(y)[x], |
| 942 |
> |
sscan(y)[xback]); |
| 943 |
> |
wscan(y)[x] = wscan(y)[xback]; |
| 944 |
> |
} else |
| 945 |
> |
copycolr(pscan(y)[x], |
| 946 |
> |
pscan(y)[xback]); |
| 947 |
|
zscan(y)[x] = zscan(y)[xback]; |
| 948 |
|
} else { |
| 949 |
|
if (samp > 0 && ABS(y-yback[x]) > samp) |
| 950 |
|
goto fillit; |
| 951 |
< |
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 951 |
> |
if (averaging) { |
| 952 |
> |
copycolor(sscan(y)[x], |
| 953 |
> |
sscan(yback[x])[x]); |
| 954 |
> |
wscan(y)[x] = |
| 955 |
> |
wscan(yback[x])[x]; |
| 956 |
> |
} else |
| 957 |
> |
copycolr(pscan(y)[x], |
| 958 |
> |
pscan(yback[x])[x]); |
| 959 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
| 960 |
|
} |
| 961 |
|
continue; |
| 971 |
|
xback = -2; |
| 972 |
|
} |
| 973 |
|
} |
| 974 |
< |
free((char *)yback); |
| 974 |
> |
free((void *)yback); |
| 975 |
|
} |
| 976 |
|
|
| 977 |
|
|
| 978 |
< |
fillpicture(fill) /* paint in empty pixels using fill */ |
| 979 |
< |
int (*fill)(); |
| 978 |
> |
static void |
| 979 |
> |
fillpicture( /* paint in empty pixels using fill */ |
| 980 |
> |
fillfunc_t *fill |
| 981 |
> |
) |
| 982 |
|
{ |
| 983 |
< |
register int x, y; |
| 983 |
> |
int x, y; |
| 984 |
|
|
| 985 |
|
for (y = 0; y < vresolu; y++) |
| 986 |
|
for (x = 0; x < hresolu; x++) |
| 987 |
|
if (zscan(y)[x] <= 0) |
| 988 |
|
(*fill)(x,y); |
| 989 |
+ |
if (fill == rcalfill) |
| 990 |
+ |
clearqueue(); |
| 991 |
|
} |
| 992 |
|
|
| 993 |
|
|
| 994 |
< |
writepicture() /* write out picture */ |
| 994 |
> |
static int |
| 995 |
> |
clipaft(void) /* perform aft clipping as indicated */ |
| 996 |
|
{ |
| 997 |
+ |
int x, y; |
| 998 |
+ |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
| 999 |
+ |
double tstdist; |
| 1000 |
+ |
double yzn2, vx; |
| 1001 |
+ |
|
| 1002 |
+ |
if (ourview.vaft <= FTINY) |
| 1003 |
+ |
return(0); |
| 1004 |
+ |
tstdist = ourview.vaft - ourview.vfore; |
| 1005 |
+ |
for (y = 0; y < vresolu; y++) { |
| 1006 |
+ |
if (adjtest) { /* adjust test */ |
| 1007 |
+ |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 1008 |
+ |
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 1009 |
+ |
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
| 1010 |
+ |
} |
| 1011 |
+ |
for (x = 0; x < hresolu; x++) |
| 1012 |
+ |
if (zscan(y)[x] > tstdist) { |
| 1013 |
+ |
if (adjtest) { |
| 1014 |
+ |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 1015 |
+ |
if (zscan(y)[x] <= (ourview.vaft - |
| 1016 |
+ |
ourview.vfore) * |
| 1017 |
+ |
sqrt(vx*vx*ourview.hn2 + yzn2)) |
| 1018 |
+ |
continue; |
| 1019 |
+ |
} |
| 1020 |
+ |
if (averaging) |
| 1021 |
+ |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
| 1022 |
+ |
else |
| 1023 |
+ |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
| 1024 |
+ |
zscan(y)[x] = 0.0; |
| 1025 |
+ |
} |
| 1026 |
+ |
} |
| 1027 |
+ |
return(1); |
| 1028 |
+ |
} |
| 1029 |
+ |
|
| 1030 |
+ |
|
| 1031 |
+ |
static int |
| 1032 |
+ |
addblur(void) /* add to blurred picture */ |
| 1033 |
+ |
{ |
| 1034 |
+ |
COLOR cval; |
| 1035 |
+ |
double d; |
| 1036 |
+ |
int i; |
| 1037 |
+ |
|
| 1038 |
+ |
if (!blurring) |
| 1039 |
+ |
return(0); |
| 1040 |
+ |
i = hresolu*vresolu; |
| 1041 |
+ |
if (nvavg < 2) |
| 1042 |
+ |
if (averaging) |
| 1043 |
+ |
while (i--) { |
| 1044 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
| 1045 |
+ |
d = 1.0/ourweigh[i]; |
| 1046 |
+ |
scalecolor(ourbpict[i], d); |
| 1047 |
+ |
} |
| 1048 |
+ |
else |
| 1049 |
+ |
while (i--) |
| 1050 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
| 1051 |
+ |
else |
| 1052 |
+ |
if (averaging) |
| 1053 |
+ |
while (i--) { |
| 1054 |
+ |
copycolor(cval, ourspict[i]); |
| 1055 |
+ |
d = 1.0/ourweigh[i]; |
| 1056 |
+ |
scalecolor(cval, d); |
| 1057 |
+ |
addcolor(ourbpict[i], cval); |
| 1058 |
+ |
} |
| 1059 |
+ |
else |
| 1060 |
+ |
while (i--) { |
| 1061 |
+ |
colr_color(cval, ourpict[i]); |
| 1062 |
+ |
addcolor(ourbpict[i], cval); |
| 1063 |
+ |
} |
| 1064 |
+ |
/* print view */ |
| 1065 |
+ |
printf("VIEW%d:", nvavg); |
| 1066 |
+ |
fprintview(&ourview, stdout); |
| 1067 |
+ |
putchar('\n'); |
| 1068 |
+ |
return(1); |
| 1069 |
+ |
} |
| 1070 |
+ |
|
| 1071 |
+ |
|
| 1072 |
+ |
static void |
| 1073 |
+ |
writepicture(void) /* write out picture (alters buffer) */ |
| 1074 |
+ |
{ |
| 1075 |
|
int y; |
| 1076 |
+ |
int x; |
| 1077 |
+ |
double d; |
| 1078 |
|
|
| 1079 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
| 1079 |
> |
fprtresolu(hresolu, vresolu, stdout); |
| 1080 |
|
for (y = vresolu-1; y >= 0; y--) |
| 1081 |
< |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 1082 |
< |
syserror(); |
| 1081 |
> |
if (blurring) { |
| 1082 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
| 1083 |
> |
d = rexpadj/nvavg; |
| 1084 |
> |
scalecolor(bscan(y)[x], d); |
| 1085 |
> |
} |
| 1086 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
| 1087 |
> |
syserror(progname); |
| 1088 |
> |
} else if (averaging) { |
| 1089 |
> |
for (x = 0; x < hresolu; x++) { /* average pixels */ |
| 1090 |
> |
d = rexpadj/wscan(y)[x]; |
| 1091 |
> |
scalecolor(sscan(y)[x], d); |
| 1092 |
> |
} |
| 1093 |
> |
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
| 1094 |
> |
syserror(progname); |
| 1095 |
> |
} else { |
| 1096 |
> |
if (expadj) |
| 1097 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
| 1098 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 1099 |
> |
syserror(progname); |
| 1100 |
> |
} |
| 1101 |
|
} |
| 1102 |
|
|
| 1103 |
|
|
| 1104 |
< |
writedistance(fname) /* write out z file */ |
| 1105 |
< |
char *fname; |
| 1104 |
> |
static void |
| 1105 |
> |
writedistance( /* write out z file (alters buffer) */ |
| 1106 |
> |
char *fname |
| 1107 |
> |
) |
| 1108 |
|
{ |
| 1109 |
< |
extern double sqrt(); |
| 1110 |
< |
int donorm = normdist && ourview.type == VT_PER; |
| 1109 |
> |
int donorm = normdist & !zisnorm ? 1 : |
| 1110 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
| 1111 |
|
int fd; |
| 1112 |
|
int y; |
| 598 |
– |
float *zout; |
| 1113 |
|
|
| 1114 |
< |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
| 1115 |
< |
perror(fname); |
| 602 |
< |
exit(1); |
| 603 |
< |
} |
| 604 |
< |
if (donorm |
| 605 |
< |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 606 |
< |
syserror(); |
| 1114 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
| 1115 |
> |
syserror(fname); |
| 1116 |
|
for (y = vresolu-1; y >= 0; y--) { |
| 1117 |
|
if (donorm) { |
| 1118 |
< |
double vx, yzn2; |
| 1119 |
< |
register int x; |
| 1120 |
< |
yzn2 = y - .5*(vresolu-1); |
| 1118 |
> |
double vx, yzn2, d; |
| 1119 |
> |
int x; |
| 1120 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 1121 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 1122 |
|
for (x = 0; x < hresolu; x++) { |
| 1123 |
< |
vx = x - .5*(hresolu-1); |
| 1124 |
< |
zout[x] = zscan(y)[x] |
| 1125 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 1123 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 1124 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
| 1125 |
> |
if (donorm > 0) |
| 1126 |
> |
zscan(y)[x] *= d; |
| 1127 |
> |
else |
| 1128 |
> |
zscan(y)[x] /= d; |
| 1129 |
|
} |
| 618 |
– |
} else |
| 619 |
– |
zout = zscan(y); |
| 620 |
– |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
| 621 |
– |
< hresolu*sizeof(float)) { |
| 622 |
– |
perror(fname); |
| 623 |
– |
exit(1); |
| 1130 |
|
} |
| 1131 |
+ |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
| 1132 |
+ |
< hresolu*sizeof(float)) |
| 1133 |
+ |
syserror(fname); |
| 1134 |
|
} |
| 626 |
– |
if (donorm) |
| 627 |
– |
free((char *)zout); |
| 1135 |
|
close(fd); |
| 1136 |
|
} |
| 1137 |
|
|
| 1138 |
|
|
| 1139 |
< |
isfloat(s) /* see if string is floating number */ |
| 1140 |
< |
register char *s; |
| 1139 |
> |
static void |
| 1140 |
> |
backfill( /* fill pixel with background */ |
| 1141 |
> |
int x, |
| 1142 |
> |
int y |
| 1143 |
> |
) |
| 1144 |
|
{ |
| 1145 |
< |
for ( ; *s; s++) |
| 1146 |
< |
if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' |
| 1147 |
< |
&& *s != 'e' && *s != 'E' && *s != '+') |
| 1148 |
< |
return(0); |
| 1149 |
< |
return(1); |
| 640 |
< |
} |
| 641 |
< |
|
| 642 |
< |
|
| 643 |
< |
backfill(x, y) /* fill pixel with background */ |
| 644 |
< |
int x, y; |
| 645 |
< |
{ |
| 646 |
< |
register BYTE *dest = pscan(y)[x]; |
| 647 |
< |
|
| 648 |
< |
copycolr(dest, backcolr); |
| 1145 |
> |
if (averaging) { |
| 1146 |
> |
copycolor(sscan(y)[x], backcolor); |
| 1147 |
> |
wscan(y)[x] = 1; |
| 1148 |
> |
} else |
| 1149 |
> |
copycolr(pscan(y)[x], backcolr); |
| 1150 |
|
zscan(y)[x] = backz; |
| 1151 |
|
} |
| 1152 |
|
|
| 1153 |
|
|
| 1154 |
< |
calstart(prog, args) /* start fill calculation */ |
| 1155 |
< |
char *prog, *args; |
| 1154 |
> |
static void |
| 1155 |
> |
calstart( /* start fill calculation */ |
| 1156 |
> |
char *prog, |
| 1157 |
> |
char *args |
| 1158 |
> |
) |
| 1159 |
|
{ |
| 1160 |
|
char combuf[512]; |
| 1161 |
< |
int p0[2], p1[2]; |
| 1161 |
> |
char *argv[64]; |
| 1162 |
> |
int rval; |
| 1163 |
> |
char **wp, *cp; |
| 1164 |
|
|
| 1165 |
< |
if (childpid != -1) { |
| 1165 |
> |
if (PDesc.running) { |
| 1166 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
| 1167 |
|
exit(1); |
| 1168 |
|
} |
| 1169 |
< |
sprintf(combuf, prog, args); |
| 1170 |
< |
if (pipe(p0) < 0 || pipe(p1) < 0) |
| 1171 |
< |
syserror(); |
| 1172 |
< |
if ((childpid = vfork()) == 0) { /* fork calculation */ |
| 1173 |
< |
close(p0[1]); |
| 1174 |
< |
close(p1[0]); |
| 1175 |
< |
if (p0[0] != 0) { |
| 1176 |
< |
dup2(p0[0], 0); |
| 1177 |
< |
close(p0[0]); |
| 1178 |
< |
} |
| 1179 |
< |
if (p1[1] != 1) { |
| 1180 |
< |
dup2(p1[1], 1); |
| 675 |
< |
close(p1[1]); |
| 676 |
< |
} |
| 677 |
< |
execl("/bin/sh", "sh", "-c", combuf, 0); |
| 678 |
< |
perror("/bin/sh"); |
| 679 |
< |
_exit(127); |
| 1169 |
> |
strcpy(combuf, prog); |
| 1170 |
> |
strcat(combuf, args); |
| 1171 |
> |
cp = combuf; |
| 1172 |
> |
wp = argv; |
| 1173 |
> |
for ( ; ; ) { |
| 1174 |
> |
while (isspace(*cp)) /* nullify spaces */ |
| 1175 |
> |
*cp++ = '\0'; |
| 1176 |
> |
if (!*cp) /* all done? */ |
| 1177 |
> |
break; |
| 1178 |
> |
*wp++ = cp; /* add argument to list */ |
| 1179 |
> |
while (*++cp && !isspace(*cp)) |
| 1180 |
> |
; |
| 1181 |
|
} |
| 1182 |
< |
if (childpid == -1) |
| 1183 |
< |
syserror(); |
| 1184 |
< |
close(p0[0]); |
| 1185 |
< |
close(p1[1]); |
| 1186 |
< |
if ((psend = fdopen(p0[1], "w")) == NULL) |
| 1187 |
< |
syserror(); |
| 1188 |
< |
if ((precv = fdopen(p1[0], "r")) == NULL) |
| 1189 |
< |
syserror(); |
| 1182 |
> |
*wp = NULL; |
| 1183 |
> |
/* start process */ |
| 1184 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
| 1185 |
> |
syserror(progname); |
| 1186 |
> |
if (rval == 0) { |
| 1187 |
> |
fprintf(stderr, "%s: command not found\n", argv[0]); |
| 1188 |
> |
exit(1); |
| 1189 |
> |
} |
| 1190 |
> |
packsiz = rval/(6*sizeof(float)) - 1; |
| 1191 |
> |
if (packsiz > PACKSIZ) |
| 1192 |
> |
packsiz = PACKSIZ; |
| 1193 |
|
queuesiz = 0; |
| 1194 |
|
} |
| 1195 |
|
|
| 1196 |
|
|
| 1197 |
< |
caldone() /* done with calculation */ |
| 1197 |
> |
static void |
| 1198 |
> |
caldone(void) /* done with calculation */ |
| 1199 |
|
{ |
| 1200 |
< |
int pid; |
| 696 |
< |
|
| 697 |
< |
if (childpid == -1) |
| 1200 |
> |
if (!PDesc.running) |
| 1201 |
|
return; |
| 1202 |
|
clearqueue(); |
| 1203 |
< |
fclose(psend); |
| 701 |
< |
fclose(precv); |
| 702 |
< |
while ((pid = wait(0)) != -1 && pid != childpid) |
| 703 |
< |
; |
| 704 |
< |
childpid = -1; |
| 1203 |
> |
close_process(&PDesc); |
| 1204 |
|
} |
| 1205 |
|
|
| 1206 |
|
|
| 1207 |
< |
rcalfill(x, y) /* fill with ray-calculated pixel */ |
| 1208 |
< |
int x, y; |
| 1207 |
> |
static void |
| 1208 |
> |
rcalfill( /* fill with ray-calculated pixel */ |
| 1209 |
> |
int x, |
| 1210 |
> |
int y |
| 1211 |
> |
) |
| 1212 |
|
{ |
| 1213 |
< |
if (queuesiz >= PACKSIZ) /* flush queue if needed */ |
| 1213 |
> |
if (queuesiz >= packsiz) /* flush queue if needed */ |
| 1214 |
|
clearqueue(); |
| 1215 |
|
/* add position to queue */ |
| 1216 |
|
queue[queuesiz][0] = x; |
| 1219 |
|
} |
| 1220 |
|
|
| 1221 |
|
|
| 1222 |
< |
clearqueue() /* process queue */ |
| 1222 |
> |
static void |
| 1223 |
> |
clearqueue(void) /* process queue */ |
| 1224 |
|
{ |
| 1225 |
|
FVECT orig, dir; |
| 1226 |
< |
float fbuf[6]; |
| 1227 |
< |
register int i; |
| 1226 |
> |
float fbuf[6*(PACKSIZ+1)]; |
| 1227 |
> |
float *fbp; |
| 1228 |
> |
int i; |
| 1229 |
> |
double vx, vy; |
| 1230 |
|
|
| 1231 |
+ |
if (queuesiz == 0) |
| 1232 |
+ |
return; |
| 1233 |
+ |
fbp = fbuf; |
| 1234 |
|
for (i = 0; i < queuesiz; i++) { |
| 1235 |
|
viewray(orig, dir, &ourview, |
| 1236 |
|
(queue[i][0]+.5)/hresolu, |
| 1237 |
|
(queue[i][1]+.5)/vresolu); |
| 1238 |
< |
fbuf[0] = orig[0]; fbuf[1] = orig[1]; fbuf[2] = orig[2]; |
| 1239 |
< |
fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2]; |
| 732 |
< |
fwrite((char *)fbuf, sizeof(float), 6, psend); |
| 1238 |
> |
*fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2]; |
| 1239 |
> |
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
| 1240 |
|
} |
| 1241 |
< |
/* flush output and get results */ |
| 1242 |
< |
fbuf[3] = fbuf[4] = fbuf[5] = 0.0; /* mark */ |
| 1243 |
< |
fwrite((char *)fbuf, sizeof(float), 6, psend); |
| 1244 |
< |
if (fflush(psend) == EOF) |
| 1245 |
< |
syserror(); |
| 1241 |
> |
/* mark end and get results */ |
| 1242 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
| 1243 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
| 1244 |
> |
4*sizeof(float)*(queuesiz+1), |
| 1245 |
> |
6*sizeof(float)*(queuesiz+1)) != |
| 1246 |
> |
4*sizeof(float)*(queuesiz+1)) { |
| 1247 |
> |
fprintf(stderr, "%s: error reading from rtrace process\n", |
| 1248 |
> |
progname); |
| 1249 |
> |
exit(1); |
| 1250 |
> |
} |
| 1251 |
> |
fbp = fbuf; |
| 1252 |
|
for (i = 0; i < queuesiz; i++) { |
| 740 |
– |
if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) { |
| 741 |
– |
fprintf(stderr, "%s: read error in clearqueue\n", |
| 742 |
– |
progname); |
| 743 |
– |
exit(1); |
| 744 |
– |
} |
| 1253 |
|
if (ourexp > 0 && ourexp != 1.0) { |
| 1254 |
< |
fbuf[0] *= ourexp; |
| 1255 |
< |
fbuf[1] *= ourexp; |
| 1256 |
< |
fbuf[2] *= ourexp; |
| 1254 |
> |
fbp[0] *= ourexp; |
| 1255 |
> |
fbp[1] *= ourexp; |
| 1256 |
> |
fbp[2] *= ourexp; |
| 1257 |
|
} |
| 1258 |
< |
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 1259 |
< |
fbuf[0], fbuf[1], fbuf[2]); |
| 1260 |
< |
zscan(queue[i][1])[queue[i][0]] = fbuf[3]; |
| 1258 |
> |
if (averaging) { |
| 1259 |
> |
setcolor(sscan(queue[i][1])[queue[i][0]], |
| 1260 |
> |
fbp[0], fbp[1], fbp[2]); |
| 1261 |
> |
wscan(queue[i][1])[queue[i][0]] = 1; |
| 1262 |
> |
} else |
| 1263 |
> |
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 1264 |
> |
fbp[0], fbp[1], fbp[2]); |
| 1265 |
> |
if (zisnorm) |
| 1266 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
| 1267 |
> |
else { |
| 1268 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
| 1269 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
| 1270 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
| 1271 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
| 1272 |
> |
} |
| 1273 |
> |
fbp += 4; |
| 1274 |
|
} |
| 1275 |
|
queuesiz = 0; |
| 1276 |
|
} |
| 1277 |
|
|
| 1278 |
|
|
| 1279 |
< |
syserror() /* report error and exit */ |
| 1279 |
> |
static void |
| 1280 |
> |
syserror( /* report error and exit */ |
| 1281 |
> |
char *s |
| 1282 |
> |
) |
| 1283 |
|
{ |
| 1284 |
< |
perror(progname); |
| 1284 |
> |
perror(s); |
| 1285 |
|
exit(1); |
| 1286 |
|
} |