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.15 by greg, Fri Mar 3 01:25:27 2017 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  
# Line 20 | Line 23 | char  *progname;                       /* argv[0] */
23  
24   int  nowarn = 0;                        /* supress warnings? */
25  
26 < int  objlim = 15;                       /* # of objects before split */
26 > int  objlim = 9;                        /* # of objects before split */
27  
28   int  resolu = 16384;                    /* octree resolution limit */
29  
30   double  mincusize;                      /* minimum cube size from resolu */
31  
32 + static void addface(CUBE  *cu, OBJECT   obj);
33 + static void add2full(CUBE  *cu, OBJECT  obj);
34  
35 < main(argc, argv)                /* compile a .OBJ file into a mesh */
36 < int  argc;
37 < char  *argv[];
35 >
36 > int
37 > main(           /* compile a .OBJ file into a mesh */
38 >        int  argc,
39 >        char  *argv[]
40 > )
41   {
42 <        int  i;
42 >        int  nmatf = 0;
43 >        int  verbose = 0;
44 >        char  pathnames[12800];
45 >        char  *pns = pathnames;
46 >        char  *matinp[128];
47 >        char  *cp;
48 >        int  i, j;
49  
50          progname = argv[0];
51          ofun[OBJ_FACE].funp = o_face;
# Line 44 | Line 58 | char  *argv[];
58                  case 'r':                               /* resolution limit */
59                          resolu = atoi(argv[++i]);
60                          break;
61 +                case 'a':                               /* material file */
62 +                        matinp[nmatf++] = argv[++i];
63 +                        break;
64 +                case 'l':                               /* library material */
65 +                        cp = getpath(argv[++i], getrlibpath(), R_OK);
66 +                        if (cp == NULL) {
67 +                                sprintf(errmsg,
68 +                                        "cannot find library material: '%s'",
69 +                                                argv[i]);
70 +                                error(SYSTEM, errmsg);
71 +                        }
72 +                        matinp[nmatf++] = strcpy(pns, cp);
73 +                        while (*pns++)
74 +                                ;
75 +                        break;
76                  case 'w':                               /* supress warnings */
77                          nowarn = 1;
78                          break;
79 +                case 'v':                               /* print mesh stats */
80 +                        verbose = 1;
81 +                        break;
82                  default:
83                          sprintf(errmsg, "unknown option: '%s'", argv[i]);
84                          error(USER, errmsg);
85                          break;
86                  }
87 +
88 +        if (i < argc-2)
89 +                error(USER, "too many file arguments");
90                                          /* initialize mesh */
91          cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
92 <
93 <        if (i == argc)                  /* read .OBJ file into triangles */
92 >                                        /* load material input */
93 >        for (j = 0; j < nmatf; j++)
94 >                readobj(matinp[j]);
95 >                                        /* read .OBJ file into triangles */
96 >        if (i == argc)
97                  wfreadobj(NULL);
98          else
99                  wfreadobj(argv[i]);
# Line 65 | Line 103 | char  *argv[];
103          if (i == argc-2)                /* open output file */
104                  if (freopen(argv[i+1], "w", stdout) == NULL)
105                          error(SYSTEM, "cannot open output file");
106 < #ifdef MSDOS
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
106 >        SET_FILE_BINARY(stdout);
107          newheader("RADIANCE", stdout);  /* new binary file header */
108          printargs(i<argc ? i+1 : argc, argv, stdout);
109          fputformat(MESHFMT, stdout);
# Line 76 | Line 112 | char  *argv[];
112          mincusize = ourmesh->mcube.cusize / resolu - FTINY;
113  
114          for (i = 0; i < nobjects; i++)  /* add triangles to octree */
115 <                addface(&ourmesh->mcube, i);
115 >                if (objptr(i)->otype == OBJ_FACE)
116 >                        addface(&ourmesh->mcube, i);
117  
118                                          /* optimize octree */
119          ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);
# Line 88 | Line 125 | char  *argv[];
125  
126          writemesh(ourmesh, stdout);     /* write mesh to output */
127          
128 < printmeshstats(ourmesh, stderr);
128 >        if (verbose)
129 >                printmeshstats(ourmesh, stderr);
130  
131          quit(0);
132 +        return 0; /* pro forma return */
133   }
134  
135  
136   void
137 < quit(code)                              /* exit program */
138 < int  code;
137 > quit(                           /* exit program */
138 >        int  code
139 > )
140   {
141          exit(code);
142   }
143  
144  
145   void
146 < cputs()                                 /* interactive error */
146 > cputs(void)                                     /* interactive error */
147   {
148          /* referenced, but not used */
149   }
150  
151  
152   void
153 < wputs(s)                                /* warning message */
154 < char  *s;
153 > wputs(                          /* warning message */
154 >        char  *s
155 > )
156   {
157          if (!nowarn)
158                  eputs(s);
# Line 119 | Line 160 | char  *s;
160  
161  
162   void
163 < eputs(s)                                /* put string to stderr */
164 < register char  *s;
163 > eputs(                          /* put string to stderr */
164 >        register char  *s
165 > )
166   {
167          static int  inln = 0;
168  
# Line 134 | Line 176 | register char  *s;
176   }
177  
178  
179 < addface(cu, obj)                        /* add a face to a cube */
180 < register CUBE  *cu;
181 < OBJECT  obj;
179 > static void
180 > addface(                        /* add a face to a cube */
181 >        register CUBE  *cu,
182 >        OBJECT  obj
183 > )
184   {
141        CUBE  cukid;
142        OCTREE  ot;
143        OBJECT  oset[MAXSET+1];
144        register int  i, j;
185  
186          if (o_face(objptr(obj), cu) == O_MISS)
187                  return;
188  
189          if (istree(cu->cutree)) {
190 <                                                /* do children */
190 >                CUBE  cukid;                    /* do children */
191 >                int  i, j;
192                  cukid.cusize = cu->cusize * 0.5;
193                  for (i = 0; i < 8; i++) {
194                          cukid.cutree = octkid(cu->cutree, i);
# Line 162 | Line 203 | OBJECT obj;
203                  return;
204          }
205          if (isempty(cu->cutree)) {
206 <                                                /* singular set */
206 >                OBJECT  oset[2];                /* singular set */
207                  oset[0] = 1; oset[1] = obj;
208                  cu->cutree = fullnode(oset);
209                  return;
210          }
211                                          /* add to full node */
212 +        add2full(cu, obj);
213 + }
214 +
215 +
216 + static void
217 + add2full(                       /* add object to full node */
218 +        register CUBE  *cu,
219 +        OBJECT  obj
220 + )
221 + {
222 +        OCTREE  ot;
223 +        OBJECT  oset[MAXSET+1];
224 +        CUBE  cukid;
225 +        register int  i, j;
226 +
227          objset(oset, cu->cutree);
228          cukid.cusize = cu->cusize * 0.5;
229  
230 <        if (oset[0] < objlim || cukid.cusize < mincusize) {
230 >        if (oset[0] < objlim || cukid.cusize <
231 >                        (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
232                                                  /* add to set */
233                  if (oset[0] >= MAXSET) {
234 <                        sprintf(errmsg, "set overflow in addface (%s)",
234 >                        sprintf(errmsg, "set overflow in addobject (%s)",
235                                          objptr(obj)->oname);
236                          error(INTERNAL, errmsg);
237                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines