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

Comparing ray/src/cv/tmesh2rad.c (file contents):
Revision 2.4 by greg, Tue Mar 22 08:54:23 1994 UTC vs.
Revision 2.14 by schorsch, Sun Jul 27 22:12:02 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert a trianglular mesh into a Radiance description.
6   *
# Line 34 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31  
32   #include "standard.h"
33  
34 + #include "tmesh.h"
35 +
36   #define VOIDID          "void"          /* this is defined in object.h */
37  
39 #define CALNAME         "tmesh.cal"     /* the name of our auxiliary file */
38   #define PATNAME         "T-pat"         /* triangle pattern name (reused) */
39   #define TEXNAME         "T-nor"         /* triangle texture name (reused) */
40  
# Line 54 | Line 52 | typedef struct {
52   VERTEX  *vlist = NULL;          /* our vertex list */
53   int     nverts = 0;             /* number of vertices in our list */
54  
55 < typedef FLOAT   BARYCCM[3][4];
55 > #define novert(i)       (((i)<0)|((i)>=nverts) || !(vlist[i].flags&V_DEFINED))
56  
59 #define novert(i)       ((i)<0|(i)>=nverts || !(vlist[i].flags&V_DEFINED))
60
57   #define CHUNKSIZ        128     /* vertex allocation chunk size */
58  
59   extern VERTEX   *vnew();        /* allocate a vertex (never freed) */
# Line 203 | Line 199 | triangle(pn, mod, obj, v1, v2, v3)     /* put out a triang
199   char    *pn, *mod, *obj;
200   register VERTEX *v1, *v2, *v3;
201   {
202 +        static char     vfmt[] = "%18.12g %18.12g %18.12g\n";
203          static int      ntri = 0;
204 +        int             flatness = ISFLAT;
205          BARYCCM bvecs;
206 +        RREAL   bvm[3][3];
207 +        register int    i;
208                                          /* compute barycentric coordinates */
209          if (v1->flags & v2->flags & v3->flags & (V_HASINDX|V_HASNORM))
210 <                if (comp_baryc(bvecs, v1->pos, v2->pos, v3->pos) < 0)
210 >                if (comp_baryc(&bvecs, v1->pos, v2->pos, v3->pos) < 0)
211                          return;
212 <                                        /* put out texture (if any) */
212 >                                        /* check flatness */
213          if (v1->flags & v2->flags & v3->flags & V_HASNORM) {
214 +                flatness = flat_tri(v1->pos, v2->pos, v3->pos,
215 +                                        v1->nor, v2->nor, v3->nor);
216 +                if (flatness == DEGEN)
217 +                        return;
218 +        }
219 +                                        /* put out texture (if any) */
220 +        if (flatness == ISBENT || flatness == RVBENT) {
221                  printf("\n%s texfunc %s\n", mod, TEXNAME);
222                  mod = TEXNAME;
223 <                printf("4 dx dy dz %s\n", CALNAME);
224 <                printf("0\n21\n");
225 <                put_baryc(bvecs);
226 <                printf("\t%14.12g %14.12g %14.12g\n",
227 <                                v1->nor[0], v2->nor[0], v3->nor[0]);
228 <                printf("\t%14.12g %14.12g %14.12g\n",
229 <                                v1->nor[1], v2->nor[1], v3->nor[1]);
230 <                printf("\t%14.12g %14.12g %14.12g\n",
224 <                                v1->nor[2], v2->nor[2], v3->nor[2]);
223 >                printf("4 dx dy dz %s\n", TCALNAME);
224 >                printf("0\n");
225 >                for (i = 0; i < 3; i++) {
226 >                        bvm[i][0] = v1->nor[i];
227 >                        bvm[i][1] = v2->nor[i];
228 >                        bvm[i][2] = v3->nor[i];
229 >                }
230 >                put_baryc(&bvecs, bvm, 3);
231          }
232                                          /* put out pattern (if any) */
233          if (*pn && (v1->flags & v2->flags & v3->flags & V_HASINDX)) {
234                  printf("\n%s colorpict %s\n", mod, PATNAME);
235                  mod = PATNAME;
236 <                printf("7 noneg noneg noneg %s %s u v\n", pn, CALNAME);
237 <                printf("0\n18\n");
238 <                put_baryc(bvecs);
239 <                printf("\t%f %f %f\n", v1->ndx[0], v2->ndx[0], v3->ndx[0]);
240 <                printf("\t%f %f %f\n", v1->ndx[1], v2->ndx[1], v3->ndx[1]);
236 >                printf("7 noneg noneg noneg %s %s u v\n", pn, TCALNAME);
237 >                printf("0\n");
238 >                for (i = 0; i < 2; i++) {
239 >                        bvm[i][0] = v1->ndx[i];
240 >                        bvm[i][1] = v2->ndx[i];
241 >                        bvm[i][2] = v3->ndx[i];
242 >                }
243 >                put_baryc(&bvecs, bvm, 2);
244          }
245 <                                        /* put out triangle */
245 >                                        /* put out (reversed) triangle */
246          printf("\n%s polygon %s.%d\n", mod, obj, ++ntri);
247          printf("0\n0\n9\n");
248 <        printf("%18.12g %18.12g %18.12g\n", v1->pos[0],v1->pos[1],v1->pos[2]);
249 <        printf("%18.12g %18.12g %18.12g\n", v2->pos[0],v2->pos[1],v2->pos[2]);
250 <        printf("%18.12g %18.12g %18.12g\n", v3->pos[0],v3->pos[1],v3->pos[2]);
251 < }
252 <
253 <
254 < int
255 < comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
247 < register BARYCCM        bcm;
248 < FLOAT   *v1, *v2, *v3;
249 < {
250 <        FLOAT   *vt;
251 <        FVECT   va, vab, vcb;
252 <        double  d;
253 <        register int    i, j;
254 <
255 <        for (j = 0; j < 3; j++) {
256 <                for (i = 0; i < 3; i++) {
257 <                        vab[i] = v1[i] - v2[i];
258 <                        vcb[i] = v3[i] - v2[i];
259 <                }
260 <                d = DOT(vcb,vcb);
261 <                if (d <= FTINY)
262 <                        return(-1);
263 <                d = DOT(vcb,vab)/d;
264 <                for (i = 0; i < 3; i++)
265 <                        va[i] = vab[i] - vcb[i]*d;
266 <                d = DOT(va,va);
267 <                if (d <= FTINY)
268 <                        return(-1);
269 <                for (i = 0; i < 3; i++) {
270 <                        va[i] /= d;
271 <                        bcm[j][i] = va[i];
272 <                }
273 <                bcm[j][3] = -DOT(v2,va);
274 <                                        /* rotate vertices */
275 <                vt = v1;
276 <                v1 = v2;
277 <                v2 = v3;
278 <                v3 = vt;
248 >        if (flatness == RVFLAT || flatness == RVBENT) {
249 >                printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]);
250 >                printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]);
251 >                printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]);
252 >        } else {
253 >                printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]);
254 >                printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]);
255 >                printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]);
256          }
280        return(0);
257   }
258  
259  
284 put_baryc(bcm)                          /* put barycentric coord. vectors */
285 register BARYCCM        bcm;
286 {
287        register int    i;
288
289        for (i = 0; i < 3; i++)
290                printf("%14.8f %14.8f %14.8f %14.8f\n",
291                                bcm[i][0], bcm[i][1], bcm[i][2], bcm[i][3]);
292 }
293
294
260   VERTEX *
261   vnew(id, x, y, z)                       /* create a new vertex */
262   register int    id;
# Line 305 | Line 270 | double x, y, z;
270                  if (vlist == NULL)
271                          vlist = (VERTEX *)malloc(nverts*sizeof(VERTEX));
272                  else
273 <                        vlist = (VERTEX *)realloc((char *)vlist,
273 >                        vlist = (VERTEX *)realloc((void *)vlist,
274                                          nverts*sizeof(VERTEX));
275                  if (vlist == NULL) {
276                          fprintf(stderr,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines