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

Comparing ray/src/rt/mkpmap.c (file contents):
Revision 2.4 by greg, Mon Mar 21 19:06:08 2016 UTC vs.
Revision 2.8 by rschregle, Fri Feb 2 19:47:55 2018 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4 +
5 +
6   /*
7 <   ==================================================================
7 >   ======================================================================
8     Photon map generator
9    
10     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
11     (c) Fraunhofer Institute for Solar Energy Systems,
12         Lucerne University of Applied Sciences & Arts
13 <   ==================================================================
13 >   (c) Lucerne University of Applied Sciences and Arts,
14 >       supported by the Swiss National Science Foundation (SNSF, #147053)
15 >   ======================================================================
16    
17     $Id$    
18   */
19  
20  
14
21   #include "pmap.h"
22   #include "pmapmat.h"
23   #include "pmapcontrib.h"
# Line 24 | Line 30
30   #include <sys/stat.h>
31  
32  
33 + /* Enable options for Ze Ekspertz only! */
34 + #define PMAP_EKSPERTZ
35  
36 +
37   extern char VersionID [];
38  
39  
40 + char*    progname;                  /* argv[0] */
41 + int      dimlist [MAXDIM];          /* sampling dimensions */
42 + int      ndims = 0;                 /* number of sampling dimenshunns */
43 + char*    octname = NULL;            /* octree name */
44 + CUBE     thescene;                  /* scene top-level octree */
45 + OBJECT   nsceneobjs;                /* number of objects in scene */
46 + double   srcsizerat = 0.01;         /* source partition size ratio */
47 + int      backvis = 1;               /* back face visibility */
48 + int      clobber = 0;               /* overwrite output */
49 + COLOR    cextinction = BLKCOLOR;    /* global extinction coefficient */
50 + COLOR    salbedo = BLKCOLOR;        /* global scattering albedo */
51 + double   seccg = 0;                 /* global scattering eccentricity */
52 + int      ambincl = -1;              /* photon port flag */
53 + char     *amblist [AMBLLEN + 1];    /* photon port list */
54 + char     *diagFile = NULL;          /* diagnostics output file */
55 + int      rand_samp = 1;             /* uncorrelated random sampling */
56 + unsigned nproc = 1;                 /* number of parallel processes */
57 + #ifdef EVALDRC_HACK
58 +   char  *angsrcfile = NULL;        /* angular source file for EvalDRC */
59 + #endif
60  
32 char* progname;                         /* argv[0] */
33 int  dimlist [MAXDIM];                  /* sampling dimensions */
34 int  ndims = 0;                         /* number of sampling dimenshunns */
35 char* octname = NULL;                   /* octree name */
36 CUBE thescene;                          /* scene top-level octree */
37 OBJECT nsceneobjs;                      /* number of objects in scene */
38 double srcsizerat = 0.01;               /* source partition size ratio */
39 int backvis = 1;                        /* back face visibility */
40 int clobber = 0;                        /* overwrite output */
41 COLOR cextinction = BLKCOLOR;           /* global extinction coefficient */
42 COLOR salbedo = BLKCOLOR;               /* global scattering albedo */
43 double seccg = 0;                       /* global scattering eccentricity */
44 int ambincl = -1;                       /* photon port flag */
45 char *amblist [AMBLLEN + 1];            /* photon port list */
46 char *diagFile = NULL;                  /* diagnostics output file */
47 int rand_samp = 1;                      /* uncorrelated random sampling */
61  
49
62   /* Dummies for linkage */
63  
64   COLOR ambval = BLKCOLOR;
# Line 59 | Line 71 | int ambvwt = 0, ambssamp = 0, ambres = 32, ambounce =
71   char *shm_boundary = NULL, *ambfile = NULL, *RCCONTEXT = NULL;
72   void (*trace)() = NULL, (*addobjnotify [])() = {ambnotify, NULL};
73  
62
74    
75   void printdefaults()
76   /* print default values to stdout */
77   {
78 <   puts("-apg file nPhotons\t\t# global photon map");
79 <   puts("-apc file nPhotons\t\t# caustic photon map");          
80 <   puts("-apd file nPhotons\t\t# direct photon map");
81 <   puts("-app file nPhotons bwidth\t# precomputed global photon map");
82 < #if 0
83 <   /* Hide this option as most likely useless and confusing to user */
84 <   puts("-appb file nPhotons minBw maxBw\t# precomp bias comp global pmap");
78 >
79 > #ifdef EVALDRC_HACK
80 >   /* EvalDRC support */
81 >   puts("-A\t\t\t\t# angular source file");
82 > #endif    
83 > #ifdef PMAP_EKSPERTZ
84 >   puts("-api xmin ymin zmin xmax ymax zmax\t# region of interest");
85   #endif
86 <   puts("-apv file nPhotons\t\t# volume photon map");
87 <   puts("-apC file nPhotons\t\t# contribution photon map");
88 <  
89 <   printf("-apD %f\t\t\t# predistribution factor\n", preDistrib);
90 <   printf("-apM %d\t\t\t\t# max predistrib passes\n", maxPreDistrib);
91 <   printf("-apm %ld\t\t\t# max photon bounces\n", photonMaxBounce);                            
92 <   puts("-apo mod\t\t\t# photon port modifier");
93 <   puts("-apO file\t\t\t# photon port file");
94 <   printf("-apP %f\t\t\t# precomputation factor\n", finalGather);
95 <   printf("-apr %d\t\t\t\t# random seed\n", randSeed);
96 <   puts("-aps mod\t\t\t# antimatter sensor modifier");
97 <   puts("-apS file\t\t\t# antimatter sensor file");
86 >   puts("-apg file nPhotons\t\t\t# global photon map");
87 >   puts("-apc file nPhotons\t\t\t# caustic photon map");          
88 >   puts("-apd file nPhotons\t\t\t# direct photon map");
89 >   puts("-app file nPhotons bwidth\t\t# precomputed global photon map");
90 >   puts("-apv file nPhotons\t\t\t# volume photon map");
91 >   puts("-apC file nPhotons\t\t\t# contribution photon map");  
92 >   printf("-apD %f\t\t\t\t# predistribution factor\n", preDistrib);
93 >   printf("-apM %d\t\t\t\t\t# max predistrib passes\n", maxPreDistrib);
94 > #if 1
95 >   /* Kept for backwards compat, will be gradually phased out by -lD, -lr */
96 >   printf("-apm %ld\t\t\t\t# limit photon bounces\n", photonMaxBounce);
97 > #endif
98 >   puts("-apo mod\t\t\t\t# photon port modifier");
99 >   puts("-apO file\t\t\t\t# photon port file");
100 >   printf("-apP %f\t\t\t\t# precomputation factor\n", finalGather);
101 >   printf("-apr %d\t\t\t\t\t# random seed\n", randSeed);
102 >   puts("-aps mod\t\t\t\t# antimatter sensor modifier");
103 >   puts("-apS file\t\t\t\t# antimatter sensor file");
104  
105 <   printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n"
106 <                  : "-bv-\t\t\t\t# back face visibility off\n");
107 <   printf("-dp  %.1f\t\t\t# PDF samples / sr\n", pdfSamples);
108 <   printf("-ds  %f\t\t\t# source partition size ratio\n", srcsizerat);
109 <   printf("-e   %s\t\t\t# diagnostics output file\n", diagFile);
110 <   printf(clobber ? "-fo+\t\t\t\t# force overwrite"
111 <                  : "-fo-\t\t\t\t# do not overwrite\n");
112 <   printf("-i   %-9ld\t\t\t# photon heap size increment\n",
113 <          photonHeapSizeInc);
114 <   printf("-ma  %.2f %.2f %.2f\t\t# scattering albedo\n",
105 >   printf(backvis ? "-bv+\t\t\t\t\t# back face visibility on\n"
106 >                  : "-bv-\t\t\t\t\t# back face visibility off\n");
107 >   printf("-dp  %.1f\t\t\t\t# PDF samples / sr\n", pdfSamples);
108 >   printf("-ds  %f\t\t\t\t# source partition size ratio\n", srcsizerat);
109 >   printf("-e   %s\t\t\t\t# diagnostics output file\n", diagFile);
110 >   printf(clobber ? "-fo+\t\t\t\t\t# force overwrite\n"
111 >                  : "-fo-\t\t\t\t\t# do not overwrite\n");
112 > #ifdef PMAP_EKSPERTZ
113 >   /* NU STUFF for Ze Exspertz! */      
114 >   printf("-ld %.1f\t\t\t\t\t# limit photon distance\n", photonMaxDist);
115 >   printf("-lr %ld\t\t\t\t# limit photon bounces\n", photonMaxBounce);  
116 > #endif  
117 >   printf("-ma  %.2f %.2f %.2f\t\t\t# scattering albedo\n",
118            colval(salbedo,RED), colval(salbedo,GRN), colval(salbedo,BLU));
119 <   printf("-me  %.2e %.2e %.2e\t# extinction coefficient\n",
119 >   printf("-me  %.2e %.2e %.2e\t\t# extinction coefficient\n",
120            colval(cextinction,RED), colval(cextinction,GRN),
121            colval(cextinction,BLU));          
122 <   printf("-mg  %.2f\t\t\t# scattering eccentricity\n", seccg);
123 <   printf("-t   %-9d\t\t\t# time between reports\n", photonRepTime);
124 <
125 < #ifdef PMAP_ROI
106 <   /* Ziss option for ze egg-spurtz only! */
107 <   printf("-api \t%.0e %.0e %.0e\n\t%.0e %.0e %.0e\t# region of interest\n",
108 <          pmapROI [0], pmapROI [1], pmapROI [2], pmapROI [3],
109 <          pmapROI [4], pmapROI [5]);
122 >   printf("-mg  %.2f\t\t\t\t# scattering eccentricity\n", seccg);
123 > #if NIX  
124 >   /* Multiprocessing on NIX only */
125 >   printf("-n   %d\t\t\t\t\t# number of parallel processes\n", nproc);
126   #endif  
127 +   printf("-t   %-9d\t\t\t\t# time between reports\n", photonRepTime);
128 +   printf(verbose ? "-v+\t\t\t\t\t# verbose console output\n"
129 +                  : "-v-\t\t\t\t\t# terse console output\n");
130   }
131  
132  
114
115
133   int main (int argc, char* argv [])
134   {
135     #define check(ol, al) if (argv [i][ol] || \
# Line 176 | Line 193 | int main (int argc, char* argv [])
193                 if (!globalPmapParams.distribTarget)
194                    goto badopt;                        
195                 globalPmapParams.minGather = globalPmapParams.maxGather = 0;
196 <            }
180 <                              
181 <            else if (!strcmp(argv [i] + 2, "pm")) {
182 <               /* Max photon bounces */
183 <               check(4, "i");
184 <               photonMaxBounce = atol(argv [++i]);
185 <               if (!photonMaxBounce)
186 <                  goto badopt;
187 <            }
196 >            }                              
197              
198              else if (!strcmp(argv [i] + 2, "pp")) {
199                 /* Precomputed global photon map */
# Line 200 | Line 209 | int main (int argc, char* argv [])
209                    goto badopt;
210              }
211              
203 #if 0
204            else if (!strcmp(argv [i] + 2, "ppb")) {
205               /* Precomputed global photon map + bias comp. */
206               check(5, "ssii");
207               preCompPmapParams.fileName = argv [++i];
208               preCompPmapParams.distribTarget =
209                  parseMultiplier(argv [++i]);
210               if (!preCompPmapParams.distribTarget)
211                  goto badopt;                      
212               preCompPmapParams.minGather = atoi(argv [++i]);
213               preCompPmapParams.maxGather = atoi(argv [++i]);
214               if (!preCompPmapParams.minGather ||
215                   preCompPmapParams.minGather >=
216                   preCompPmapParams.maxGather)
217                  goto badopt;
218            }
219 #endif
220            
212              else if (!strcmp(argv [i] + 2, "pc")) {
213                 /* Caustic photon map */
214                 check(4, "ss");
# Line 257 | Line 248 | int main (int argc, char* argv [])
248                 if (!contribPmapParams.distribTarget)
249                    goto badopt;
250              }
251 <            
251 >
252              else if (!strcmp(argv [i] + 2, "pD")) {
253                 /* Predistribution factor */
254                 check(4, "f");
255                 preDistrib = atof(argv [++i]);
256                 if (preDistrib <= 0)
257                    error(USER, "predistribution factor must be > 0");
258 <            }  
258 >            }
259  
260 < #ifdef PMAP_ROI
261 <            /* Region of interest; ziss option for ze egg-spurtz only! */
260 >            else if (!strcmp(argv [i] + 2, "pM")) {
261 >               /* Max predistribution passes */
262 >               check(4, "i");
263 >               maxPreDistrib = atoi(argv [++i]);
264 >               if (maxPreDistrib <= 0)
265 >                  error(USER, "max predistribution passes must be > 0");
266 >            }
267 > #if 1
268 >            /* Kept for backwards compat, to be phased out by -lr */
269 >            else if (!strcmp(argv [i] + 2, "pm")) {
270 >               /* Max photon bounces */
271 >               check(4, "i");              
272 >               photonMaxBounce = atol(argv [++i]);
273 >               if (photonMaxBounce <= 0)
274 >                  error(USER, "max photon bounces must be > 0");
275 >            }            
276 > #endif
277 > #ifdef PMAP_EKSPERTZ
278 >            /* Add region of interest; for Ze Ekspertz only! */
279              else if (!strcmp(argv [i] + 2, "pi")) {
280 <               int j;
280 >               unsigned j, n = pmapNumROI;
281                 check(4, "ffffff");
282 <               for (j = 0; j < 6; j++)
283 <                  pmapROI [j] = atof(argv [++i]);
284 <            }              
285 < #endif
286 <            
282 >              
283 >               pmapROI = realloc(pmapROI,
284 >                                 ++pmapNumROI * sizeof(PhotonMapROI));
285 >               if (!pmapROI)
286 >                  error(SYSTEM, "failed to allocate ROI");
287 >                  
288 >               pmapROI [n].min [0] = atof(argv [++i]);
289 >               pmapROI [n].min [1] = atof(argv [++i]);
290 >               pmapROI [n].min [2] = atof(argv [++i]);
291 >               pmapROI [n].max [0] = atof(argv [++i]);
292 >               pmapROI [n].max [1] = atof(argv [++i]);
293 >               pmapROI [n].max [2] = atof(argv [++i]);
294 >              
295 >               for (j = 0; j < 3; j++)
296 >                  if (pmapROI [n].min [j] >= pmapROI [n].max [j])
297 >                     error(USER,
298 >                           "invalid region of interest (swapped min/max?)");
299 >            }
300 > #endif            
301              else if (!strcmp(argv [i] + 2, "pP")) {
302                 /* Global photon precomputation factor */
303                 check(4, "f");
# Line 296 | Line 318 | int main (int argc, char* argv [])
318                 }
319                
320                 if (argv[i][3] == 'O') {
321 <                  /* Get port modifiers file */
321 >                  /* Get port modifiers from file */
322                    rval = wordfile(portLp, AMBLLEN-(portLp-amblist),
323 <                                getpath(argv [++i], getrlibpath(), R_OK));
323 >                                  getpath(argv [++i], getrlibpath(), R_OK));
324 >                                  
325                    if (rval < 0) {
326                        sprintf(errmsg, "cannot open photon port file %s",
327                                argv [i]);
# Line 329 | Line 352 | int main (int argc, char* argv [])
352                 if (argv[i][3] == 'S') {
353                    /* Get sensor modifiers from file */
354                    rval = wordfile(sensLp, MAXSET-(sensLp-photonSensorList),
355 <                                getpath(argv [++i], getrlibpath(), R_OK));
355 >                                  getpath(argv [++i], getrlibpath(), R_OK));
356 >                                  
357                    if (rval < 0) {
358                        sprintf(errmsg, "cannot open antimatter sensor file %s",
359                                argv [i]);
# Line 387 | Line 411 | int main (int argc, char* argv [])
411                    
412              else goto badopt;
413              break;
414 <            
415 <         case 'i': /* Photon heap size increment */
416 <            check(2, "i");
417 <            photonHeapSizeInc = atol(argv [++i]);
414 > #ifdef PMAP_EKSPERTZ
415 >         case 'l': /* Limits */
416 >            switch (argv [i][2]) {
417 >               case 'd': /* Limit photon path distance */
418 >                  check(3, "f");
419 >                  photonMaxDist = atof(argv [++i]);
420 >                  if (photonMaxDist <= 0)
421 >                     error(USER, "max photon distance must be > 0");
422 >                  break;
423 >                
424 >               case 'r': /* Limit photon bounces */              
425 >                  check(3, "i");              
426 >                  photonMaxBounce = atol(argv [++i]);
427 >                  if (photonMaxBounce <= 0)
428 >                     error(USER, "max photon bounces must be > 0");
429 >                  break;
430 >              
431 >               default: goto badopt;
432 >            }
433              break;
434 <                  
434 > #endif
435           case 'm': /* Medium */
436              switch (argv[i][2]) {
437                 case 'e':        /* Eggs-tinction coefficient */
# Line 417 | Line 456 | int main (int argc, char* argv [])
456                 default: goto badopt;
457              }                  
458              break;
459 <                  
459 > #if NIX
460 >         case 'n': /* Num parallel processes (NIX only) */
461 >            check(2, "i");
462 >            nproc = atoi(argv [++i]);
463 >            
464 >            if (nproc > PMAP_MAXPROC) {
465 >               nproc = PMAP_MAXPROC;
466 >               sprintf(errmsg, "too many parallel processes, clamping to "
467 >                       "%d\n", nproc);
468 >               error(WARNING, errmsg);
469 >            }            
470 >            break;                  
471 > #endif                        
472           case 't': /* Timer */
473              check(2, "i");
474              photonRepTime = atoi(argv [++i]);
475              break;
476 <                  
476 >            
477 >         case 'v':   /* Verbosity */
478 >            check_bool(2, verbose);
479 >            break;            
480 > #ifdef EVALDRC_HACK
481 >         case 'A':   /* Angular source file */
482 >            check(2,"s");
483 >            angsrcfile = argv[++i];
484 >            break;                  
485 > #endif                              
486           default: goto badopt;
487        }
488     }
# Line 462 | Line 522 | int main (int argc, char* argv [])
522        error(USER, "no photon maps specified");
523    
524     readoct(octname, loadflags, &thescene, NULL);
525 + #ifdef EVALDRC_HACK  
526 +   if (angsrcfile)
527 +      readobj(angsrcfile);    /* load angular sources */
528 + #endif        
529     nsceneobjs = nobjects;
530    
531     /* Get sources */
# Line 470 | Line 534 | int main (int argc, char* argv [])
534     /* Do forward pass and build photon maps */
535     if (contribPmap)
536        /* Just build contrib pmap, ignore others */
537 <      distribPhotonContrib(contribPmap);
537 >      distribPhotonContrib(contribPmap, nproc);
538     else
539 <      distribPhotons(photonMaps);
539 >      distribPhotons(photonMaps, nproc);
540    
541     /* Save photon maps; no idea why GCC needs an explicit cast here... */
542     savePmaps((const PhotonMap**)photonMaps, argc, argv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines