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.11 by greg, Fri Apr 23 00:56:27 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  pathnames[12800];
43 >        char  *pns = pathnames;
44 >        char  *matinp[128];
45 >        char  *cp;
46 >        int  i, j;
47  
48          progname = argv[0];
49          ofun[OBJ_FACE].funp = o_face;
# Line 44 | Line 56 | char  *argv[];
56                  case 'r':                               /* resolution limit */
57                          resolu = atoi(argv[++i]);
58                          break;
59 +                case 'a':                               /* material file */
60 +                        matinp[nmatf++] = argv[++i];
61 +                        break;
62 +                case 'l':                               /* library material */
63 +                        cp = getpath(argv[++i], getrlibpath(), R_OK);
64 +                        if (cp == NULL) {
65 +                                sprintf(errmsg,
66 +                                        "cannot find library material: '%s'",
67 +                                                argv[i]);
68 +                                error(USER, errmsg);
69 +                        }
70 +                        matinp[nmatf++] = strcpy(pns, cp);
71 +                        while (*pns++)
72 +                                ;
73 +                        break;
74                  case 'w':                               /* supress warnings */
75                          nowarn = 1;
76                          break;
# Line 52 | Line 79 | char  *argv[];
79                          error(USER, errmsg);
80                          break;
81                  }
82 +
83 +        if (i < argc-2)
84 +                error(USER, "too many file arguments");
85                                          /* initialize mesh */
86          cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
87 <
88 <        if (i == argc)                  /* read .OBJ file into triangles */
87 >                                        /* load material input */
88 >        for (j = 0; j < nmatf; j++)
89 >                readobj(matinp[j]);
90 >                                        /* read .OBJ file into triangles */
91 >        if (i == argc)
92                  wfreadobj(NULL);
93          else
94                  wfreadobj(argv[i]);
# Line 65 | Line 98 | char  *argv[];
98          if (i == argc-2)                /* open output file */
99                  if (freopen(argv[i+1], "w", stdout) == NULL)
100                          error(SYSTEM, "cannot open output file");
101 < #ifdef MSDOS
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
101 >        SET_FILE_BINARY(stdout);
102          newheader("RADIANCE", stdout);  /* new binary file header */
103          printargs(i<argc ? i+1 : argc, argv, stdout);
104          fputformat(MESHFMT, stdout);
# Line 76 | Line 107 | char  *argv[];
107          mincusize = ourmesh->mcube.cusize / resolu - FTINY;
108  
109          for (i = 0; i < nobjects; i++)  /* add triangles to octree */
110 <                addface(&ourmesh->mcube, i);
110 >                if (objptr(i)->otype == OBJ_FACE)
111 >                        addface(&ourmesh->mcube, i);
112  
113                                          /* optimize octree */
114          ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);
# Line 88 | Line 120 | char  *argv[];
120  
121          writemesh(ourmesh, stdout);     /* write mesh to output */
122          
123 < printmeshstats(ourmesh, stderr);
123 >        /* printmeshstats(ourmesh, stderr); */
124  
125          quit(0);
126 +        return 0; /* pro forma return */
127   }
128  
129  
130   void
131 < quit(code)                              /* exit program */
132 < int  code;
131 > quit(                           /* exit program */
132 >        int  code
133 > )
134   {
135          exit(code);
136   }
137  
138  
139   void
140 < cputs()                                 /* interactive error */
140 > cputs(void)                                     /* interactive error */
141   {
142          /* referenced, but not used */
143   }
144  
145  
146   void
147 < wputs(s)                                /* warning message */
148 < char  *s;
147 > wputs(                          /* warning message */
148 >        char  *s
149 > )
150   {
151          if (!nowarn)
152                  eputs(s);
# Line 119 | Line 154 | char  *s;
154  
155  
156   void
157 < eputs(s)                                /* put string to stderr */
158 < register char  *s;
157 > eputs(                          /* put string to stderr */
158 >        register char  *s
159 > )
160   {
161          static int  inln = 0;
162  
# Line 134 | Line 170 | register char  *s;
170   }
171  
172  
173 < addface(cu, obj)                        /* add a face to a cube */
174 < register CUBE  *cu;
175 < OBJECT  obj;
173 > static void
174 > addface(                        /* add a face to a cube */
175 >        register CUBE  *cu,
176 >        OBJECT  obj
177 > )
178   {
141        CUBE  cukid;
142        OCTREE  ot;
143        OBJECT  oset[MAXSET+1];
144        register int  i, j;
179  
180          if (o_face(objptr(obj), cu) == O_MISS)
181                  return;
182  
183          if (istree(cu->cutree)) {
184 <                                                /* do children */
184 >                CUBE  cukid;                    /* do children */
185 >                int  i, j;
186                  cukid.cusize = cu->cusize * 0.5;
187                  for (i = 0; i < 8; i++) {
188                          cukid.cutree = octkid(cu->cutree, i);
# Line 162 | Line 197 | OBJECT obj;
197                  return;
198          }
199          if (isempty(cu->cutree)) {
200 <                                                /* singular set */
200 >                OBJECT  oset[2];                /* singular set */
201                  oset[0] = 1; oset[1] = obj;
202                  cu->cutree = fullnode(oset);
203                  return;
204          }
205                                          /* add to full node */
206 +        add2full(cu, obj);
207 + }
208 +
209 +
210 + static void
211 + add2full(                       /* add object to full node */
212 +        register CUBE  *cu,
213 +        OBJECT  obj
214 + )
215 + {
216 +        OCTREE  ot;
217 +        OBJECT  oset[MAXSET+1];
218 +        CUBE  cukid;
219 +        register int  i, j;
220 +
221          objset(oset, cu->cutree);
222          cukid.cusize = cu->cusize * 0.5;
223  
224 <        if (oset[0] < objlim || cukid.cusize < mincusize) {
224 >        if (oset[0] < objlim || cukid.cusize <
225 >                        (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
226                                                  /* add to set */
227                  if (oset[0] >= MAXSET) {
228 <                        sprintf(errmsg, "set overflow in addface (%s)",
228 >                        sprintf(errmsg, "set overflow in addobject (%s)",
229                                          objptr(obj)->oname);
230                          error(INTERNAL, errmsg);
231                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines