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

Comparing ray/src/util/rfluxmtx.c (file contents):
Revision 2.30 by greg, Wed Jul 22 04:23:27 2015 UTC vs.
Revision 2.41 by greg, Sat Aug 20 03:43:24 2016 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include <stdlib.h>
12   #include "rtio.h"
13   #include "rtmath.h"
14 < #include "rtprocess.h"
14 > #include "paths.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
17   #include "random.h"
18   #include "triangulate.h"
19   #include "platform.h"
20  
21 #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
22 #undef getc
23 #define getc    getc_unlocked
24 #endif
25
26 #ifdef _WIN32
27 #define SPECIALS        " \t\"$*?"
28 #define QUOTCHAR        '"'
29 #else
30 #define SPECIALS        " \t\n'\"()${}*?[];|&"
31 #define QUOTCHAR        '\''
32 #define ALTQUOT         '"'
33 #endif
34
21   #define MAXRCARG        512
22  
23   char            *progname;              /* global argv[0] */
# Line 78 | Line 64 | typedef struct {
64          FVECT   uva[2];                 /* tangent axes */
65          int     ntris;                  /* number of triangles */
66          struct ptri {
67 <                float   afrac;                  /* fraction of total area */
67 >                double  afrac;                  /* fraction of total area */
68                  short   vndx[3];                /* vertex indices */
69          }       tri[1];                 /* triangle array (extends struct) */
70   } POLYTRIS;                     /* triangulated polygon */
# Line 142 | Line 128 | surf_type(const char *otype)
128          return(ST_NONE);
129   }
130  
145 /* Check if any of the characters in str2 are found in str1 */
146 static int
147 matchany(const char *str1, const char *str2)
148 {
149        while (*str1) {
150                const char      *cp = str2;
151                while (*cp)
152                        if (*cp++ == *str1)
153                                return(*str1);
154                ++str1;
155        }
156        return(0);
157 }
158
131   /* Add arguments to oconv command */
132   static char *
133   oconv_command(int ac, char *av[])
# Line 192 | Line 164 | overrun:
164          exit(1);
165   }
166  
195 /* Convert a set of arguments into a command line for pipe() or system() */
196 static char *
197 convert_commandline(char *cmd, const int len, char *av[])
198 {
199        int     match;
200        char    *cp;
201
202        for (cp = cmd; *av != NULL; av++) {
203                const int       n = strlen(*av);
204                if (cp+n >= cmd+(len-3)) {
205                        fputs(progname, stderr);
206                        return(NULL);
207                }
208                if (matchany(*av, SPECIALS)) {
209                        const int       quote =
210 #ifdef ALTQUOT
211                                strchr(*av, QUOTCHAR) ? ALTQUOT :
212 #endif
213                                        QUOTCHAR;
214                        *cp++ = quote;
215                        strcpy(cp, *av);
216                        cp += n;
217                        *cp++ = quote;
218                } else {
219                        strcpy(cp, *av);
220                        cp += n;
221                }
222                *cp++ = ' ';
223        }
224        if (cp <= cmd)
225                return(NULL);
226        *--cp = '\0';
227        return(cmd);
228 }
229
167   /* Open a pipe to/from a command given as an argument list */
168   static FILE *
169   popen_arglist(char *av[], char *mode)
# Line 244 | Line 181 | popen_arglist(char *av[], char *mode)
181          return(popen(cmd, mode));
182   }
183  
184 < #ifdef _WIN32
184 > #if defined(_WIN32) || defined(_WIN64)
185   /* Execute system command (Windows version) */
186   static int
187   my_exec(char *av[])
# Line 329 | Line 266 | parse_params(PARAMS *p, char *pargs)
266   {
267          char    *cp = pargs;
268          int     nparams = 0;
269 +        int     quot;
270          int     i;
271  
272          for ( ; ; ) {
# Line 365 | Line 303 | parse_params(PARAMS *p, char *pargs)
303                  case 'o':
304                          if (*cp++ != '=')
305                                  break;
306 +                        quot = 0;
307 +                        if ((*cp == '"') | (*cp == '\''))
308 +                                quot = *cp++;
309                          i = 0;
310 <                        while (*cp && !isspace(*cp++))
311 <                                i++;
310 >                        while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) {
311 >                                i++; cp++;
312 >                        }
313                          if (!i)
314                                  break;
315 <                        *--cp = '\0';
315 >                        if (!*cp) {
316 >                                if (quot)
317 >                                        break;
318 >                                cp[1] = '\0';
319 >                        }
320 >                        *cp = '\0';
321                          p->outfn = savqstr(cp-i);
322 <                        *cp++ = ' ';
322 >                        *cp++ = quot ? quot : ' ';
323                          ++nparams;
324                          continue;
325                  case ' ':
# Line 655 | Line 602 | ssamp_poly(FVECT orig, SURF *sp, double x)
602                  sp->priv = (void *)ptp;
603          }
604                                          /* pick triangle by partial area */
605 <        for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++)
605 >        for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++)
606                  x -= ptp->tri[i].afrac;
607          SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac);
608          samp2[0] *= samp2[1] = sqrt(samp2[1]);
# Line 685 | Line 632 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
632                                          /* special case for lone surface */
633          if (p->nsurfs == 1) {
634                  sp = p->slist;
635 <                if (DOT(sp->snrm, rdir) >= -FTINY) {
635 >                if (DOT(sp->snrm, rdir) >= FTINY) {
636                          fprintf(stderr,
637                                  "%s: internal - sample behind sender '%s'\n",
638                                          progname, sp->sname);
# Line 696 | Line 643 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
643          if (p->nsurfs > nall) {         /* (re)allocate surface area cache */
644                  if (projsa) free(projsa);
645                  projsa = (double *)malloc(sizeof(double)*p->nsurfs);
646 <                if (!projsa) return(0);
646 >                if (projsa == NULL) {
647 >                        fputs(progname, stderr);
648 >                        fputs(": out of memory in sample_origin!\n", stderr);
649 >                        exit(1);
650 >                }
651                  nall = p->nsurfs;
652          }
653                                          /* compute projected areas */
# Line 739 | Line 690 | sample_uniform(PARAMS *p, int b, FILE *fp)
690                                                  duvw[2]*p->nrm[i] ;
691                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
692                          return(0);
693 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
693 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
694                          return(0);
695          }
696          return(1);
# Line 769 | Line 720 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
720                                                  duvw[2]*p->nrm[i] ;
721                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
722                          return(0);
723 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
723 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
724                          return(0);
725          }
726          return(1);
# Line 817 | Line 768 | sample_reinhart(PARAMS *p, int b, FILE *fp)
768                                                  duvw[2]*p->nrm[i] ;
769                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0]))
770                          return(0);
771 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
771 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
772                          return(0);
773          }
774          return(1);
# Line 868 | Line 819 | sample_klems(PARAMS *p, int b, FILE *fp)
819                                                  duvw[2]*p->nrm[i] ;
820                  if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0]))
821                          return(0);
822 <                if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2)
822 >                if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2)
823                          return(0);
824          }
825          return(1);
# Line 995 | Line 946 | add_surface(int st, const char *oname, FILE *fp)
946          snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1));
947          if (snew == NULL) {
948                  fputs(progname, stderr);
949 <                fputs(": out of memory!\n", stderr);
949 >                fputs(": out of memory in add_surface!\n", stderr);
950                  exit(1);
951          }
952          strncpy(snew->sname, oname, sizeof(snew->sname)-1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines