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

Comparing ray/src/ot/obj2mesh.c (file contents):
Revision 2.1 by greg, Tue Mar 11 17:08:55 2003 UTC vs.
Revision 2.18 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   */
7  
8   #include "copyright.h"
9 + #include "paths.h"
10 + #include "platform.h"
11   #include "standard.h"
12 + #include "resolu.h"
13   #include "cvmesh.h"
14   #include "otypes.h"
15  
16 < extern int      o_face();
16 > extern int      o_face(); /* XXX should go to a header file */
17  
18   int     o_default() { return(O_MISS); }
19  
20   FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* needed for link resolution */
21  
19 char  *progname;                        /* argv[0] */
20
22   int  nowarn = 0;                        /* supress warnings? */
23  
24 < int  objlim = 15;                       /* # of objects before split */
24 > int  objlim = 9;                        /* # of objects before split */
25  
26   int  resolu = 16384;                    /* octree resolution limit */
27  
28   double  mincusize;                      /* minimum cube size from resolu */
29  
30 + static void addface(CUBE  *cu, OBJECT   obj);
31 + static void add2full(CUBE  *cu, OBJECT  obj);
32  
33 < main(argc, argv)                /* compile a .OBJ file into a mesh */
34 < int  argc;
35 < char  *argv[];
33 >
34 > int
35 > main(           /* compile a .OBJ file into a mesh */
36 >        int  argc,
37 >        char  *argv[]
38 > )
39   {
40 <        int  i;
40 >        int  verbose = 0;
41 >        char  *cp;
42 >        int  i, j;
43  
44 <        progname = argv[0];
44 >        fixargv0(argv[0]);              /* sets global progname */
45 >
46          ofun[OBJ_FACE].funp = o_face;
47  
48          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 44 | Line 53 | char  *argv[];
53                  case 'r':                               /* resolution limit */
54                          resolu = atoi(argv[++i]);
55                          break;
56 +                case 'a':                               /* material file */
57 +                        readobj(argv[++i]);
58 +                        break;
59 +                case 'l':                               /* library material */
60 +                        cp = getpath(argv[++i], getrlibpath(), R_OK);
61 +                        if (cp == NULL) {
62 +                                sprintf(errmsg,
63 +                                        "cannot find library material: '%s'",
64 +                                                argv[i]);
65 +                                error(SYSTEM, errmsg);
66 +                        }
67 +                        readobj(cp);
68 +                        break;
69                  case 'w':                               /* supress warnings */
70                          nowarn = 1;
71                          break;
72 +                case 'v':                               /* print mesh stats */
73 +                        verbose = 1;
74 +                        break;
75                  default:
76                          sprintf(errmsg, "unknown option: '%s'", argv[i]);
77                          error(USER, errmsg);
78                          break;
79                  }
80 +
81 +        if (i < argc-2)
82 +                error(USER, "too many file arguments");
83                                          /* initialize mesh */
84          cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
85 <
86 <        if (i == argc)                  /* read .OBJ file into triangles */
85 >                                        /* read .OBJ file into triangles */
86 >        if (i == argc)
87                  wfreadobj(NULL);
88          else
89                  wfreadobj(argv[i]);
# Line 65 | Line 93 | char  *argv[];
93          if (i == argc-2)                /* open output file */
94                  if (freopen(argv[i+1], "w", stdout) == NULL)
95                          error(SYSTEM, "cannot open output file");
96 < #ifdef MSDOS
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
96 >        SET_FILE_BINARY(stdout);
97          newheader("RADIANCE", stdout);  /* new binary file header */
98          printargs(i<argc ? i+1 : argc, argv, stdout);
99          fputformat(MESHFMT, stdout);
# Line 76 | Line 102 | char  *argv[];
102          mincusize = ourmesh->mcube.cusize / resolu - FTINY;
103  
104          for (i = 0; i < nobjects; i++)  /* add triangles to octree */
105 <                addface(&ourmesh->mcube, i);
105 >                if (objptr(i)->otype == OBJ_FACE)
106 >                        addface(&ourmesh->mcube, i);
107  
108                                          /* optimize octree */
109          ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);
# Line 88 | Line 115 | char  *argv[];
115  
116          writemesh(ourmesh, stdout);     /* write mesh to output */
117          
118 < printmeshstats(ourmesh, stderr);
118 >        if (verbose)
119 >                printmeshstats(ourmesh, stderr);
120  
121          quit(0);
122 +        return 0; /* pro forma return */
123   }
124  
125  
126   void
127 < quit(code)                              /* exit program */
128 < int  code;
127 > quit(                           /* exit program */
128 >        int  code
129 > )
130   {
131          exit(code);
132   }
133  
134  
135   void
136 < cputs()                                 /* interactive error */
136 > cputs(void)                                     /* interactive error */
137   {
138          /* referenced, but not used */
139   }
140  
141  
142   void
143 < wputs(s)                                /* warning message */
144 < char  *s;
143 > wputs(                          /* warning message */
144 >        const char  *s
145 > )
146   {
147          if (!nowarn)
148                  eputs(s);
# Line 119 | Line 150 | char  *s;
150  
151  
152   void
153 < eputs(s)                                /* put string to stderr */
154 < register char  *s;
153 > eputs(                          /* put string to stderr */
154 >        const char  *s
155 > )
156   {
157          static int  inln = 0;
158  
# Line 134 | Line 166 | register char  *s;
166   }
167  
168  
169 < addface(cu, obj)                        /* add a face to a cube */
170 < register CUBE  *cu;
171 < OBJECT  obj;
169 > static void
170 > addface(                        /* add a face to a cube */
171 >        CUBE  *cu,
172 >        OBJECT  obj
173 > )
174   {
141        CUBE  cukid;
142        OCTREE  ot;
143        OBJECT  oset[MAXSET+1];
144        register int  i, j;
175  
176          if (o_face(objptr(obj), cu) == O_MISS)
177                  return;
178  
179          if (istree(cu->cutree)) {
180 <                                                /* do children */
180 >                CUBE  cukid;                    /* do children */
181 >                int  i, j;
182                  cukid.cusize = cu->cusize * 0.5;
183                  for (i = 0; i < 8; i++) {
184                          cukid.cutree = octkid(cu->cutree, i);
# Line 162 | Line 193 | OBJECT obj;
193                  return;
194          }
195          if (isempty(cu->cutree)) {
196 <                                                /* singular set */
196 >                OBJECT  oset[2];                /* singular set */
197                  oset[0] = 1; oset[1] = obj;
198                  cu->cutree = fullnode(oset);
199                  return;
200          }
201                                          /* add to full node */
202 +        add2full(cu, obj);
203 + }
204 +
205 +
206 + static void
207 + add2full(                       /* add object to full node */
208 +        CUBE  *cu,
209 +        OBJECT  obj
210 + )
211 + {
212 +        OCTREE  ot;
213 +        OBJECT  oset[MAXSET+1];
214 +        CUBE  cukid;
215 +        int  i, j;
216 +
217          objset(oset, cu->cutree);
218          cukid.cusize = cu->cusize * 0.5;
219  
220 <        if (oset[0] < objlim || cukid.cusize < mincusize) {
220 >        if (oset[0] < objlim || cukid.cusize <
221 >                        (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
222                                                  /* add to set */
223                  if (oset[0] >= MAXSET) {
224 <                        sprintf(errmsg, "set overflow in addface (%s)",
224 >                        sprintf(errmsg, "set overflow in addobject (%s)",
225                                          objptr(obj)->oname);
226                          error(INTERNAL, errmsg);
227                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines