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.4 by greg, Thu May 4 13:55:30 1995 UTC vs.
Revision 2.9 by schorsch, Sat Nov 15 17:54:06 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 2-d graphics
6   */
7  
8   #include <stdio.h>
9 + #include <stdlib.h>
10 + #include <string.h>
11   #include <math.h>
12 +
13 + #include "meta.h"
14   #include "random.h"
15   #include "mgflib/parser.h"
16 + #include "plocate.h" /* XXX shouldn't this rather be in rtmath.h? */
17  
18 < #define MX(v)   (int)(((1<<14)-1)*(v)[(proj_axis+1)%3])
19 < #define MY(v)   (int)(((1<<14)-1)*(v)[(proj_axis+2)%3])
18 > #define MSIZE   ((1<<14)-1)
19 > #define MX(v)   (int)(MSIZE*(v)[(proj_axis+1)%3])
20 > #define MY(v)   (int)(MSIZE*(v)[(proj_axis+2)%3])
21  
19 int     r_face();
22   int     proj_axis;
23   double  limit[3][2];
24   int     layer;
25 + long    rthresh = 1;
26  
27   extern int      mg_nqcdivs;
28  
29 + static int r_face(int ac, char **av);
30 + static void newlayer(void);
31 + static int doline(int v1x, int v1y, int v2x, int v2y);
32  
33 < main(argc, argv)                /* convert files to stdout */
34 < int     argc;
35 < char    *argv[];
33 >
34 > int
35 > main(           /* convert files to stdout */
36 >        int     argc,
37 >        char    *argv[]
38 > )
39   {
40          int     i;
41                                  /* initialize dispatch table */
# Line 37 | Line 46 | char   *argv[];
46          mg_nqcdivs = 3;         /* reduce object subdivision */
47          mg_init();              /* initialize the parser */
48                                          /* get arguments */
49 +        if (argc > 9 && !strcmp(argv[1], "-t")) {
50 +                rthresh = atof(argv[2])*MSIZE + 0.5;
51 +                rthresh *= rthresh;
52 +                argv += 2;
53 +                argc -= 2;
54 +        }
55          if (argc < 8 || (proj_axis = argv[1][0]-'x') < 0 || proj_axis > 2)
56                  goto userr;
57          limit[0][0] = atof(argv[2]); limit[0][1] = atof(argv[3]);
# Line 56 | Line 71 | char   *argv[];
71          mdone();                        /* close output */
72          exit(0);
73   userr:
74 <        fprintf(stderr, "Usage: %s {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
75 <                        argv[0]);
74 >        fputs("Usage: mgf2meta [-t thresh] {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n",
75 >                        stderr);
76          exit(1);
77   }
78  
79  
80   int
81 < r_face(ac, av)                  /* convert a face */
82 < int     ac;
83 < char    **av;
81 > r_face(                 /* convert a face */
82 >        int     ac,
83 >        char    **av
84 > )
85   {
86          static FVECT    bbmin = {0,0,0}, bbmax = {1,1,1};
87          register int    i, j;
# Line 102 | Line 118 | short  hshtab[HTBLSIZ][4];             /* done line segments */
118   #define  hash(mx1,my1,mx2,my2)  ((long)(mx1)<<15 ^ (long)(my1)<<10 ^ \
119                                          (long)(mx2)<<5 ^ (long)(my2))
120  
105 #define  RANDMASK       ((1L<<14)-1)
121  
122 <
123 < newlayer()                              /* start a new layer */
122 > void
123 > newlayer(void)                          /* start a new layer */
124   {
125 < #ifdef BSD
111 <        bzero((char *)hshtab, sizeof(hshtab));
112 < #else
113 <        (void)memset((char *)hshtab, 0, sizeof(hshtab));
114 < #endif
125 >        (void)memset((char *)hshtab, '\0', sizeof(hshtab));
126          if (++layer >= 16) {
127                  mendpage();
128                  layer = 0;
# Line 120 | Line 131 | newlayer()                             /* start a new layer */
131  
132  
133   int
134 < doline(v1x, v1y, v2x, v2y)              /* draw line conditionally */
135 < int     v1x, v1y, v2x, v2y;
134 > doline(         /* draw line conditionally */
135 >        int     v1x,
136 >        int v1y,
137 >        int v2x,
138 >        int v2y
139 > )
140   {
141          register int    h;
142  
# Line 136 | Line 151 | int    v1x, v1y, v2x, v2y;
151          hshtab[h][0] = v1x; hshtab[h][1] = v1y;
152          hshtab[h][2] = v2x; hshtab[h][3] = v2y;
153          if ((long)(v2x-v1x)*(v2x-v1x) + (long)(v2y-v1y)*(v2y-v1y)
154 <                        <= (random()&RANDMASK))
154 >                        <= random() % rthresh)
155                  return(0);
156          mline(v1x, v1y, layer/4, 0, layer%4);
157          mdraw(v2x, v2y);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines