53 |
|
|
54 |
|
/* temporary settings for testing */ |
55 |
|
#define e_ies e_any_toss |
56 |
– |
#define e_cmix e_any_toss |
57 |
– |
#define e_cspec e_any_toss |
56 |
|
/* alternate handler routines */ |
57 |
|
|
58 |
|
static int e_any_toss(), /* discard unneeded entity */ |
60 |
|
e_include(), /* include file */ |
61 |
|
e_sph(), /* sphere */ |
62 |
|
e_cmix(), /* color mixtures */ |
63 |
< |
e_cspec(); /* color spectra */ |
63 |
> |
e_cspec(), /* color spectra */ |
64 |
|
e_cyl(), /* cylinder */ |
65 |
|
e_cone(), /* cone */ |
66 |
|
e_prism(), /* prism */ |
117 |
|
} else |
118 |
|
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
119 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
120 |
< |
if (mg_ehand[MG_E_CMIX] == NULL) |
120 |
> |
if (mg_ehand[MG_E_CMIX] == NULL) { |
121 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
122 |
< |
if (mg_ehand[MG_E_CSPEC] == NULL) |
122 |
> |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
123 |
> |
} |
124 |
> |
if (mg_ehand[MG_E_CSPEC] == NULL) { |
125 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
126 |
+ |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
127 |
+ |
} |
128 |
|
} |
129 |
|
/* check for consistency */ |
130 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
131 |
|
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
132 |
< |
if (mg_ehand[MG_E_CXY] != NULL) |
132 |
> |
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
133 |
> |
mg_ehand[MG_E_CMIX] != NULL) |
134 |
|
uneed |= 1<<MG_E_COLOR; |
135 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
136 |
|
mg_ehand[MG_E_ED] != NULL || |
137 |
|
mg_ehand[MG_E_RS] != NULL || |
138 |
< |
mg_ehand[MG_E_TS] != NULL) |
138 |
> |
mg_ehand[MG_E_TS] != NULL || |
139 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
140 |
|
uneed |= 1<<MG_E_MATERIAL; |
141 |
|
for (i = 0; i < MG_NENTITIES; i++) |
142 |
|
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
151 |
|
e_supp[MG_E_POINT] = c_hvertex; |
152 |
|
if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
153 |
|
e_supp[MG_E_NORMAL] = c_hvertex; |
154 |
+ |
if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
155 |
+ |
e_supp[MG_E_COLOR] = c_hcolor; |
156 |
+ |
if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
157 |
+ |
e_supp[MG_E_CXY] = c_hcolor; |
158 |
+ |
if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
159 |
+ |
e_supp[MG_E_CSPEC] = c_hcolor; |
160 |
+ |
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
161 |
+ |
e_supp[MG_E_CMIX] = c_hcolor; |
162 |
|
/* discard remaining entities */ |
163 |
|
for (i = 0; i < MG_NENTITIES; i++) |
164 |
|
if (mg_ehand[i] == NULL) |
171 |
|
mg_entity(name) /* get entity number from its name */ |
172 |
|
char *name; |
173 |
|
{ |
174 |
< |
static LUTAB ent_tab; /* entity lookup table */ |
174 |
> |
static LUTAB ent_tab = LU_SINIT(NULL,NULL); /* lookup table */ |
175 |
|
register char *cp; |
176 |
|
|
177 |
|
if (!ent_tab.tsiz) { /* initialize hash table */ |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
static int |
192 |
< |
handle_it(en, ac, av) /* pass entity to appropriate handler */ |
191 |
> |
int |
192 |
> |
mg_handle(en, ac, av) /* pass entity to appropriate handler */ |
193 |
|
register int en; |
194 |
|
int ac; |
195 |
|
char **av; |
211 |
|
register MG_FCTXT *ctx; |
212 |
|
char *fn; |
213 |
|
{ |
214 |
+ |
static int nfids; |
215 |
|
int olen; |
216 |
|
register char *cp; |
217 |
|
|
218 |
+ |
ctx->fid = ++nfids; |
219 |
|
ctx->lineno = 0; |
220 |
|
if (fn == NULL) { |
221 |
< |
ctx->fname = "<stdin>"; |
221 |
> |
strcpy(ctx->fname, "<stdin>"); |
222 |
|
ctx->fp = stdin; |
223 |
|
ctx->prev = mg_file; |
224 |
|
mg_file = ctx; |
230 |
|
olen = cp - mg_file->fname + 1; |
231 |
|
else |
232 |
|
olen = 0; |
219 |
– |
ctx->fname = (char *)malloc(olen+strlen(fn)+1); |
220 |
– |
if (ctx->fname == NULL) |
221 |
– |
return(MG_EMEM); |
233 |
|
if (olen) |
234 |
|
strcpy(ctx->fname, mg_file->fname); |
235 |
|
strcpy(ctx->fname+olen, fn); |
236 |
|
ctx->fp = fopen(ctx->fname, "r"); |
237 |
< |
if (ctx->fp == NULL) { |
227 |
< |
free((MEM_PTR)ctx->fname); |
237 |
> |
if (ctx->fp == NULL) |
238 |
|
return(MG_ENOFILE); |
229 |
– |
} |
239 |
|
ctx->prev = mg_file; /* establish new context */ |
240 |
|
mg_file = ctx; |
241 |
|
return(MG_OK); |
251 |
|
if (ctx->fp == stdin) |
252 |
|
return; /* don't close standard input */ |
253 |
|
fclose(ctx->fp); |
245 |
– |
free((MEM_PTR)ctx->fname); |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
+ |
void |
258 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
259 |
+ |
register MG_FPOS *pos; |
260 |
+ |
{ |
261 |
+ |
extern long ftell(); |
262 |
+ |
|
263 |
+ |
pos->fid = mg_file->fid; |
264 |
+ |
pos->lineno = mg_file->lineno; |
265 |
+ |
pos->offset = ftell(mg_file->fp); |
266 |
+ |
} |
267 |
+ |
|
268 |
+ |
|
269 |
|
int |
270 |
< |
mg_rewind() /* rewind input file */ |
270 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
271 |
> |
register MG_FPOS *pos; |
272 |
|
{ |
273 |
< |
if (mg_file->lineno == 0) |
273 |
> |
if (pos->fid != mg_file->fid) |
274 |
> |
return(MG_ESEEK); |
275 |
> |
if (pos->lineno == mg_file->lineno) |
276 |
|
return(MG_OK); |
277 |
|
if (mg_file->fp == stdin) |
278 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
279 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
279 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
280 |
|
return(MG_ESEEK); |
281 |
< |
mg_file->lineno = 0; |
281 |
> |
mg_file->lineno = pos->lineno; |
282 |
|
return(MG_OK); |
283 |
|
} |
284 |
|
|
327 |
|
return(MG_OK); /* no words in line */ |
328 |
|
*ap = NULL; |
329 |
|
/* else handle it */ |
330 |
< |
return(handle_it(-1, ap-argv, argv)); |
330 |
> |
return(mg_handle(-1, ap-argv, argv)); |
331 |
|
} |
332 |
|
|
333 |
|
|
362 |
|
} |
363 |
|
|
364 |
|
|
342 |
– |
int |
343 |
– |
mg_iterate(ac, av, f) /* iterate on statement */ |
344 |
– |
int ac; |
345 |
– |
register char **av; |
346 |
– |
int (*f)(); |
347 |
– |
{ |
348 |
– |
int niter, rval; |
349 |
– |
register int i, j; |
350 |
– |
char *argv[MG_MAXARGC]; |
351 |
– |
char cntbuf[10]; |
352 |
– |
/* build partial transformation */ |
353 |
– |
for (i = 0; i < ac; i++) { |
354 |
– |
if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') |
355 |
– |
break; |
356 |
– |
argv[i+1] = av[i]; |
357 |
– |
} |
358 |
– |
argv[i+1] = NULL; |
359 |
– |
if (i) { /* handle transformation */ |
360 |
– |
argv[0] = mg_ename[MG_E_XF]; |
361 |
– |
if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) |
362 |
– |
return(rval); |
363 |
– |
} |
364 |
– |
if (i < ac) { /* run array */ |
365 |
– |
if (i+1 >= ac || !isint(av[i+1])) |
366 |
– |
return(MG_ETYPE); |
367 |
– |
niter = atoi(av[i+1]); |
368 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
369 |
– |
argv[1] = cntbuf; |
370 |
– |
for (j = 2; j+i < ac; j++) |
371 |
– |
argv[j] = av[j+i]; |
372 |
– |
argv[j] = NULL; |
373 |
– |
for (j = 0; j < niter; j++) { |
374 |
– |
sprintf(cntbuf, "%d", j); |
375 |
– |
if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK) |
376 |
– |
return(rval); |
377 |
– |
argv[0] = "-i"; |
378 |
– |
if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) |
379 |
– |
return(rval); |
380 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
381 |
– |
if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK) |
382 |
– |
return(rval); |
383 |
– |
} |
384 |
– |
} else if ((rval = (*f)()) != MG_OK) /* else do this instance */ |
385 |
– |
return(rval); |
386 |
– |
if (i) { /* reset the transform */ |
387 |
– |
argv[0] = mg_ename[MG_E_XF]; |
388 |
– |
argv[1] = NULL; |
389 |
– |
(void)handle_it(MG_E_XF, 1, argv); |
390 |
– |
} |
391 |
– |
return(MG_OK); |
392 |
– |
} |
393 |
– |
|
394 |
– |
|
365 |
|
/**************************************************************************** |
366 |
|
* The following routines handle unsupported entities |
367 |
|
*/ |
377 |
|
|
378 |
|
|
379 |
|
static int |
410 |
– |
reload_file() /* reload current MGF file */ |
411 |
– |
{ |
412 |
– |
register int rval; |
413 |
– |
|
414 |
– |
if ((rval = mg_rewind()) != MG_OK) |
415 |
– |
return(rval); |
416 |
– |
while (mg_read()) |
417 |
– |
if ((rval = mg_parse()) != MG_OK) |
418 |
– |
return(rval); |
419 |
– |
return(MG_OK); |
420 |
– |
} |
421 |
– |
|
422 |
– |
|
423 |
– |
static int |
380 |
|
e_include(ac, av) /* include file */ |
381 |
|
int ac; |
382 |
|
char **av; |
383 |
|
{ |
384 |
+ |
char *xfarg[MG_MAXARGC]; |
385 |
|
MG_FCTXT ictx; |
386 |
|
int rv; |
387 |
|
|
389 |
|
return(MG_EARGC); |
390 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
391 |
|
return(rv); |
392 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
393 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
394 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
395 |
< |
mg_close(); |
396 |
< |
return(MG_EINCL); |
392 |
> |
if (ac > 2) { |
393 |
> |
register int i; |
394 |
> |
|
395 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
396 |
> |
for (i = 1; i < ac-1; i++) |
397 |
> |
xfarg[i] = av[i+1]; |
398 |
> |
xfarg[ac-1] = NULL; |
399 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
400 |
> |
return(rv); |
401 |
|
} |
402 |
+ |
while (!feof(mg_file->fp)) { |
403 |
+ |
while (mg_read()) |
404 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
405 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
406 |
+ |
ictx.lineno, mg_err[rv], |
407 |
+ |
ictx.inpline); |
408 |
+ |
mg_close(); |
409 |
+ |
return(MG_EINCL); |
410 |
+ |
} |
411 |
+ |
if (ac > 2) |
412 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
413 |
+ |
return(rv); |
414 |
+ |
} |
415 |
|
mg_close(); |
416 |
|
return(MG_OK); |
417 |
|
} |
459 |
|
rad = atof(av[2]); |
460 |
|
/* initialize */ |
461 |
|
warpconends = 1; |
462 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
462 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
463 |
|
return(rval); |
464 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
465 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
466 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
467 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
467 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
468 |
|
return(rval); |
469 |
|
r2[0] = '0'; r2[1] = '\0'; |
470 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
471 |
|
theta = i*(PI/2)/mg_nqcdivs; |
472 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
472 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
473 |
|
return(rval); |
474 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
475 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
475 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
476 |
|
return(rval); |
477 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
477 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
478 |
|
return(rval); |
479 |
|
strcpy(r1, r2); |
480 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
481 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
481 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
482 |
|
return(rval); |
483 |
|
} |
484 |
|
warpconends = 0; |
533 |
|
for (j = 0; j < 3; j++) |
534 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
535 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
536 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
536 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
537 |
|
return(rval); |
538 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
538 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
539 |
|
return(rval); |
540 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
541 |
|
/* run outer section */ |
542 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
543 |
|
theta = i*(PI/2)/mg_nqcdivs; |
544 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
544 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
545 |
|
return(rval); |
546 |
|
for (j = 0; j < 3; j++) |
547 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
548 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
549 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
549 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
550 |
|
return(rval); |
551 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
551 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
552 |
|
return(rval); |
553 |
|
strcpy(r1, r2); |
554 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
555 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
555 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
556 |
|
return(rval); |
557 |
|
} |
558 |
|
/* run inner section */ |
562 |
|
for (j = 0; j < 3; j++) |
563 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
564 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
565 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
565 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
566 |
|
return(rval); |
567 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
567 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
568 |
|
return(rval); |
569 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
569 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
570 |
|
return(rval); |
571 |
|
strcpy(r1, r2); |
572 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
573 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
573 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
574 |
|
return(rval); |
575 |
|
} |
576 |
|
warpconends = 0; |
591 |
|
avnew[2] = av[2]; |
592 |
|
avnew[3] = av[3]; |
593 |
|
avnew[4] = av[2]; |
594 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
594 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
595 |
|
} |
596 |
|
|
597 |
|
|
633 |
|
make_axes(u, v, cv->n); |
634 |
|
for (j = 0; j < 3; j++) |
635 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
636 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
636 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
637 |
|
return(rv); |
638 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
638 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
639 |
|
return(rv); |
640 |
|
if (minrad == 0.) { /* closed */ |
641 |
|
v1ent[3] = av[1]; |
642 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
642 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
643 |
|
return(rv); |
644 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
644 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
645 |
|
return(rv); |
646 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
647 |
|
theta = i*(PI/2)/mg_nqcdivs; |
648 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
648 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
649 |
|
return(rv); |
650 |
|
for (j = 0; j < 3; j++) |
651 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
652 |
|
maxrad*u[j]*cos(theta) + |
653 |
|
maxrad*v[j]*sin(theta)); |
654 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
654 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
655 |
|
return(rv); |
656 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
656 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
657 |
|
return(rv); |
658 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
658 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
659 |
|
return(rv); |
660 |
|
} |
661 |
|
} else { /* open */ |
662 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
662 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
663 |
|
return(rv); |
664 |
|
for (j = 0; j < 3; j++) |
665 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
666 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
666 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
667 |
|
return(rv); |
668 |
|
v1ent[3] = "_rv4"; |
669 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
670 |
|
theta = i*(PI/2)/mg_nqcdivs; |
671 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
671 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
672 |
|
return(rv); |
673 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
673 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
674 |
|
return(rv); |
675 |
|
for (j = 0; j < 3; j++) { |
676 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
677 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
678 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
679 |
|
} |
680 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
680 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
681 |
|
return(rv); |
682 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
682 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
683 |
|
return(rv); |
684 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
684 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
685 |
|
return(rv); |
686 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
686 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
687 |
|
return(rv); |
688 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
688 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
689 |
|
return(rv); |
690 |
|
} |
691 |
|
} |
767 |
|
else |
768 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
769 |
|
} |
770 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
770 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
771 |
|
return(rv); |
772 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
772 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
773 |
|
return(rv); |
774 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
774 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
775 |
|
return(rv); |
776 |
|
if (rad1 == 0.) { /* triangles */ |
777 |
|
v1ent[3] = av[1]; |
778 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
778 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
779 |
|
return(rv); |
780 |
|
for (j = 0; j < 3; j++) |
781 |
|
sprintf(n4[j], FLTFMT, w[j]); |
782 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
782 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
783 |
|
return(rv); |
784 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
785 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
786 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
786 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
787 |
|
return(rv); |
788 |
|
for (j = 0; j < 3; j++) { |
789 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
791 |
|
if (n2off > -FHUGE) |
792 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
793 |
|
} |
794 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
794 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
795 |
|
return(rv); |
796 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
796 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
797 |
|
return(rv); |
798 |
|
if (n2off > -FHUGE && |
799 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
799 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
800 |
|
return(rv); |
801 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
801 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
802 |
|
return(rv); |
803 |
|
} |
804 |
|
} else { /* quads */ |
817 |
|
else |
818 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
819 |
|
} |
820 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
820 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
821 |
|
return(rv); |
822 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
822 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
823 |
|
return(rv); |
824 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
824 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
825 |
|
return(rv); |
826 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
827 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
828 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
828 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
829 |
|
return(rv); |
830 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
830 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
831 |
|
return(rv); |
832 |
|
for (j = 0; j < 3; j++) { |
833 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
838 |
|
if (n1off < FHUGE) |
839 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
840 |
|
} |
841 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
841 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
842 |
|
return(rv); |
843 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
843 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
844 |
|
return(rv); |
845 |
|
if (n2off > -FHUGE && |
846 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
846 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
847 |
|
return(rv); |
848 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
848 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
849 |
|
return(rv); |
850 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
850 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
851 |
|
return(rv); |
852 |
|
if (n1off < FHUGE && |
853 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
853 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
854 |
|
return(rv); |
855 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
855 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
856 |
|
return(rv); |
857 |
|
} |
858 |
|
} |
866 |
|
char **av; |
867 |
|
{ |
868 |
|
static char p[3][24]; |
869 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
869 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
870 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
871 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
872 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
873 |
|
double length; |
874 |
+ |
int hasnorm; |
875 |
|
FVECT v1, v2, v3, norm; |
876 |
|
register C_VERTEX *cv; |
877 |
|
C_VERTEX *cv0; |
878 |
|
int rv; |
879 |
|
register int i, j; |
880 |
< |
|
880 |
> |
/* check arguments */ |
881 |
|
if (ac < 5) |
882 |
|
return(MG_EARGC); |
883 |
|
if (!isflt(av[ac-1])) |
885 |
|
length = atof(av[ac-1]); |
886 |
|
if (length <= FTINY && length >= -FTINY) |
887 |
|
return(MG_EILL); |
888 |
< |
/* do bottom face */ |
889 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
914 |
< |
for (i = 1; i < ac-1; i++) |
915 |
< |
newav[i] = av[i]; |
916 |
< |
newav[i] = NULL; |
917 |
< |
if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) |
918 |
< |
return(rv); |
919 |
< |
/* compute face normal */ |
920 |
< |
if ((cv0 = c_getvert(av[2])) == NULL) |
888 |
> |
/* compute face normal */ |
889 |
> |
if ((cv0 = c_getvert(av[1])) == NULL) |
890 |
|
return(MG_EUNDEF); |
891 |
+ |
hasnorm = 0; |
892 |
|
norm[0] = norm[1] = norm[2] = 0.; |
893 |
|
v1[0] = v1[1] = v1[2] = 0.; |
894 |
|
for (i = 2; i < ac-1; i++) { |
895 |
|
if ((cv = c_getvert(av[i])) == NULL) |
896 |
|
return(MG_EUNDEF); |
897 |
+ |
hasnorm += !is0vect(cv->n); |
898 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
899 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
900 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
906 |
|
} |
907 |
|
if (normalize(norm) == 0.) |
908 |
|
return(MG_EILL); |
909 |
< |
/* create moved vertices */ |
909 |
> |
/* create moved vertices */ |
910 |
|
for (i = 1; i < ac-1; i++) { |
911 |
|
sprintf(nvn[i-1], "_pv%d", i); |
912 |
|
vent[1] = nvn[i-1]; |
913 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
913 |
> |
vent[3] = av[i]; |
914 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
915 |
|
return(rv); |
916 |
|
cv = c_getvert(av[i]); /* checked above */ |
917 |
|
for (j = 0; j < 3; j++) |
918 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
919 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
919 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
920 |
|
return(rv); |
949 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
921 |
|
} |
922 |
< |
/* do top face */ |
923 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
953 |
< |
return(rv); |
922 |
> |
/* make faces */ |
923 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
924 |
|
/* do the side faces */ |
925 |
|
newav[5] = NULL; |
926 |
|
newav[3] = av[ac-2]; |
928 |
|
for (i = 1; i < ac-1; i++) { |
929 |
|
newav[1] = nvn[i-1]; |
930 |
|
newav[2] = av[i]; |
931 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
931 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
932 |
|
return(rv); |
933 |
|
newav[3] = newav[2]; |
934 |
|
newav[4] = newav[1]; |
935 |
+ |
} |
936 |
+ |
/* do top face */ |
937 |
+ |
for (i = 1; i < ac-1; i++) { |
938 |
+ |
if (hasnorm) { /* zero normals */ |
939 |
+ |
vent[1] = nvn[i-1]; |
940 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
941 |
+ |
return(rv); |
942 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
943 |
+ |
return(rv); |
944 |
+ |
} |
945 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
946 |
+ |
} |
947 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
948 |
+ |
return(rv); |
949 |
+ |
/* do bottom face */ |
950 |
+ |
if (hasnorm) |
951 |
+ |
for (i = 1; i < ac-1; i++) { |
952 |
+ |
vent[1] = nvn[i-1]; |
953 |
+ |
vent[3] = av[i]; |
954 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
955 |
+ |
return(rv); |
956 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
957 |
+ |
return(rv); |
958 |
+ |
newav[i] = nvn[i-1]; |
959 |
+ |
} |
960 |
+ |
else |
961 |
+ |
for (i = 1; i < ac-1; i++) |
962 |
+ |
newav[i] = av[i]; |
963 |
+ |
newav[i] = NULL; |
964 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
965 |
+ |
return(rv); |
966 |
+ |
return(MG_OK); |
967 |
+ |
} |
968 |
+ |
|
969 |
+ |
|
970 |
+ |
static int |
971 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
972 |
+ |
int ac; |
973 |
+ |
char **av; |
974 |
+ |
{ |
975 |
+ |
static char xbuf[24], ybuf[24]; |
976 |
+ |
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
977 |
+ |
int rv; |
978 |
+ |
|
979 |
+ |
c_ccvt(c_ccolor, C_CSXY); |
980 |
+ |
/* if it's really their handler, use it */ |
981 |
+ |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
982 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
983 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
984 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
985 |
+ |
return(rv); |
986 |
+ |
} |
987 |
+ |
return(MG_OK); |
988 |
+ |
} |
989 |
+ |
|
990 |
+ |
|
991 |
+ |
static int |
992 |
+ |
e_cmix(ac, av) /* handle mixing of colors */ |
993 |
+ |
int ac; |
994 |
+ |
char **av; |
995 |
+ |
{ |
996 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
997 |
+ |
char *newav[C_CNSS+4]; |
998 |
+ |
int rv; |
999 |
+ |
register int i; |
1000 |
+ |
/* |
1001 |
+ |
* Contorted logic works as follows: |
1002 |
+ |
* 1. the colors are already mixed in c_hcolor() support function |
1003 |
+ |
* 2. if we would handle a spectral result, make sure it's not |
1004 |
+ |
* 3. if c_hcolor() would handle a spectral result, don't bother |
1005 |
+ |
* 4. otherwise, make cspec entity and pass it to their handler |
1006 |
+ |
* 5. if we have only xy results, handle it as c_spec() would |
1007 |
+ |
*/ |
1008 |
+ |
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1009 |
+ |
c_ccvt(c_ccolor, C_CSXY); |
1010 |
+ |
else if (c_ccolor->flags & C_CDSPEC) { |
1011 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1012 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1013 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1014 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1015 |
+ |
newav[1] = wl[0]; |
1016 |
+ |
newav[2] = wl[1]; |
1017 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1018 |
+ |
sprintf(vbuf[i], "%.6f", |
1019 |
+ |
(double)c_ccolor->ssamp[i] / |
1020 |
+ |
c_ccolor->ssum); |
1021 |
+ |
newav[i+3] = vbuf[i]; |
1022 |
+ |
} |
1023 |
+ |
newav[C_CNSS+3] = NULL; |
1024 |
+ |
if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1025 |
+ |
return(rv); |
1026 |
+ |
} |
1027 |
+ |
return(MG_OK); |
1028 |
+ |
} |
1029 |
+ |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1030 |
+ |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1031 |
+ |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1032 |
+ |
newav[0] = mg_ename[MG_E_CXY]; |
1033 |
+ |
newav[1] = vbuf[0]; |
1034 |
+ |
newav[2] = vbuf[1]; |
1035 |
+ |
newav[3] = NULL; |
1036 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK) |
1037 |
+ |
return(rv); |
1038 |
|
} |
1039 |
|
return(MG_OK); |
1040 |
|
} |