1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
59 |
|
e_ies(), /* IES luminaire file */ |
60 |
|
e_include(), /* include file */ |
61 |
|
e_sph(), /* sphere */ |
62 |
+ |
e_cct(), /* color temperature */ |
63 |
|
e_cmix(), /* color mixtures */ |
64 |
|
e_cspec(), /* color spectra */ |
65 |
|
e_cyl(), /* cylinder */ |
120 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
121 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
122 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
123 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
123 |
> |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
124 |
|
} |
125 |
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
126 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
127 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
127 |
> |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
128 |
|
} |
129 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
130 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
131 |
+ |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
132 |
+ |
} |
133 |
|
} |
134 |
|
/* check for consistency */ |
135 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
138 |
|
mg_ehand[MG_E_CMIX] != NULL) |
139 |
|
uneed |= 1<<MG_E_COLOR; |
140 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
141 |
+ |
mg_ehand[MG_E_IR] != NULL || |
142 |
|
mg_ehand[MG_E_ED] != NULL || |
143 |
|
mg_ehand[MG_E_RS] != NULL || |
144 |
< |
mg_ehand[MG_E_TS] != NULL) |
144 |
> |
mg_ehand[MG_E_TS] != NULL || |
145 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
146 |
|
uneed |= 1<<MG_E_MATERIAL; |
147 |
|
for (i = 0; i < MG_NENTITIES; i++) |
148 |
|
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
165 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
166 |
|
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
167 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
168 |
+ |
if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
169 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
170 |
|
/* discard remaining entities */ |
171 |
|
for (i = 0; i < MG_NENTITIES; i++) |
172 |
|
if (mg_ehand[i] == NULL) |
174 |
|
} |
175 |
|
|
176 |
|
|
168 |
– |
|
177 |
|
int |
178 |
|
mg_entity(name) /* get entity number from its name */ |
179 |
|
char *name; |
180 |
|
{ |
181 |
< |
static LUTAB ent_tab; /* entity lookup table */ |
181 |
> |
static LUTAB ent_tab = LU_SINIT(NULL,NULL); /* lookup table */ |
182 |
|
register char *cp; |
183 |
|
|
184 |
|
if (!ent_tab.tsiz) { /* initialize hash table */ |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
< |
static int |
199 |
< |
handle_it(en, ac, av) /* pass entity to appropriate handler */ |
198 |
> |
int |
199 |
> |
mg_handle(en, ac, av) /* pass entity to appropriate handler */ |
200 |
|
register int en; |
201 |
|
int ac; |
202 |
|
char **av; |
218 |
|
register MG_FCTXT *ctx; |
219 |
|
char *fn; |
220 |
|
{ |
221 |
< |
int olen; |
221 |
> |
static int nfids; |
222 |
|
register char *cp; |
223 |
|
|
224 |
+ |
ctx->fid = ++nfids; |
225 |
|
ctx->lineno = 0; |
226 |
|
if (fn == NULL) { |
227 |
< |
ctx->fname = "<stdin>"; |
227 |
> |
strcpy(ctx->fname, "<stdin>"); |
228 |
|
ctx->fp = stdin; |
229 |
|
ctx->prev = mg_file; |
230 |
|
mg_file = ctx; |
231 |
|
return(MG_OK); |
232 |
|
} |
233 |
|
/* get name relative to this context */ |
234 |
< |
if (mg_file != NULL && |
226 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
227 |
< |
olen = cp - mg_file->fname + 1; |
228 |
< |
else |
229 |
< |
olen = 0; |
230 |
< |
ctx->fname = (char *)malloc(olen+strlen(fn)+1); |
231 |
< |
if (ctx->fname == NULL) |
232 |
< |
return(MG_EMEM); |
233 |
< |
if (olen) |
234 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
235 |
|
strcpy(ctx->fname, mg_file->fname); |
236 |
< |
strcpy(ctx->fname+olen, fn); |
236 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
237 |
> |
} else |
238 |
> |
strcpy(ctx->fname, fn); |
239 |
|
ctx->fp = fopen(ctx->fname, "r"); |
240 |
< |
if (ctx->fp == NULL) { |
238 |
< |
free((MEM_PTR)ctx->fname); |
240 |
> |
if (ctx->fp == NULL) |
241 |
|
return(MG_ENOFILE); |
240 |
– |
} |
242 |
|
ctx->prev = mg_file; /* establish new context */ |
243 |
|
mg_file = ctx; |
244 |
|
return(MG_OK); |
254 |
|
if (ctx->fp == stdin) |
255 |
|
return; /* don't close standard input */ |
256 |
|
fclose(ctx->fp); |
256 |
– |
free((MEM_PTR)ctx->fname); |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
+ |
void |
261 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
262 |
+ |
register MG_FPOS *pos; |
263 |
+ |
{ |
264 |
+ |
extern long ftell(); |
265 |
+ |
|
266 |
+ |
pos->fid = mg_file->fid; |
267 |
+ |
pos->lineno = mg_file->lineno; |
268 |
+ |
pos->offset = ftell(mg_file->fp); |
269 |
+ |
} |
270 |
+ |
|
271 |
+ |
|
272 |
|
int |
273 |
< |
mg_rewind() /* rewind input file */ |
273 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
274 |
> |
register MG_FPOS *pos; |
275 |
|
{ |
276 |
< |
if (mg_file->lineno == 0) |
276 |
> |
if (pos->fid != mg_file->fid) |
277 |
> |
return(MG_ESEEK); |
278 |
> |
if (pos->lineno == mg_file->lineno) |
279 |
|
return(MG_OK); |
280 |
|
if (mg_file->fp == stdin) |
281 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
282 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
282 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
283 |
|
return(MG_ESEEK); |
284 |
< |
mg_file->lineno = 0; |
284 |
> |
mg_file->lineno = pos->lineno; |
285 |
|
return(MG_OK); |
286 |
|
} |
287 |
|
|
330 |
|
return(MG_OK); /* no words in line */ |
331 |
|
*ap = NULL; |
332 |
|
/* else handle it */ |
333 |
< |
return(handle_it(-1, ap-argv, argv)); |
333 |
> |
return(mg_handle(-1, ap-argv, argv)); |
334 |
|
} |
335 |
|
|
336 |
|
|
365 |
|
} |
366 |
|
|
367 |
|
|
353 |
– |
int |
354 |
– |
mg_iterate(ac, av, f) /* iterate on statement */ |
355 |
– |
int ac; |
356 |
– |
register char **av; |
357 |
– |
int (*f)(); |
358 |
– |
{ |
359 |
– |
int niter, rval; |
360 |
– |
register int i, j; |
361 |
– |
char *argv[MG_MAXARGC]; |
362 |
– |
char cntbuf[10]; |
363 |
– |
/* build partial transformation */ |
364 |
– |
for (i = 0; i < ac; i++) { |
365 |
– |
if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') |
366 |
– |
break; |
367 |
– |
argv[i+1] = av[i]; |
368 |
– |
} |
369 |
– |
argv[i+1] = NULL; |
370 |
– |
if (i) { /* handle transformation */ |
371 |
– |
argv[0] = mg_ename[MG_E_XF]; |
372 |
– |
if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) |
373 |
– |
return(rval); |
374 |
– |
} |
375 |
– |
if (i < ac) { /* run array */ |
376 |
– |
if (i+1 >= ac || !isint(av[i+1])) |
377 |
– |
return(MG_ETYPE); |
378 |
– |
niter = atoi(av[i+1]); |
379 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
380 |
– |
argv[1] = cntbuf; |
381 |
– |
for (j = 2; j+i < ac; j++) |
382 |
– |
argv[j] = av[j+i]; |
383 |
– |
argv[j] = NULL; |
384 |
– |
for (j = 0; j < niter; j++) { |
385 |
– |
sprintf(cntbuf, "%d", j); |
386 |
– |
if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK) |
387 |
– |
return(rval); |
388 |
– |
argv[0] = "-i"; |
389 |
– |
if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) |
390 |
– |
return(rval); |
391 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
392 |
– |
if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK) |
393 |
– |
return(rval); |
394 |
– |
} |
395 |
– |
} else if ((rval = (*f)()) != MG_OK) /* else do this instance */ |
396 |
– |
return(rval); |
397 |
– |
if (i) { /* reset the transform */ |
398 |
– |
argv[0] = mg_ename[MG_E_XF]; |
399 |
– |
argv[1] = NULL; |
400 |
– |
(void)handle_it(MG_E_XF, 1, argv); |
401 |
– |
} |
402 |
– |
return(MG_OK); |
403 |
– |
} |
404 |
– |
|
405 |
– |
|
368 |
|
/**************************************************************************** |
369 |
|
* The following routines handle unsupported entities |
370 |
|
*/ |
380 |
|
|
381 |
|
|
382 |
|
static int |
421 |
– |
reload_file() /* reload current MGF file */ |
422 |
– |
{ |
423 |
– |
register int rval; |
424 |
– |
|
425 |
– |
if ((rval = mg_rewind()) != MG_OK) |
426 |
– |
return(rval); |
427 |
– |
while (mg_read()) |
428 |
– |
if ((rval = mg_parse()) != MG_OK) |
429 |
– |
return(rval); |
430 |
– |
return(MG_OK); |
431 |
– |
} |
432 |
– |
|
433 |
– |
|
434 |
– |
static int |
383 |
|
e_include(ac, av) /* include file */ |
384 |
|
int ac; |
385 |
|
char **av; |
386 |
|
{ |
387 |
+ |
char *xfarg[MG_MAXARGC]; |
388 |
|
MG_FCTXT ictx; |
389 |
+ |
XF_SPEC *xf_orig = xf_context; |
390 |
|
int rv; |
391 |
|
|
392 |
|
if (ac < 2) |
393 |
|
return(MG_EARGC); |
394 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
395 |
|
return(rv); |
396 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
397 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
398 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
399 |
< |
mg_close(); |
400 |
< |
return(MG_EINCL); |
396 |
> |
if (ac > 2) { |
397 |
> |
register int i; |
398 |
> |
|
399 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
400 |
> |
for (i = 1; i < ac-1; i++) |
401 |
> |
xfarg[i] = av[i+1]; |
402 |
> |
xfarg[ac-1] = NULL; |
403 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
404 |
> |
return(rv); |
405 |
|
} |
406 |
+ |
do { |
407 |
+ |
while (mg_read()) |
408 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
409 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
410 |
+ |
ictx.lineno, mg_err[rv], |
411 |
+ |
ictx.inpline); |
412 |
+ |
mg_close(); |
413 |
+ |
return(MG_EINCL); |
414 |
+ |
} |
415 |
+ |
if (ac > 2) |
416 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
417 |
+ |
return(rv); |
418 |
+ |
} while (xf_context != xf_orig); |
419 |
|
mg_close(); |
420 |
|
return(MG_OK); |
421 |
|
} |
463 |
|
rad = atof(av[2]); |
464 |
|
/* initialize */ |
465 |
|
warpconends = 1; |
466 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
466 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
467 |
|
return(rval); |
468 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
469 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
470 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
471 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
471 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
472 |
|
return(rval); |
473 |
|
r2[0] = '0'; r2[1] = '\0'; |
474 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
475 |
|
theta = i*(PI/2)/mg_nqcdivs; |
476 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
476 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
477 |
|
return(rval); |
478 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
479 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
479 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
480 |
|
return(rval); |
481 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
481 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
482 |
|
return(rval); |
483 |
|
strcpy(r1, r2); |
484 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
485 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
485 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
486 |
|
return(rval); |
487 |
|
} |
488 |
|
warpconends = 0; |
537 |
|
for (j = 0; j < 3; j++) |
538 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
539 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
540 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
540 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
541 |
|
return(rval); |
542 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
542 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
543 |
|
return(rval); |
544 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
545 |
|
/* run outer section */ |
546 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
547 |
|
theta = i*(PI/2)/mg_nqcdivs; |
548 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
548 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
549 |
|
return(rval); |
550 |
|
for (j = 0; j < 3; j++) |
551 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
552 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
553 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
553 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
554 |
|
return(rval); |
555 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
555 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
556 |
|
return(rval); |
557 |
|
strcpy(r1, r2); |
558 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
559 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
559 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
560 |
|
return(rval); |
561 |
|
} |
562 |
|
/* run inner section */ |
566 |
|
for (j = 0; j < 3; j++) |
567 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
568 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
569 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
569 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
570 |
|
return(rval); |
571 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
571 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
572 |
|
return(rval); |
573 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
573 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
574 |
|
return(rval); |
575 |
|
strcpy(r1, r2); |
576 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
577 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
577 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
578 |
|
return(rval); |
579 |
|
} |
580 |
|
warpconends = 0; |
595 |
|
avnew[2] = av[2]; |
596 |
|
avnew[3] = av[3]; |
597 |
|
avnew[4] = av[2]; |
598 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
598 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
599 |
|
} |
600 |
|
|
601 |
|
|
637 |
|
make_axes(u, v, cv->n); |
638 |
|
for (j = 0; j < 3; j++) |
639 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
640 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
640 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
641 |
|
return(rv); |
642 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
642 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
643 |
|
return(rv); |
644 |
|
if (minrad == 0.) { /* closed */ |
645 |
|
v1ent[3] = av[1]; |
646 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
646 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
647 |
|
return(rv); |
648 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
648 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
649 |
|
return(rv); |
650 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
651 |
|
theta = i*(PI/2)/mg_nqcdivs; |
652 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
652 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
653 |
|
return(rv); |
654 |
|
for (j = 0; j < 3; j++) |
655 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
656 |
|
maxrad*u[j]*cos(theta) + |
657 |
|
maxrad*v[j]*sin(theta)); |
658 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
658 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
659 |
|
return(rv); |
660 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
660 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
661 |
|
return(rv); |
662 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
662 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
663 |
|
return(rv); |
664 |
|
} |
665 |
|
} else { /* open */ |
666 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
666 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
667 |
|
return(rv); |
668 |
|
for (j = 0; j < 3; j++) |
669 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
670 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
670 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
671 |
|
return(rv); |
672 |
|
v1ent[3] = "_rv4"; |
673 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
674 |
|
theta = i*(PI/2)/mg_nqcdivs; |
675 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
675 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
676 |
|
return(rv); |
677 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
677 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
678 |
|
return(rv); |
679 |
|
for (j = 0; j < 3; j++) { |
680 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
681 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
682 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
683 |
|
} |
684 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
684 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
685 |
|
return(rv); |
686 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
686 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
687 |
|
return(rv); |
688 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
688 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
689 |
|
return(rv); |
690 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
690 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
691 |
|
return(rv); |
692 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
692 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
693 |
|
return(rv); |
694 |
|
} |
695 |
|
} |
771 |
|
else |
772 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
773 |
|
} |
774 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
774 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
775 |
|
return(rv); |
776 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
776 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
777 |
|
return(rv); |
778 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
778 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
779 |
|
return(rv); |
780 |
|
if (rad1 == 0.) { /* triangles */ |
781 |
|
v1ent[3] = av[1]; |
782 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
782 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
783 |
|
return(rv); |
784 |
|
for (j = 0; j < 3; j++) |
785 |
|
sprintf(n4[j], FLTFMT, w[j]); |
786 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
786 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
787 |
|
return(rv); |
788 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
789 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
790 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
790 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
791 |
|
return(rv); |
792 |
|
for (j = 0; j < 3; j++) { |
793 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
795 |
|
if (n2off > -FHUGE) |
796 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
797 |
|
} |
798 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
798 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
799 |
|
return(rv); |
800 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
800 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
801 |
|
return(rv); |
802 |
|
if (n2off > -FHUGE && |
803 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
803 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
804 |
|
return(rv); |
805 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
805 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
806 |
|
return(rv); |
807 |
|
} |
808 |
|
} else { /* quads */ |
821 |
|
else |
822 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
823 |
|
} |
824 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
824 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
825 |
|
return(rv); |
826 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
826 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
827 |
|
return(rv); |
828 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
828 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
829 |
|
return(rv); |
830 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
831 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
832 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
832 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
833 |
|
return(rv); |
834 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
834 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
835 |
|
return(rv); |
836 |
|
for (j = 0; j < 3; j++) { |
837 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
842 |
|
if (n1off < FHUGE) |
843 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
844 |
|
} |
845 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
845 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
846 |
|
return(rv); |
847 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
847 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
848 |
|
return(rv); |
849 |
|
if (n2off > -FHUGE && |
850 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
850 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
851 |
|
return(rv); |
852 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
852 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
853 |
|
return(rv); |
854 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
854 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
855 |
|
return(rv); |
856 |
|
if (n1off < FHUGE && |
857 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
857 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
858 |
|
return(rv); |
859 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
859 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
860 |
|
return(rv); |
861 |
|
} |
862 |
|
} |
870 |
|
char **av; |
871 |
|
{ |
872 |
|
static char p[3][24]; |
873 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
873 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
874 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
875 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
876 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
877 |
|
double length; |
878 |
+ |
int hasnorm; |
879 |
|
FVECT v1, v2, v3, norm; |
880 |
|
register C_VERTEX *cv; |
881 |
|
C_VERTEX *cv0; |
882 |
|
int rv; |
883 |
|
register int i, j; |
884 |
< |
|
884 |
> |
/* check arguments */ |
885 |
|
if (ac < 5) |
886 |
|
return(MG_EARGC); |
887 |
|
if (!isflt(av[ac-1])) |
889 |
|
length = atof(av[ac-1]); |
890 |
|
if (length <= FTINY && length >= -FTINY) |
891 |
|
return(MG_EILL); |
892 |
< |
/* do bottom face */ |
924 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
925 |
< |
for (i = 1; i < ac-1; i++) |
926 |
< |
newav[i] = av[i]; |
927 |
< |
newav[i] = NULL; |
928 |
< |
if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) |
929 |
< |
return(rv); |
930 |
< |
/* compute face normal */ |
892 |
> |
/* compute face normal */ |
893 |
|
if ((cv0 = c_getvert(av[1])) == NULL) |
894 |
|
return(MG_EUNDEF); |
895 |
+ |
hasnorm = 0; |
896 |
|
norm[0] = norm[1] = norm[2] = 0.; |
897 |
|
v1[0] = v1[1] = v1[2] = 0.; |
898 |
|
for (i = 2; i < ac-1; i++) { |
899 |
|
if ((cv = c_getvert(av[i])) == NULL) |
900 |
|
return(MG_EUNDEF); |
901 |
+ |
hasnorm += !is0vect(cv->n); |
902 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
903 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
904 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
910 |
|
} |
911 |
|
if (normalize(norm) == 0.) |
912 |
|
return(MG_EILL); |
913 |
< |
/* create moved vertices */ |
913 |
> |
/* create moved vertices */ |
914 |
|
for (i = 1; i < ac-1; i++) { |
915 |
|
sprintf(nvn[i-1], "_pv%d", i); |
916 |
|
vent[1] = nvn[i-1]; |
917 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
917 |
> |
vent[3] = av[i]; |
918 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
919 |
|
return(rv); |
920 |
|
cv = c_getvert(av[i]); /* checked above */ |
921 |
|
for (j = 0; j < 3; j++) |
922 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
923 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
923 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
924 |
|
return(rv); |
960 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
925 |
|
} |
926 |
< |
/* do top face */ |
927 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
964 |
< |
return(rv); |
926 |
> |
/* make faces */ |
927 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
928 |
|
/* do the side faces */ |
929 |
|
newav[5] = NULL; |
930 |
|
newav[3] = av[ac-2]; |
932 |
|
for (i = 1; i < ac-1; i++) { |
933 |
|
newav[1] = nvn[i-1]; |
934 |
|
newav[2] = av[i]; |
935 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
935 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
936 |
|
return(rv); |
937 |
|
newav[3] = newav[2]; |
938 |
|
newav[4] = newav[1]; |
939 |
|
} |
940 |
+ |
/* do top face */ |
941 |
+ |
for (i = 1; i < ac-1; i++) { |
942 |
+ |
if (hasnorm) { /* zero normals */ |
943 |
+ |
vent[1] = nvn[i-1]; |
944 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
945 |
+ |
return(rv); |
946 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
947 |
+ |
return(rv); |
948 |
+ |
} |
949 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
950 |
+ |
} |
951 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
952 |
+ |
return(rv); |
953 |
+ |
/* do bottom face */ |
954 |
+ |
if (hasnorm) |
955 |
+ |
for (i = 1; i < ac-1; i++) { |
956 |
+ |
vent[1] = nvn[i-1]; |
957 |
+ |
vent[3] = av[i]; |
958 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
959 |
+ |
return(rv); |
960 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
961 |
+ |
return(rv); |
962 |
+ |
newav[i] = nvn[i-1]; |
963 |
+ |
} |
964 |
+ |
else |
965 |
+ |
for (i = 1; i < ac-1; i++) |
966 |
+ |
newav[i] = av[i]; |
967 |
+ |
newav[i] = NULL; |
968 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
969 |
+ |
return(rv); |
970 |
|
return(MG_OK); |
971 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
static int |
975 |
< |
e_cspec(ac, av) /* handle spectral color */ |
983 |
< |
int ac; |
984 |
< |
char **av; |
975 |
> |
put_cxy() /* put out current xy chromaticities */ |
976 |
|
{ |
977 |
|
static char xbuf[24], ybuf[24]; |
978 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
979 |
|
int rv; |
980 |
|
|
981 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
982 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
983 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
984 |
+ |
return(rv); |
985 |
+ |
return(MG_OK); |
986 |
+ |
} |
987 |
+ |
|
988 |
+ |
|
989 |
+ |
static int |
990 |
+ |
put_cspec() /* put out current color spectrum */ |
991 |
+ |
{ |
992 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
993 |
+ |
char *newav[C_CNSS+4]; |
994 |
+ |
double sf; |
995 |
+ |
register int i; |
996 |
+ |
|
997 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
998 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
999 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1000 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1001 |
+ |
newav[1] = wl[0]; |
1002 |
+ |
newav[2] = wl[1]; |
1003 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1004 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1005 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1006 |
+ |
newav[i+3] = vbuf[i]; |
1007 |
+ |
} |
1008 |
+ |
newav[C_CNSS+3] = NULL; |
1009 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1010 |
+ |
return(i); |
1011 |
+ |
} |
1012 |
+ |
return(MG_OK); |
1013 |
+ |
} |
1014 |
+ |
|
1015 |
+ |
|
1016 |
+ |
static int |
1017 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1018 |
+ |
int ac; |
1019 |
+ |
char **av; |
1020 |
+ |
{ |
1021 |
+ |
/* convert to xy chromaticity */ |
1022 |
|
c_ccvt(c_ccolor, C_CSXY); |
1023 |
|
/* if it's really their handler, use it */ |
1024 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1025 |
< |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
994 |
< |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
995 |
< |
if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK) |
996 |
< |
return(rv); |
997 |
< |
} |
1024 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1025 |
> |
return(put_cxy()); |
1026 |
|
return(MG_OK); |
1027 |
|
} |
1028 |
|
|
1032 |
|
int ac; |
1033 |
|
char **av; |
1034 |
|
{ |
1007 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
1008 |
– |
char *newav[C_CNSS+4]; |
1009 |
– |
int rv; |
1010 |
– |
register int i; |
1035 |
|
/* |
1036 |
|
* Contorted logic works as follows: |
1037 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1042 |
|
*/ |
1043 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1044 |
|
c_ccvt(c_ccolor, C_CSXY); |
1045 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1046 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1047 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1048 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1049 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1050 |
< |
newav[1] = wl[0]; |
1051 |
< |
newav[2] = wl[1]; |
1052 |
< |
for (i = 0; i < C_CNSS; i++) { |
1053 |
< |
sprintf(vbuf[i], "%.6f", |
1054 |
< |
(double)c_ccolor->ssamp[i] / |
1055 |
< |
c_ccolor->ssum); |
1056 |
< |
newav[i+3] = vbuf[i]; |
1057 |
< |
} |
1058 |
< |
newav[C_CNSS+3] = NULL; |
1059 |
< |
if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1060 |
< |
return(rv); |
1061 |
< |
} |
1062 |
< |
return(MG_OK); |
1063 |
< |
} |
1064 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1065 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1066 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1067 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1068 |
< |
newav[1] = vbuf[0]; |
1045 |
< |
newav[2] = vbuf[1]; |
1046 |
< |
newav[3] = NULL; |
1047 |
< |
if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK) |
1048 |
< |
return(rv); |
1049 |
< |
} |
1045 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1046 |
> |
return(put_cspec()); |
1047 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1048 |
> |
return(put_cxy()); |
1049 |
> |
return(MG_OK); |
1050 |
> |
} |
1051 |
> |
|
1052 |
> |
|
1053 |
> |
static int |
1054 |
> |
e_cct(ac, av) /* handle color temperature */ |
1055 |
> |
int ac; |
1056 |
> |
char **av; |
1057 |
> |
{ |
1058 |
> |
/* |
1059 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1060 |
> |
* converted temperature to spectral color. Put it out as such |
1061 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1062 |
> |
* put it out if they handle it. |
1063 |
> |
*/ |
1064 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1065 |
> |
return(put_cspec()); |
1066 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1067 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1068 |
> |
return(put_cxy()); |
1069 |
|
return(MG_OK); |
1070 |
|
} |