Back to index

radiance  4R0+20100331
getbbox.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: getbbox.c,v 2.6 2004/03/27 12:41:45 schorsch Exp $";
00003 #endif
00004 /*
00005  *  getbbox.c - compute bounding box for scene files
00006  *
00007  *  Adapted from oconv.c 29 May 1991
00008  */
00009 
00010 #include  "standard.h"
00011 #include  "octree.h"
00012 #include  "object.h"
00013 #include  "oconv.h"
00014 
00015 char  *progname;                   /* argv[0] */
00016 
00017 int  nowarn = 0;                   /* supress warnings? */
00018 
00019 void  (*addobjnotify[])() = {NULL};       /* new object notifier functions */
00020 
00021 FVECT  bbmin, bbmax;               /* bounding box */
00022 
00023 static void addobject(OBJREC       *o);
00024 
00025 
00026 
00027 static void
00028 addobject(                  /* add object to bounding box */
00029        OBJREC *o
00030 )
00031 {
00032        add2bbox(o, bbmin, bbmax);
00033 }
00034 
00035 
00036 int
00037 main(         /* read object files and compute bounds */
00038        int  argc,
00039        char  **argv
00040 )
00041 {
00042        extern char  *getenv();
00043        int  nohead = 0;
00044        int  i;
00045 
00046        progname = argv[0];
00047 
00048        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
00049               switch (argv[i][1]) {
00050               case 'w':
00051                      nowarn = 1;
00052                      continue;
00053               case 'h':
00054                      nohead = 1;
00055                      continue;
00056               }
00057               break;
00058        }
00059                                           /* find bounding box */
00060        bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
00061        bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
00062                                           /* read input */
00063        if (i >= argc)
00064               readobj2(NULL, addobject);
00065        else
00066               for ( ; i < argc; i++)
00067                      if (!strcmp(argv[i], "-"))  /* from stdin */
00068                             readobj2(NULL, addobject);
00069                      else                        /* from file */
00070                             readobj2(argv[i], addobject);
00071                                           /* print bounding box */
00072        if (!nohead)
00073               printf(
00074 "     xmin      xmax      ymin      ymax      zmin      zmax\n");
00075 
00076        printf("%9g %9g %9g %9g %9g %9g\n", bbmin[0], bbmax[0],
00077                      bbmin[1], bbmax[1], bbmin[2], bbmax[2]);
00078        quit(0);
00079        return 0; /* pro forma return */
00080 }
00081 
00082 
00083 void
00084 quit(                       /* exit program */
00085        int  code
00086 )
00087 {
00088        exit(code);
00089 }
00090 
00091 
00092 void
00093 cputs(void)                               /* interactive error */
00094 {
00095        /* referenced, but not used */
00096 }
00097 
00098 
00099 void
00100 wputs(                      /* warning message */
00101        char  *s
00102 )
00103 {
00104        if (!nowarn)
00105               eputs(s);
00106 }
00107 
00108 
00109 void
00110 eputs(                      /* put string to stderr */
00111        register char  *s
00112 )
00113 {
00114        static int  inln = 0;
00115 
00116        if (!inln++) {
00117               fputs(progname, stderr);
00118               fputs(": ", stderr);
00119        }
00120        fputs(s, stderr);
00121        if (*s && s[strlen(s)-1] == '\n')
00122               inln = 0;
00123 }