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