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

Comparing ray/src/ot/cvmesh.c (file contents):
Revision 2.3 by greg, Fri Mar 14 21:27:46 2003 UTC vs.
Revision 2.8 by greg, Thu Jan 29 22:21:34 2004 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "cvmesh.h"
11   #include "otypes.h"
12   #include "face.h"
13 + #include "tmesh.h"
14  
15   /*
16   * We need to divide faces into triangles and record auxiliary information
# Line 23 | Line 24 | typedef struct {
24          int             fl;             /* flags of what we're storing */
25          OBJECT          obj;            /* mesh triangle ID */
26          FVECT           vn[3];          /* normals */
27 <        FLOAT           vc[3][2];       /* uv coords. */
27 >        RREAL           vc[3][2];       /* uv coords. */
28   } TRIDATA;
29  
30   #define tdsize(fl)      ((fl)&MT_UV ? sizeof(TRIDATA) : \
31 <                                (fl)&MT_N ? sizeof(TRIDATA)-2*sizeof(FLOAT) : \
31 >                                (fl)&MT_N ? sizeof(TRIDATA)-6*sizeof(RREAL) : \
32                                  sizeof(int)+sizeof(OBJECT))
33  
34   #define  OMARGIN        (10*FTINY)      /* margin around global cube */
# Line 74 | Line 75 | OBJECT mo;
75   int     n;
76   FVECT   *vp;
77   FVECT   *vn;
78 < FLOAT   (*vc)[2];
78 > RREAL   (*vc)[2];
79   {
80          int     tcnt = 0;
81          int     flags;
82 <        FLOAT   *tn[3], *tc[3];
82 >        RREAL   *tn[3], *tc[3];
83          int     *ord;
84          int     i, j;
85  
# Line 133 | Line 134 | FLOAT  (*vc)[2];
134   static void
135   add2bounds(vp, vc)              /* add point and uv coordinate to bounds */
136   FVECT   vp;
137 < FLOAT   vc[2];
137 > RREAL   vc[2];
138   {
139          register int    j;
140  
# Line 159 | Line 160 | cvtri(mo, vp1, vp2, vp3, vn1, vn2, vn3, vc1, vc2, vc3)
160   OBJECT  mo;
161   FVECT   vp1, vp2, vp3;
162   FVECT   vn1, vn2, vn3;
163 < FLOAT   vc1[2], vc2[2], vc3[2];
163 > RREAL   vc1[2], vc2[2], vc3[2];
164   {
165          static OBJECT   fobj = OVOID;
166          char            buf[32];
# Line 169 | Line 170 | FLOAT  vc1[2], vc2[2], vc3[2];
170          OBJREC          *fop;
171          int             j;
172          
173 <        flags = MT_V;
174 <        if (vn1 != NULL && vn2 != NULL && vn3 != NULL)
175 <                flags |= MT_N;
173 >        flags = MT_V;           /* check what we have */
174 >        if (vn1 != NULL && vn2 != NULL && vn3 != NULL) {
175 >                RREAL   *rp;
176 >                switch (flat_tri(vp1, vp2, vp3, vn1, vn2, vn3)) {
177 >                case ISBENT:
178 >                        flags |= MT_N;
179 >                        /* fall through */
180 >                case ISFLAT:
181 >                        break;
182 >                case RVBENT:
183 >                        flags |= MT_N;
184 >                        rp = vn1; vn1 = vn3; vn3 = rp;
185 >                        /* fall through */
186 >                case RVFLAT:
187 >                        rp = vp1; vp1 = vp3; vp3 = rp;
188 >                        rp = vc1; vc1 = vc3; vc3 = rp;
189 >                        break;
190 >                case DEGEN:
191 >                        error(WARNING, "degenerate triangle");
192 >                        return(0);
193 >                default:
194 >                        error(INTERNAL, "bad return from flat_tri()");
195 >                }
196 >        }
197          if (vc1 != NULL && vc2 != NULL && vc3 != NULL)
198                  flags |= MT_UV;
199          if (fobj == OVOID) {    /* create new triangle object */
# Line 184 | Line 206 | FLOAT  vc1[2], vc2[2], vc3[2];
206                  sprintf(buf, "t%d", fobj);
207                  fop->oname = savqstr(buf);
208                  fop->oargs.nfargs = 9;
209 <                fop->oargs.farg = (FLOAT *)malloc(9*sizeof(FLOAT));
209 >                fop->oargs.farg = (RREAL *)malloc(9*sizeof(RREAL));
210                  if (fop->oargs.farg == NULL)
211                          goto nomem;
212          } else {                /* else reuse failed one */
# Line 285 | Line 307 | cvmeshbounds()                 /* set mesh boundaries */
307                  return;
308                                  /* fix coordinate bounds */
309          for (i = 0; i < 3; i++) {
310 <                if (meshbounds[0][i] >= meshbounds[1][i])
310 >                if (meshbounds[0][i] > meshbounds[1][i])
311                          error(USER, "no polygons in mesh");
312                  meshbounds[0][i] -= OMARGIN;
313                  meshbounds[1][i] += OMARGIN;
# Line 301 | Line 323 | cvmeshbounds()                 /* set mesh boundaries */
323                  ourmesh->uvlim[1][0] = ourmesh->uvlim[1][1] = 0.;
324          } else {
325                  for (i = 0; i < 2; i++) {
326 <                        double  marg;
327 <                        marg = 1e-6*(ourmesh->uvlim[1][i] -
328 <                                        ourmesh->uvlim[0][i]);
326 >                        double  marg;           /* expand past endpoints */
327 >                        marg = (2./(1L<<(8*sizeof(uint16)))) *
328 >                                        (ourmesh->uvlim[1][i] -
329 >                                         ourmesh->uvlim[0][i]);
330                          ourmesh->uvlim[0][i] -= marg;
331                          ourmesh->uvlim[1][i] += marg;
332                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines