source: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp @ 2008

Revision 2008, 71.5 KB checked in by bittner, 17 years ago (diff)

ray sort update

Line 
1// ================================================================
2// $Id: environ.cpp,v 1.1 2004/02/16 14:45:59 bittner Exp $
3//
4// environ.cpp
5//     Implementation of the environment operations, ie. reading
6//     environment file, reading command line parameters etc.
7//
8
9//#define _DEBUG_PARAMS
10
11#include <math.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15#include <fstream>
16
17#include "gzstream.h"
18#include "common.h"
19#include "Environment.h"
20#include "Vector3.h"
21
22using namespace std;
23 
24namespace GtpVisibilityPreprocessor {
25
26
27Environment *Environment::sEnvironment = NULL;
28
29
30Environment *Environment::GetSingleton()
31{
32        if (!sEnvironment)
33        {
34                sEnvironment = new Environment();
35        }
36
37        return sEnvironment;
38}
39
40
41void Environment::DelSingleton()
42{
43        DEL_PTR(sEnvironment);
44}
45
46
47Environment::~Environment()
48{
49  int i, j;
50
51  // delete the params structure
52  for (i = 0; i < numParams; i++) {
53    for (j = 0; j < paramRows; j++)
54      if (params[i][j] != NULL)
55        delete[] params[i][j];
56    if (params[i] != NULL)
57      delete[] params[i];
58  }
59
60  if (params != NULL)
61    delete[] params;
62 
63  // delete the options structure
64  if (options != NULL)
65    delete[] options;
66 
67  if (optionalParams != NULL)
68    DEL_PTR(optionalParams);
69}
70
71bool
72Environment::CheckForSwitch(const int argc,
73                                                        char **argv,
74                                                        const char swtch) const
75{
76  for (int i = 1; i < argc; i++)
77    if ((argv[i][0] == '-') && (argv[i][1] == swtch))
78      return true;
79  return false;
80}
81
82bool
83Environment::CheckType(const char *value,
84                        const EOptType type) const
85{
86  char *s, *t, *u;
87
88  switch (type) {
89    case optInt: {
90      strtol(value, &t, 10);
91      if (value + strlen(value) != t)
92        return false;
93      else
94        return true;
95    }
96    case optFloat: {
97      strtod(value, &t);
98      if (value + strlen(value) != t)
99        return false;
100      else
101        return true;
102    }
103    case optBool: {
104      if (!strcasecmp(value, "true") ||
105          !strcasecmp(value, "false") ||
106          !strcasecmp(value, "YES") ||
107          !strcasecmp(value, "NO") ||
108          !strcmp(value, "+") ||
109          !strcmp(value, "-") ||
110          !strcasecmp(value, "ON") ||
111          !strcasecmp(value, "OFF"))
112        return true;
113      return false;
114    }
115    case optVector:{
116      strtod(value, &s);
117      if (*s == ' ' || *s == '\t') {
118        while (*s == ' ' || *s == '\t')
119          s++;
120        if (*s != ',')
121          s--;
122      }
123      if ((*s != ',' && *s != ' ' && *s != '\t') || value == s)
124        return false;
125      t = s;
126      strtod(s + 1, &u);
127      if (*u == ' ' || *u == '\t') {
128        while (*u == ' ' || *u == '\t')
129          u++;
130        if (*u != ',')
131          u--;
132      }
133      if ((*u != ',' && *s != ' ' && *s != '\t') || t == u)
134        return false;
135      t = u;
136      strtod(u + 1, &s);
137      if (t == s || value + strlen(value) != s)
138        return false;
139      return true;
140    }
141    case optString: {
142      return true;
143    }
144    default: {
145      Debug << "Internal error: Unknown type of option.\n" << flush;
146      exit(1);
147    }
148  }
149  return false;
150}
151
152void
153Environment::ReadCmdlineParams(const int argc,
154                                                           char **argv,
155                                                           const char *optParams)
156{
157  int i;
158
159  // Make sure we are called for the first time
160  if (optionalParams != NULL)
161    return;
162
163  numParams = (int)strlen(optParams) + 1;
164  optionalParams = new char[numParams];
165  strcpy(optionalParams, optParams);
166
167  // First, count all non-optional parameters on the command line
168  for (i = 1; i < argc; i++)
169    if (argv[i][0] != '-')
170      paramRows++;
171
172  // if there is no non-optional parameter add a default one...
173  if (paramRows == 0)
174    paramRows = 1;
175 
176  // allocate and initialize the table for parameters
177  params = new char **[numParams];
178  for (i = 0; i < numParams; i++) {
179    params[i] = new char *[paramRows];
180    for (int j = 0; j < paramRows; j++)
181      params[i][j] = NULL;
182  }
183  // Now read all non-optional and optional parameters into the table
184  curRow = -1;
185  for (i = 1; i < argc; i++) {
186    if (argv[i][0] != '-') {
187      // non-optional parameter encountered
188      curRow++;
189      params[0][curRow] = new char[strlen(argv[i]) + 1];
190      strcpy(params[0][curRow], argv[i]);
191    }
192    else {
193      // option encountered
194      char *t = strchr(optionalParams, argv[i][1]);
195      if (t != NULL) {
196        // this option is optional parameter
197        int index = t - optionalParams + 1;
198        if (curRow < 0) {
199          // it's a global parameter
200          for (int j = 0; j < paramRows; j++) {
201            params[index][j] = new char[strlen(argv[i] + 2) + 1];
202            strcpy(params[index][j], argv[i] + 2);
203          }
204        }
205        else {
206          // it's a scene parameter
207          if (params[index][curRow] != NULL) {
208            delete[] params[index][curRow];
209          }
210          params[index][curRow] = new char[strlen(argv[i] + 2) + 1];
211          strcpy(params[index][curRow], argv[i] + 2);
212        }
213      }
214    }
215  }
216  curRow = 0;
217
218#ifdef _DEBUG_PARAMS
219  // write out the parameter table
220  cerr << "Parameter table for " << numParams << " columns and "
221       << paramRows << " rows:\n";
222  for (int j = 0; j < paramRows; j++) {
223    for (i = 0; i < numParams; i++) {
224      if (params[i][j] != NULL)
225        cerr << params[i][j];
226      else
227        cerr << "NULL";
228      cerr << "\t";
229    }
230    cerr << "\n";
231  }
232  cerr << "Params done.\n" << flush;
233#endif // _DEBUG_PARAMS
234}
235
236bool
237Environment::GetParam(const char name,
238                                          const int index,
239                                          char *value) const
240{
241  int column;
242
243  if (index >= paramRows || index < 0)
244    return false;
245  if (name == ' ')
246    column = 0;
247  else {
248    char *t = strchr(optionalParams, name);
249
250    if (t == NULL)
251      return false;
252    column = t - optionalParams + 1;
253  }
254
255  if (params[column][index] == NULL)
256    return false;
257  //  value = new char[strlen(params[column][index]) + 1];
258  strcpy(value, params[column][index]);
259  return true;
260}
261
262void
263Environment::RegisterOption(const char *name,
264                                                        const EOptType type,
265                                                        const char *abbrev,
266                                                        const char *defValue)
267{
268  int i;
269
270  // make sure this option was not yet registered
271  for (i = 0; i < numOptions; i++)
272    if (!strcmp(name, options[i].name)) {
273      Debug << "Error: Option " << name << " registered twice.\n";
274      exit(1);
275    }
276  // make sure we have enough room in memory
277  if (numOptions >= maxOptions) {
278    Debug << "Error: Too many options. Try enlarge the maxOptions "
279          << "definition.\n";
280    exit(1);
281  }
282
283  // make sure the abbreviation doesn't start with 'D'
284  if (abbrev != NULL && (abbrev[0] == 'D' )) {
285    Debug << "Internal error: reserved switch " << abbrev
286         << " used as an abbreviation.\n";
287    exit(1);
288  }
289  // new option
290  options[numOptions].type = type;
291  options[numOptions].name = ::strdup(name);
292  // assign abbreviation, if requested
293  if (abbrev != NULL) {
294          options[numOptions].abbrev = ::strdup(abbrev);
295  }
296  // assign default value, if requested
297  if (defValue != NULL) {
298          options[numOptions].defaultValue = ::strdup(defValue);
299    if (!CheckType(defValue, type)) {
300      Debug << "Internal error: Inconsistent type and default value in option "
301           << name << ".\n";
302      exit(1);
303    }
304  }
305  // new option registered
306  numOptions++;
307}
308
309bool
310Environment::OptionPresent(const char *name) const
311{
312  bool found = false;
313  int i;
314
315  for (i = 0; i < numOptions; i++)
316    if (!strcmp(options[i].name, name)) {
317      found = true;
318      break;
319    }
320  if (!found) {
321    Debug << "Internal error: Option " << name << " not registered.\n" << flush;
322    exit(1);
323  }
324  if (options[i].value != NULL || options[i].defaultValue != NULL)
325    return true;
326  else
327    return false;
328}
329
330int
331Environment::FindOption(const char *name, const bool isFatal) const
332{
333  int i;
334  bool found = false;
335  // is this option registered ?
336  for (i = 0; i < numOptions; i++)
337    if (!strcmp(options[i].name, name)) {
338      found = true;
339      break;
340    }
341  if (!found) {
342    // no registration found
343    Debug << "Internal error: Required option " << name
344          << " not registered.\n" << flush;
345    exit(1);
346  }
347  if (options[i].value == NULL && options[i].defaultValue == NULL)
348    // this option was not initialised to some value
349    if (isFatal) {
350      Debug << "Error: Required option " << name << " not found.\n" << flush;
351      exit(1);
352    }
353    else {
354      Debug << "Error: Required option " << name << " not found.\n" << flush;
355      return -1;
356    }
357  return i;
358}
359
360bool
361Environment::GetIntValue(const char *name,
362                         int &value,
363                         const bool isFatal) const
364{
365  int i = FindOption(name, isFatal);
366
367  if (i<0)
368    return false;
369
370  if (options[i].value != NULL) {
371    // option was explicitly specified
372    value = strtol(options[i].value, NULL, 10);
373  } else {
374    // option was not read, so use the default
375    value = strtol(options[i].defaultValue, NULL, 10);
376  }
377
378  return true;
379}
380
381bool
382Environment::GetDoubleValue(const char *name,
383                            double &value,
384                            const bool isFatal) const
385{
386  int i = FindOption(name, isFatal);
387
388  if (i<0)
389    return false;
390
391  if (options[i].value != NULL) {
392    // option was explicitly specified
393    value = strtod(options[i].value, NULL);
394  } else {
395    // option was not read, so use the default
396    value = strtod(options[i].defaultValue, NULL);
397  }
398  return true;
399}
400
401bool
402Environment::GetRealValue(const char *name,
403                          Real &value,
404                          const bool isFatal) const
405{
406  int i = FindOption(name, isFatal);
407 
408  if (i<0)
409    return false;
410
411  if (options[i].value != NULL) {
412    // option was explicitly specified
413    value = (Real)strtod(options[i].value, NULL);
414  } else {
415    // option was not read, so use the default
416    value = (Real)strtod(options[i].defaultValue, NULL);
417  }
418  return true;
419}
420
421bool
422Environment::GetFloatValue(const char *name,
423                           float &value,
424                           const bool isFatal) const
425{
426  int i = FindOption(name, isFatal);
427
428  if (i<0)
429    return false;
430
431  if (options[i].value != NULL) {
432    // option was explicitly specified
433    value = (float)strtod(options[i].value, NULL);
434  } else {
435    // option was not read, so use the default
436    value = (float)strtod(options[i].defaultValue, NULL);
437  }
438  return true;
439}
440
441bool
442Environment::GetBool(const char *name,
443                     const bool isFatal) const
444{
445  bool ret;
446  if (GetBoolValue(name, ret, isFatal))
447    return ret;
448  else
449    return false;
450}
451
452bool
453Environment::ParseBool(const char *name) const
454{
455
456  bool value = true;
457 
458  if (!strcasecmp(name, "false") ||
459      !strcasecmp(name, "NO") ||
460      !strcmp(name, "-") ||
461      !strcasecmp(name, "OFF"))
462    value = false;
463 
464  return value;
465}
466
467void
468Environment::ParseVector(const char *name, Vector3 &v) const
469{
470  // option was not read, so use the default
471  char *s, *t;
472 
473  v.x = (Real)strtod(name, &s);
474  v.y = (Real)strtod(s + 1, &t);
475  v.z = (Real)strtod(t + 1, NULL);
476
477}
478
479bool
480Environment::GetBoolValue(const char *name,
481                           bool &value,
482                           const bool isFatal) const
483{
484  int i = FindOption(name, isFatal);
485
486  if (i<0)
487    return false;
488
489 
490  if (options[i].value != NULL)
491    value = ParseBool(options[i].value);
492  else
493    value = ParseBool(options[i].defaultValue);
494
495  return true;
496}
497
498bool
499Environment::GetVectorValue(const char *name,
500                            Vector3 &v,
501                            const bool isFatal) const
502{
503  int i = FindOption(name, isFatal);
504  if (i<0)
505    return false;
506
507  if (options[i].value != NULL)
508
509   
510  if (options[i].value != NULL) {
511    ParseVector(options[i].value, v);
512  }
513  else {
514    ParseVector(options[i].defaultValue, v);
515  }
516  return true;
517}
518
519bool
520Environment::GetStringValue(const char *name,
521                                                        char *value,
522                                                        const bool isFatal) const
523{
524  int i = FindOption(name, isFatal);
525
526  if (i<0)
527    return false;
528
529 
530  if (options[i].value != NULL) {
531    // option was not read, so use the default
532    strcpy(value, options[i].value);
533  }
534  else {
535    // option was explicitly specified
536    strcpy(value, options[i].defaultValue);
537  }
538  return true;
539}
540
541void
542Environment::SetInt(const char *name, const int value)
543{
544
545  int i = FindOption(name);
546  if (i<0)
547    return;
548
549  if (options[i].type == optInt) {
550    delete options[i].value;
551    options[i].value = new char[16];
552    sprintf(options[i].value, "%.15d", value);
553  }
554  else {
555    Debug << "Internal error: Trying to set non-integer option " << name
556          << " to integral value.\n" << flush;
557    exit(1);
558  }
559}
560
561void
562Environment::SetFloat(const char *name, const Real value)
563{
564  int i = FindOption(name);
565  if (i<0)
566    return;
567
568  if (options[i].type == optFloat) {
569    delete options[i].value;
570    options[i].value = new char[25];
571    sprintf(options[i].value, "%.15e", value);
572  }
573  else {
574    Debug << "Internal error: Trying to set non-Real option " << name
575          << " to Real value.\n" << flush;
576    exit(1);
577  }
578}
579
580void
581Environment::SetBool(const char *name, const bool value)
582{
583  int i = FindOption(name);
584  if (i<0)
585    return;
586
587  if (options[i].type == optBool) {
588    delete options[i].value;
589    options[i].value = new char[6];
590    if (value)
591      sprintf(options[i].value, "true");
592    else
593      sprintf(options[i].value, "false");
594  }
595  else {
596    Debug << "Internal error: Trying to set non-bool option " << name
597          << " to boolean value.\n" << flush;
598    exit(1);
599  }
600}
601
602void
603Environment::SetVector(const char *name,
604                       const Vector3 &v)
605{
606  int i = FindOption(name);
607  if (i<0)
608    return;
609
610  if (options[i].type == optVector) {
611    delete options[i].value;
612    options[i].value = new char[128];
613    sprintf(options[i].value, "%.15e,%.15e,%.15e", v.x, v.y, v.z);
614  }
615  else {
616    Debug << "Internal error: Trying to set non-vector option " << name
617          << " to vector value.\n" << flush;
618    exit(1);
619  }
620}
621
622void
623Environment::SetString(const char *name, const char *value)
624{
625  int i = FindOption(name);
626  if (i<0)
627    return;
628
629  if (options[i].type == optString) {
630    delete options[i].value;
631        options[i].value = ::strdup(value);
632  }
633  else {
634    Debug << "Internal error: Trying to set non-string option " << name
635          << " to string value.\n" << flush;
636    exit(1);
637  }
638}
639
640void
641Environment::ParseCmdline(const int argc,
642                                                  char **argv,
643                                                  const int index)
644{
645  int curIndex = -1;
646
647  for (int i = 1; i < argc; i++) {
648    // if this parameter is non-optional, skip it and increment the counter
649    if (argv[i][0] != '-') {
650      curIndex++;
651      continue;
652    }
653    // make sure to skip all non-optional parameters
654    char *t = strchr(optionalParams, argv[i][1]);
655    if (t != NULL)
656      continue;
657
658    // if we are in the scope of the current parameter, parse it
659    if (curIndex == -1 || curIndex == index) {
660      if (argv[i][1] == 'D') {
661        // it's a full name definition
662        bool found = false;
663        int j;
664
665        char *t = strchr(argv[i] + 2, '=');
666        if (t == NULL) {
667          Debug << "Error: Missing '=' in option. "
668                << "Syntax is -D<name>=<value>.\n" << flush;
669          exit(1);
670        }
671        for (j = 0; j < numOptions; j++)
672          if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) &&
673              (unsigned)(t - argv[i] - 2) == strlen(options[j].name)) {
674            found = true;
675            break;
676          }
677        if (!found) {
678          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
679          //  exit(1);
680        }
681        if (found) {
682          if (!CheckType(t + 1, options[j].type)) {
683            Debug << "Error: invalid type of value " << t + 1 << " in option "
684                  << options[j].name << ".\n";
685            exit(1);
686          }
687          if (options[j].value != NULL)
688            delete options[j].value;
689          options[j].value = strdup(t + 1);
690        }
691      }
692      else {
693        // it's an abbreviation
694        bool found = false;
695        int j;
696       
697        for (j = 0; j < numOptions; j++)
698          if (options[j].abbrev != NULL &&
699              !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev))) {
700            found = true;
701            break;
702          }
703        if (!found) {
704          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
705          //          exit(1);
706        }
707        if (found) {
708          if (!CheckType(argv[i] + 1 + strlen(options[j].abbrev), options[j].type)) {
709            Debug << "Error: invalid type of value "
710                  << argv[i] + 1 + strlen(options[j].abbrev) << "in option "
711                  << options[j].name << ".\n";
712            exit(1);
713          }
714          if (options[j].value != NULL)
715            delete options[j].value;
716          options[j].value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
717        }
718      }
719    }
720  }
721#ifdef _DEBUG_PARAMS
722  // write out the options table
723  cerr << "Options table for " << numOptions << " options:\n";
724  for (int j = 0; j < numOptions; j++) {
725    cerr << options[j];
726    cerr << "\n";
727  }
728  cerr << "Options done.\n" << flush;
729#endif // _DEBUG_PARAMS
730}
731
732
733char *
734Environment::ParseString(char *buffer, char *string) const
735{
736  char *s = buffer;
737  char *t = string + strlen(string);
738
739  // skip leading whitespaces
740  while (*s == ' ' || *s == '\t')
741    s++;
742  if (*s == '\0')
743    return NULL;
744  while ((*s >= 'a' && *s <= 'z') ||
745         (*s >= 'A' && *s <= 'Z') ||
746         (*s >= '0' && *s <= '9') ||
747         *s == '_')
748    *t++ = *s++;
749  *t = '\0';
750  // skip trailing whitespaces
751  while (*s == ' ' || *s == '\t')
752    s++;
753  return s;
754}
755
756const char code[] = "JIDHipewhfdhyd74387hHO&{WK:DOKQEIDKJPQ*H#@USX:#FWCQ*EJMQAHPQP(@G#RD";
757
758void
759Environment::DecodeString(char *buff, int max)
760{
761  buff[max] = 0;
762  char *p = buff;
763  const char *cp = code;
764  for (; *p; p++) {
765    if (*p != '\n')
766      *p = *p ^ *cp;
767    ++cp;
768    if (*cp == 0)
769      cp = code;
770  }
771}
772
773void
774Environment::CodeString(char *buff, int max)
775{
776  buff[max] = 0;
777  char *p = buff;
778  const char *cp = code;
779  for (; *p; p++) {
780    if (*p != '\n')
781      *p = *p ^ *cp;
782    ++cp;
783    if (*cp == 0)
784      cp = code;
785  }
786}
787
788void
789Environment::SaveCodedFile(char *filenameText,
790                            char *filenameCoded)
791{
792  ifstream envStream(filenameText);
793 
794  // some error had occured
795  if (envStream.fail()) {
796    cerr << "Error: Can't open file " << filenameText << " for reading (err. "
797         << envStream.rdstate() << ").\n";
798    return;
799  }
800
801  char buff[256];
802  envStream.getline(buff, 255);
803  buff[8] = 0;
804  if (strcmp(buff, "CGX_CF10") == 0)
805    return;
806
807  ofstream cStream(filenameCoded);
808  cStream<<"CGX_CF10";
809 
810  // main loop
811  for (;;) {
812    // read in one line
813    envStream.getline(buff, 255);
814    if (!envStream)
815      break;
816    CodeString(buff, 255);
817    cStream<<buff;
818  }
819 
820}
821
822bool
823Environment::ReadEnvFile(const char *envFilename)
824{
825  char buff[MaxStringLength], name[MaxStringLength];
826  char *s, *t;
827  int i, line = 0;
828  bool found;
829  igzstream envStream(envFilename);
830
831  // some error had occured
832  if (envStream.fail()) {
833    cerr << "Error: Can't open file " << envFilename << " for reading (err. "
834         << envStream.rdstate() << ").\n";
835    return false;
836  }
837
838  name[0] = '\0';
839
840//    bool coded;
841//    envStream.getline(buff, 255);
842//    buff[8] = 0;
843//    if (strcmp(buff, "CGX_CF10") == 0)
844//      coded = true;
845//    else {
846//      coded = false;
847//      envStream.Rewind();
848//    }
849 
850  // main loop
851  for (;;) {
852    // read in one line
853    envStream.getline(buff, MaxStringLength-1);
854   
855    if (!envStream)
856      break;
857
858//      if (coded)
859//        DecodeString(buff, 255);
860
861    line++;
862    // get rid of comments
863    s = strchr(buff, '#');
864    if (s != NULL)
865      *s = '\0';
866
867    // get one identifier
868    s = ParseString(buff, name);
869    // parse line
870    while (s != NULL) {
871      // it's a group name - make the full name
872      if (*s == '{') {
873        strcat(name, ".");
874        s++;
875        s = ParseString(s, name);
876        continue;
877      }
878      // end of group
879      if (*s == '}') {
880        if (strlen(name) == 0) {
881          cerr << "Error: unpaired } in " << envFilename << " (line "
882               << line << ").\n";
883          envStream.close();
884          return false;
885        }
886        name[strlen(name) - 1] = '\0';
887        t = strrchr(name, '.');
888        if (t == NULL)
889          name[0] = '\0';
890        else
891          *(t + 1) = '\0';
892        s++;
893        s = ParseString(s, name);
894        continue;
895      }
896      // find variable name in the table
897      found = false;
898      for (i = 0; i < numOptions; i++)
899        if (!strcmp(name, options[i].name)) {
900          found = true;
901          break;
902        }
903      if (!found) {
904        cerr << "Warning: unknown option " << name << " in environment file "
905             << envFilename << " (line " << line << ").\n";
906      } else
907        switch (options[i].type) {
908        case optInt: {
909          strtol(s, &t, 10);
910          if (t == s || (*t != ' ' && *t != '\t' &&
911                         *t != '\0' && *t != '}')) {
912            cerr << "Error: Mismatch in int variable " << name << " in "
913                 << "environment file " << envFilename << " (line "
914                 << line << ").\n";
915            envStream.close();
916            return false;
917          }
918          if (options[i].value != NULL)
919            delete options[i].value;
920          options[i].value = new char[t - s + 1];
921          strncpy(options[i].value, s, t - s);
922          options[i].value[t - s] = '\0';
923          s = t;
924          break;
925        }
926        case optFloat: {
927          strtod(s, &t);
928          if (t == s || (*t != ' ' && *t != '\t' &&
929                         *t != '\0' && *t != '}')) {
930            cerr << "Error: Mismatch in Real variable " << name << " in "
931                 << "environment file " << envFilename << " (line "
932                 << line << ").\n";
933            envStream.close();
934            return false;
935          }
936          if (options[i].value != NULL)
937            delete options[i].value;
938          options[i].value = new char[t - s + 1];
939          strncpy(options[i].value, s, t - s);
940          options[i].value[t - s] = '\0';
941          s = t;
942          break;
943        }
944        case optBool: {
945          t = s;
946          while ((*t >= 'a' && *t <= 'z') ||
947                 (*t >= 'A' && *t <= 'Z') ||
948                 *t == '+' || *t == '-')
949            t++;
950          if (((!strncasecmp(s, "true", t - s)  && t - s == 4) ||
951               (!strncasecmp(s, "false", t - s) && t - s == 5) ||
952               (!strncasecmp(s, "YES", t -s)    && t - s == 3) ||
953               (!strncasecmp(s, "NO", t - s)    && t - s == 2) ||
954               (!strncasecmp(s, "ON", t - s)    && t - s == 2) ||
955               (!strncasecmp(s, "OFF", t - s)   && t - s == 3) ||
956               (t - s == 1 && (*s == '+' || *s == '-'))) &&
957              (*t == ' ' || *t == '\t' || *t == '\0' || *t == '}')) {
958            if (options[i].value != NULL)
959              delete options[i].value;
960            options[i].value = new char[t - s + 1];
961            strncpy(options[i].value, s, t - s);
962            options[i].value[t - s] = '\0';
963            s = t;
964          }
965          else {
966            cerr << "Error: Mismatch in bool variable " << name << " in "
967                 << "environment file " << envFilename << " (line "
968                 << line << ").\n";
969            envStream.close();
970            return false;
971          }
972          break;
973        }
974        case optVector:{
975          strtod(s, &t);
976          if (*t == ' ' || *t == '\t') {
977            while (*t == ' ' || *t == '\t')
978              t++;
979            if (*t != ',')
980              t--;
981          }
982          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
983            cerr << "Error: Mismatch in vector variable " << name << " in "
984                 << "environment file " << envFilename << " (line "
985                 << line << ").\n";
986            envStream.close();
987            return false;
988          }
989          char *u;
990          strtod(t, &u);
991          t = u;
992          if (*t == ' ' || *t == '\t') {
993            while (*t == ' ' || *t == '\t')
994              t++;
995            if (*t != ',')
996              t--;
997          }
998          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
999            cerr << "Error: Mismatch in vector variable " << name << " in "
1000                 << "environment file " << envFilename << " (line "
1001                 << line << ").\n";
1002            envStream.close();
1003            return false;
1004          }
1005          strtod(t, &u);
1006          t = u;
1007          if (t == s || (*t != ' ' && *t != '\t' &&
1008                         *t != '\0' && *t != '}')) {
1009            cerr << "Error: Mismatch in vector variable " << name << " in "
1010                 << "environment file " << envFilename << " (line "
1011                 << line << ").\n";
1012            envStream.close();
1013            return false;
1014          }
1015          if (options[i].value != NULL)
1016            delete options[i].value;
1017          options[i].value = new char[t - s + 1];
1018          strncpy(options[i].value, s, t - s);
1019          options[i].value[t - s] = '\0';
1020          s = t;
1021          break;
1022        }
1023        case optString: {
1024          if (options[i].value != NULL)
1025            delete options[i].value;
1026          options[i].value = new char[strlen(s) + 1];
1027          strcpy(options[i].value, s);
1028          s += strlen(s);
1029          break;
1030        }
1031        default: {
1032          Debug << "Internal error: Unknown type of option.\n" << flush;
1033          exit(1);
1034        }
1035      }
1036      // prepare the variable name for next pass
1037      t = strrchr(name, '.');
1038      if (t == NULL)
1039        name[0] = '\0';
1040      else
1041        *(t + 1) = '\0';
1042      // get next identifier
1043      s = ParseString(s, name);
1044    }
1045  }
1046  envStream.close();
1047  return true;
1048}
1049
1050void
1051Environment::PrintUsage(ostream &s) const
1052{
1053  // Print out all environment variable names
1054  s << "Registered options:\n";
1055  for (int j = 0; j < numOptions; j++)
1056    s << options[j] << "\n";
1057  s << flush;
1058}
1059
1060  /**
1061         Input scene filename. Currently simplified X3D (.x3d), Unigraphics (.dat),
1062         and UNC (.ply) formats are supported.
1063  */
1064
1065Environment::Environment()
1066{
1067  optionalParams = NULL;
1068  paramRows = 0;
1069  numParams = 0;
1070  params = NULL;
1071  maxOptions = 500;
1072
1073 
1074// this is maximal nuber of options.
1075  numOptions = 0;
1076
1077  options = new COption[maxOptions];
1078
1079  if (options == NULL ) {
1080    Debug << "Error: Memory allocation failed.\n";
1081    exit(1);
1082  }
1083 
1084  // register all basic options
1085
1086  RegisterOption("Limits.threshold", optFloat, NULL, "0.01");
1087  RegisterOption("Limits.small", optFloat, NULL, "1e-6");
1088  RegisterOption("Limits.infinity", optFloat, NULL, "1e6");
1089
1090  RegisterOption("Scene.filename",
1091                                 optString,
1092                                 "scene_filename=",
1093                                 "atlanta2.x3d");
1094
1095  RegisterOption("Unigraphics.meshGrouping",
1096                                 optInt,
1097                                 "unigraphics_mesh_grouping=",
1098                                 "0");
1099 
1100   RegisterOption("ObjParser.meshGrouping",
1101                                 optInt,
1102                                 "objparser_mesh_grouping=",
1103                                 "0");
1104
1105  RegisterOption("KdTree.Termination.minCost",
1106                                 optInt,
1107                                 "kd_term_min_cost=",
1108                                 "10");
1109 
1110  RegisterOption("KdTree.Termination.maxNodes",
1111                                 optInt,
1112                                 "kd_term_max_nodes=",
1113                                 "200000");
1114 
1115  RegisterOption("KdTree.Termination.maxDepth",
1116                                 optInt,
1117                                 "kd_term_max_depth=",
1118                                 "20");
1119
1120  RegisterOption("KdTree.Termination.maxCostRatio",
1121                                 optFloat,
1122                                 "kd_term_max_cost_ratio=",
1123                                 "1.5");
1124
1125  RegisterOption("KdTree.Termination.ct_div_ci",
1126                                 optFloat,
1127                                 "kd_term_ct_div_ci=",
1128                                 "1.0");
1129
1130  RegisterOption("KdTree.splitMethod",
1131                                 optString,
1132                                 "kd_split_method=",
1133                                 "spatialMedian");
1134
1135  RegisterOption("KdTree.splitBorder",
1136                 optFloat,
1137                 "kd_split_border=",
1138                 "0.1");
1139
1140  RegisterOption("KdTree.sahUseFaces",
1141                 optBool,
1142                 "kd_sah_use_faces=",
1143                 "true");
1144
1145  RegisterOption("MeshKdTree.Termination.minCost",
1146                 optInt,
1147                 "kd_term_min_cost=",
1148                 "10");
1149 
1150  RegisterOption("MeshKdTree.Termination.maxDepth",
1151                 optInt,
1152                 "kd_term_max_depth=",
1153                 "20");
1154
1155  RegisterOption("MeshKdTree.Termination.maxCostRatio",
1156                 optFloat,
1157                 "kd_term_max_cost_ratio=",
1158                 "1.5");
1159
1160  RegisterOption("MeshKdTree.Termination.ct_div_ci",
1161                 optFloat,
1162                 "kd_term_ct_div_ci=",
1163                 "1.0");
1164
1165  RegisterOption("MeshKdTree.splitMethod",
1166                 optString,
1167                 "kd_split_method=",
1168                 "spatialMedian");
1169
1170  RegisterOption("MeshKdTree.splitBorder",
1171                 optFloat,
1172                 "kd_split_border=",
1173                 "0.1");
1174
1175  RegisterOption("Preprocessor.totalSamples",
1176                                 optInt,
1177                                 "total_samples=",
1178                                 "10000000");
1179
1180  RegisterOption("Preprocessor.samplesPerPass",
1181                                 optInt,
1182                                 "samples_per_pass=",
1183                                 "100000");
1184 
1185  RegisterOption("Preprocessor.samplesPerEvaluation",
1186                                 optInt,
1187                                 "samples_per_evaluation=",
1188                                 "1000000");
1189
1190  RegisterOption("Preprocessor.useHwGlobalLines",
1191                                 optBool,
1192                                 "preprocessor_use_hw_global_lines=",
1193                                 "false");
1194
1195   RegisterOption("Preprocessor.HwGlobalLines.texHeight",
1196                                  optInt,
1197                                  "preprocessor_hw_global_lines_texheight=",
1198                                  "128");
1199
1200    RegisterOption("Preprocessor.HwGlobalLines.texWidth",
1201                                   optInt,
1202                                   "preprocessor_hw_global_lines_texwidth=",
1203                                   "128");
1204
1205        RegisterOption("Preprocessor.HwGlobalLines.stepSize",
1206                                   optFloat,
1207                                   "preprocessor_hw_global_lines_stepsize=",
1208                                   "0.0001");
1209
1210        RegisterOption("Preprocessor.HwGlobalLines.maxDepth",
1211                                   optInt,
1212                                   "preprocessor_hw_global_lines_max_depth=",
1213                                   "50");
1214
1215        RegisterOption("Preprocessor.HwGlobalLines.sampleReverse",
1216                                   optBool,
1217                                   "preprocessor_hw_global_lines_sample_reverse=",
1218                                   "true");
1219
1220  RegisterOption("RenderSampler.samples",
1221                                 optInt,
1222                                 "render_sampler_samples=",
1223                                 "1000");
1224
1225  RegisterOption("RenderSampler.visibleThreshold",
1226                                 optInt,
1227                                 "render_sampler_visible_threshold=",
1228                                 "0");
1229
1230   RegisterOption("RenderSampler.useOcclusionQueries",
1231                                 optBool,
1232                                 "render_sampler_use_occlusion_queries=",
1233                                 "true");
1234
1235//    RegisterOption("VssPreprocessor.initialSamples",
1236//                               optInt,
1237//                               "vss_initial_samples=",
1238//                               "100000");
1239 
1240  RegisterOption("VssPreprocessor.testBeamSampling",
1241                                optBool,
1242                                "vss_beam_sampling=",
1243                                "false");
1244
1245//   RegisterOption("VssPreprocessor.vssSamples",
1246//                               optInt,
1247//                               "vss_samples=",
1248//                               "1000000");
1249       
1250//   RegisterOption("VssPreprocessor.vssSamplesPerPass",
1251//                               optInt,
1252//                               "vss_samples_per_pass=",
1253//                               "1000");
1254 
1255//   RegisterOption("VssPreprocessor.samplesPerPass",
1256//                               optInt,
1257//                               "vss_samples_per_pass=",
1258//                               "100000");
1259
1260  RegisterOption("VssPreprocessor.useImportanceSampling",
1261                                 optBool,
1262                                 "vss_use_importance=",
1263                                 "true");
1264
1265 
1266   RegisterOption("VssPreprocessor.enlargeViewSpace",
1267                                 optBool,
1268                                 "vss_enlarge_viewspace=",
1269                                 "false");
1270
1271   RegisterOption("VssPreprocessor.loadInitialSamples",
1272          optBool,
1273          "vss_load_loadInitialSamples=",
1274          "false");
1275
1276   RegisterOption("VssPreprocessor.storeInitialSamples",
1277          optBool,
1278          "vss_store_storedInitialSamples=",
1279          "false");
1280 
1281
1282
1283   /*************************************************************************/
1284   /*                       GvsPrerpocessor related options                 */
1285   /*************************************************************************/
1286
1287
1288   RegisterOption("GvsPreprocessor.totalSamples",
1289                 optInt,
1290                 "gvs_total_samples=",
1291                 "1000000");
1292   
1293   RegisterOption("GvsPreprocessor.samplesPerPass",
1294                 optInt,
1295                 "gvs_samples_per_pass=",
1296                 "100000");
1297   
1298   RegisterOption("GvsPreprocessor.initialSamples",
1299                 optInt,
1300                 "gvs_initial_samples=",
1301                 "256");
1302
1303   RegisterOption("GvsPreprocessor.epsilon",
1304                 optFloat,
1305                 "gvs_epsilon=",
1306                 "0.00001");
1307
1308    RegisterOption("GvsPreprocessor.threshold",
1309                 optFloat,
1310                 "gvs_threshold=",
1311                 "1.5");
1312
1313        RegisterOption("GvsPreprocessor.perViewCell",
1314                optBool,
1315                "gvs_per_viewcell=",
1316                "false");
1317
1318        RegisterOption("GvsPreprocessor.stats",
1319                optString,
1320                "gvs_stats=",
1321                "gvsStats.log");
1322
1323        RegisterOption("GvsPreprocessor.minContribution",
1324                 optInt,
1325                 "gvs_min_contribution=",
1326                 "50");
1327
1328         RegisterOption("GvsPreprocessor.maxViewCells",
1329                 optInt,
1330                 "gvs_max_viewcells=",
1331                 "5");
1332
1333
1334  /**********************************************************************/
1335  /*                     View cells related options                     */
1336  /**********************************************************************/
1337
1338
1339        RegisterOption("ViewCells.type",
1340                        optString,
1341                        "view_cells_type=",
1342                        "vspBspTree");
1343
1344        RegisterOption("ViewCells.samplingType",
1345                        optString,
1346                        "view_cells_sampling_type=",
1347                        "box");
1348
1349        RegisterOption("ViewCells.mergeStats",
1350                                        optString,
1351                                        "view_cells_merge_stats=",
1352                                        "mergeStats.log");
1353
1354        RegisterOption("ViewCells.Evaluation.statsPrefix",
1355                                        optString,
1356                                        "view_cells_evaluation_stats_prefix=",
1357                                        "viewCells");
1358
1359        RegisterOption("ViewCells.Evaluation.histogram",
1360                                        optBool,
1361                                        "view_cells_evaluation_histogram=",
1362                                        "false");
1363
1364        RegisterOption("ViewCells.Evaluation.histoStepSize",
1365                                        optInt,
1366                                        "view_cells_evaluation_histo_step_size=",
1367                                        "5000");
1368
1369        RegisterOption("ViewCells.Evaluation.histoMem",
1370                                        optInt,
1371                                        "view_cells_evaluation_histo_mem=",
1372                                        "50");
1373
1374        RegisterOption("ViewCells.renderCostEvaluationType",
1375                                        optString,
1376                                        "view_cells_render_cost_evaluation=",
1377                                        "perobject");
1378
1379        RegisterOption("ViewCells.active",
1380                                        optInt,
1381                                        "view_cells_active=",
1382                                        "1000");
1383
1384        RegisterOption("ViewCells.Construction.samples",
1385                                        optInt,
1386                                        "view_cells_construction_samples=",
1387                                        "0");
1388
1389        RegisterOption("ViewCells.Construction.samplesPerPass",
1390                                        optInt,
1391                                        "view_cells_construction_samples_per_pass=",
1392                                        "500000");
1393
1394        RegisterOption("ViewCells.PostProcess.samples",
1395                                        optInt,
1396                                        "view_cells_post_process_samples=",
1397                                        "0");
1398
1399        RegisterOption("ViewCells.Visualization.samples",
1400                                        optInt,
1401                                        "view_cells_visualization_samples=",
1402                                        "0");
1403
1404        RegisterOption("ViewCells.Visualization.maxOutput",
1405                                        optInt,
1406                                        "view_cells_visualization_max_output=",
1407                                        "20");
1408
1409        RegisterOption("ViewCells.Filter.maxSize",
1410                                        optInt,
1411                                        "view_cells_filter_max_size=",
1412                                        "4");
1413
1414        RegisterOption("ViewCells.Filter.width",
1415                                        optFloat,
1416                                        "view_cells_filter_width=",
1417                                        "200.0");
1418
1419        RegisterOption("ViewCells.loadFromFile",
1420                                        optBool,
1421                                        "view_cells_load_from_file=",
1422                                        "false");
1423
1424        RegisterOption("ViewCells.PostProcess.refine",
1425                                        optBool,
1426                                        "view_cells_refine=",
1427                                        "false");
1428
1429        RegisterOption("ViewCells.PostProcess.compress",
1430                                        optBool,
1431                                        "view_cells_post_process_compress=",
1432                                        "false");
1433
1434        RegisterOption("ViewCells.Evaluation.samples",
1435                                        optInt,
1436                                        "view_cells_evaluation_samples=",
1437                                        "8000000");
1438
1439        RegisterOption("ViewCells.Evaluation.samplingType",
1440                                        optString,
1441                                        "view_cells_evaluation_sampling_type=",
1442                                        "box");
1443
1444        RegisterOption("ViewCells.Evaluation.samplesPerPass",
1445                                        optInt,
1446                                        "view_cells_evaluation_samples_per_pass=",
1447                                        "300000");
1448
1449        RegisterOption("ViewCells.Evaluation.samplesForStats",
1450                                        optInt,
1451                                        "view_cells_evaluation_samples_for_stats=",
1452                                        "300000");
1453
1454        RegisterOption("ViewCells.exportToFile",
1455                                        optBool,
1456                                        "view_cells_export_to_file=",
1457                                        "false");
1458
1459        RegisterOption("ViewCells.exportPvs",
1460                                        optBool,
1461                                        "view_cells_export_pvs=",
1462                                        "false");
1463
1464        RegisterOption("ViewCells.exportBboxesForPvs",
1465                                        optBool,
1466                                        "view_cells_export_bounding_boxes=",
1467                                        "true");
1468       
1469        RegisterOption("ViewCells.boxesFilename",
1470                                        optString,
1471                                        "view_cells_boxes_filename=",
1472                                        "boxes.out");
1473
1474        RegisterOption("ViewCells.evaluateViewCells",
1475                                        optBool,
1476                                        "view_cells_evaluate=",
1477                                        "false");
1478
1479        RegisterOption("ViewCells.maxViewCells",
1480                                        optInt,
1481                                        "view_cells_max_view_cells=",
1482                                        "0");
1483
1484        RegisterOption("ViewCells.Evaluation.stepSize",
1485                                        optInt,
1486                                        "view_cells_evaluation_step_size=",
1487                                        "100");
1488
1489        RegisterOption("ViewCells.maxPvsRatio",
1490                                        optFloat,
1491                                        "view_cells_max_pvs_ratio=",
1492                                        "0.1");
1493
1494        RegisterOption("ViewCells.filename",
1495                                        optString,
1496                                        "view_cells_filename=",
1497                                        "atlanta_viewcells_large.x3d");
1498
1499        RegisterOption("ViewCells.height",
1500                                        optFloat,
1501                                        "view_cells_height=",
1502                                        "5.0");
1503
1504        RegisterOption("ViewCells.Visualization.colorCode",
1505                                        optString,
1506                                        "view_cells_visualization_color_code=",
1507                                        "PVS");
1508
1509        RegisterOption("ViewCells.Visualization.clipPlanePos",
1510                                        optFloat,
1511                                        "view_cells_visualization_clip_plane_pos=",
1512                                        "0.35");
1513       
1514        RegisterOption("ViewCells.Visualization.exportGeometry",
1515                                        optBool,
1516                                        "view_cells_visualization_export_geometry=",
1517                                        "false");
1518
1519        RegisterOption("ViewCells.Visualization.exportRays",
1520                                        optBool,
1521                                        "view_cells_visualization_export_rays=",
1522                                        "false");
1523
1524        RegisterOption("ViewCells.processOnlyValidViewCells",
1525                                        optBool,
1526                                        "view_cells_process_only_valid_view_cells",
1527                                        "false");
1528
1529        RegisterOption("ViewCells.PostProcess.maxCostRatio",
1530                        optFloat,
1531                        "view_cells_post_process_max_cost_ratio=",
1532                        "0.9");
1533       
1534        RegisterOption("ViewCells.PostProcess.renderCostWeight",
1535                        optFloat,
1536                        "view_cells_post_process_render_cost_weight",
1537                        "0.5");
1538       
1539        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation",
1540                        optFloat,
1541                        "view_cells_avgcost_max_deviations",
1542                        "0.5");
1543
1544        RegisterOption("ViewCells.PostProcess.maxMergesPerPass",
1545                optInt,
1546                "view_cells_post_process_max_merges_per_pass=",
1547                "500");
1548
1549        RegisterOption("ViewCells.PostProcess.minViewCells",
1550                optInt,
1551                "view_cells_post_process_min_view_cells=",
1552                "1000");
1553
1554        RegisterOption("ViewCells.PostProcess.useRaysForMerge",
1555                optBool,
1556                "view_cells_post_process_use_rays_for_merge=",
1557                "false");
1558       
1559        RegisterOption("ViewCells.PostProcess.merge",
1560                optBool,
1561                "view_cells_post_process_merge=",
1562                "true");
1563
1564        RegisterOption("ViewCells.Visualization.exportMergedViewCells",
1565                optBool,
1566                "view_cells_viz_export_merged_viewcells=",
1567                "false");
1568
1569        RegisterOption("ViewCells.maxStaticMemory",
1570                optFloat,
1571                "view_cells_max_static_mem=",
1572                "8.0");
1573
1574        RegisterOption("ViewCells.Visualization.useClipPlane",
1575                optBool,
1576                "view_cells_viz_use_clip_plane=",
1577                "false");
1578       
1579        RegisterOption("ViewCells.showVisualization",
1580                optBool,
1581                "view_cells_show_visualization=",
1582                "false");
1583
1584        RegisterOption("ViewCells.Visualization.clipPlaneAxis",
1585                optInt,
1586                "view_cells_viz_clip_plane_axis=",
1587                "0");
1588
1589        RegisterOption("ViewCells.loadGeometry",
1590                optBool,
1591                "view_cells_load_geometry=",
1592                "false");
1593       
1594        RegisterOption("ViewCells.geometryFilename",
1595                optString,
1596                "view_cells_geometry_filename=",
1597                "viewCellsGeometry.x3d");
1598
1599        RegisterOption("ViewCells.useBaseTrianglesAsGeometry",
1600                optBool,
1601                "view_cells_use_base_triangles_as_geometry=",
1602                "false");
1603
1604        RegisterOption("ViewCells.compressObjects",
1605                optBool,
1606                "view_cells_compress_objects=",
1607                "false");
1608
1609        RegisterOption("ViewCells.useKdPvs",
1610                optBool,
1611                "view_cells_use_kd_pvs",
1612                "false");
1613
1614        RegisterOption("ViewCells.useKdPvsAfterFiltering",
1615                                   optBool,
1616                                   "view_cells_use_kd_pvs_after_filtering",
1617                                   "false");
1618
1619
1620
1621        /****************************************************************************/
1622        /*                     Render simulation related options                    */
1623        /****************************************************************************/
1624
1625
1626        RegisterOption("Simulation.objRenderCost",
1627                        optFloat,
1628                        "simulation_obj_render_cost",
1629                        "1.0");
1630
1631        RegisterOption("Simulation.vcOverhead",
1632                        optFloat,
1633                        "simulation_vc_overhead",
1634                        "0.05");
1635
1636        RegisterOption("Simulation.moveSpeed",
1637                        optFloat,
1638                        "simulation_moveSpeed",
1639                        "1.0");
1640
1641
1642
1643        /******************************************************************/
1644        /*                    Bsp tree related options                    */
1645        /******************************************************************/
1646
1647
1648        RegisterOption("BspTree.Construction.input",
1649                optString,
1650                "bsp_construction_input=",
1651                "fromViewCells");
1652       
1653        RegisterOption("BspTree.subdivisionStats",
1654                                        optString,
1655                                        "bsp_subdivision_stats=",
1656                                        "bspSubdivisionStats.log");
1657
1658        RegisterOption("BspTree.Construction.samples",
1659                optInt,
1660                "bsp_construction_samples=",
1661                "100000");
1662
1663        RegisterOption("BspTree.Construction.epsilon",
1664                optFloat,
1665                "bsp_construction_epsilon=",
1666                "0.002");
1667
1668        RegisterOption("BspTree.Termination.minPolygons",
1669                        optInt,
1670                        "bsp_term_min_polygons=",
1671                        "5");
1672
1673        RegisterOption("BspTree.Termination.minPvs",
1674                        optInt,
1675                        "bsp_term_min_pvs=",
1676                        "20");
1677
1678        RegisterOption("BspTree.Termination.minProbability",
1679                        optFloat,
1680                        "bsp_term_min_probability=",
1681                        "0.001");
1682
1683        RegisterOption("BspTree.Termination.maxRayContribution",
1684                        optFloat,
1685                        "bsp_term_ray_contribution=",
1686                        "0.005");
1687
1688        RegisterOption("BspTree.Termination.minAccRayLenght",
1689                        optFloat,
1690                        "bsp_term_min_acc_ray_length=",
1691                        "50");
1692
1693        RegisterOption("BspTree.Termination.minRays",
1694                        optInt,
1695                        "bsp_term_min_rays=",
1696                        "-1");
1697
1698        RegisterOption("BspTree.Termination.ct_div_ci",
1699                        optFloat,
1700                        "bsp_term_ct_div_ci=",
1701                        "0.0");
1702
1703        RegisterOption("BspTree.Termination.maxDepth",
1704                        optInt,
1705                        "bsp_term_max_depth=",
1706                        "100");
1707
1708        RegisterOption("BspTree.Termination.maxCostRatio",
1709                        optFloat,
1710                        "bsp_term_axis_aligned_max_cost_ratio=",
1711                        "1.5");
1712
1713        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1714                        optFloat,
1715                        "bsp_term_axis_aligned_ct_div_ci=",
1716                        "0.5");
1717
1718        RegisterOption("BspTree.AxisAligned.splitBorder",
1719                        optFloat,
1720                        "bsp__axis_aligned_split_border=",
1721                        "0.1");
1722
1723        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1724                        optInt,
1725                        "bsp_term_axis_aligned_max_polygons=",
1726                        "50");
1727
1728        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1729                        optInt,
1730                        "bsp_term_min_objects=",
1731                        "3");
1732
1733        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1734                        optInt,
1735                        "bsp_term_axis_aligned_min_rays=",
1736                        "-1");
1737
1738        RegisterOption("BspTree.splitPlaneStrategy",
1739                        optString,
1740                        "bsp_split_method=",
1741                        "leastSplits");
1742
1743        RegisterOption("BspTree.maxPolyCandidates",
1744                optInt,
1745                "bsp_max_poly_candidates=",
1746                "20");
1747
1748        RegisterOption("BspTree.maxRayCandidates",
1749                optInt,
1750                "bsp_max_plane_candidates=",
1751                "20");
1752
1753        RegisterOption("BspTree.maxTests",
1754                optInt,
1755                "bsp_max_tests=",
1756                "5000");
1757
1758        RegisterOption("BspTree.Termination.maxViewCells",
1759                optInt,
1760                "bsp_max_view_cells=",
1761                "5000");
1762
1763        RegisterOption("BspTree.Visualization.exportSplits",
1764                optBool,
1765                "bsp_visualization.export_splits=",
1766                "false");
1767
1768        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1769        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1770        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1771        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1772        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1773        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1774        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1775        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1776        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1777
1778        /************************************************************************************/
1779        /*                         Preprocessor related options                             */
1780        /************************************************************************************/
1781
1782        RegisterOption("Preprocessor.type",
1783                                        optString,
1784                                        "preprocessor=",
1785                                        "sampling");
1786
1787        RegisterOption("Preprocessor.stats",
1788                                        optString,
1789                                        "preprocessor_stats=",
1790                                        "stats.log");
1791
1792        RegisterOption("Preprocessor.samplesFilename",
1793                                        optString,
1794                                        "preprocessor_samples_filename=",
1795                                        "rays.out");
1796
1797        RegisterOption("Preprocessor.loadMeshes",
1798                                        optBool,
1799                                        "preprocessor_load_meshes",
1800                                        "true");
1801
1802        RegisterOption("Preprocessor.evaluateFilter",
1803                                   optBool,
1804                                   "preprocessor_evaluate_filter",
1805                                   "false");
1806
1807        RegisterOption("Preprocessor.delayVisibilityComputation",
1808                                   optBool,
1809                                   "preprocessor_delay_computation",
1810                                   "true");
1811
1812        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1813                                   optInt,
1814                                   "preprocessor_pvs_rendererror_samples=",
1815                                   "10000");
1816       
1817        RegisterOption("Preprocessor.useGlRenderer",
1818                                        optBool,
1819                                        "preprocessor_use_gl_renderer",
1820                                        "false");
1821
1822        RegisterOption("Preprocessor.useGlDebugger",
1823                                        optBool,
1824                                        "preprocessor_use_gl_debugger",
1825                                        "false");
1826
1827        RegisterOption("Preprocessor.detectEmptyViewSpace",
1828                                   optBool,
1829                                   "preprocessor_detect_empty_viewspace",
1830                                   "false");
1831       
1832        RegisterOption("Preprocessor.quitOnFinish",
1833                                   optBool,
1834                                   "preprocessor_quit_on_finish",
1835                                   "true");
1836
1837        RegisterOption("Preprocessor.computeVisibility",
1838                                   optBool,
1839                                   "preprocessor_compute_visibility",
1840                                   "true");
1841
1842        RegisterOption("Preprocessor.exportVisibility",
1843                                   optBool,
1844                                   "preprocessor_export_visibility",
1845                                   "true");
1846
1847        RegisterOption("Preprocessor.visibilityFile",
1848                                   optString,
1849                                   "preprocessor_visibility_file=",
1850                                   "visibility.xml");
1851
1852        RegisterOption("Preprocessor.applyVisibilityFilter",
1853                                   optBool,
1854                                   "preprocessor_apply_filter",
1855                                   "false");
1856       
1857        RegisterOption("Preprocessor.applyVisibilitySpatialFilter",
1858                                   optBool,
1859                                   "preprocessor_apply_spatial_filter",
1860                                   "false");
1861
1862        RegisterOption("Preprocessor.visibilityFilterWidth",
1863                                   optFloat,
1864                                   "preprocessor_visibility_filter_width=",
1865                                   "0.02");
1866
1867        RegisterOption("Preprocessor.histogram.maxValue",
1868                                        optInt,
1869                                        "preprocessor_histogram_max_value=",
1870                                        "1000");
1871
1872        RegisterOption("Preprocessor.rayCastMethod",
1873                                        optInt,
1874                                        "preprocessor_ray_cast_method=",
1875                                        "0");
1876
1877        RegisterOption("Preprocessor.histogram.intervals",
1878                                        optInt,
1879                                        "preprocessor_histogram_intervals=",
1880                                        "20");
1881
1882        RegisterOption("Preprocessor.histogram.file",
1883                                   optString,
1884                                   "preprocessor_histogram_file=",
1885                                   "histogram.log");
1886
1887        RegisterOption("Preprocessor.exportKdTree",
1888                                        optBool,
1889                                        "preprocessor_export_kd_tree=",
1890                                        "false");
1891
1892        RegisterOption("Preprocessor.loadKdTree",
1893                                        optBool,
1894                                        "preprocessor_load_kd_tree=",
1895                                        "false");
1896
1897        RegisterOption("Preprocessor.kdTreeFilename",
1898                                        optString,
1899                                        "preprocessor_kd_tree_filename=",
1900                                        "vienna_kdtree.bin.gz");
1901
1902        RegisterOption("Preprocessor.exportObj",
1903                                        optBool,
1904                                        "preprocessor_export_obj=",
1905                                        "false");
1906
1907   RegisterOption("Preprocessor.useViewSpaceBox",
1908                                        optBool,
1909                                        "preprocessor_use_viewspace_box=",
1910                                        "false");   
1911
1912   RegisterOption("Preprocessor.Export.rays", optBool, "export_rays", "false");
1913   RegisterOption("Preprocessor.Export.animation", optBool, "export_animation", "false");
1914   RegisterOption("Preprocessor.Export.numRays", optInt, "export_num_rays=", "5000");
1915   
1916        /*************************************************************************/
1917        /*             VSS Preprocessor cells related options                    */
1918        /*************************************************************************/
1919
1920        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
1921        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
1922        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
1923        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1924        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1925
1926        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1927        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1928        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
1929        RegisterOption("VssTree.splitType", optString, "split=", "queries");
1930        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1931        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
1932        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1933
1934        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
1935
1936        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1937        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1938
1939        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
1940
1941       
1942       
1943        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1944        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false");
1945        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
1946        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1947        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1948        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
1949
1950        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
1951        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1952
1953
1954//      RegisterOption("RssPreprocessor.initialSamples",
1955//                                                                      optInt,
1956//                                                                      "rss_initial_samples=",
1957//                                                                      "100000");
1958
1959//      RegisterOption("RssPreprocessor.vssSamples",
1960//                                      optInt,
1961//                                      "rss_vss_samples=",
1962//                                      "1000000");
1963
1964//      RegisterOption("RssPreprocessor.vssSamplesPerPass",
1965//                                      optInt,
1966//                                      "rss_vss_samples_per_pass=",
1967//                                      "1000");
1968
1969//      RegisterOption("RssPreprocessor.samplesPerPass",
1970//                                      optInt,
1971//                                      "rss_samples_per_pass=",
1972//                                      "100000");
1973
1974        RegisterOption("RssPreprocessor.useImportanceSampling",
1975                                        optBool,
1976                                        "rss_use_importance",
1977                                        "true");
1978
1979        RegisterOption("RssPreprocessor.useRssTree",
1980                                        optBool,
1981                                        "rss_use_rss_tree",
1982                                        "true");
1983
1984        RegisterOption("RssPreprocessor.objectBasedSampling",
1985                                        optBool,
1986                                        "rss_object_based_sampling",
1987                                        "true");
1988
1989        RegisterOption("RssPreprocessor.directionalSampling",
1990                                        optBool,
1991                                        "rss_directional_sampling",
1992                                        "false");
1993
1994        RegisterOption("RssPreprocessor.distributions",
1995                                   optString,
1996                                   "rss_distributions=",
1997                                   "rss+spatial+object");
1998       
1999        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10");
2000        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
2001        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
2002        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
2003        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
2004        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
2005
2006        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
2007        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
2008        RegisterOption("RssTree.randomize", optBool, "randomize=", "false");
2009        RegisterOption("RssTree.splitType", optString, "rss_split=", "queries");
2010        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
2011
2012        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
2013
2014        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
2015
2016        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
2017        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
2018
2019        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
2020
2021        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
2022        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
2023        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
2024        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
2025        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
2026        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
2027
2028        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true");
2029        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
2030        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true");
2031        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
2032
2033        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
2034
2035        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
2036        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
2037
2038        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
2039        RegisterOption("RssPreprocessor.updateSubdivision",
2040                                   optBool,
2041                                   "rss_update_subdivision=",
2042                                   "false");
2043
2044
2045/************************************************************************************/
2046/*                      Rss preprocessor related options                            */
2047/************************************************************************************/
2048
2049
2050        RegisterOption("RssPreprocessor.loadInitialSamples",
2051                                        optBool,
2052                                        "vss_load_loadInitialSamples=",
2053                                        "false");
2054
2055        RegisterOption("RssPreprocessor.storeInitialSamples",
2056                                        optBool,
2057                                        "vss_store_storeInitialSamples=",
2058                                        "false");
2059
2060
2061/************************************************************************************/
2062/*                 View space partition BSP tree related options                    */
2063/************************************************************************************/
2064
2065        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
2066                                        optFloat,
2067                                        "vsp_bsp_term_min_global_cost_ratio=",
2068                                        "0.0001");
2069
2070        RegisterOption("VspBspTree.useSplitCostQueue",
2071                                        optBool,
2072                                        "vsp_bsp_use_split_cost_queue=",
2073                                        "true");
2074
2075        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
2076                                        optInt,
2077                                        "vsp_bsp_term_global_cost_miss_tolerance=",
2078                                        "4");
2079
2080        RegisterOption("VspBspTree.Termination.minPolygons",
2081                                        optInt,
2082                                        "vsp_bsp_term_min_polygons=",
2083                                        "-1");
2084
2085        RegisterOption("VspBspTree.Termination.minPvs",
2086                                        optInt,
2087                                        "vsp_bsp_term_min_pvs=",
2088                                        "20");
2089
2090        RegisterOption("VspBspTree.Termination.minProbability",
2091                                        optFloat,
2092                                        "vsp_bsp_term_min_probability=",
2093                                        "0.001");
2094
2095        RegisterOption("VspBspTree.subdivisionStats",
2096                                        optString,
2097                                        "vsp_bsp_subdivision_stats=",
2098                                        "vspBspSubdivisionStats.log");
2099
2100        RegisterOption("VspBspTree.Termination.maxRayContribution",
2101                                        optFloat,
2102                                        "vsp_bsp_term_ray_contribution=",
2103                                        "2");
2104
2105        RegisterOption("VspBspTree.Termination.minAccRayLenght",
2106                                        optFloat,
2107                                        "vsp_bsp_term_min_acc_ray_length=",
2108                                        "50");
2109
2110        RegisterOption("VspBspTree.Termination.minRays",
2111                                        optInt,
2112                                        "vsp_bsp_term_min_rays=",
2113                                        "-1");
2114
2115        RegisterOption("VspBspTree.Termination.ct_div_ci",
2116                                        optFloat,
2117                                        "vsp_bsp_term_ct_div_ci=",
2118                                        "0.0");
2119
2120        RegisterOption("VspBspTree.Termination.maxDepth",
2121                                        optInt,
2122                                        "vsp_bsp_term_max_depth=",
2123                                        "50");
2124
2125        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
2126                optFloat,
2127                "vsp_bsp_term_axis_aligned_max_cost_ratio=",
2128                "1.5");
2129
2130        RegisterOption("VspBspTree.useCostHeuristics",
2131                optBool,
2132                "vsp_bsp_use_cost_heuristics=",
2133                "false");
2134
2135        RegisterOption("VspBspTree.Termination.maxViewCells",
2136                optInt,
2137                "vsp_bsp_term_max_view_cells=",
2138                "10000");
2139
2140        RegisterOption("VspBspTree.Termination.maxCostRatio",
2141                optFloat,
2142                "vsp_bsp_term_max_cost_ratio=",
2143                "1.5");
2144
2145        RegisterOption("VspBspTree.Termination.missTolerance",
2146                optInt,
2147                "vsp_bsp_term_miss_tolerance=",
2148                "4");
2149
2150        RegisterOption("VspBspTree.splitPlaneStrategy",
2151                                        optInt,
2152                                        "vsp_bsp_split_method=",
2153                                        "1026");
2154
2155        RegisterOption("VspBspTree.maxPolyCandidates",
2156                                        optInt,
2157                                        "vsp_bsp_max_poly_candidates=",
2158                                        "20");
2159
2160        RegisterOption("VspBspTree.maxRayCandidates",
2161                                        optInt,
2162                                        "vsp_bsp_max_plane_candidates=",
2163                                        "20");
2164
2165        RegisterOption("VspBspTree.maxTests",
2166                                        optInt,
2167                                        "vsp_bsp_max_tests=",
2168                                        "5000");
2169
2170        RegisterOption("VspBspTree.Construction.samples",
2171                                        optInt,
2172                                        "vsp_bsp_construction_samples=",
2173                                        "100000");
2174
2175        RegisterOption("VspBspTree.Construction.minBand",
2176                                        optFloat,
2177                                        "vsp_bsp_construction_min_band=",
2178                                        "0.01");
2179
2180        RegisterOption("VspBspTree.Construction.maxBand",
2181                                        optFloat,
2182                                        "vsp_bsp_construction_max_band=",
2183                                        "0.99");
2184
2185        RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost",
2186                                        optBool,
2187                                        "vsp_bsp_construction_use_drivingaxis_for_maxcost=",
2188                                        "false");
2189
2190        RegisterOption("VspBspTree.Construction.epsilon",
2191                                        optFloat,
2192                                        "vsp_bsp_construction_epsilon=",
2193                                        "0.002");
2194
2195        RegisterOption("VspBspTree.Visualization.exportSplits",
2196                                        optBool,
2197                                        "vsp_bsp_visualization.export_splits",
2198                                        "false");
2199
2200        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
2201                                        optBool,
2202                                        "vsp_bsp_split_only_driving_axis=",
2203                                        "false");
2204
2205        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
2206                                        optBool,
2207                    "vsp_bsp_usePolygonSplitIfAvailable=",
2208                                        "false");
2209
2210        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
2211                        optInt,
2212                        "bsp_term_axis_aligned_min_rays=",
2213                        "0");
2214       
2215        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
2216                        optFloat,
2217                        "bsp_term_axis_aligned_min_rays=",
2218                        "2");
2219
2220        RegisterOption("VspBspTree.Factor.leastRaySplits",
2221                                        optFloat,
2222                                        "vsp_bsp_factor_least_ray_splits=",
2223                                        "1.0");
2224
2225        RegisterOption("VspBspTree.Factor.balancedRays",
2226                                        optFloat,
2227                                        "vsp_bsp_factor_balanced_rays=",
2228                                        "1.0");
2229
2230        RegisterOption("VspBspTree.Factor.pvs",
2231                                        optFloat,
2232                                        "vsp_bsp_factor_pvs=",
2233                                        "1.0");
2234       
2235        RegisterOption("VspBspTree.Construction.renderCostWeight",
2236                        optFloat,
2237                        "vsp_bsp_post_process_render_cost_weight=",
2238                        "1.0");
2239
2240        RegisterOption("VspBspTree.Construction.renderCostDecreaseWeight",
2241                        optFloat,
2242                        "vsp_bsp_construction_render_cost_decrease_weight=",
2243                        "0.99");
2244
2245        RegisterOption("VspBspTree.Construction.randomize",
2246                optBool,
2247                "vsp_bsp_construction_randomize=",
2248                "false");
2249
2250        RegisterOption("VspBspTree.simulateOctree",
2251                optBool,
2252                "vsp_bsp_simulate_octree=",
2253                "false");
2254
2255        RegisterOption("VspBspTree.nodePriorityQueueType",
2256                optInt,
2257                "vsp_bsp_node_queue_type=",
2258                "0");
2259
2260        RegisterOption("VspBspTree.useRandomAxis",
2261                optBool,
2262                "-vsp_bsp_use_random_axis=",
2263                "false");
2264
2265        RegisterOption("VspBspTree.maxTotalMemory",
2266                optFloat,
2267                "vsp_bsp_max_total_mem=",
2268                "60.0");
2269
2270        RegisterOption("VspBspTree.maxStaticMemory",
2271                optFloat,
2272                "vsp_bsp_max_static_mem=",
2273                "8.0");
2274
2275
2276
2277/***************************************************************************/
2278/*                 View space partition tree related options               */
2279/***************************************************************************/
2280
2281       
2282        RegisterOption("VspTree.Construction.samples",
2283                                        optInt,
2284                                        "vsp_construction_samples=",
2285                                        "10000");
2286
2287        RegisterOption("VspTree.Construction.renderCostDecreaseWeight",
2288                                optFloat,
2289                                "vsp_construction_render_cost_decrease_weight=",
2290                                "0.99");
2291
2292        RegisterOption("VspTree.Termination.maxDepth",
2293                                        optInt,
2294                                        "vsp_term_max_depth=",
2295                                        "100");
2296
2297        RegisterOption("VspTree.Termination.minRays",
2298                                        optInt,
2299                                        "vsp_term_min_rays=",
2300                                        "-1");
2301
2302
2303        RegisterOption("VspTree.Termination.minPvs",
2304                                        optInt,
2305                                        "vsp_term_min_pvs=",
2306                                        "20");
2307
2308        RegisterOption("VspTree.Termination.minProbability",
2309                                        optFloat,
2310                                        "vsp_term_min_probability=",
2311                                        "0.0000001");
2312
2313        RegisterOption("VspTree.Termination.maxRayContribution",
2314                                optFloat,
2315                                "vsp_term_ray_contribution=",
2316                                "0.9");
2317       
2318        RegisterOption("VspTree.Termination.maxCostRatio",
2319                                optFloat,
2320                                "vsp_term_max_cost_ratio=",
2321                                "1.5");
2322       
2323        RegisterOption("VspTree.Termination.maxViewCells",
2324                                optInt,
2325                                "vsp_term_max_view_cells=",
2326                                "10000");
2327
2328       
2329        RegisterOption("VspTree.Termination.missTolerance",
2330                                optInt,
2331                                "vsp_term_miss_tolerance=",
2332                                "4");
2333
2334        RegisterOption("VspTree.Termination.minGlobalCostRatio",
2335                                        optFloat,
2336                                        "vsp_term_min_global_cost_ratio=",
2337                                        "0.0001");
2338
2339        RegisterOption("VspTree.Termination.globalCostMissTolerance",
2340                                        optInt,
2341                                        "vsp_term_global_cost_miss_tolerance=",
2342                                        "4");
2343
2344        RegisterOption("VspTree.Termination.ct_div_ci",
2345                                        optFloat,
2346                                        "vsp_term_ct_div_ci=",
2347                                        "0.0");
2348
2349        RegisterOption("VspTree.Construction.epsilon",
2350                                        optFloat,
2351                                        "vsp_construction_epsilon=",
2352                                        "0.002");
2353
2354        RegisterOption("VspTree.splitUseOnlyDrivingAxis",
2355                                        optBool,
2356                                        "vsp_split_only_driving_axis=",
2357                                        "false");
2358
2359        RegisterOption("VspTree.maxStaticMemory",
2360                                        optFloat,
2361                                        "vsp_max_static_mem=",
2362                                        "8.0");
2363
2364        RegisterOption("VspTree.useCostHeuristics",
2365                                        optBool,
2366                                        "vsp_use_cost_heuristics=",
2367                                        "false");
2368
2369        RegisterOption("VspTree.simulateOctree",
2370                                        optBool,
2371                                        "vsp_simulate_octree=",
2372                                        "false");
2373
2374        RegisterOption("VspTree.Construction.randomize",
2375                                        optBool,
2376                                        "vsp_construction_randomize=",
2377                                        "false");
2378
2379        RegisterOption("VspTree.subdivisionStats",
2380                                        optString,
2381                                        "vsp_subdivision_stats=",
2382                                        "vspSubdivisionStats.log");
2383
2384        RegisterOption("VspTree.Construction.minBand",
2385                                        optFloat,
2386                                        "vsp_construction_min_band=",
2387                                        "0.01");
2388
2389        RegisterOption("VspTree.Construction.maxBand",
2390                                        optFloat,
2391                                        "vsp_construction_max_band=",
2392                                        "0.99");
2393       
2394        RegisterOption("VspTree.maxTests",
2395                                        optInt,
2396                                        "vsp_max_tests=",
2397                                        "5000");
2398
2399
2400
2401/***********************************************************************/
2402/*           Object space partition tree related options               */
2403/***********************************************************************/
2404
2405
2406        RegisterOption("OspTree.Construction.randomize",
2407                                        optBool,
2408                                        "osp_construction_randomize=",
2409                                        "false");
2410
2411        RegisterOption("OspTree.Termination.maxDepth",
2412                                        optInt,
2413                                        "osp_term_max_depth=",
2414                                        "30");
2415       
2416        RegisterOption("OspTree.Termination.maxLeaves",
2417                                        optInt,
2418                                        "osp_term_max_leaves=",
2419                                        "1000");
2420       
2421        RegisterOption("OspTree.Termination.minObjects",
2422                                        optInt,
2423                                        "osp_term_min_objects=",
2424                                        "1");
2425
2426        RegisterOption("OspTree.Termination.minProbability",
2427                                        optFloat,
2428                                        "osp_term_min_objects=",
2429                                        "0.00001");
2430
2431        RegisterOption("OspTree.Termination.missTolerance",
2432                                        optInt,
2433                                        "osp_term_miss_tolerance=",
2434                                        "8");
2435
2436        RegisterOption("OspTree.Termination.maxCostRatio",
2437                                        optFloat,
2438                                        "osp_term_max_cost_ratio=",
2439                                        "0.99");
2440
2441        RegisterOption("OspTree.Termination.minGlobalCostRatio",
2442                                        optFloat,
2443                                        "osp_term_min_global_cost_ratio=",
2444                                        "0.00001");
2445
2446        RegisterOption("OspTree.Termination.globalCostMissTolerance",
2447                                        optInt,
2448                                        "osp_term_global_cost_miss_tolerance=",
2449                                        "4");
2450
2451        RegisterOption("OspTree.Termination.ct_div_ci",
2452                                        optFloat,
2453                                        "osp_term_ct_div_ci=",
2454                                        "0");
2455       
2456        RegisterOption("OspTree.Construction.epsilon",
2457                                   optFloat,
2458                                   "osp_construction_epsilon=",
2459                                   "0.00001");
2460       
2461        // if only the driving axis is used for axis aligned split
2462        RegisterOption("OspTree.splitUseOnlyDrivingAxis",
2463                                   optBool,
2464                                   "osp_split_only_driving_axis=",
2465                                   "false");
2466
2467        RegisterOption("OspTree.maxStaticMemory",
2468                                   optFloat,
2469                                   "osp_max_static_mem=",
2470                                   "8.0");
2471
2472        RegisterOption("OspTree.useCostHeuristics",
2473                                   optBool,
2474                                   "osp_use_cost_heuristics=",
2475                                   "true");
2476
2477        RegisterOption("OspTree.subdivisionStats",
2478                                        optString,
2479                                        "osp_subdivision_stats=",
2480                                        "ospSubdivisionStats.log");
2481
2482        RegisterOption("OspTree.Construction.splitBorder",
2483                                        optFloat,
2484                                        "osp_construction_split_border=",
2485                                        "0.01");
2486
2487        RegisterOption("OspTree.Construction.renderCostDecreaseWeight",
2488                                   optFloat,
2489                                   "osp_construction_render_cost_decrease_weight=",
2490                                   "0.99");
2491
2492
2493
2494/**********************************************************************/
2495/*            Bounding Volume Hierarchy related options               */
2496/**********************************************************************/
2497
2498        RegisterOption("BvHierarchy.Construction.randomize",
2499                                        optBool,
2500                                        "bvh_construction_randomize=",
2501                                        "false");
2502
2503        RegisterOption("BvHierarchy.Termination.maxDepth",
2504                                        optInt,
2505                                        "bvh_term_max_depth=",
2506                                        "30");
2507       
2508        RegisterOption("BvHierarchy.Termination.maxLeaves",
2509                                        optInt,
2510                                        "bvh_term_max_leaves=",
2511                                        "1000");
2512       
2513        RegisterOption("BvHierarchy.Termination.minObjects",
2514                                        optInt,
2515                                        "bvh_term_min_objects=",
2516                                        "1");
2517
2518        RegisterOption("BvHierarchy.Termination.minProbability",
2519                                        optFloat,
2520                                        "bvh_term_min_objects=",
2521                                        "0.0000001");
2522
2523        RegisterOption("BvHierarchy.Termination.minRays",
2524                                        optInt,
2525                                        "bvh_term_min_rays=",
2526                                        "0");
2527
2528        RegisterOption("BvHierarchy.Termination.missTolerance",
2529                                        optInt,
2530                                        "osp_term_miss_tolerance=",
2531                                        "8");
2532
2533        RegisterOption("BvHierarchy.Termination.maxCostRatio",
2534                                        optFloat,
2535                                        "bvh_term_max_cost_ratio=",
2536                                        "0.99");
2537
2538        RegisterOption("BvHierarchy.Termination.minGlobalCostRatio",
2539                                        optFloat,
2540                                        "bvh_term_min_global_cost_ratio=",
2541                                        "0.00001");
2542
2543        RegisterOption("BvHierarchy.Termination.globalCostMissTolerance",
2544                                        optInt,
2545                                        "bvh_term_global_cost_miss_tolerance=",
2546                                        "4");
2547
2548        // if only the driving axis is used for axis aligned split
2549        RegisterOption("BvHierarchy.splitUseOnlyDrivingAxis",
2550                                   optBool,
2551                                   "bvh_split_only_driving_axis=",
2552                                   "false");
2553
2554        RegisterOption("BvHierarchy.maxStaticMemory",
2555                                   optFloat,
2556                                   "bvh_max_static_mem=",
2557                                   "8.0");
2558
2559        RegisterOption("BvHierarchy.useCostHeuristics",
2560                                   optBool,
2561                                   "bvh_use_cost_heuristics=",
2562                                   "true");
2563       
2564        RegisterOption("BvHierarchy.useSah",
2565                                   optBool,
2566                                   "bvh_use_sah=",
2567                                   "false");
2568
2569        RegisterOption("BvHierarchy.subdivisionStats",
2570                                        optString,
2571                                        "bvh_subdivision_stats=",
2572                                        "bvhSubdivisionStats.log");
2573
2574        RegisterOption("BvHierarchy.Construction.renderCostDecreaseWeight",
2575                                   optFloat,
2576                                   "bvh_construction_render_cost_decrease_weight=",
2577                                   "0.99");
2578       
2579        RegisterOption("BvHierarchy.Construction.useGlobalSorting",
2580                                        optBool,
2581                                        "bvh_construction_use_global_sorting=",
2582                                        "true");
2583       
2584        RegisterOption("BvHierarchy.Construction.useInitialSubdivision",
2585                                        optBool,
2586                                        "bvh_construction_use_initial_subdivision=",
2587                                        "false");
2588
2589        RegisterOption("BvHierarchy.Construction.Initial.minObjects",
2590                                        optInt,
2591                                        "bvh_construction_use_initial_min_objects=",
2592                                        "100000");
2593
2594        RegisterOption("BvHierarchy.Construction.Initial.minArea",
2595                                        optFloat,
2596                                        "bvh_construction_use_initial_min_area=",
2597                                        "0.0001");
2598
2599        RegisterOption("BvHierarchy.Construction.Initial.maxAreaRatio",
2600                                        optFloat,
2601                                        "bvh_construction_use_initial_max_area_ratio=",
2602                                        "0.9");
2603
2604        RegisterOption("BvHierarchy.minRaysForVisibility",
2605                                        optInt,
2606                                        "bvh_min_rays_for_vis=",
2607                                        "0");
2608
2609        RegisterOption("BvHierarchy.maxTests",
2610                                        optInt,
2611                                        "bvh_max_tests=",
2612                                        "50000");
2613
2614
2615        /*******************************************************************/
2616        /*               Hierarchy Manager related options                 */
2617        /*******************************************************************/
2618
2619        RegisterOption("Hierarchy.Construction.samples",
2620                                        optInt,
2621                                        "hierarchy_construction_samples=",
2622                                        "100000");
2623
2624        RegisterOption("Hierarchy.subdivisionStats",
2625                           optString,
2626                                   "hierarchy_subdivision_stats=",
2627                                   "hierarchySubdivisionStats.log");
2628
2629        RegisterOption("Hierarchy.type",
2630                           optString,
2631                                   "hierarchy_type=",
2632                                   "bvh");
2633
2634        RegisterOption("Hierarchy.Termination.minGlobalCostRatio",
2635                                        optFloat,
2636                                        "hierarchy_term_min_global_cost_ratio=",
2637                                        "0.000000001");
2638
2639        RegisterOption("Hierarchy.Termination.globalCostMissTolerance",
2640                                        optInt,
2641                                        "hierarchy_term_global_cost_miss_tolerance=",
2642                                        "4");
2643
2644        RegisterOption("Hierarchy.Termination.maxLeaves",
2645                                        optInt,
2646                                        "hierarchy_term_max_leaves=",
2647                                        "1000");
2648       
2649        RegisterOption("Hierarchy.Construction.type",
2650                                        optInt,
2651                                        "hierarchy_construction_type=",
2652                                        "0");
2653
2654        RegisterOption("Hierarchy.Construction.minDepthForOsp",
2655                                        optInt,
2656                                        "hierarchy_construction_min_depth_for_osp=",
2657                                        "-1");
2658
2659        RegisterOption("Hierarchy.Construction.startWithObjectSpace",
2660                                        optBool,
2661                                        "hierarchy_construction_start_with_osp=",
2662                                        "true");
2663
2664        RegisterOption("Hierarchy.Construction.considerMemory",
2665                                        optBool,
2666                                        "hierarchy_construction_consider_memory=",
2667                                        "true");
2668
2669        RegisterOption("Hierarchy.Construction.repairQueue",
2670                                        optBool,
2671                                        "hierarchy_construction_repair_queue=",
2672                                        "true");
2673
2674        RegisterOption("Hierarchy.Construction.minDepthForVsp",
2675                                        optInt,
2676                                        "hierarchy_construction_min_depth_for_vsp=",
2677                                        "-1");
2678
2679        RegisterOption("Hierarchy.Termination.maxMemory",
2680                                        optFloat,
2681                                        "hierarchy_term_max_memory=",
2682                                        "1");
2683
2684        RegisterOption("Hierarchy.Termination.memoryConst",
2685                                        optFloat,
2686                                        "hierarchy_term_memory_const=",
2687                                        "1.0");
2688
2689        RegisterOption("Hierarchy.Construction.useMultiLevel",
2690                                        optBool,
2691                                        "hierarchy_construction_multilevel=",
2692                                        "false");
2693
2694        RegisterOption("Hierarchy.Construction.levels",
2695                                        optInt,
2696                                        "hierarchy_construction_levels=",
2697                                        "4");
2698
2699        RegisterOption("Hierarchy.Construction.maxRepairs",
2700                                        optInt,
2701                                        "hierarchy_construction_max_repairs=",
2702                                        "1000");
2703
2704        RegisterOption("Hierarchy.Construction.minStepsOfSameType",
2705                                        optInt,
2706                                        "hierarchy_construction_min_steps_same_type=",
2707                                        "200");
2708
2709        RegisterOption("Hierarchy.Construction.maxStepsOfSameType",
2710                                        optInt,
2711                                        "hierarchy_construction_max_steps_same_type=",
2712                                        "700");
2713
2714        RegisterOption("Hierarchy.Construction.recomputeSplitPlaneOnRepair",
2715                                        optBool,
2716                                        "hierarchy_construction_recompute_split_on_repair=",
2717                                        "true");
2718
2719        RegisterOption("Hierarchy.Construction.maxAvgRayContri",
2720                                        optFloat,
2721                                        "hierarchy_construction_max_avg_raycontri=",
2722                                        "99999.0");
2723       
2724        RegisterOption("Hierarchy.Construction.minAvgRayContri",
2725                                        optFloat,
2726                                        "hierarchy_construction_min_avg_raycontri=",
2727                                        "99990.0");
2728       
2729        /////////////////////////////////////////////////////////////////
2730
2731}
2732
2733void
2734Environment::SetStaticOptions()
2735{
2736 
2737  // get Global option values
2738  GetRealValue("Limits.threshold", Limits::Threshold);
2739  GetRealValue("Limits.small", Limits::Small);
2740  GetRealValue("Limits.infinity", Limits::Infinity);
2741
2742
2743}
2744
2745bool
2746Environment::Parse(const int argc, char **argv, bool useExePath)
2747{
2748  bool result = true;
2749  // Read the names of the scene, environment and output files
2750  ReadCmdlineParams(argc, argv, "");
2751
2752  char *envFilename = new char[128];
2753
2754  char filename[64];
2755
2756  // Get the environment file name
2757  if (!GetParam(' ', 0, filename)) {
2758    // user didn't specified environment file explicitly, so
2759    strcpy(filename, "default.env");
2760  }
2761
2762 
2763  if (useExePath) {
2764    char *path = GetPath(argv[0]);
2765    if (*path != 0)
2766      sprintf(envFilename, "%s/%s", path, filename);
2767    else
2768      strcpy(envFilename, filename);
2769   
2770    delete path;
2771  }
2772  else
2773    strcpy(envFilename, filename);
2774
2775 
2776  // Now it's time to read in environment file.
2777  if (!ReadEnvFile(envFilename)) {
2778    // error - bad input file name specified ?
2779    cerr<<"Error parsing environment file "<<envFilename<<endl;
2780        result = false;
2781  }
2782  delete envFilename;
2783
2784  // Parse the command line; options given on the command line subsume
2785  // stuff specified in the input environment file.
2786  ParseCmdline(argc, argv, 0);
2787
2788  SetStaticOptions();
2789
2790  // Check for request for help
2791  if (CheckForSwitch(argc, argv, '?')) {
2792    PrintUsage(cout);
2793    exit(0);
2794  }
2795 
2796  return true;
2797}
2798
2799}
Note: See TracBrowser for help on using the repository browser.