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 |
+ |
static int nfids; |
222 |
|
int olen; |
223 |
|
register char *cp; |
224 |
|
|
225 |
+ |
ctx->fid = ++nfids; |
226 |
|
ctx->lineno = 0; |
227 |
|
if (fn == NULL) { |
228 |
< |
ctx->fname = "<stdin>"; |
228 |
> |
strcpy(ctx->fname, "<stdin>"); |
229 |
|
ctx->fp = stdin; |
230 |
|
ctx->prev = mg_file; |
231 |
|
mg_file = ctx; |
237 |
|
olen = cp - mg_file->fname + 1; |
238 |
|
else |
239 |
|
olen = 0; |
230 |
– |
ctx->fname = (char *)malloc(olen+strlen(fn)+1); |
231 |
– |
if (ctx->fname == NULL) |
232 |
– |
return(MG_EMEM); |
240 |
|
if (olen) |
241 |
|
strcpy(ctx->fname, mg_file->fname); |
242 |
|
strcpy(ctx->fname+olen, fn); |
243 |
|
ctx->fp = fopen(ctx->fname, "r"); |
244 |
< |
if (ctx->fp == NULL) { |
238 |
< |
free((MEM_PTR)ctx->fname); |
244 |
> |
if (ctx->fp == NULL) |
245 |
|
return(MG_ENOFILE); |
240 |
– |
} |
246 |
|
ctx->prev = mg_file; /* establish new context */ |
247 |
|
mg_file = ctx; |
248 |
|
return(MG_OK); |
258 |
|
if (ctx->fp == stdin) |
259 |
|
return; /* don't close standard input */ |
260 |
|
fclose(ctx->fp); |
256 |
– |
free((MEM_PTR)ctx->fname); |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
+ |
void |
265 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
266 |
+ |
register MG_FPOS *pos; |
267 |
+ |
{ |
268 |
+ |
extern long ftell(); |
269 |
+ |
|
270 |
+ |
pos->fid = mg_file->fid; |
271 |
+ |
pos->lineno = mg_file->lineno; |
272 |
+ |
pos->offset = ftell(mg_file->fp); |
273 |
+ |
} |
274 |
+ |
|
275 |
+ |
|
276 |
|
int |
277 |
< |
mg_rewind() /* rewind input file */ |
277 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
278 |
> |
register MG_FPOS *pos; |
279 |
|
{ |
280 |
< |
if (mg_file->lineno == 0) |
280 |
> |
if (pos->fid != mg_file->fid) |
281 |
> |
return(MG_ESEEK); |
282 |
> |
if (pos->lineno == mg_file->lineno) |
283 |
|
return(MG_OK); |
284 |
|
if (mg_file->fp == stdin) |
285 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
286 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
286 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
287 |
|
return(MG_ESEEK); |
288 |
< |
mg_file->lineno = 0; |
288 |
> |
mg_file->lineno = pos->lineno; |
289 |
|
return(MG_OK); |
290 |
|
} |
291 |
|
|
334 |
|
return(MG_OK); /* no words in line */ |
335 |
|
*ap = NULL; |
336 |
|
/* else handle it */ |
337 |
< |
return(handle_it(-1, ap-argv, argv)); |
337 |
> |
return(mg_handle(-1, ap-argv, argv)); |
338 |
|
} |
339 |
|
|
340 |
|
|
369 |
|
} |
370 |
|
|
371 |
|
|
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 |
– |
|
372 |
|
/**************************************************************************** |
373 |
|
* The following routines handle unsupported entities |
374 |
|
*/ |
384 |
|
|
385 |
|
|
386 |
|
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 |
387 |
|
e_include(ac, av) /* include file */ |
388 |
|
int ac; |
389 |
|
char **av; |
390 |
|
{ |
391 |
+ |
char *xfarg[MG_MAXARGC]; |
392 |
|
MG_FCTXT ictx; |
393 |
|
int rv; |
394 |
|
|
396 |
|
return(MG_EARGC); |
397 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
398 |
|
return(rv); |
399 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
400 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
401 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
402 |
< |
mg_close(); |
403 |
< |
return(MG_EINCL); |
399 |
> |
if (ac > 2) { |
400 |
> |
register int i; |
401 |
> |
|
402 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
403 |
> |
for (i = 1; i < ac-1; i++) |
404 |
> |
xfarg[i] = av[i+1]; |
405 |
> |
xfarg[ac-1] = NULL; |
406 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
407 |
> |
return(rv); |
408 |
|
} |
409 |
+ |
while (!feof(mg_file->fp)) { |
410 |
+ |
while (mg_read()) |
411 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
412 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
413 |
+ |
ictx.lineno, mg_err[rv], |
414 |
+ |
ictx.inpline); |
415 |
+ |
mg_close(); |
416 |
+ |
return(MG_EINCL); |
417 |
+ |
} |
418 |
+ |
if (ac > 2) |
419 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
420 |
+ |
return(rv); |
421 |
+ |
} |
422 |
|
mg_close(); |
423 |
|
return(MG_OK); |
424 |
|
} |
466 |
|
rad = atof(av[2]); |
467 |
|
/* initialize */ |
468 |
|
warpconends = 1; |
469 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
469 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
470 |
|
return(rval); |
471 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
472 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
473 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
474 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
474 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
475 |
|
return(rval); |
476 |
|
r2[0] = '0'; r2[1] = '\0'; |
477 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
478 |
|
theta = i*(PI/2)/mg_nqcdivs; |
479 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
479 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
480 |
|
return(rval); |
481 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
482 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
482 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
483 |
|
return(rval); |
484 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
484 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
485 |
|
return(rval); |
486 |
|
strcpy(r1, r2); |
487 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
488 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
488 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
489 |
|
return(rval); |
490 |
|
} |
491 |
|
warpconends = 0; |
540 |
|
for (j = 0; j < 3; j++) |
541 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
542 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
543 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
543 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
544 |
|
return(rval); |
545 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
545 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
546 |
|
return(rval); |
547 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
548 |
|
/* run outer section */ |
549 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
550 |
|
theta = i*(PI/2)/mg_nqcdivs; |
551 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
551 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
552 |
|
return(rval); |
553 |
|
for (j = 0; j < 3; j++) |
554 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
555 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
556 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
556 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
557 |
|
return(rval); |
558 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
558 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
559 |
|
return(rval); |
560 |
|
strcpy(r1, r2); |
561 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
562 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
562 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
563 |
|
return(rval); |
564 |
|
} |
565 |
|
/* run inner section */ |
569 |
|
for (j = 0; j < 3; j++) |
570 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
571 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
572 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
572 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
573 |
|
return(rval); |
574 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
574 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
575 |
|
return(rval); |
576 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
576 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
577 |
|
return(rval); |
578 |
|
strcpy(r1, r2); |
579 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
580 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
580 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
581 |
|
return(rval); |
582 |
|
} |
583 |
|
warpconends = 0; |
598 |
|
avnew[2] = av[2]; |
599 |
|
avnew[3] = av[3]; |
600 |
|
avnew[4] = av[2]; |
601 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
601 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
602 |
|
} |
603 |
|
|
604 |
|
|
640 |
|
make_axes(u, v, cv->n); |
641 |
|
for (j = 0; j < 3; j++) |
642 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
643 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
643 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
644 |
|
return(rv); |
645 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
645 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
646 |
|
return(rv); |
647 |
|
if (minrad == 0.) { /* closed */ |
648 |
|
v1ent[3] = av[1]; |
649 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
649 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
650 |
|
return(rv); |
651 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
651 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
652 |
|
return(rv); |
653 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
654 |
|
theta = i*(PI/2)/mg_nqcdivs; |
655 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
655 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
656 |
|
return(rv); |
657 |
|
for (j = 0; j < 3; j++) |
658 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
659 |
|
maxrad*u[j]*cos(theta) + |
660 |
|
maxrad*v[j]*sin(theta)); |
661 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
661 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
662 |
|
return(rv); |
663 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
663 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
664 |
|
return(rv); |
665 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
665 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
666 |
|
return(rv); |
667 |
|
} |
668 |
|
} else { /* open */ |
669 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
669 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
670 |
|
return(rv); |
671 |
|
for (j = 0; j < 3; j++) |
672 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
673 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
673 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
674 |
|
return(rv); |
675 |
|
v1ent[3] = "_rv4"; |
676 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
677 |
|
theta = i*(PI/2)/mg_nqcdivs; |
678 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
678 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
679 |
|
return(rv); |
680 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
680 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
681 |
|
return(rv); |
682 |
|
for (j = 0; j < 3; j++) { |
683 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
684 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
685 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
686 |
|
} |
687 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
687 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
688 |
|
return(rv); |
689 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
689 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
690 |
|
return(rv); |
691 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
691 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
692 |
|
return(rv); |
693 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
693 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
694 |
|
return(rv); |
695 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
695 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
696 |
|
return(rv); |
697 |
|
} |
698 |
|
} |
774 |
|
else |
775 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
776 |
|
} |
777 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
777 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
778 |
|
return(rv); |
779 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
779 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
780 |
|
return(rv); |
781 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
781 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
782 |
|
return(rv); |
783 |
|
if (rad1 == 0.) { /* triangles */ |
784 |
|
v1ent[3] = av[1]; |
785 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
785 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
786 |
|
return(rv); |
787 |
|
for (j = 0; j < 3; j++) |
788 |
|
sprintf(n4[j], FLTFMT, w[j]); |
789 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
789 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
790 |
|
return(rv); |
791 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
792 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
793 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
793 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
794 |
|
return(rv); |
795 |
|
for (j = 0; j < 3; j++) { |
796 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
798 |
|
if (n2off > -FHUGE) |
799 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
800 |
|
} |
801 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
801 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
802 |
|
return(rv); |
803 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
803 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
804 |
|
return(rv); |
805 |
|
if (n2off > -FHUGE && |
806 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
806 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
807 |
|
return(rv); |
808 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
808 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
809 |
|
return(rv); |
810 |
|
} |
811 |
|
} else { /* quads */ |
824 |
|
else |
825 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
826 |
|
} |
827 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
827 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
828 |
|
return(rv); |
829 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
829 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
830 |
|
return(rv); |
831 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
831 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
832 |
|
return(rv); |
833 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
834 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
835 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
835 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
836 |
|
return(rv); |
837 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
837 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
838 |
|
return(rv); |
839 |
|
for (j = 0; j < 3; j++) { |
840 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
845 |
|
if (n1off < FHUGE) |
846 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
847 |
|
} |
848 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
848 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
849 |
|
return(rv); |
850 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
850 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
851 |
|
return(rv); |
852 |
|
if (n2off > -FHUGE && |
853 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
853 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
854 |
|
return(rv); |
855 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
855 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
856 |
|
return(rv); |
857 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
857 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
858 |
|
return(rv); |
859 |
|
if (n1off < FHUGE && |
860 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
860 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
861 |
|
return(rv); |
862 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
862 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
863 |
|
return(rv); |
864 |
|
} |
865 |
|
} |
873 |
|
char **av; |
874 |
|
{ |
875 |
|
static char p[3][24]; |
876 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
876 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
877 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
878 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
879 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
880 |
|
double length; |
881 |
+ |
int hasnorm; |
882 |
|
FVECT v1, v2, v3, norm; |
883 |
|
register C_VERTEX *cv; |
884 |
|
C_VERTEX *cv0; |
885 |
|
int rv; |
886 |
|
register int i, j; |
887 |
< |
|
887 |
> |
/* check arguments */ |
888 |
|
if (ac < 5) |
889 |
|
return(MG_EARGC); |
890 |
|
if (!isflt(av[ac-1])) |
892 |
|
length = atof(av[ac-1]); |
893 |
|
if (length <= FTINY && length >= -FTINY) |
894 |
|
return(MG_EILL); |
895 |
< |
/* 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 */ |
895 |
> |
/* compute face normal */ |
896 |
|
if ((cv0 = c_getvert(av[1])) == NULL) |
897 |
|
return(MG_EUNDEF); |
898 |
+ |
hasnorm = 0; |
899 |
|
norm[0] = norm[1] = norm[2] = 0.; |
900 |
|
v1[0] = v1[1] = v1[2] = 0.; |
901 |
|
for (i = 2; i < ac-1; i++) { |
902 |
|
if ((cv = c_getvert(av[i])) == NULL) |
903 |
|
return(MG_EUNDEF); |
904 |
+ |
hasnorm += !is0vect(cv->n); |
905 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
906 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
907 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
913 |
|
} |
914 |
|
if (normalize(norm) == 0.) |
915 |
|
return(MG_EILL); |
916 |
< |
/* create moved vertices */ |
916 |
> |
/* create moved vertices */ |
917 |
|
for (i = 1; i < ac-1; i++) { |
918 |
|
sprintf(nvn[i-1], "_pv%d", i); |
919 |
|
vent[1] = nvn[i-1]; |
920 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
920 |
> |
vent[3] = av[i]; |
921 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
922 |
|
return(rv); |
923 |
|
cv = c_getvert(av[i]); /* checked above */ |
924 |
|
for (j = 0; j < 3; j++) |
925 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
926 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
926 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
927 |
|
return(rv); |
960 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
928 |
|
} |
929 |
< |
/* do top face */ |
930 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
964 |
< |
return(rv); |
929 |
> |
/* make faces */ |
930 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
931 |
|
/* do the side faces */ |
932 |
|
newav[5] = NULL; |
933 |
|
newav[3] = av[ac-2]; |
935 |
|
for (i = 1; i < ac-1; i++) { |
936 |
|
newav[1] = nvn[i-1]; |
937 |
|
newav[2] = av[i]; |
938 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
938 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
939 |
|
return(rv); |
940 |
|
newav[3] = newav[2]; |
941 |
|
newav[4] = newav[1]; |
942 |
|
} |
943 |
+ |
/* do top face */ |
944 |
+ |
for (i = 1; i < ac-1; i++) { |
945 |
+ |
if (hasnorm) { /* zero normals */ |
946 |
+ |
vent[1] = nvn[i-1]; |
947 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
948 |
+ |
return(rv); |
949 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
950 |
+ |
return(rv); |
951 |
+ |
} |
952 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
953 |
+ |
} |
954 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
955 |
+ |
return(rv); |
956 |
+ |
/* do bottom face */ |
957 |
+ |
if (hasnorm) |
958 |
+ |
for (i = 1; i < ac-1; i++) { |
959 |
+ |
vent[1] = nvn[i-1]; |
960 |
+ |
vent[3] = av[i]; |
961 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
962 |
+ |
return(rv); |
963 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
964 |
+ |
return(rv); |
965 |
+ |
newav[i] = nvn[i-1]; |
966 |
+ |
} |
967 |
+ |
else |
968 |
+ |
for (i = 1; i < ac-1; i++) |
969 |
+ |
newav[i] = av[i]; |
970 |
+ |
newav[i] = NULL; |
971 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
972 |
+ |
return(rv); |
973 |
|
return(MG_OK); |
974 |
|
} |
975 |
|
|
976 |
|
|
977 |
|
static int |
978 |
< |
e_cspec(ac, av) /* handle spectral color */ |
983 |
< |
int ac; |
984 |
< |
char **av; |
978 |
> |
put_cxy() /* put out current xy chromaticities */ |
979 |
|
{ |
980 |
|
static char xbuf[24], ybuf[24]; |
981 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
982 |
|
int rv; |
983 |
|
|
984 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
985 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
986 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
987 |
+ |
return(rv); |
988 |
+ |
return(MG_OK); |
989 |
+ |
} |
990 |
+ |
|
991 |
+ |
|
992 |
+ |
static int |
993 |
+ |
put_cspec() /* put out current color spectrum */ |
994 |
+ |
{ |
995 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
996 |
+ |
char *newav[C_CNSS+4]; |
997 |
+ |
double sf; |
998 |
+ |
register int i; |
999 |
+ |
|
1000 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1001 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1002 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1003 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1004 |
+ |
newav[1] = wl[0]; |
1005 |
+ |
newav[2] = wl[1]; |
1006 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1007 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1008 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1009 |
+ |
newav[i+3] = vbuf[i]; |
1010 |
+ |
} |
1011 |
+ |
newav[C_CNSS+3] = NULL; |
1012 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1013 |
+ |
return(i); |
1014 |
+ |
} |
1015 |
+ |
return(MG_OK); |
1016 |
+ |
} |
1017 |
+ |
|
1018 |
+ |
|
1019 |
+ |
static int |
1020 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1021 |
+ |
int ac; |
1022 |
+ |
char **av; |
1023 |
+ |
{ |
1024 |
+ |
/* convert to xy chromaticity */ |
1025 |
|
c_ccvt(c_ccolor, C_CSXY); |
1026 |
|
/* if it's really their handler, use it */ |
1027 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1028 |
< |
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 |
< |
} |
1027 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1028 |
> |
return(put_cxy()); |
1029 |
|
return(MG_OK); |
1030 |
|
} |
1031 |
|
|
1035 |
|
int ac; |
1036 |
|
char **av; |
1037 |
|
{ |
1007 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
1008 |
– |
char *newav[C_CNSS+4]; |
1009 |
– |
int rv; |
1010 |
– |
register int i; |
1038 |
|
/* |
1039 |
|
* Contorted logic works as follows: |
1040 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1045 |
|
*/ |
1046 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1047 |
|
c_ccvt(c_ccolor, C_CSXY); |
1048 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1049 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1050 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1051 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1052 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1053 |
< |
newav[1] = wl[0]; |
1054 |
< |
newav[2] = wl[1]; |
1055 |
< |
for (i = 0; i < C_CNSS; i++) { |
1056 |
< |
sprintf(vbuf[i], "%.6f", |
1057 |
< |
(double)c_ccolor->ssamp[i] / |
1058 |
< |
c_ccolor->ssum); |
1059 |
< |
newav[i+3] = vbuf[i]; |
1060 |
< |
} |
1061 |
< |
newav[C_CNSS+3] = NULL; |
1062 |
< |
if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1063 |
< |
return(rv); |
1064 |
< |
} |
1065 |
< |
return(MG_OK); |
1066 |
< |
} |
1067 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1068 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1069 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1070 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1071 |
< |
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 |
< |
} |
1048 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1049 |
> |
return(put_cspec()); |
1050 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1051 |
> |
return(put_cxy()); |
1052 |
> |
return(MG_OK); |
1053 |
> |
} |
1054 |
> |
|
1055 |
> |
|
1056 |
> |
static int |
1057 |
> |
e_cct(ac, av) /* handle color temperature */ |
1058 |
> |
int ac; |
1059 |
> |
char **av; |
1060 |
> |
{ |
1061 |
> |
/* |
1062 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1063 |
> |
* converted temperature to spectral color. Put it out as such |
1064 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1065 |
> |
* put it out if they handle it. |
1066 |
> |
*/ |
1067 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1068 |
> |
return(put_cspec()); |
1069 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1070 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1071 |
> |
return(put_cxy()); |
1072 |
|
return(MG_OK); |
1073 |
|
} |