ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/renderopts.c
Revision: 2.25
Committed: Fri Apr 5 17:52:20 2024 UTC (5 weeks, 6 days ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.24: +6 -4 lines
Log Message:
fix(rpict,rtrace,rcontrib,rvu): Fixed bug in feature sublist check

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: renderopts.c,v 2.24 2023/11/18 18:14:26 greg Exp $";
3 #endif
4 /*
5 * renderopts.c - process common rendering options
6 *
7 * External symbols declared in ray.h
8 */
9
10 #include "copyright.h"
11
12 #include "ray.h"
13 #include "paths.h"
14 #include "pmapopt.h"
15
16 extern char *progname; /* global argv[0] */
17
18 char RFeatureList[2048] = /* newline-separated feature list */
19 "VirtualSources\nSecondarySources\nSourceSubsampling\n"
20 "SourceVisibility\nAmbientModifierSelection\n"
21 "PathTracing\nRussianRoulette\nLowDiscrepancySeq\n"
22 "SpecularSampling\nMaterialMixtures\nAntimatter\nBackFaceVisibility\n"
23 "ScatteringModels=WGMD,Ashikhmin-Shirley\n"
24 "TabulatedBSDFs=DataFile,KlemsXML,TensorTreeXML,+ViewPeakExtraction\n"
25 "Instancing=Octree,TriangleMesh\nAliases\n"
26 #if MAXCSAMP>3
27 "Hyperspectral\n"
28 #endif
29 #if !defined(SHADCACHE) || SHADCACHE > 0
30 "ShadowCache\n"
31 #endif
32 #ifdef DISPERSE
33 "DielectricDispersion\n"
34 #endif
35 /* PMAP_FEATURES XXX @Roland: need to define this in pmapopt.h */
36 ;
37
38
39 static char *
40 get_feature( /* find a specific feature (with optional sublist) */
41 const char *feat
42 )
43 {
44 char *cp = RFeatureList;
45 int n = 0;
46
47 while ((feat[n] != '\0') & (feat[n] != '='))
48 n++;
49 if (!n)
50 return(NULL);
51 while (*cp) {
52 if (!strncmp(cp, feat, n) && (cp[n] == '\n') | !feat[n] | (cp[n] == feat[n]))
53 return(cp);
54 while (*cp++ != '\n')
55 ;
56 }
57 return(NULL);
58 }
59
60
61 static int
62 match_subfeatures( /* check if subfeatures are supported */
63 char *mysublist,
64 char *reqs
65 )
66 {
67 if (mysublist)
68 mysublist = strchr(mysublist, '=');
69 if (!mysublist++ | !reqs)
70 return(0); /* not a feature list */
71 while (*reqs) { /* check each of their subfeature requests */
72 char subfeat[64];
73 char *cp = subfeat;
74 int n;
75 while (*reqs && (*cp = *reqs++) != ',')
76 cp++;
77 *cp = '\0';
78 n = cp - subfeat;
79 for (cp = mysublist; (cp = strstr(cp, subfeat)) != NULL; cp++)
80 if ((cp[-1] == ',') | (cp[-1] == '=') &&
81 (cp[n] == ',') | (cp[n] == '\n'))
82 break; /* match */
83 if (!cp)
84 return(0); /* missing this one! */
85 }
86 return(1); /* matched them all */
87 }
88
89
90 int
91 feature_status( /* report active feature list / check specifics */
92 int ac,
93 char *av[]
94 )
95 {
96 if (ac <= 0) /* report entire list? */
97 fputs(RFeatureList, stdout);
98
99 for ( ; ac-- > 0; av++) { /* check each argument */
100 char *cp;
101 if (!*av[0]) continue;
102 if ((cp = strchr(av[0], '=')) != NULL) {
103 if (!match_subfeatures(get_feature(av[0]), cp+1))
104 goto missing_feature;
105 } else if ((cp = get_feature(av[0])) != NULL) {
106 char *tp = strchr(cp, '=');
107 if (tp && tp < strchr(cp, '\n'))
108 do
109 fputc(*cp, stdout);
110 while (*cp++ != '\n');
111 } else
112 goto missing_feature;
113 }
114 return(0); /* return satisfactory status */
115 missing_feature: /* or report error */
116 fprintf(stderr, "%s: missing feature - %s\n", progname, av[0]);
117 return(1);
118 }
119
120
121 int
122 getrenderopt( /* get next render option */
123 int ac,
124 char *av[]
125 )
126 {
127 #define check(ol,al) if (av[0][ol] || \
128 badarg(ac-1,av+1,al)) \
129 return(-1)
130 #define check_bool(olen,var) switch (av[0][olen]) { \
131 case '\0': var = !var; break; \
132 case 'y': case 'Y': case 't': case 'T': \
133 case '+': case '1': var = 1; break; \
134 case 'n': case 'N': case 'f': case 'F': \
135 case '-': case '0': var = 0; break; \
136 default: return(-1); }
137 static char **amblp; /* pointer to build ambient list */
138 int rval;
139 /* is it even an option? */
140 if (ac < 1 || av[0] == NULL || av[0][0] != '-')
141 return(-1);
142 /* check if it's one we know */
143 switch (av[0][1]) {
144 case 'u': /* uncorrelated sampling */
145 check_bool(2,rand_samp);
146 return(0);
147 case 'b': /* back face vis. */
148 if (av[0][2] == 'v') {
149 check_bool(3,backvis);
150 return(0);
151 }
152 break;
153 case 'd': /* direct */
154 switch (av[0][2]) {
155 case 't': /* threshold */
156 check(3,"f");
157 shadthresh = atof(av[1]);
158 return(1);
159 case 'c': /* certainty */
160 check(3,"f");
161 shadcert = atof(av[1]);
162 return(1);
163 case 'j': /* jitter */
164 check(3,"f");
165 dstrsrc = atof(av[1]);
166 return(1);
167 case 'r': /* relays */
168 check(3,"i");
169 directrelay = atoi(av[1]);
170 return(1);
171 case 'p': /* pretest */
172 check(3,"i");
173 vspretest = atoi(av[1]);
174 return(1);
175 case 'v': /* visibility */
176 check_bool(3,directvis);
177 return(0);
178 case 's': /* size */
179 check(3,"f");
180 srcsizerat = atof(av[1]);
181 return(1);
182 }
183 break;
184 case 's': /* specular */
185 switch (av[0][2]) {
186 case 't': /* threshold */
187 check(3,"f");
188 specthresh = atof(av[1]);
189 return(1);
190 case 's': /* sampling */
191 check(3,"f");
192 specjitter = atof(av[1]);
193 return(1);
194 }
195 break;
196 case 'l': /* limit */
197 switch (av[0][2]) {
198 case 'r': /* recursion */
199 check(3,"i");
200 maxdepth = atoi(av[1]);
201 return(1);
202 case 'w': /* weight */
203 check(3,"f");
204 minweight = atof(av[1]);
205 return(1);
206 }
207 break;
208 case 'i': /* irradiance */
209 check_bool(2,do_irrad);
210 return(0);
211 case 'a': /* ambient */
212 switch (av[0][2]) {
213 case 'v': /* value */
214 check(3,"fff");
215 setcolor(ambval, atof(av[1]),
216 atof(av[2]),
217 atof(av[3]));
218 return(3);
219 case 'w': /* weight */
220 check(3,"i");
221 ambvwt = atoi(av[1]);
222 return(1);
223 case 'a': /* accuracy */
224 check(3,"f");
225 ambacc = atof(av[1]);
226 return(1);
227 case 'r': /* resolution */
228 check(3,"i");
229 ambres = atoi(av[1]);
230 return(1);
231 case 'd': /* divisions */
232 check(3,"i");
233 ambdiv = atoi(av[1]);
234 return(1);
235 case 's': /* super-samp */
236 check(3,"i");
237 ambssamp = atoi(av[1]);
238 return(1);
239 case 'b': /* bounces */
240 check(3,"i");
241 ambounce = atoi(av[1]);
242 return(1);
243 case 'i': /* include */
244 case 'I':
245 check(3,"s");
246 if (ambincl != 1) {
247 ambincl = 1;
248 amblp = amblist;
249 }
250 if (av[0][2] == 'I') { /* file */
251 rval = wordfile(amblp, AMBLLEN-(amblp-amblist),
252 getpath(av[1],getrlibpath(),R_OK));
253 if (rval < 0) {
254 sprintf(errmsg,
255 "cannot open ambient include file \"%s\"", av[1]);
256 error(SYSTEM, errmsg);
257 }
258 amblp += rval;
259 } else {
260 *amblp++ = savqstr(av[1]);
261 *amblp = NULL;
262 }
263 return(1);
264 case 'e': /* exclude */
265 case 'E':
266 check(3,"s");
267 if (ambincl != 0) {
268 ambincl = 0;
269 amblp = amblist;
270 }
271 if (av[0][2] == 'E') { /* file */
272 rval = wordfile(amblp, AMBLLEN-(amblp-amblist),
273 getpath(av[1],getrlibpath(),R_OK));
274 if (rval < 0) {
275 sprintf(errmsg,
276 "cannot open ambient exclude file \"%s\"", av[1]);
277 error(SYSTEM, errmsg);
278 }
279 amblp += rval;
280 } else {
281 *amblp++ = savqstr(av[1]);
282 *amblp = NULL;
283 }
284 return(1);
285 case 'f': /* file */
286 check(3,"s");
287 ambfile = savqstr(av[1]);
288 return(1);
289 }
290 break;
291 case 'm': /* medium */
292 switch (av[0][2]) {
293 case 'e': /* extinction */
294 check(3,"fff");
295 setcolor(cextinction, atof(av[1]),
296 atof(av[2]),
297 atof(av[3]));
298 return(3);
299 case 'a': /* albedo */
300 check(3,"fff");
301 setcolor(salbedo, atof(av[1]),
302 atof(av[2]),
303 atof(av[3]));
304 return(3);
305 case 'g': /* eccentr. */
306 check(3,"f");
307 seccg = atof(av[1]);
308 return(1);
309 case 's': /* sampling */
310 check(3,"f");
311 ssampdist = atof(av[1]);
312 return(1);
313 }
314 break;
315 #if MAXCSAMP>3
316 case 'c': /* spectral sampling */
317 switch (av[0][2]) {
318 case 's': /* spectral bin count */
319 check(3,"i");
320 NCSAMP = atoi(av[1]);
321 return(1);
322 case 'w': /* wavelength extrema */
323 check(3,"ff");
324 WLPART[0] = atof(av[1]);
325 WLPART[3] = atof(av[2]);
326 return(2);
327 }
328 break;
329 #endif
330 }
331
332 /* PMAP: Parse photon mapping options */
333 return(getPmapRenderOpt(ac, av));
334
335 /* return(-1); */ /* unknown option */
336
337 #undef check
338 #undef check_bool
339 }
340
341
342 void
343 print_rdefaults(void) /* print default render values to stdout */
344 {
345 printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" :
346 "-i-\t\t\t\t# irradiance calculation off\n");
347 printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" :
348 "-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n");
349 printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" :
350 "-bv-\t\t\t\t# back face visibility off\n");
351 printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
352 printf("-dc %f\t\t\t# direct certainty\n", shadcert);
353 printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
354 printf("-ds %f\t\t\t# direct sampling\n", srcsizerat);
355 printf("-dr %-9d\t\t\t# direct relays\n", directrelay);
356 printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest);
357 printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" :
358 "-dv-\t\t\t\t# direct visibility off\n");
359 printf("-ss %f\t\t\t# specular sampling\n", specjitter);
360 printf("-st %f\t\t\t# specular threshold\n", specthresh);
361 printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
362 colval(ambval,GRN), colval(ambval, BLU));
363 printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt);
364 printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
365 printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
366 printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
367 printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
368 printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
369 printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n",
370 colval(cextinction,RED),
371 colval(cextinction,GRN),
372 colval(cextinction,BLU));
373 printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED),
374 colval(salbedo,GRN), colval(salbedo,BLU));
375 printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg);
376 printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist);
377 if (NCSAMP > 3) {
378 printf("-cs %-2d\t\t\t\t# number of spectral bins\n", NCSAMP);
379 printf("-cw %3.0f %3.0f\t\t\t# wavelength limits (nm)\n",
380 WLPART[3], WLPART[0]);
381 }
382 printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth,
383 maxdepth<=0 ? " (Russian roulette)" : "");
384 printf("-lw %.2e\t\t\t# limit weight\n", minweight);
385
386 /* PMAP: output photon map defaults */
387 printPmapDefaults();
388 }