ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgf2meta.c
Revision: 2.2
Committed: Tue Apr 4 11:06:53 1995 UTC (29 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +8 -6 lines
Log Message:
bug fix

File Contents

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