ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgf2meta.c
Revision: 2.1
Committed: Tue Apr 4 10:20:21 1995 UTC (29 years ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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     * Convert MGF (Materials and Geometry Format) to Metafile graphics
9     */
10    
11     #include <stdio.h>
12     #include <math.h>
13     #include "mgflib/parser.h"
14    
15     #define MX(v) (int)((1<<14)*(v)[(proj_axis+1)%3])
16     #define MY(v) (int)((1<<14)*(v)[(proj_axis+2)%3])
17    
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     } else /* convert each file */
48     for (i = 8; i < argc; i++)
49     if (mg_load(argv[i]) != MG_OK)
50     exit(1);
51     mendpage(); /* close output */
52     mdone();
53     exit(0);
54     userr:
55     fprintf(stderr, "Usage: %s {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
56     argv[0]);
57     exit(1);
58     }
59    
60    
61     int
62     r_face(ac, av) /* convert a face */
63     int ac;
64     char **av;
65     {
66     static FVECT bbmin = {0,0,0}, bbmax = {1,1,1};
67     register int i, j;
68     register C_VERTEX *cv;
69     FVECT v1, v2, vo;
70     int newline = 1;
71    
72     if (ac < 4)
73     return(MG_EARGC);
74     /* connect to last point */
75     if ((cv = c_getvert(av[ac-1])) == NULL)
76     return(MG_EUNDEF);
77     xf_xfmpoint(vo, cv->p);
78     for (j = 0; j < 3; j++)
79     vo[j] = (vo[j] - limit[j][0])/(limit[j][1]-limit[j][0]);
80     for (i = 1; i < ac; i++) { /* go around face */
81     if ((cv = c_getvert(av[i])) == NULL)
82     return(MG_EUNDEF);
83     xf_xfmpoint(v2, cv->p);
84     for (j = 0; j < 3; j++)
85     v2[j] = (v2[j] - limit[j][0])/(limit[j][1]-limit[j][0]);
86     VCOPY(v1, vo);
87     VCOPY(vo, v2);
88     if (clip(v1, v2, bbmin, bbmax)) {
89     mline(MX(v1), MY(v1), 0, 0, 0);
90     mdraw(MX(v2), MY(v2));
91     }
92     }
93     return(MG_OK);
94     }