ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgf2meta.c
(Generate patch)

Comparing ray/src/cv/mgf2meta.c (file contents):
Revision 2.1 by greg, Tue Apr 4 10:20:21 1995 UTC vs.
Revision 2.8 by schorsch, Tue Oct 21 19:19:28 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5 < * Convert MGF (Materials and Geometry Format) to Metafile graphics
5 > * Convert MGF (Materials and Geometry Format) to Metafile 2-d graphics
6   */
7  
8   #include <stdio.h>
9 + #include <stdlib.h>
10 + #include <string.h>
11   #include <math.h>
12 + #include "random.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])
15 > #define MSIZE   ((1<<14)-1)
16 > #define MX(v)   (int)(MSIZE*(v)[(proj_axis+1)%3])
17 > #define MY(v)   (int)(MSIZE*(v)[(proj_axis+2)%3])
18  
19 < int     r_face();
19 > int     r_face(int ac, char **av);
20   int     proj_axis;
21   double  limit[3][2];
22 + int     layer;
23 + long    rthresh = 1;
24  
25   extern int      mg_nqcdivs;
26  
# Line 35 | Line 38 | char   *argv[];
38          mg_nqcdivs = 3;         /* reduce object subdivision */
39          mg_init();              /* initialize the parser */
40                                          /* get arguments */
41 +        if (argc > 9 && !strcmp(argv[1], "-t")) {
42 +                rthresh = atof(argv[2])*MSIZE + 0.5;
43 +                rthresh *= rthresh;
44 +                argv += 2;
45 +                argc -= 2;
46 +        }
47          if (argc < 8 || (proj_axis = argv[1][0]-'x') < 0 || proj_axis > 2)
48                  goto userr;
49          limit[0][0] = atof(argv[2]); limit[0][1] = atof(argv[3]);
# Line 45 | Line 54 | char   *argv[];
54                  if (mg_load(NULL) != MG_OK)
55                          exit(1);
56          } else                          /* convert each file */
57 <                for (i = 8; i < argc; i++)
57 >                for (i = 8; i < argc; i++) {
58                          if (mg_load(argv[i]) != MG_OK)
59                                  exit(1);
60 <        mendpage();                     /* close output */
61 <        mdone();
60 >                        newlayer();
61 >                }
62 >        mendpage();                     /* print page */
63 >        mdone();                        /* close output */
64          exit(0);
65   userr:
66 <        fprintf(stderr, "Usage: %s {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
67 <                        argv[0]);
66 >        fputs("Usage: mgf2meta [-t thresh] {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
67 >                        stderr);
68          exit(1);
69   }
70  
# Line 67 | Line 78 | char   **av;
78          register int    i, j;
79          register C_VERTEX       *cv;
80          FVECT   v1, v2, vo;
70        int     newline = 1;
81  
82          if (ac < 4)
83                  return(MG_EARGC);
# Line 85 | Line 95 | char   **av;
95                          v2[j] = (v2[j] - limit[j][0])/(limit[j][1]-limit[j][0]);
96                  VCOPY(v1, vo);
97                  VCOPY(vo, v2);
98 <                if (clip(v1, v2, bbmin, bbmax)) {
99 <                        mline(MX(v1), MY(v1), 0, 0, 0);
90 <                        mdraw(MX(v2), MY(v2));
91 <                }
98 >                if (clip(v1, v2, bbmin, bbmax))
99 >                        doline(MX(v1), MY(v1), MX(v2), MY(v2));
100          }
101          return(MG_OK);
102 + }
103 +
104 +
105 + #define  HTBLSIZ        16381           /* prime hash table size */
106 +
107 + short   hshtab[HTBLSIZ][4];             /* done line segments */
108 +
109 + #define  hash(mx1,my1,mx2,my2)  ((long)(mx1)<<15 ^ (long)(my1)<<10 ^ \
110 +                                        (long)(mx2)<<5 ^ (long)(my2))
111 +
112 +
113 + newlayer()                              /* start a new layer */
114 + {
115 +        (void)memset((char *)hshtab, '\0', sizeof(hshtab));
116 +        if (++layer >= 16) {
117 +                mendpage();
118 +                layer = 0;
119 +        }
120 + }
121 +
122 +
123 + int
124 + doline(v1x, v1y, v2x, v2y)              /* draw line conditionally */
125 + int     v1x, v1y, v2x, v2y;
126 + {
127 +        register int    h;
128 +
129 +        if (v1x > v2x || (v1x == v2x && v1y > v2y)) {   /* sort endpoints */
130 +                h=v1x; v1x=v2x; v2x=h;
131 +                h=v1y; v1y=v2y; v2y=h;
132 +        }
133 +        h = hash(v1x, v1y, v2x, v2y) % HTBLSIZ;
134 +        if (hshtab[h][0] == v1x && hshtab[h][1] == v1y &&
135 +                        hshtab[h][2] == v2x && hshtab[h][3] == v2y)
136 +                return(0);
137 +        hshtab[h][0] = v1x; hshtab[h][1] = v1y;
138 +        hshtab[h][2] = v2x; hshtab[h][3] = v2y;
139 +        if ((long)(v2x-v1x)*(v2x-v1x) + (long)(v2y-v1y)*(v2y-v1y)
140 +                        <= random() % rthresh)
141 +                return(0);
142 +        mline(v1x, v1y, layer/4, 0, layer%4);
143 +        mdraw(v2x, v2y);
144 +        return(1);
145   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines