ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgf2meta.c
Revision: 2.3
Committed: Tue Apr 11 13:32:47 1995 UTC (29 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +7 -3 lines
Log Message:
added colors to layers

File Contents

# Content
1 /* Copyright (c) 1995 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Convert MGF (Materials and Geometry Format) to Metafile 2-d graphics
9 */
10
11 #include <stdio.h>
12 #include <math.h>
13 #include "mgflib/parser.h"
14
15 #define MX(v) (int)(((1<<14)-1)*(v)[(proj_axis+1)%3])
16 #define MY(v) (int)(((1<<14)-1)*(v)[(proj_axis+2)%3])
17
18 int r_face();
19 int proj_axis;
20 double limit[3][2];
21 int layer;
22
23 extern int mg_nqcdivs;
24
25
26 main(argc, argv) /* convert files to stdout */
27 int argc;
28 char *argv[];
29 {
30 int i;
31 /* initialize dispatch table */
32 mg_ehand[MG_E_FACE] = r_face;
33 mg_ehand[MG_E_POINT] = c_hvertex;
34 mg_ehand[MG_E_VERTEX] = c_hvertex;
35 mg_ehand[MG_E_XF] = xf_handler;
36 mg_nqcdivs = 3; /* reduce object subdivision */
37 mg_init(); /* initialize the parser */
38 /* get arguments */
39 if (argc < 8 || (proj_axis = argv[1][0]-'x') < 0 || proj_axis > 2)
40 goto userr;
41 limit[0][0] = atof(argv[2]); limit[0][1] = atof(argv[3]);
42 limit[1][0] = atof(argv[4]); limit[1][1] = atof(argv[5]);
43 limit[2][0] = atof(argv[6]); limit[2][1] = atof(argv[7]);
44
45 if (argc == 8) { /* convert stdin */
46 if (mg_load(NULL) != MG_OK)
47 exit(1);
48 } else /* convert each file */
49 for (i = 8; i < argc; i++) {
50 if (mg_load(argv[i]) != MG_OK)
51 exit(1);
52 if (++layer >= 16) {
53 mendpage();
54 layer = 0;
55 }
56 }
57 mendpage(); /* print page */
58 mdone(); /* close output */
59 exit(0);
60 userr:
61 fprintf(stderr, "Usage: %s {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
62 argv[0]);
63 exit(1);
64 }
65
66
67 int
68 r_face(ac, av) /* convert a face */
69 int ac;
70 char **av;
71 {
72 static FVECT bbmin = {0,0,0}, bbmax = {1,1,1};
73 register int i, j;
74 register C_VERTEX *cv;
75 FVECT v1, v2, vo;
76 int newline = 1;
77
78 if (ac < 4)
79 return(MG_EARGC);
80 /* connect to last point */
81 if ((cv = c_getvert(av[ac-1])) == NULL)
82 return(MG_EUNDEF);
83 xf_xfmpoint(vo, cv->p);
84 for (j = 0; j < 3; j++)
85 vo[j] = (vo[j] - limit[j][0])/(limit[j][1]-limit[j][0]);
86 for (i = 1; i < ac; i++) { /* go around face */
87 if ((cv = c_getvert(av[i])) == NULL)
88 return(MG_EUNDEF);
89 xf_xfmpoint(v2, cv->p);
90 for (j = 0; j < 3; j++)
91 v2[j] = (v2[j] - limit[j][0])/(limit[j][1]-limit[j][0]);
92 VCOPY(v1, vo);
93 VCOPY(vo, v2);
94 if (clip(v1, v2, bbmin, bbmax)) {
95 mline(MX(v1), MY(v1), layer/4, 0, layer%4);
96 mdraw(MX(v2), MY(v2));
97 }
98 }
99 return(MG_OK);
100 }