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.10 by greg, Thu Apr 22 17:35:54 2004 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   */
7  
8   #include "copyright.h"
9 + #include "platform.h"
10   #include "standard.h"
11 + #include "resolu.h"
12   #include "cvmesh.h"
13   #include "otypes.h"
14  
15 < extern int      o_face();
15 > extern int      o_face(); /* XXX should go to a header file */
16  
17   int     o_default() { return(O_MISS); }
18  
# Line 26 | Line 28 | int  resolu = 16384;                   /* octree resolution limit */
28  
29   double  mincusize;                      /* minimum cube size from resolu */
30  
31 + static void addface(CUBE  *cu, OBJECT   obj);
32 + static void add2full(CUBE  *cu, OBJECT  obj);
33  
34 < main(argc, argv)                /* compile a .OBJ file into a mesh */
35 < int  argc;
36 < char  *argv[];
34 >
35 > int
36 > main(           /* compile a .OBJ file into a mesh */
37 >        int  argc,
38 >        char  *argv[]
39 > )
40   {
41 <        int  i;
41 >        int  nmatf = 0;
42 >        char  *matinp[32];
43 >        int  i, j;
44  
45          progname = argv[0];
46          ofun[OBJ_FACE].funp = o_face;
# Line 44 | Line 53 | char  *argv[];
53                  case 'r':                               /* resolution limit */
54                          resolu = atoi(argv[++i]);
55                          break;
56 +                case 'a':                               /* material file */
57 +                        matinp[nmatf++] = argv[++i];
58 +                        break;
59                  case 'w':                               /* supress warnings */
60                          nowarn = 1;
61                          break;
# Line 52 | Line 64 | char  *argv[];
64                          error(USER, errmsg);
65                          break;
66                  }
67 +
68 +        if (i < argc-2)
69 +                error(USER, "too many file arguments");
70                                          /* initialize mesh */
71          cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
72 <
73 <        if (i == argc)                  /* read .OBJ file into triangles */
72 >                                        /* load material input */
73 >        for (j = 0; j < nmatf; j++)
74 >                readobj(matinp[j]);
75 >                                        /* read .OBJ file into triangles */
76 >        if (i == argc)
77                  wfreadobj(NULL);
78          else
79                  wfreadobj(argv[i]);
# Line 65 | Line 83 | char  *argv[];
83          if (i == argc-2)                /* open output file */
84                  if (freopen(argv[i+1], "w", stdout) == NULL)
85                          error(SYSTEM, "cannot open output file");
86 < #ifdef MSDOS
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
86 >        SET_FILE_BINARY(stdout);
87          newheader("RADIANCE", stdout);  /* new binary file header */
88          printargs(i<argc ? i+1 : argc, argv, stdout);
89          fputformat(MESHFMT, stdout);
# Line 76 | Line 92 | char  *argv[];
92          mincusize = ourmesh->mcube.cusize / resolu - FTINY;
93  
94          for (i = 0; i < nobjects; i++)  /* add triangles to octree */
95 <                addface(&ourmesh->mcube, i);
95 >                if (objptr(i)->otype == OBJ_FACE)
96 >                        addface(&ourmesh->mcube, i);
97  
98                                          /* optimize octree */
99          ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);
# Line 88 | Line 105 | char  *argv[];
105  
106          writemesh(ourmesh, stdout);     /* write mesh to output */
107          
108 < printmeshstats(ourmesh, stderr);
108 >        /* printmeshstats(ourmesh, stderr); */
109  
110          quit(0);
111 +        return 0; /* pro forma return */
112   }
113  
114  
115   void
116 < quit(code)                              /* exit program */
117 < int  code;
116 > quit(                           /* exit program */
117 >        int  code
118 > )
119   {
120          exit(code);
121   }
122  
123  
124   void
125 < cputs()                                 /* interactive error */
125 > cputs(void)                                     /* interactive error */
126   {
127          /* referenced, but not used */
128   }
129  
130  
131   void
132 < wputs(s)                                /* warning message */
133 < char  *s;
132 > wputs(                          /* warning message */
133 >        char  *s
134 > )
135   {
136          if (!nowarn)
137                  eputs(s);
# Line 119 | Line 139 | char  *s;
139  
140  
141   void
142 < eputs(s)                                /* put string to stderr */
143 < register char  *s;
142 > eputs(                          /* put string to stderr */
143 >        register char  *s
144 > )
145   {
146          static int  inln = 0;
147  
# Line 134 | Line 155 | register char  *s;
155   }
156  
157  
158 < addface(cu, obj)                        /* add a face to a cube */
159 < register CUBE  *cu;
160 < OBJECT  obj;
158 > static void
159 > addface(                        /* add a face to a cube */
160 >        register CUBE  *cu,
161 >        OBJECT  obj
162 > )
163   {
141        CUBE  cukid;
142        OCTREE  ot;
143        OBJECT  oset[MAXSET+1];
144        register int  i, j;
164  
165          if (o_face(objptr(obj), cu) == O_MISS)
166                  return;
167  
168          if (istree(cu->cutree)) {
169 <                                                /* do children */
169 >                CUBE  cukid;                    /* do children */
170 >                int  i, j;
171                  cukid.cusize = cu->cusize * 0.5;
172                  for (i = 0; i < 8; i++) {
173                          cukid.cutree = octkid(cu->cutree, i);
# Line 162 | Line 182 | OBJECT obj;
182                  return;
183          }
184          if (isempty(cu->cutree)) {
185 <                                                /* singular set */
185 >                OBJECT  oset[2];                /* singular set */
186                  oset[0] = 1; oset[1] = obj;
187                  cu->cutree = fullnode(oset);
188                  return;
189          }
190                                          /* add to full node */
191 +        add2full(cu, obj);
192 + }
193 +
194 +
195 + static void
196 + add2full(                       /* add object to full node */
197 +        register CUBE  *cu,
198 +        OBJECT  obj
199 + )
200 + {
201 +        OCTREE  ot;
202 +        OBJECT  oset[MAXSET+1];
203 +        CUBE  cukid;
204 +        register int  i, j;
205 +
206          objset(oset, cu->cutree);
207          cukid.cusize = cu->cusize * 0.5;
208  
209 <        if (oset[0] < objlim || cukid.cusize < mincusize) {
209 >        if (oset[0] < objlim || cukid.cusize <
210 >                        (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
211                                                  /* add to set */
212                  if (oset[0] >= MAXSET) {
213 <                        sprintf(errmsg, "set overflow in addface (%s)",
213 >                        sprintf(errmsg, "set overflow in addobject (%s)",
214                                          objptr(obj)->oname);
215                          error(INTERNAL, errmsg);
216                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines