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.7 by greg, Mon Jul 14 05:00:45 2003 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 "cvmesh.h"
12   #include "otypes.h"
# Line 31 | Line 32 | main(argc, argv)               /* compile a .OBJ file into a mesh *
32   int  argc;
33   char  *argv[];
34   {
35 <        int  i;
35 >        int  nmatf = 0;
36 >        char  *matinp[32];
37 >        int  i, j;
38  
39          progname = argv[0];
40          ofun[OBJ_FACE].funp = o_face;
# Line 44 | Line 47 | char  *argv[];
47                  case 'r':                               /* resolution limit */
48                          resolu = atoi(argv[++i]);
49                          break;
50 +                case 'a':                               /* material file */
51 +                        matinp[nmatf++] = argv[++i];
52 +                        break;
53                  case 'w':                               /* supress warnings */
54                          nowarn = 1;
55                          break;
# Line 52 | Line 58 | char  *argv[];
58                          error(USER, errmsg);
59                          break;
60                  }
61 +
62 +        if (i < argc-2)
63 +                error(USER, "too many file arguments");
64                                          /* initialize mesh */
65          cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
66 <
67 <        if (i == argc)                  /* read .OBJ file into triangles */
66 >                                        /* load material input */
67 >        for (j = 0; j < nmatf; j++)
68 >                readobj(matinp[j]);
69 >                                        /* read .OBJ file into triangles */
70 >        if (i == argc)
71                  wfreadobj(NULL);
72          else
73                  wfreadobj(argv[i]);
# Line 65 | Line 77 | char  *argv[];
77          if (i == argc-2)                /* open output file */
78                  if (freopen(argv[i+1], "w", stdout) == NULL)
79                          error(SYSTEM, "cannot open output file");
80 < #ifdef MSDOS
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
80 >        SET_FILE_BINARY(stdout);
81          newheader("RADIANCE", stdout);  /* new binary file header */
82          printargs(i<argc ? i+1 : argc, argv, stdout);
83          fputformat(MESHFMT, stdout);
# Line 76 | Line 86 | char  *argv[];
86          mincusize = ourmesh->mcube.cusize / resolu - FTINY;
87  
88          for (i = 0; i < nobjects; i++)  /* add triangles to octree */
89 <                addface(&ourmesh->mcube, i);
89 >                if (objptr(i)->otype == OBJ_FACE)
90 >                        addface(&ourmesh->mcube, i);
91  
92                                          /* optimize octree */
93          ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);
# Line 88 | Line 99 | char  *argv[];
99  
100          writemesh(ourmesh, stdout);     /* write mesh to output */
101          
102 < printmeshstats(ourmesh, stderr);
102 >        /* printmeshstats(ourmesh, stderr); */
103  
104          quit(0);
105   }
# Line 138 | Line 149 | addface(cu, obj)                       /* add a face to a cube */
149   register CUBE  *cu;
150   OBJECT  obj;
151   {
141        CUBE  cukid;
142        OCTREE  ot;
143        OBJECT  oset[MAXSET+1];
144        register int  i, j;
152  
153          if (o_face(objptr(obj), cu) == O_MISS)
154                  return;
155  
156          if (istree(cu->cutree)) {
157 <                                                /* do children */
157 >                CUBE  cukid;                    /* do children */
158 >                int  i, j;
159                  cukid.cusize = cu->cusize * 0.5;
160                  for (i = 0; i < 8; i++) {
161                          cukid.cutree = octkid(cu->cutree, i);
# Line 162 | Line 170 | OBJECT obj;
170                  return;
171          }
172          if (isempty(cu->cutree)) {
173 <                                                /* singular set */
173 >                OBJECT  oset[2];                /* singular set */
174                  oset[0] = 1; oset[1] = obj;
175                  cu->cutree = fullnode(oset);
176                  return;
177          }
178                                          /* add to full node */
179 +        add2full(cu, obj);
180 + }
181 +
182 +
183 + add2full(cu, obj)                       /* add object to full node */
184 + register CUBE  *cu;
185 + OBJECT  obj;
186 + {
187 +        OCTREE  ot;
188 +        OBJECT  oset[MAXSET+1];
189 +        CUBE  cukid;
190 +        register int  i, j;
191 +
192          objset(oset, cu->cutree);
193          cukid.cusize = cu->cusize * 0.5;
194  
195          if (oset[0] < objlim || cukid.cusize < mincusize) {
196                                                  /* add to set */
197                  if (oset[0] >= MAXSET) {
198 <                        sprintf(errmsg, "set overflow in addface (%s)",
198 >                        sprintf(errmsg, "set overflow in addobject (%s)",
199                                          objptr(obj)->oname);
200                          error(INTERNAL, errmsg);
201                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines