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.10 by greg, Thu Apr 13 14:43:30 1995 UTC vs.
Revision 2.21 by schorsch, Mon Oct 27 10:26:45 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 Radiance scene description to MGF
6   */
7  
8 < #include <stdio.h>
9 < #include <math.h>
8 > #include "platform.h"
9 > #include "standard.h"
10 > #include <ctype.h>
11   #include <string.h>
12 < #include "fvect.h"
12 > #include <stdio.h>
13 >
14 > #include "rtprocess.h"
15   #include "object.h"
16   #include "color.h"
17   #include "lookup.h"
18  
19 #define PI      3.14159265358979323846
20
19   #define C_1SIDEDTHICK   0.005
20  
21   int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
22 < int     o_instance(), o_source(), o_illum();
22 > int     o_instance(), o_illum();
23   int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
24 <                o_mirror(), o_trans(), o_light();
24 >        o_mirror(), o_trans(), o_light();
25  
28 extern void     free();
29 extern char     *malloc();
30
26   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
27  
28   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
# Line 194 | Line 189 | FUNARGS        *fa;
189                          fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
190                          exit(1);
191                  }
192 <        } else if (lu_find(&rmats, mod)->data != NULL)  /* make alias */
193 <                newmat(id, mod);
192 >        } else {                                        /* unsupported */
193 >                o_unsupported(mod, typ, id, fa);
194 >                if (lu_find(&rmats, mod)->data != NULL) /* make alias */
195 >                        newmat(id, mod);
196 >        }
197   }
198  
199  
# Line 260 | Line 258 | char   *id;
258          if (end == NULL)
259                  end = cp;
260                                  /* copy to current object */
261 <        for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++)
261 >        cp2 = curobj;
262 >        if (!isalpha(*id)) {    /* start with letter */
263 >                diff = *cp2 != 'O';
264 >                *cp2++ = 'O';
265 >        }
266 >        for (cp = id; cp < end; *cp2++ = *cp++) {
267 >                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
268 >                        *cp = '?';
269                  diff += *cp != *cp2;
270 +        }
271          if (!diff && !*cp2)
272                  return;
273          *cp2 = '\0';
# Line 283 | Line 289 | init()                 /* initialize dispatch table and output */
289          add2dispatch("tube", o_cylinder);
290          add2dispatch("ring", o_ring);
291          add2dispatch("instance", o_instance);
292 +        add2dispatch("mesh", o_instance);
293          add2dispatch("plastic", o_plastic);
294          add2dispatch("plastic2", o_plastic);
295          add2dispatch("metal", o_metal);
# Line 296 | Line 303 | init()                 /* initialize dispatch table and output */
303          add2dispatch("spotlight", o_light);
304          add2dispatch("glow", o_light);
305          add2dispatch("illum", o_illum);
306 <        puts("# The following was converted from Radiance scene input");
306 >        puts("# The following was converted from RADIANCE scene input");
307          if (hasmult)
308                  printf("xf -s %.4e\n", unit_mult);
309          printf("o %s\n", curobj);
# Line 308 | Line 315 | uninit()                       /* mark end of MGF file */
315          puts("o");
316          if (hasmult)
317                  puts("xf");
318 <        puts("# End of data converted from Radiance scene input");
318 >        puts("# End of data converted from RADIANCE scene input");
319          lu_done(&rdispatch);
320          lu_done(&rmats);
321          lu_done(&vertab);
# Line 388 | Line 395 | memerr:
395  
396  
397   int
398 + o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
399 + char    *mod, *typ, *id;
400 + FUNARGS *fa;
401 + {
402 +        register int    i;
403 +
404 +        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
405 +        printf("# %s %s %s", mod, typ, id);
406 +        printf("\n# %d", fa->nsargs);
407 +        for (i = 0; i < fa->nsargs; i++)
408 +                printf(" %s", fa->sarg[i]);
409 + #ifdef IARGS
410 +        printf("\n# %d", fa->niargs);
411 +        for (i = 0; i < fa->niargs; i++)
412 +                printf(" %ld", fa->iarg[i]);
413 + #else
414 +        fputs("\n# 0", stdout);
415 + #endif
416 +        printf("\n# %d", fa->nfargs);
417 +        for (i = 0; i < fa->nfargs; i++)
418 +                printf(" %g", fa->farg[i]);
419 +        fputs("\n\n", stdout);
420 +        return(0);
421 + }
422 +
423 +
424 + int
425   o_face(mod, typ, id, fa)                /* print out a polygon */
426   char    *mod, *typ, *id;
427   FUNARGS *fa;
428   {
429 <        char    entbuf[512];
429 >        char    entbuf[2048], *linestart;
430          register char   *cp;
431          register int    i;
432  
433 <        if (fa->nfargs < 9 | fa->nfargs % 3)
433 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
434                  return(-1);
435          setmat(mod);
436          setobj(id);
437 <        cp = entbuf;
437 >        cp = linestart = entbuf;
438          *cp++ = 'f';
439          for (i = 0; i < fa->nfargs; i += 3) {
440                  *cp++ = ' ';
441 +                if (cp - linestart > 72) {
442 +                        *cp++ = '\\'; *cp++ = '\n';
443 +                        linestart = cp;
444 +                        *cp++ = ' '; *cp++ = ' ';
445 +                }
446                  getvertid(cp, fa->farg + i);
447                  while (*cp)
448                          cp++;
# Line 496 | Line 535 | register FUNARGS       *fa;
535  
536  
537   int
538 < o_instance(mod, typ, id, fa)    /* convert an instance */
538 > o_instance(mod, typ, id, fa)    /* convert an instance (or mesh) */
539   char    *mod, *typ, *id;
540   FUNARGS *fa;
541   {
# Line 533 | Line 572 | FUNARGS        *fa;
572          putchar('\n');
573          clrverts();                     /* vertex id's no longer reliable */
574          return(0);
536 }
537
538
539 int
540 o_source(mod, typ, id, fa)      /* convert a source */
541 char    *mod, *typ, *id;
542 FUNARGS *fa;
543 {
544        return(0);              /* there is no MGF equivalent! */
575   }
576  
577  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines