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

Comparing ray/src/cv/rad2mgf.c (file contents):
Revision 2.1 by greg, Thu Jul 7 17:30:33 1994 UTC vs.
Revision 2.2 by greg, Fri Jul 8 16:10:06 1994 UTC

# Line 26 | Line 26 | LUTAB  rmats = LU_SINIT(free,NULL);            /* defined materia
26  
27   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
28  
29 < char    curmat[80];             /* current material */
29 > char    curmat[80];                             /* current material */
30 > char    curobj[128] = "Untitled";               /* current object name */
31  
32 < double  unit_mult = 1.;         /* units multiplier */
32 > double  unit_mult = 1.;                         /* units multiplier */
33  
34 + #define hasmult         (unit_mult < .999 || unit_mult > 1.001)
35  
36 +
37   main(argc, argv)
38   int     argc;
39   char    **argv;
# Line 85 | Line 88 | char   *inp;
88          register int    c;
89  
90          if (inp == NULL) {
91 <                inp = "the standard input";
91 >                inp = "standard input";
92                  fp = stdin;
93          } else if (inp[0] == '!') {
94                  if ((fp = popen(inp+1, "r")) == NULL) {
# Line 209 | Line 212 | char   *id;
212   {
213          if (!strcmp(id, curmat))        /* already set? */
214                  return;
215 +        if (!strcmp(id, VOIDID))        /* cannot set */
216 +                return;
217          printf("m %s\n", id);
218          strcpy(curmat, id);
219   }
220  
221  
222 + setobj(id)                      /* set object name to this one */
223 + char    *id;
224 + {
225 +        register char   *cp, *cp2;
226 +        char    *end = NULL;
227 +        int     diff = 0;
228 +                                /* use all but final suffix */
229 +        for (cp = id; *cp; cp++)
230 +                if (*cp == '.')
231 +                        end = cp;
232 +        if (end == NULL)
233 +                end = cp;
234 +                                /* copy to current object */
235 +        for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++)
236 +                diff += *cp != *cp2;
237 +        if (!diff && !*cp2)
238 +                return;
239 +        *cp2 = '\0';
240 +        fputs("o\no ", stdout);
241 +        puts(curobj);
242 + }
243 +
244 +
245   init()                  /* initialize dispatch table and output */
246   {
247          lu_init(&rdispatch, 22);
# Line 239 | Line 267 | init()                 /* initialize dispatch table and output */
267          add2dispatch("glow", o_light);
268          add2dispatch("illum", o_illum);
269          puts("# The following was converted from Radiance scene input");
270 <        if (unit_mult < .999 || unit_mult > 1.001)
270 >        if (hasmult)
271                  printf("xf -s %.4e\n", unit_mult);
272 +        printf("o %s\n", curobj);
273   }
274  
275  
276   uninit()                        /* mark end of MGF file */
277   {
278 <        if (unit_mult < .999 || unit_mult > 1.001)
278 >        puts("o");
279 >        if (hasmult)
280                  puts("xf");
281          puts("# End of data converted from Radiance scene input");
282          lu_done(&rdispatch);
# Line 271 | Line 301 | int    (*func)();
301   }
302  
303  
304 + /*
305 + * Stuff for tracking and reusing vertices:
306 + */
307 +
308   char    VKFMT[] = "%+1.9e %+1.9e %+1.9e";
309   #define VKLEN           64
310  
# Line 289 | Line 323 | LUTAB  vertab = LU_SINIT(free,NULL);   /* our vertex look
323  
324  
325   char *
326 < getvertid(vp)                   /* get/set vertex ID for this point */
326 > getvertid(vname, vp)            /* get/set vertex ID for this point */
327 > char    *vname;
328   FVECT   vp;
329   {
295        static char     vname[6];
330          char    vkey[VKLEN];
331          register LUENT  *lp;
332          register int    i, vndx;
# Line 321 | Line 355 | FVECT  vp;
355                  }
356                  vert[vndx].lused = clock;                       /* assign it */
357                  VCOPY(vert[vndx].p, vp);
358 <                printf("v v%d =\np %.15g %.15g %.15g\n",        /* print it */
358 >                printf("v v%d =\n\tp %.15g %.15g %.15g\n",      /* print it */
359                                  vndx, vp[0], vp[1], vp[2]);
360                  lp->data = (char *)&vert[vndx];                 /* set it */
361          } else
# Line 340 | Line 374 | char   *mod, *typ, *id;
374   FUNARGS *fa;
375   {
376          char    entbuf[512];
377 <        register char   *cp1, *cp2;
377 >        register char   *cp;
378          register int    i;
379  
380          if (fa->nfargs < 9 | fa->nfargs % 3)
381                  return(-1);
382          setmat(mod);
383 <        printf("o %s\n", id);
384 <        cp1 = entbuf;
385 <        *cp1++ = 'f';
383 >        setobj(id);
384 >        cp = entbuf;
385 >        *cp++ = 'f';
386          for (i = 0; i < fa->nfargs; i += 3) {
387 <                cp2 = getvertid(fa->farg + i);
388 <                *cp1++ = ' ';
389 <                while ((*cp1 = *cp2++))
390 <                        cp1++;
387 >                *cp++ = ' ';
388 >                getvertid(cp, fa->farg + i);
389 >                while (*cp)
390 >                        cp++;
391          }
392          puts(entbuf);
359        puts("o");
393          return(0);
394   }
395  
# Line 366 | Line 399 | o_cone(mod, typ, id, fa)       /* print out a cone */
399   char    *mod, *typ, *id;
400   register FUNARGS        *fa;
401   {
402 +        char    v1[6], v2[6];
403 +
404          if (fa->nfargs != 8)
405                  return(-1);
406          setmat(mod);
407 <        printf("o %s\n", id);
408 <        printf("v cv1 =\np %.12g %.12g %.12g\n",
409 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
375 <        printf("v cv2 =\np %.12g %.12g %.12g\n",
376 <                        fa->farg[3], fa->farg[4], fa->farg[5]);
407 >        setobj(id);
408 >        getvertid(v1, fa->farg);
409 >        getvertid(v2, fa->farg + 3);
410          if (typ[1] == 'u')                      /* cup -> inverted cone */
411 <                printf("cone cv1 %.12g cv2 %.12g\n",
412 <                                -fa->farg[6], -fa->farg[7]);
411 >                printf("cone %s %.12g %s %.12g\n",
412 >                                v1, -fa->farg[6], v2, -fa->farg[7]);
413          else
414 <                printf("cone cv1 %.12g cv2 %.12g\n",
415 <                                fa->farg[6], fa->farg[7]);
383 <        puts("o");
414 >                printf("cone %s %.12g %s %.12g\n",
415 >                                v1, fa->farg[6], v2, fa->farg[7]);
416          return(0);
417   }
418  
# Line 390 | Line 422 | o_sphere(mod, typ, id, fa)     /* print out a sphere */
422   char    *mod, *typ, *id;
423   register FUNARGS        *fa;
424   {
425 +        char    cent[6];
426 +
427          if (fa->nfargs != 4)
428                  return(-1);
429          setmat(mod);
430 <        printf("o %s\n", id);
431 <        printf("v cent =\np %.12g %.12g %.12g\n",
432 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
399 <        printf("sph cent %.12g\n", typ[0]=='b' ? -fa->farg[3] : fa->farg[3]);
400 <        puts("o");
430 >        setobj(id);
431 >        printf("sph %s %.12g\n", getvertid(cent, fa->farg),
432 >                        typ[0]=='b' ? -fa->farg[3] : fa->farg[3]);
433          return(0);
434   }
435  
# Line 407 | Line 439 | o_cylinder(mod, typ, id, fa)   /* print out a cylinder *
439   char    *mod, *typ, *id;
440   register FUNARGS        *fa;
441   {
442 +        char    v1[6], v2[6];
443 +
444          if (fa->nfargs != 7)
445                  return(-1);
446          setmat(mod);
447 <        printf("o %s\n", id);
448 <        printf("v cv1 =\np %.12g %.12g %.12g\n",
449 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
450 <        printf("v cv2 =\np %.12g %.12g %.12g\n",
451 <                        fa->farg[3], fa->farg[4], fa->farg[5]);
418 <        printf("cyl cv1 %.12g cv2\n",
419 <                        typ[0]=='t' ? -fa->farg[6] : fa->farg[6]);
420 <        puts("o");
447 >        setobj(id);
448 >        getvertid(v1, fa->farg);
449 >        getvertid(v2, fa->farg + 3);
450 >        printf("cyl %s %.12g %s\n", v1,
451 >                        typ[0]=='t' ? -fa->farg[6] : fa->farg[6], v2);
452          return(0);
453   }
454  
# Line 430 | Line 461 | register FUNARGS       *fa;
461          if (fa->nfargs != 8)
462                  return(-1);
463          setmat(mod);
464 <        printf("o %s\n", id);
465 <        printf("v cent =\np %.12g %.12g %.12g\n",
464 >        setobj(id);
465 >        printf("v cent =\n\tp %.12g %.12g %.12g\n",
466                          fa->farg[0], fa->farg[1], fa->farg[2]);
467 <        printf("n %.12g %.12g %.12g\n",
467 >        printf("\tn %.12g %.12g %.12g\n",
468                          fa->farg[3], fa->farg[4], fa->farg[5]);
469          if (fa->farg[6] < fa->farg[7])
470                  printf("ring cent %.12g %.12g\n",
# Line 441 | Line 472 | register FUNARGS       *fa;
472          else
473                  printf("ring cent %.12g %.12g\n",
474                                  fa->farg[7], fa->farg[6]);
444        puts("o");
475          return(0);
476   }
477  
# Line 451 | Line 481 | o_instance(mod, typ, id, fa)   /* convert an instance */
481   char    *mod, *typ, *id;
482   FUNARGS *fa;
483   {
484 <        return(0);              /* this is too damned difficult! */
484 >        register int    i;
485 >        register char   *cp;
486 >        char    *start = NULL, *end = NULL;
487 >        /*
488 >         * We don't really know how to do this, so we just create
489 >         * a reference to an undefined MGF file and it's the user's
490 >         * responsibility to create this file and put the appropriate
491 >         * stuff into it.
492 >         */
493 >        if (fa->nsargs < 1)
494 >                return(-1);
495 >        setmat(mod);                    /* only works if surfaces are void */
496 >        setobj(id);
497 >        for (cp = fa->sarg[0]; *cp; cp++)       /* construct MGF file name */
498 >                if (*cp == '/')
499 >                        start = cp+1;
500 >                else if (*cp == '.')
501 >                        end = cp;
502 >        if (start == NULL)
503 >                start = fa->sarg[0];
504 >        if (end == NULL || start >= end)
505 >                end = cp;
506 >        fputs("i ", stdout);                    /* print include entity */
507 >        for (cp = start; cp < end; cp++)
508 >                putchar(*cp);
509 >        fputs(".mgf", stdout);                  /* add MGF suffix */
510 >        for (i = 1; i < fa->nsargs; i++) {      /* add transform */
511 >                putchar(' ');
512 >                fputs(fa->sarg[i], stdout);
513 >        }
514 >        putchar('\n');
515 >        return(0);
516   }
517  
518  
# Line 475 | Line 536 | FUNARGS        *fa;
536          }
537                                          /* else create invisible material */
538          newmat(id, NULL);
539 <        puts("ts 1 0");
539 >        puts("\tts 1 0");
540          return(0);
541   }
542  
# Line 493 | Line 554 | register FUNARGS       *fa;
554          newmat(id, NULL);
555          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
556          rgb_cie(cxyz, rrgb);
557 <        puts("c");                              /* put diffuse component */
557 >        puts("\tc");                            /* put diffuse component */
558          d = cxyz[0] + cxyz[1] + cxyz[2];
559          if (d > FTINY)
560 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
561 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
562 <        puts("c");                              /* put specular component */
563 <        printf("rs %.4f %.4f\n", fa->farg[3],
564 <                        typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
565 <                                        fa->farg[4]);
560 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
561 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
562 >        if (fa->farg[3] > FTINY) {              /* put specular component */
563 >                puts("\tc");
564 >                printf("\trs %.4f %.4f\n", fa->farg[3],
565 >                                typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
566 >                                                fa->farg[4]);
567 >        }
568          return(0);
569   }
570  
# Line 519 | Line 582 | register FUNARGS       *fa;
582          newmat(id, NULL);
583          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
584          rgb_cie(cxyz, rrgb);
585 <        puts("c");                              /* put diffuse component */
585 >        puts("\tc");                            /* put diffuse component */
586          d = cxyz[0] + cxyz[1] + cxyz[2];
587          if (d > FTINY)
588 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
589 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
588 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
589 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
590                                                  /* put specular component */
591 <        printf("rs %.4f %.4f\n", cxyz[1]*fa->farg[3],
591 >        printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3],
592                          typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
593                                          fa->farg[4]);
594          return(0);
# Line 549 | Line 612 | register FUNARGS       *fa;
612          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
613          F *= F;
614          for (i = 0; i < 3; i++) {
615 <                rrgb[i] = (1. - F)*(1. - F)/(1. - F*F*fa->farg[i]*fa->farg[i]);
553 <                trgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) /
615 >                trgb[i] = fa->farg[i] * (1. - F)*(1. - F) /
616                                  (1. - F*F*fa->farg[i]*fa->farg[i]);
617 +                rrgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) /
618 +                                (1. - F*F*fa->farg[i]*fa->farg[i]);
619          }
620          rgb_cie(cxyz, rrgb);                    /* put reflected component */
621 <        puts("c");
621 >        puts("\tc");
622          d = cxyz[0] + cxyz[1] + cxyz[2];
623          if (d > FTINY)
624 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
625 <        printf("rs %.4f 0\n", cxyz[1]);
624 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
625 >        printf("\trs %.4f 0\n", cxyz[1]);
626          rgb_cie(cxyz, trgb);                    /* put transmitted component */
627 <        puts("c");
627 >        puts("\tc");
628          d = cxyz[0] + cxyz[1] + cxyz[2];
629          if (d > FTINY)
630 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
631 <        printf("ts %.4f 0\n", cxyz[1]);
630 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
631 >        printf("\tts %.4f 0\n", cxyz[1]);
632          return(0);
633   }
634  
# Line 586 | Line 650 | register FUNARGS       *fa;
650          newmat(id, NULL);
651          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
652          rgb_cie(cxyz, rrgb);
653 <        puts("c");                              /* put specular component */
653 >        puts("\tc");                            /* put specular component */
654          d = cxyz[0] + cxyz[1] + cxyz[2];
655          if (d > FTINY)
656 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
657 <        printf("rs %.4f 0\n", cxyz[1]);
656 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
657 >        printf("\trs %.4f 0\n", cxyz[1]);
658          return(0);
659   }
660  
# Line 619 | Line 683 | register FUNARGS       *fa;
683          newmat(id, NULL);
684          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
685          rgb_cie(cxyz, rrgb);
686 <        puts("c");                              /* put transmitted diffuse */
686 >        puts("\tc");                            /* put transmitted diffuse */
687          d = cxyz[0] + cxyz[1] + cxyz[2];
688          if (d > FTINY)
689 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
690 <        printf("td %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec));
689 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
690 >        printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec));
691                                                  /* put transmitted specular */
692 <        printf("ts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough);
692 >        printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough);
693                                                  /* put reflected diffuse */
694 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans));
695 <        puts("c");                              /* put reflected specular */
696 <        printf("rs %.4f %.4f\n", fa->farg[3], rough);
694 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans));
695 >        puts("\tc");                            /* put reflected specular */
696 >        printf("\trs %.4f %.4f\n", fa->farg[3], rough);
697          return(0);
698   }
699  
# Line 648 | Line 712 | register FUNARGS       *fa;
712          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
713          rgb_cie(cxyz, rrgb);
714          d = cxyz[0] + cxyz[1] + cxyz[2];
715 <        puts("c");
715 >        puts("\tc");
716          if (d > FTINY)
717 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
718 <        printf("ed %.4g\n", cxyz[1]);
717 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
718 >        printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY);
719          return(0);
720   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines