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

Revision 1415, 64.9 KB checked in by mattausch, 18 years ago (diff)
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
27
28//Environment *environment = NULL;
29Environment *Environment::sEnvironment = NULL;
30
31
32Environment *Environment::GetSingleton()
33{
34        if (!sEnvironment)
35        {
36                sEnvironment = new Environment();
37        }
38
39        return sEnvironment;
40}
41
42void Environment::DelSingleton()
43{
44        DEL_PTR(sEnvironment);
45}
46
47
48Environment::~Environment()
49{
50  int i, j;
51
52  // delete the params structure
53  for (i = 0; i < numParams; i++) {
54    for (j = 0; j < paramRows; j++)
55      if (params[i][j] != NULL)
56        delete[] params[i][j];
57    if (params[i] != NULL)
58      delete[] params[i];
59  }
60
61  if (params != NULL)
62    delete[] params;
63 
64  // delete the options structure
65  if (options != NULL)
66    delete[] options;
67 
68  if (optionalParams != NULL)
69    DEL_PTR(optionalParams);
70}
71
72bool
73Environment::CheckForSwitch(const int argc,
74                                                        char **argv,
75                                                        const char swtch) const
76{
77  for (int i = 1; i < argc; i++)
78    if ((argv[i][0] == '-') && (argv[i][1] == swtch))
79      return true;
80  return false;
81}
82
83bool
84Environment::CheckType(const char *value,
85                        const EOptType type) const
86{
87  char *s, *t, *u;
88
89  switch (type) {
90    case optInt: {
91      strtol(value, &t, 10);
92      if (value + strlen(value) != t)
93        return false;
94      else
95        return true;
96    }
97    case optFloat: {
98      strtod(value, &t);
99      if (value + strlen(value) != t)
100        return false;
101      else
102        return true;
103    }
104    case optBool: {
105      if (!strcasecmp(value, "true") ||
106          !strcasecmp(value, "false") ||
107          !strcasecmp(value, "YES") ||
108          !strcasecmp(value, "NO") ||
109          !strcmp(value, "+") ||
110          !strcmp(value, "-") ||
111          !strcasecmp(value, "ON") ||
112          !strcasecmp(value, "OFF"))
113        return true;
114      return false;
115    }
116    case optVector:{
117      strtod(value, &s);
118      if (*s == ' ' || *s == '\t') {
119        while (*s == ' ' || *s == '\t')
120          s++;
121        if (*s != ',')
122          s--;
123      }
124      if ((*s != ',' && *s != ' ' && *s != '\t') || value == s)
125        return false;
126      t = s;
127      strtod(s + 1, &u);
128      if (*u == ' ' || *u == '\t') {
129        while (*u == ' ' || *u == '\t')
130          u++;
131        if (*u != ',')
132          u--;
133      }
134      if ((*u != ',' && *s != ' ' && *s != '\t') || t == u)
135        return false;
136      t = u;
137      strtod(u + 1, &s);
138      if (t == s || value + strlen(value) != s)
139        return false;
140      return true;
141    }
142    case optString: {
143      return true;
144    }
145    default: {
146      Debug << "Internal error: Unknown type of option.\n" << flush;
147      exit(1);
148    }
149  }
150  return false;
151}
152
153void
154Environment::ReadCmdlineParams(const int argc,
155                                                           char **argv,
156                                                           const char *optParams)
157{
158  int i;
159
160  // Make sure we are called for the first time
161  if (optionalParams != NULL)
162    return;
163
164  numParams = (int)strlen(optParams) + 1;
165  optionalParams = new char[numParams];
166  strcpy(optionalParams, optParams);
167
168  // First, count all non-optional parameters on the command line
169  for (i = 1; i < argc; i++)
170    if (argv[i][0] != '-')
171      paramRows++;
172
173  // if there is no non-optional parameter add a default one...
174  if (paramRows == 0)
175    paramRows = 1;
176 
177  // allocate and initialize the table for parameters
178  params = new char **[numParams];
179  for (i = 0; i < numParams; i++) {
180    params[i] = new char *[paramRows];
181    for (int j = 0; j < paramRows; j++)
182      params[i][j] = NULL;
183  }
184  // Now read all non-optional and optional parameters into the table
185  curRow = -1;
186  for (i = 1; i < argc; i++) {
187    if (argv[i][0] != '-') {
188      // non-optional parameter encountered
189      curRow++;
190      params[0][curRow] = new char[strlen(argv[i]) + 1];
191      strcpy(params[0][curRow], argv[i]);
192    }
193    else {
194      // option encountered
195      char *t = strchr(optionalParams, argv[i][1]);
196      if (t != NULL) {
197        // this option is optional parameter
198        int index = t - optionalParams + 1;
199        if (curRow < 0) {
200          // it's a global parameter
201          for (int j = 0; j < paramRows; j++) {
202            params[index][j] = new char[strlen(argv[i] + 2) + 1];
203            strcpy(params[index][j], argv[i] + 2);
204          }
205        }
206        else {
207          // it's a scene parameter
208          if (params[index][curRow] != NULL) {
209            delete[] params[index][curRow];
210          }
211          params[index][curRow] = new char[strlen(argv[i] + 2) + 1];
212          strcpy(params[index][curRow], argv[i] + 2);
213        }
214      }
215    }
216  }
217  curRow = 0;
218
219#ifdef _DEBUG_PARAMS
220  // write out the parameter table
221  cerr << "Parameter table for " << numParams << " columns and "
222       << paramRows << " rows:\n";
223  for (int j = 0; j < paramRows; j++) {
224    for (i = 0; i < numParams; i++) {
225      if (params[i][j] != NULL)
226        cerr << params[i][j];
227      else
228        cerr << "NULL";
229      cerr << "\t";
230    }
231    cerr << "\n";
232  }
233  cerr << "Params done.\n" << flush;
234#endif // _DEBUG_PARAMS
235}
236
237bool
238Environment::GetParam(const char name,
239                       const int index,
240                       char *value) const
241{
242  int column;
243
244  if (index >= paramRows || index < 0)
245    return false;
246  if (name == ' ')
247    column = 0;
248  else {
249    char *t = strchr(optionalParams, name);
250
251    if (t == NULL)
252      return false;
253    column = t - optionalParams + 1;
254  }
255
256  if (params[column][index] == NULL)
257    return false;
258  //  value = new char[strlen(params[column][index]) + 1];
259  strcpy(value, params[column][index]);
260  return true;
261}
262
263void
264Environment::RegisterOption(const char *name,
265                                                        const EOptType type,
266                                                        const char *abbrev,
267                                                        const char *defValue)
268{
269  int i;
270
271  // make sure this option was not yet registered
272  for (i = 0; i < numOptions; i++)
273    if (!strcmp(name, options[i].name)) {
274      Debug << "Error: Option " << name << " registered twice.\n";
275      exit(1);
276    }
277  // make sure we have enough room in memory
278  if (numOptions >= maxOptions) {
279    Debug << "Error: Too many options. Try enlarge the maxOptions "
280          << "definition.\n";
281    exit(1);
282  }
283
284  // make sure the abbreviation doesn't start with 'D'
285  if (abbrev != NULL && (abbrev[0] == 'D' )) {
286    Debug << "Internal error: reserved switch " << abbrev
287         << " used as an abbreviation.\n";
288    exit(1);
289  }
290  // new option
291  options[numOptions].type = type;
292  options[numOptions].name = ::strdup(name);
293  // assign abbreviation, if requested
294  if (abbrev != NULL) {
295          options[numOptions].abbrev = ::strdup(abbrev);
296  }
297  // assign default value, if requested
298  if (defValue != NULL) {
299          options[numOptions].defaultValue = ::strdup(defValue);
300    if (!CheckType(defValue, type)) {
301      Debug << "Internal error: Inconsistent type and default value in option "
302           << name << ".\n";
303      exit(1);
304    }
305  }
306  // new option registered
307  numOptions++;
308}
309
310bool
311Environment::OptionPresent(const char *name) const
312{
313  bool found = false;
314  int i;
315
316  for (i = 0; i < numOptions; i++)
317    if (!strcmp(options[i].name, name)) {
318      found = true;
319      break;
320    }
321  if (!found) {
322    Debug << "Internal error: Option " << name << " not registered.\n" << flush;
323    exit(1);
324  }
325  if (options[i].value != NULL || options[i].defaultValue != NULL)
326    return true;
327  else
328    return false;
329}
330
331int
332Environment::FindOption(const char *name, const bool isFatal) const
333{
334  int i;
335  bool found = false;
336  // is this option registered ?
337  for (i = 0; i < numOptions; i++)
338    if (!strcmp(options[i].name, name)) {
339      found = true;
340      break;
341    }
342  if (!found) {
343    // no registration found
344    Debug << "Internal error: Required option " << name
345          << " not registered.\n" << flush;
346    exit(1);
347  }
348  if (options[i].value == NULL && options[i].defaultValue == NULL)
349    // this option was not initialised to some value
350    if (isFatal) {
351      Debug << "Error: Required option " << name << " not found.\n" << flush;
352      exit(1);
353    }
354    else {
355      Debug << "Error: Required option " << name << " not found.\n" << flush;
356      return -1;
357    }
358  return i;
359}
360
361bool
362Environment::GetIntValue(const char *name,
363                         int &value,
364                         const bool isFatal) const
365{
366  int i = FindOption(name, isFatal);
367
368  if (i<0)
369    return false;
370
371  if (options[i].value != NULL) {
372    // option was explicitly specified
373    value = strtol(options[i].value, NULL, 10);
374  } else {
375    // option was not read, so use the default
376    value = strtol(options[i].defaultValue, NULL, 10);
377  }
378
379  return true;
380}
381
382bool
383Environment::GetDoubleValue(const char *name,
384                            double &value,
385                            const bool isFatal) const
386{
387  int i = FindOption(name, isFatal);
388
389  if (i<0)
390    return false;
391
392  if (options[i].value != NULL) {
393    // option was explicitly specified
394    value = strtod(options[i].value, NULL);
395  } else {
396    // option was not read, so use the default
397    value = strtod(options[i].defaultValue, NULL);
398  }
399  return true;
400}
401
402bool
403Environment::GetRealValue(const char *name,
404                          Real &value,
405                          const bool isFatal) const
406{
407  int i = FindOption(name, isFatal);
408 
409  if (i<0)
410    return false;
411
412  if (options[i].value != NULL) {
413    // option was explicitly specified
414    value = (Real)strtod(options[i].value, NULL);
415  } else {
416    // option was not read, so use the default
417    value = (Real)strtod(options[i].defaultValue, NULL);
418  }
419  return true;
420}
421
422bool
423Environment::GetFloatValue(const char *name,
424                           float &value,
425                           const bool isFatal) const
426{
427  int i = FindOption(name, isFatal);
428
429  if (i<0)
430    return false;
431
432  if (options[i].value != NULL) {
433    // option was explicitly specified
434    value = (float)strtod(options[i].value, NULL);
435  } else {
436    // option was not read, so use the default
437    value = (float)strtod(options[i].defaultValue, NULL);
438  }
439  return true;
440}
441
442bool
443Environment::GetBool(const char *name,
444                     const bool isFatal) const
445{
446  bool ret;
447  if (GetBoolValue(name, ret, isFatal))
448    return ret;
449  else
450    return false;
451}
452
453bool
454Environment::ParseBool(const char *name) const
455{
456
457  bool value = true;
458 
459  if (!strcasecmp(name, "false") ||
460      !strcasecmp(name, "NO") ||
461      !strcmp(name, "-") ||
462      !strcasecmp(name, "OFF"))
463    value = false;
464 
465  return value;
466}
467
468void
469Environment::ParseVector(const char *name, Vector3 &v) const
470{
471  // option was not read, so use the default
472  char *s, *t;
473 
474  v.x = (Real)strtod(name, &s);
475  v.y = (Real)strtod(s + 1, &t);
476  v.z = (Real)strtod(t + 1, NULL);
477
478}
479
480bool
481Environment::GetBoolValue(const char *name,
482                           bool &value,
483                           const bool isFatal) const
484{
485  int i = FindOption(name, isFatal);
486
487  if (i<0)
488    return false;
489
490 
491  if (options[i].value != NULL)
492    value = ParseBool(options[i].value);
493  else
494    value = ParseBool(options[i].defaultValue);
495
496  return true;
497}
498
499bool
500Environment::GetVectorValue(const char *name,
501                            Vector3 &v,
502                            const bool isFatal) const
503{
504  int i = FindOption(name, isFatal);
505  if (i<0)
506    return false;
507
508  if (options[i].value != NULL)
509
510   
511  if (options[i].value != NULL) {
512    ParseVector(options[i].value, v);
513  }
514  else {
515    ParseVector(options[i].defaultValue, v);
516  }
517  return true;
518}
519
520bool
521Environment::GetStringValue(const char *name,
522                            char *value,
523                            const bool isFatal) const
524{
525  int i = FindOption(name, isFatal);
526
527  if (i<0)
528    return false;
529
530 
531  if (options[i].value != NULL) {
532    // option was not read, so use the default
533    strcpy(value, options[i].value);
534  }
535  else {
536    // option was explicitly specified
537    strcpy(value, options[i].defaultValue);
538  }
539  return true;
540}
541
542void
543Environment::SetInt(const char *name, const int value)
544{
545
546  int i = FindOption(name);
547  if (i<0)
548    return;
549
550  if (options[i].type == optInt) {
551    delete options[i].value;
552    options[i].value = new char[16];
553    sprintf(options[i].value, "%.15d", value);
554  }
555  else {
556    Debug << "Internal error: Trying to set non-integer option " << name
557          << " to integral value.\n" << flush;
558    exit(1);
559  }
560}
561
562void
563Environment::SetFloat(const char *name, const Real value)
564{
565  int i = FindOption(name);
566  if (i<0)
567    return;
568
569  if (options[i].type == optFloat) {
570    delete options[i].value;
571    options[i].value = new char[25];
572    sprintf(options[i].value, "%.15e", value);
573  }
574  else {
575    Debug << "Internal error: Trying to set non-Real option " << name
576          << " to Real value.\n" << flush;
577    exit(1);
578  }
579}
580
581void
582Environment::SetBool(const char *name, const bool value)
583{
584  int i = FindOption(name);
585  if (i<0)
586    return;
587
588  if (options[i].type == optBool) {
589    delete options[i].value;
590    options[i].value = new char[6];
591    if (value)
592      sprintf(options[i].value, "true");
593    else
594      sprintf(options[i].value, "false");
595  }
596  else {
597    Debug << "Internal error: Trying to set non-bool option " << name
598          << " to boolean value.\n" << flush;
599    exit(1);
600  }
601}
602
603void
604Environment::SetVector(const char *name,
605                       const Vector3 &v)
606{
607  int i = FindOption(name);
608  if (i<0)
609    return;
610
611  if (options[i].type == optVector) {
612    delete options[i].value;
613    options[i].value = new char[128];
614    sprintf(options[i].value, "%.15e,%.15e,%.15e", v.x, v.y, v.z);
615  }
616  else {
617    Debug << "Internal error: Trying to set non-vector option " << name
618          << " to vector value.\n" << flush;
619    exit(1);
620  }
621}
622
623void
624Environment::SetString(const char *name, const char *value)
625{
626  int i = FindOption(name);
627  if (i<0)
628    return;
629
630  if (options[i].type == optString) {
631    delete options[i].value;
632        options[i].value = ::strdup(value);
633  }
634  else {
635    Debug << "Internal error: Trying to set non-string option " << name
636          << " to string value.\n" << flush;
637    exit(1);
638  }
639}
640
641void
642Environment::ParseCmdline(const int argc,
643                                                  char **argv,
644                                                  const int index)
645{
646  int curIndex = -1;
647
648  for (int i = 1; i < argc; i++) {
649    // if this parameter is non-optional, skip it and increment the counter
650    if (argv[i][0] != '-') {
651      curIndex++;
652      continue;
653    }
654    // make sure to skip all non-optional parameters
655    char *t = strchr(optionalParams, argv[i][1]);
656    if (t != NULL)
657      continue;
658
659    // if we are in the scope of the current parameter, parse it
660    if (curIndex == -1 || curIndex == index) {
661      if (argv[i][1] == 'D') {
662        // it's a full name definition
663        bool found = false;
664        int j;
665
666        char *t = strchr(argv[i] + 2, '=');
667        if (t == NULL) {
668          Debug << "Error: Missing '=' in option. "
669                << "Syntax is -D<name>=<value>.\n" << flush;
670          exit(1);
671        }
672        for (j = 0; j < numOptions; j++)
673          if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) &&
674              (unsigned)(t - argv[i] - 2) == strlen(options[j].name)) {
675            found = true;
676            break;
677          }
678        if (!found) {
679          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
680          //  exit(1);
681        }
682        if (found) {
683          if (!CheckType(t + 1, options[j].type)) {
684            Debug << "Error: invalid type of value " << t + 1 << " in option "
685                  << options[j].name << ".\n";
686            exit(1);
687          }
688          if (options[j].value != NULL)
689            delete options[j].value;
690          options[j].value = strdup(t + 1);
691        }
692      }
693      else {
694        // it's an abbreviation
695        bool found = false;
696        int j;
697       
698        for (j = 0; j < numOptions; j++)
699          if (options[j].abbrev != NULL &&
700              !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev))) {
701            found = true;
702            break;
703          }
704        if (!found) {
705          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
706          //          exit(1);
707        }
708        if (found) {
709          if (!CheckType(argv[i] + 1 + strlen(options[j].abbrev), options[j].type)) {
710            Debug << "Error: invalid type of value "
711                  << argv[i] + 1 + strlen(options[j].abbrev) << "in option "
712                  << options[j].name << ".\n";
713            exit(1);
714          }
715          if (options[j].value != NULL)
716            delete options[j].value;
717          options[j].value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
718        }
719      }
720    }
721  }
722#ifdef _DEBUG_PARAMS
723  // write out the options table
724  cerr << "Options table for " << numOptions << " options:\n";
725  for (int j = 0; j < numOptions; j++) {
726    cerr << options[j];
727    cerr << "\n";
728  }
729  cerr << "Options done.\n" << flush;
730#endif // _DEBUG_PARAMS
731}
732
733
734char *
735Environment::ParseString(char *buffer, char *string) const
736{
737  char *s = buffer;
738  char *t = string + strlen(string);
739
740  // skip leading whitespaces
741  while (*s == ' ' || *s == '\t')
742    s++;
743  if (*s == '\0')
744    return NULL;
745  while ((*s >= 'a' && *s <= 'z') ||
746         (*s >= 'A' && *s <= 'Z') ||
747         (*s >= '0' && *s <= '9') ||
748         *s == '_')
749    *t++ = *s++;
750  *t = '\0';
751  // skip trailing whitespaces
752  while (*s == ' ' || *s == '\t')
753    s++;
754  return s;
755}
756
757const char code[] = "JIDHipewhfdhyd74387hHO&{WK:DOKQEIDKJPQ*H#@USX:#FWCQ*EJMQAHPQP(@G#RD";
758
759void
760Environment::DecodeString(char *buff, int max)
761{
762  buff[max] = 0;
763  char *p = buff;
764  const char *cp = code;
765  for (; *p; p++) {
766    if (*p != '\n')
767      *p = *p ^ *cp;
768    ++cp;
769    if (*cp == 0)
770      cp = code;
771  }
772}
773
774void
775Environment::CodeString(char *buff, int max)
776{
777  buff[max] = 0;
778  char *p = buff;
779  const char *cp = code;
780  for (; *p; p++) {
781    if (*p != '\n')
782      *p = *p ^ *cp;
783    ++cp;
784    if (*cp == 0)
785      cp = code;
786  }
787}
788
789void
790Environment::SaveCodedFile(char *filenameText,
791                            char *filenameCoded)
792{
793  ifstream envStream(filenameText);
794 
795  // some error had occured
796  if (envStream.fail()) {
797    cerr << "Error: Can't open file " << filenameText << " for reading (err. "
798         << envStream.rdstate() << ").\n";
799    return;
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, 255);
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("SamplingPreprocessor.totalSamples",
1176                 optInt,
1177                 "total_samples=",
1178                 "1000000");
1179
1180  RegisterOption("SamplingPreprocessor.samplesPerPass",
1181                 optInt,
1182                 "samples_per_pass=",
1183                 "10");
1184
1185  RegisterOption("RenderSampler.samples",
1186                                 optInt,
1187                                 "render_sampler_samples=",
1188                                 "1000");
1189
1190  RegisterOption("RenderSampler.visibleThreshold",
1191                                 optInt,
1192                                 "render_sampler_visible_threshold=",
1193                                 "0");
1194
1195
1196   RegisterOption("RenderSampler.useOcclusionQueries",
1197                                 optBool,
1198                                 "render_sampler_use_occlusion_queries=",
1199                                 "true");
1200
1201   RegisterOption("VssPreprocessor.initialSamples",
1202                                 optInt,
1203                                 "initial_samples=",
1204                                 "100000");
1205 
1206  RegisterOption("VssPreprocessor.testBeamSampling",
1207                                optBool,
1208                                "beam_sampling",
1209                                "false");
1210
1211  RegisterOption("VssPreprocessor.vssSamples",
1212                                 optInt,
1213                                 "vss_samples=",
1214                                 "1000000");
1215       
1216  RegisterOption("VssPreprocessor.vssSamplesPerPass",
1217                                 optInt,
1218                                 "vss_samples_per_pass=",
1219                                 "1000");
1220 
1221  RegisterOption("VssPreprocessor.samplesPerPass",
1222                                 optInt,
1223                                 "samples_per_pass=",
1224                                 "100000");
1225
1226  RegisterOption("VssPreprocessor.useImportanceSampling",
1227                                 optBool,
1228                                 "vss_use_importance=",
1229                                 "true");
1230
1231   RegisterOption("VssPreprocessor.enlargeViewSpace",
1232                                 optBool,
1233                                 "vss_enlarge_viewspace=",
1234                                 "false");
1235
1236   RegisterOption("VssPreprocessor.loadInitialSamples",
1237          optBool,
1238          "vss_load_loadInitialSamples=",
1239          "false");
1240
1241   RegisterOption("VssPreprocessor.storeInitialSamples",
1242          optBool,
1243          "vss_store_storedInitialSamples=",
1244          "false");
1245   
1246
1247    RegisterOption("VssPreprocessor.useViewSpaceBox",
1248          optBool,
1249          "vss_use_viewspace_box=",
1250          "false");
1251   
1252
1253  /************************************************************************************/
1254  /*                         View cells related options                               */
1255  /************************************************************************************/
1256
1257
1258        RegisterOption("ViewCells.type",
1259                        optString,
1260                        "view_cells_type=",
1261                        "vspBspTree");
1262
1263        RegisterOption("ViewCells.samplingType",
1264                        optString,
1265                        "view_cells_sampling_type=",
1266                        "box");
1267
1268        RegisterOption("ViewCells.mergeStats",
1269                                        optString,
1270                                        "view_cells_merge_stats=",
1271                                        "mergeStats.log");
1272
1273        RegisterOption("ViewCells.Evaluation.statsPrefix",
1274                                        optString,
1275                                        "view_cells_evaluation_stats_prefix=",
1276                                        "viewCells");
1277        RegisterOption("ViewCells.Evaluation.histogram",
1278                                        optBool,
1279                                        "view_cells_evaluation_histogram=",
1280                                        "false");
1281
1282        RegisterOption("ViewCells.Evaluation.histoStepSize",
1283                                        optInt,
1284                                        "view_cells_evaluation_histo_step_size=",
1285                                        "5000");
1286
1287        RegisterOption("ViewCells.renderCostEvaluationType",
1288                                        optString,
1289                                        "view_cells_render_cost_evaluation=",
1290                                        "perobject");
1291
1292        RegisterOption("ViewCells.active",
1293                                        optInt,
1294                                        "view_cells_active=",
1295                                        "1000");
1296
1297        RegisterOption("ViewCells.Construction.samples",
1298                                        optInt,
1299                                        "view_cells_construction_samples=",
1300                                        "0");
1301
1302        RegisterOption("ViewCells.Construction.samplesPerPass",
1303                                        optInt,
1304                                        "view_cells_construction_samples_per_pass=",
1305                                        "500000");
1306
1307        RegisterOption("ViewCells.PostProcess.samples",
1308                                        optInt,
1309                                        "view_cells_post_process_samples=",
1310                                        "0");
1311
1312        RegisterOption("ViewCells.Visualization.samples",
1313                                        optInt,
1314                                        "view_cells_visualization_samples=",
1315                                        "0");
1316
1317        RegisterOption("ViewCells.Visualization.maxOutput",
1318                                        optInt,
1319                                        "view_cells_visualization_max_output=",
1320                                        "20");
1321
1322        RegisterOption("ViewCells.Filter.maxSize",
1323                                        optInt,
1324                                        "view_cells_filter_max_size=",
1325                                        "4");
1326
1327        RegisterOption("ViewCells.Filter.width",
1328                                        optFloat,
1329                                        "view_cells_filter_width=",
1330                                        "200.0");
1331
1332        RegisterOption("ViewCells.loadFromFile",
1333                                        optBool,
1334                                        "view_cells_load_from_file=",
1335                                        "false");
1336
1337        RegisterOption("ViewCells.PostProcess.refine",
1338                                        optBool,
1339                                        "view_cells_refine=",
1340                                        "false");
1341
1342        RegisterOption("ViewCells.PostProcess.compress",
1343                                        optBool,
1344                                        "view_cells_post_process_compress=",
1345                                        "false");
1346
1347        RegisterOption("ViewCells.Evaluation.samples",
1348                                        optInt,
1349                                        "view_cells_evaluation_samples=",
1350                                        "8000000");
1351
1352        RegisterOption("ViewCells.Evaluation.samplingType",
1353                                        optString,
1354                                        "view_cells_evaluation_sampling_type=",
1355                                        "box");
1356
1357        RegisterOption("ViewCells.Evaluation.samplesPerPass",
1358                                        optInt,
1359                                        "view_cells_evaluation_samples_per_pass=",
1360                                        "300000");
1361
1362        RegisterOption("ViewCells.exportToFile",
1363                                        optBool,
1364                                        "view_cells_export_to_file=",
1365                                        "false");
1366
1367        RegisterOption("ViewCells.exportPvs",
1368                                        optBool,
1369                                        "view_cells_export_pvs=",
1370                                        "false");
1371
1372        RegisterOption("ViewCells.exportBboxesForPvs",
1373                                        optBool,
1374                                        "view_cells_export_bounding_boxes=",
1375                                        "true");
1376       
1377        RegisterOption("ViewCells.boxesFilename",
1378                                        optString,
1379                                        "view_cells_boxes_filename=",
1380                                        "boxes.out");
1381
1382        RegisterOption("ViewCells.evaluateViewCells",
1383                                        optBool,
1384                                        "view_cells_evaluate=",
1385                                        "false");
1386
1387        RegisterOption("ViewCells.maxViewCells",
1388                                        optInt,
1389                                        "view_cells_max_view_cells=",
1390                                        "0");
1391
1392        RegisterOption("ViewCells.maxPvsRatio",
1393                                        optFloat,
1394                                        "view_cells_max_pvs_ratio=",
1395                                        "0.1");
1396
1397        RegisterOption("ViewCells.filename",
1398                                        optString,
1399                                        "view_cells_filename=",
1400                                        "atlanta_viewcells_large.x3d");
1401
1402        RegisterOption("ViewCells.height",
1403                                        optFloat,
1404                                        "view_cells_height=",
1405                                        "5.0");
1406
1407        RegisterOption("ViewCells.Visualization.colorCode",
1408                                        optString,
1409                                        "view_cells_visualization_color_code=",
1410                                        "PVS");
1411
1412        RegisterOption("ViewCells.Visualization.clipPlanePos",
1413                                        optFloat,
1414                                        "view_cells_visualization_clip_plane_pos=",
1415                                        "0.35");
1416       
1417        RegisterOption("ViewCells.Visualization.exportGeometry",
1418                                        optBool,
1419                                        "view_cells_visualization_export_geometry=",
1420                                        "false");
1421
1422        RegisterOption("ViewCells.Visualization.exportRays",
1423                                        optBool,
1424                                        "view_cells_visualization_export_rays=",
1425                                        "false");
1426
1427        RegisterOption("ViewCells.processOnlyValidViewCells",
1428                                        optBool,
1429                                        "view_cells_process_only_valid_view_cells=",
1430                                        "false");
1431
1432        RegisterOption("ViewCells.PostProcess.maxCostRatio",
1433                        optFloat,
1434                        "view_cells_post_process_max_cost_ratio=",
1435                        "0.9");
1436       
1437        RegisterOption("ViewCells.PostProcess.renderCostWeight",
1438                        optFloat,
1439                        "view_cells_post_process_render_cost_weight",
1440                        "0.5");
1441       
1442        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation",
1443                        optFloat,
1444                        "view_cells_avgcost_max_deviations",
1445                        "0.5");
1446
1447        RegisterOption("ViewCells.PostProcess.maxMergesPerPass",
1448                optInt,
1449                "view_cells_post_process_max_merges_per_pass=",
1450                "500");
1451
1452        RegisterOption("ViewCells.PostProcess.minViewCells",
1453                optInt,
1454                "view_cells_post_process_min_view_cells=",
1455                "1000");
1456
1457        RegisterOption("ViewCells.PostProcess.useRaysForMerge",
1458                optBool,
1459                "view_cells_post_process_use_rays_for_merge=",
1460                "false");
1461       
1462        RegisterOption("ViewCells.PostProcess.merge",
1463                optBool,
1464                "view_cells_post_process_merge=",
1465                "true");
1466
1467        RegisterOption("ViewCells.Visualization.exportMergedViewCells",
1468                optBool,
1469                "view_cells_viz_export_merged_viewcells=",
1470                "false");
1471
1472        RegisterOption("ViewCells.maxStaticMemory",
1473                optFloat,
1474                "view_cells_max_static_mem=",
1475                "8.0");
1476
1477        RegisterOption("ViewCells.Visualization.useClipPlane",
1478                optBool,
1479                "view_cells_viz_use_clip_plane=",
1480                "false");
1481       
1482        RegisterOption("ViewCells.showVisualization",
1483                optBool,
1484                "view_cells_show_visualization=",
1485                "false");
1486
1487        RegisterOption("ViewCells.Visualization.clipPlaneAxis",
1488                optInt,
1489                "view_cells_viz_clip_plane_axis=",
1490                "0");
1491
1492       
1493        /************************************************************************************/
1494        /*                         Render simulation related options                        */
1495        /************************************************************************************/
1496
1497
1498        RegisterOption("Simulation.objRenderCost",
1499                        optFloat,
1500                        "simulation_obj_render_cost",
1501                        "1.0");
1502
1503        RegisterOption("Simulation.vcOverhead",
1504                        optFloat,
1505                        "simulation_vc_overhead",
1506                        "0.05");
1507
1508        RegisterOption("Simulation.moveSpeed",
1509                        optFloat,
1510                        "simulation_moveSpeed",
1511                        "1.0");
1512
1513
1514
1515
1516        /************************************************************************************/
1517        /*                         Bsp tree related options                                 */
1518        /************************************************************************************/
1519
1520
1521        RegisterOption("BspTree.Construction.input",
1522                optString,
1523                "bsp_construction_input=",
1524                "fromViewCells");
1525
1526        RegisterOption("BspTree.subdivisionStats",
1527                                        optString,
1528                                        "bsp_subdivision_stats=",
1529                                        "bspSubdivisionStats.log");
1530
1531        RegisterOption("BspTree.Construction.samples",
1532                optInt,
1533                "bsp_construction_samples=",
1534                "100000");
1535
1536        RegisterOption("BspTree.Construction.epsilon",
1537                optFloat,
1538                "bsp_construction_epsilon=",
1539                "0.002");
1540
1541        RegisterOption("BspTree.Termination.minPolygons",
1542                        optInt,
1543                        "bsp_term_min_polygons=",
1544                        "5");
1545
1546        RegisterOption("BspTree.Termination.minPvs",
1547                        optInt,
1548                        "bsp_term_min_pvs=",
1549                        "20");
1550
1551        RegisterOption("BspTree.Termination.minProbability",
1552                        optFloat,
1553                        "bsp_term_min_probability=",
1554                        "0.001");
1555
1556        RegisterOption("BspTree.Termination.maxRayContribution",
1557                        optFloat,
1558                        "bsp_term_ray_contribution=",
1559                        "0.005");
1560
1561        RegisterOption("BspTree.Termination.minAccRayLenght",
1562                        optFloat,
1563                        "bsp_term_min_acc_ray_length=",
1564                        "50");
1565
1566        RegisterOption("BspTree.Termination.minRays",
1567                        optInt,
1568                        "bsp_term_min_rays=",
1569                        "-1");
1570
1571        RegisterOption("BspTree.Termination.ct_div_ci",
1572                        optFloat,
1573                        "bsp_term_ct_div_ci=",
1574                        "0.0");
1575
1576        RegisterOption("BspTree.Termination.maxDepth",
1577                        optInt,
1578                        "bsp_term_max_depth=",
1579                        "100");
1580
1581        RegisterOption("BspTree.Termination.maxCostRatio",
1582                        optFloat,
1583                        "bsp_term_axis_aligned_max_cost_ratio=",
1584                        "1.5");
1585
1586        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1587                        optFloat,
1588                        "bsp_term_axis_aligned_ct_div_ci=",
1589                        "0.5");
1590
1591        RegisterOption("BspTree.AxisAligned.splitBorder",
1592                        optFloat,
1593                        "bsp__axis_aligned_split_border=",
1594                        "0.1");
1595
1596        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1597                        optInt,
1598                        "bsp_term_axis_aligned_max_polygons=",
1599                        "50");
1600
1601        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1602                        optInt,
1603                        "bsp_term_min_objects=",
1604                        "3");
1605
1606        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1607                        optInt,
1608                        "bsp_term_axis_aligned_min_rays=",
1609                        "-1");
1610
1611        RegisterOption("BspTree.splitPlaneStrategy",
1612                        optString,
1613                        "bsp_split_method=",
1614                        "leastSplits");
1615
1616        RegisterOption("BspTree.maxPolyCandidates",
1617                optInt,
1618                "bsp_max_poly_candidates=",
1619                "20");
1620
1621        RegisterOption("BspTree.maxRayCandidates",
1622                optInt,
1623                "bsp_max_plane_candidates=",
1624                "20");
1625
1626        RegisterOption("BspTree.maxTests",
1627                optInt,
1628                "bsp_max_tests=",
1629                "5000");
1630
1631        RegisterOption("BspTree.Termination.maxViewCells",
1632                optInt,
1633                "bsp_max_view_cells=",
1634                "5000");
1635
1636        RegisterOption("BspTree.Visualization.exportSplits",
1637                optBool,
1638                "bsp_visualization.export_splits",
1639                "false");
1640
1641        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1642        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1643        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1644        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1645        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1646        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1647        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1648        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1649        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1650
1651        /************************************************************************************/
1652        /*                         Preprocessor related options                             */
1653        /************************************************************************************/
1654
1655        RegisterOption("Preprocessor.type",
1656                                        optString,
1657                                        "preprocessor=",
1658                                        "sampling");
1659
1660        RegisterOption("Preprocessor.samplesFilename",
1661                                        optString,
1662                                        "preprocessor_samples_filename=",
1663                                        "rays.out");
1664
1665        RegisterOption("Preprocessor.loadMeshes",
1666                                        optBool,
1667                                        "loadMeshes=",
1668                                        "true");
1669
1670        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1671                                   optInt,
1672                                   "pvsRenderErrorSamples=",
1673                                   "10000");
1674       
1675        RegisterOption("Preprocessor.useGlRenderer",
1676                                        optBool,
1677                                        "preprocessor_use_gl_renderer=",
1678                                        "false");
1679
1680        RegisterOption("Preprocessor.useGlDebugger",
1681                                        optBool,
1682                                        "preprocessor_use_gl_debugger=",
1683                                        "false");
1684
1685        RegisterOption("Preprocessor.detectEmptyViewSpace",
1686                                   optBool,
1687                                   "preprocessor_detect_empty_viewspace=",
1688                                   "false");
1689       
1690        RegisterOption("Preprocessor.quitOnFinish",
1691                                   optBool,
1692                                   "preprocessor_quit_on_finish",
1693                                   "true");
1694
1695        RegisterOption("Preprocessor.computeVisibility",
1696                                   optBool,
1697                                   "preprocessor_compute_visibility=",
1698                                   "true");
1699
1700        RegisterOption("Preprocessor.exportVisibility",
1701                                   optBool,
1702                                   "preprocessor_export_visibility=",
1703                                   "true");
1704
1705        RegisterOption("Preprocessor.visibilityFile",
1706                                   optString,
1707                                   "preprocessor_visibility_file=",
1708                                   "visibility.xml");
1709
1710        RegisterOption("Preprocessor.applyVisibilityFilter",
1711                                   optBool,
1712                                   "preprocessor_apply_filter=",
1713                                   "true");
1714       
1715        RegisterOption("Preprocessor.applyVisibilitySpatialFilter",
1716                                   optBool,
1717                                   "preprocessor_apply_spatial_filter=",
1718                                   "true");
1719
1720        RegisterOption("Preprocessor.visibilityFilterWidth",
1721                                   optFloat,
1722                                   "preprocessor_visibility_filter_width=",
1723                                   "0.02");
1724
1725        RegisterOption("Preprocessor.histogram.maxValue",
1726                                        optInt,
1727                                        "preprocessor_histogram_max_value=",
1728                                        "1000");
1729
1730        RegisterOption("Preprocessor.rayCastMethod",
1731                                        optInt,
1732                                        "preprocessor_ray_cast_method=",
1733                                        "0");
1734
1735        RegisterOption("Preprocessor.histogram.intervals",
1736                                        optInt,
1737                                        "preprocessor_histogram_intervals=",
1738                                        "20");
1739
1740        RegisterOption("Preprocessor.exportKdTree",
1741                                        optBool,
1742                                        "preprocessor_export_kd_tree=",
1743                                        "false");
1744
1745        RegisterOption("Preprocessor.loadKdTree",
1746                                        optBool,
1747                                        "preprocessor_load_kd_tree=",
1748                                        "false");
1749
1750        RegisterOption("Preprocessor.kdTreeFilename",
1751                                        optString,
1752                                        "preprocessor_kd_tree_filename=",
1753                                        "vienna_kdtree.bin.gz");
1754       
1755
1756        /*************************************************************************/
1757        /*             VSS Preprocessor cells related options                    */
1758        /*************************************************************************/
1759
1760        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
1761        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
1762        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
1763        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1764        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1765
1766        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1767        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1768        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
1769        RegisterOption("VssTree.splitType", optString, "split=", "queries");
1770        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1771        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
1772        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1773
1774        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
1775
1776        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1777        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1778
1779        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
1780
1781       
1782       
1783        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1784        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false");
1785        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
1786        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1787        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1788        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
1789
1790        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
1791        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1792
1793
1794        RegisterOption("RssPreprocessor.initialSamples",
1795                                                                        optInt,
1796                                                                        "initial_samples=",
1797                                                                        "100000");
1798
1799        RegisterOption("RssPreprocessor.vssSamples",
1800                                        optInt,
1801                                        "rss_vss_samples=",
1802                                        "1000000");
1803
1804        RegisterOption("RssPreprocessor.vssSamplesPerPass",
1805                                        optInt,
1806                                        "rss_vss_samples_per_pass=",
1807                                        "1000");
1808
1809        RegisterOption("RssPreprocessor.samplesPerPass",
1810                                        optInt,
1811                                        "rss_samples_per_pass=",
1812                                        "100000");
1813
1814        RegisterOption("RssPreprocessor.useImportanceSampling",
1815                                        optBool,
1816                                        "rss_use_importance",
1817                                        "true");
1818
1819        RegisterOption("RssPreprocessor.objectBasedSampling",
1820                                        optBool,
1821                                        "rss_object_based_sampling",
1822                                        "true");
1823
1824        RegisterOption("RssPreprocessor.directionalSampling",
1825                                        optBool,
1826                                        "rss_directional_sampling",
1827                                        "false");
1828
1829        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10");
1830        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
1831        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
1832        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
1833        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1834        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1835
1836        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1837        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1838        RegisterOption("RssTree.randomize", optBool, "randomize=", "false");
1839        RegisterOption("RssTree.splitType", optString, "rss_split=", "queries");
1840        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1841
1842        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1843
1844        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
1845
1846        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1847        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1848
1849        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
1850
1851        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1852        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
1853        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
1854        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1855        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1856        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
1857
1858        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true");
1859        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1860        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true");
1861        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
1862
1863        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
1864
1865        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
1866        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
1867        RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays=", "false");
1868        RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000");
1869        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
1870        RegisterOption("RssPreprocessor.updateSubdivision",
1871                                   optBool,
1872                                   "rss_update_subdivision=",
1873                                   "false");
1874
1875
1876/************************************************************************************/
1877/*                      Rss preprocessor related options                            */
1878/************************************************************************************/
1879
1880
1881        RegisterOption("RssPreprocessor.loadInitialSamples",
1882                                        optBool,
1883                                        "vss_load_loadInitialSamples=",
1884                                        "false");
1885
1886        RegisterOption("RssPreprocessor.storeInitialSamples",
1887                                        optBool,
1888                                        "vss_store_storeInitialSamples=",
1889                                        "false");
1890
1891
1892/************************************************************************************/
1893/*                 View space partition BSP tree related options                    */
1894/************************************************************************************/
1895
1896        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
1897                                        optFloat,
1898                                        "vsp_bsp_term_min_global_cost_ratio=",
1899                                        "0.0001");
1900
1901        RegisterOption("VspBspTree.useSplitCostQueue",
1902                optBool,
1903                "vsp_bsp_use_split_cost_queue=",
1904                "true");
1905
1906        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
1907                                        optInt,
1908                                        "vsp_bsp_term_global_cost_miss_tolerance=",
1909                                        "4");
1910
1911        RegisterOption("VspBspTree.Termination.minPolygons",
1912                                        optInt,
1913                                        "vsp_bsp_term_min_polygons=",
1914                                        "-1");
1915
1916        RegisterOption("VspBspTree.Termination.minPvs",
1917                                        optInt,
1918                                        "vsp_bsp_term_min_pvs=",
1919                                        "20");
1920
1921        RegisterOption("VspBspTree.Termination.minProbability",
1922                                        optFloat,
1923                                        "vsp_bsp_term_min_probability=",
1924                                        "0.001");
1925
1926        RegisterOption("VspBspTree.subdivisionStats",
1927                                        optString,
1928                                        "vsp_bsp_subdivision_stats=",
1929                                        "vspBspSubdivisionStats.log");
1930
1931        RegisterOption("VspBspTree.Termination.maxRayContribution",
1932                                        optFloat,
1933                                        "vsp_bsp_term_ray_contribution=",
1934                                        "2");
1935
1936        RegisterOption("VspBspTree.Termination.minAccRayLenght",
1937                                        optFloat,
1938                                        "vsp_bsp_term_min_acc_ray_length=",
1939                                        "50");
1940
1941        RegisterOption("VspBspTree.Termination.minRays",
1942                                        optInt,
1943                                        "vsp_bsp_term_min_rays=",
1944                                        "-1");
1945
1946        RegisterOption("VspBspTree.Termination.ct_div_ci",
1947                                        optFloat,
1948                                        "vsp_bsp_term_ct_div_ci=",
1949                                        "0.0");
1950
1951        RegisterOption("VspBspTree.Termination.maxDepth",
1952                                        optInt,
1953                                        "vsp_bsp_term_max_depth=",
1954                                        "50");
1955
1956        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
1957                optFloat,
1958                "vsp_bsp_term_axis_aligned_max_cost_ratio=",
1959                "1.5");
1960
1961        RegisterOption("VspBspTree.useCostHeuristics",
1962                optBool,
1963                "vsp_bsp_use_cost_heuristics=",
1964                "false");
1965
1966        RegisterOption("VspBspTree.Termination.maxViewCells",
1967                optInt,
1968                "vsp_bsp_term_max_view_cells=",
1969                "10000");
1970
1971        RegisterOption("VspBspTree.Termination.maxCostRatio",
1972                optFloat,
1973                "vsp_bsp_term_max_cost_ratio=",
1974                "1.5");
1975
1976        RegisterOption("VspBspTree.Termination.missTolerance",
1977                optInt,
1978                "vsp_bsp_term_miss_tolerance=",
1979                "4");
1980
1981        RegisterOption("VspBspTree.splitPlaneStrategy",
1982                                        optInt,
1983                                        "vsp_bsp_split_method=",
1984                                        "1026");
1985
1986        RegisterOption("VspBspTree.maxPolyCandidates",
1987                                        optInt,
1988                                        "vsp_bsp_max_poly_candidates=",
1989                                        "20");
1990
1991        RegisterOption("VspBspTree.maxRayCandidates",
1992                                        optInt,
1993                                        "vsp_bsp_max_plane_candidates=",
1994                                        "20");
1995
1996        RegisterOption("VspBspTree.maxTests",
1997                                        optInt,
1998                                        "vsp_bsp_max_tests=",
1999                                        "5000");
2000
2001        RegisterOption("VspBspTree.Construction.samples",
2002                                        optInt,
2003                                        "vsp_bsp_construction_samples=",
2004                                        "100000");
2005
2006        RegisterOption("VspBspTree.Construction.minBand",
2007                                        optFloat,
2008                                        "vsp_bsp_construction_min_band=",
2009                                        "0.01");
2010
2011        RegisterOption("VspBspTree.Construction.maxBand",
2012                                        optFloat,
2013                                        "vsp_bsp_construction_max_band=",
2014                                        "0.99");
2015
2016        RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost",
2017                                        optBool,
2018                                        "vsp_bsp_construction_use_drivingaxis_for_maxcost=",
2019                                        "false");
2020
2021        RegisterOption("VspBspTree.Construction.epsilon",
2022                                        optFloat,
2023                                        "vsp_bsp_construction_epsilon=",
2024                                        "0.002");
2025
2026        RegisterOption("VspBspTree.Visualization.exportSplits",
2027                                        optBool,
2028                                        "vsp_bsp_visualization.export_splits",
2029                                        "false");
2030
2031        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
2032                                        optBool,
2033                                        "vsp_bsp_split_only_driving_axis=",
2034                                        "false");
2035
2036        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
2037                                        optBool,
2038                    "vsp_bsp_usePolygonSplitIfAvailable=",
2039                                        "false");
2040
2041        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
2042                        optInt,
2043                        "bsp_term_axis_aligned_min_rays=",
2044                        "0");
2045       
2046        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
2047                        optFloat,
2048                        "bsp_term_axis_aligned_min_rays=",
2049                        "2");
2050
2051        RegisterOption("VspBspTree.Factor.leastRaySplits",
2052                                        optFloat,
2053                                        "vsp_bsp_factor_least_ray_splits=",
2054                                        "1.0");
2055
2056        RegisterOption("VspBspTree.Factor.balancedRays",
2057                                        optFloat,
2058                                        "vsp_bsp_factor_balanced_rays=",
2059                                        "1.0");
2060
2061        RegisterOption("VspBspTree.Factor.pvs",
2062                                        optFloat,
2063                                        "vsp_bsp_factor_pvs=",
2064                                        "1.0");
2065       
2066        RegisterOption("VspBspTree.Construction.renderCostWeight",
2067                        optFloat,
2068                        "vsp_bsp_post_process_render_cost_weight=",
2069                        "1.0");
2070
2071        RegisterOption("VspBspTree.Construction.renderCostDecreaseWeight",
2072                        optFloat,
2073                        "vsp_bsp_construction_render_cost_decrease_weight=",
2074                        "0.99");
2075
2076        RegisterOption("VspBspTree.Construction.randomize",
2077                optBool,
2078                "vsp_bsp_construction_randomize=",
2079                "false");
2080
2081        RegisterOption("VspBspTree.simulateOctree",
2082                optBool,
2083                "vsp_bsp_simulate_octree=",
2084                "false");
2085
2086        RegisterOption("VspBspTree.nodePriorityQueueType",
2087                optInt,
2088                "vsp_bsp_node_queue_type=",
2089                "0");
2090
2091        RegisterOption("VspBspTree.useRandomAxis",
2092                optBool,
2093                "-vsp_bsp_use_random_axis=",
2094                "false");
2095
2096        RegisterOption("VspBspTree.maxTotalMemory",
2097                optFloat,
2098                "vsp_bsp_max_total_mem=",
2099                "60.0");
2100
2101        RegisterOption("VspBspTree.maxStaticMemory",
2102                optFloat,
2103                "vsp_bsp_max_static_mem=",
2104                "8.0");
2105
2106
2107
2108/***************************************************************************/
2109/*                 View space partition tree related options               */
2110/***************************************************************************/
2111
2112       
2113        RegisterOption("VspTree.Construction.samples",
2114                                        optInt,
2115                                        "vsp_construction_samples=",
2116                                        "10000");
2117
2118       
2119        RegisterOption("VspTree.Construction.renderCostDecreaseWeight",
2120                        optFloat,
2121                        "vsp_construction_render_cost_decrease_weight=",
2122                        "0.99");
2123
2124        RegisterOption("VspTree.Termination.maxDepth",
2125                                        optInt,
2126                                        "vsp_term_max_depth=",
2127                                        "100");
2128
2129        RegisterOption("VspTree.Termination.minRays",
2130                                        optInt,
2131                                        "vsp_term_min_rays=",
2132                                        "-1");
2133
2134
2135        RegisterOption("VspTree.Termination.minPvs",
2136                                        optInt,
2137                                        "vsp_term_min_pvs=",
2138                                        "20");
2139
2140        RegisterOption("VspTree.Termination.minProbability",
2141                                        optFloat,
2142                                        "vsp_term_min_probability=",
2143                                        "0.001");
2144
2145        RegisterOption("VspTree.Termination.maxRayContribution",
2146                        optFloat,
2147                        "vsp_term_ray_contribution=",
2148                        "0.9");
2149       
2150        RegisterOption("VspTree.Termination.maxCostRatio",
2151                optFloat,
2152                "vsp_term_max_cost_ratio=",
2153                "1.5");
2154       
2155        RegisterOption("VspTree.Termination.maxViewCells",
2156                optInt,
2157                "vsp_term_max_view_cells=",
2158                "10000");
2159
2160       
2161        RegisterOption("VspTree.Termination.missTolerance",
2162                optInt,
2163                "vsp_term_miss_tolerance=",
2164                "4");
2165
2166        RegisterOption("VspTree.Termination.minGlobalCostRatio",
2167                                        optFloat,
2168                                        "vsp_term_min_global_cost_ratio=",
2169                                        "0.0001");
2170
2171        RegisterOption("VspTree.Termination.globalCostMissTolerance",
2172                                        optInt,
2173                                        "vsp_term_global_cost_miss_tolerance=",
2174                                        "4");
2175
2176        RegisterOption("VspTree.Termination.ct_div_ci",
2177                                        optFloat,
2178                                        "vsp_term_ct_div_ci=",
2179                                        "0.0");
2180
2181        RegisterOption("VspTree.Construction.epsilon",
2182                                        optFloat,
2183                                        "vsp_construction_epsilon=",
2184                                        "0.002");
2185
2186        RegisterOption("VspTree.splitUseOnlyDrivingAxis",
2187                                        optBool,
2188                                        "vsp_split_only_driving_axis=",
2189                                        "false");
2190
2191        RegisterOption("VspTree.maxStaticMemory",
2192                optFloat,
2193                "vsp_max_static_mem=",
2194                "8.0");
2195
2196        RegisterOption("VspTree.useCostHeuristics",
2197                optBool,
2198                "vsp_use_cost_heuristics=",
2199                "false");
2200
2201        RegisterOption("VspTree.simulateOctree",
2202                optBool,
2203                "vsp_simulate_octree=",
2204                "false");
2205
2206        RegisterOption("VspTree.Construction.randomize",
2207                optBool,
2208                "vsp_construction_randomize=",
2209                "false");
2210
2211        RegisterOption("VspTree.subdivisionStats",
2212                                        optString,
2213                                        "vsp_subdivision_stats=",
2214                                        "vspSubdivisionStats.log");
2215
2216        RegisterOption("VspTree.Construction.minBand",
2217                                        optFloat,
2218                                        "vsp_construction_min_band=",
2219                                        "0.01");
2220
2221        RegisterOption("VspTree.Construction.maxBand",
2222                                        optFloat,
2223                                        "vsp_construction_max_band=",
2224                                        "0.99");
2225       
2226        RegisterOption("VspTree.maxTests",
2227                                        optInt,
2228                                        "vsp_max_tests=",
2229                                        "5000");
2230
2231
2232
2233/***********************************************************************/
2234/*           Object space partition tree related options               */
2235/***********************************************************************/
2236
2237
2238        RegisterOption("OspTree.Construction.randomize",
2239                                        optBool,
2240                                        "osp_construction_randomize=",
2241                                        "false");
2242
2243        RegisterOption("OspTree.Termination.maxDepth",
2244                                        optInt,
2245                                        "osp_term_max_depth=",
2246                                        "30");
2247       
2248        RegisterOption("OspTree.Termination.maxLeaves",
2249                                        optInt,
2250                                        "osp_term_max_leaves=",
2251                                        "1000");
2252       
2253        RegisterOption("OspTree.Termination.minObjects",
2254                                        optInt,
2255                                        "osp_term_min_objects=",
2256                                        "1");
2257
2258        RegisterOption("OspTree.Termination.minProbability",
2259                                        optFloat,
2260                                        "osp_term_min_objects=",
2261                                        "0.00001");
2262
2263        RegisterOption("OspTree.Termination.missTolerance",
2264                                        optInt,
2265                                        "osp_term_miss_tolerance=",
2266                                        "8");
2267
2268        RegisterOption("OspTree.Termination.maxCostRatio",
2269                                        optFloat,
2270                                        "osp_term_max_cost_ratio=",
2271                                        "0.99");
2272
2273        RegisterOption("OspTree.Termination.minGlobalCostRatio",
2274                                        optFloat,
2275                                        "osp_term_min_global_cost_ratio=",
2276                                        "0.00001");
2277
2278        RegisterOption("OspTree.Termination.globalCostMissTolerance",
2279                                        optInt,
2280                                        "osp_term_global_cost_miss_tolerance=",
2281                                        "4");
2282
2283        RegisterOption("OspTree.Termination.ct_div_ci",
2284                                        optFloat,
2285                                        "osp_term_ct_div_ci=",
2286                                        "0");
2287       
2288        RegisterOption("OspTree.Construction.epsilon",
2289                                   optFloat,
2290                                   "osp_construction_epsilon=",
2291                                   "0.00001");
2292       
2293        // if only the driving axis is used for axis aligned split
2294        RegisterOption("OspTree.splitUseOnlyDrivingAxis",
2295                                   optBool,
2296                                   "osp_split_only_driving_axis=",
2297                                   "false");
2298
2299        RegisterOption("OspTree.maxStaticMemory",
2300                                   optFloat,
2301                                   "osp_max_static_mem=",
2302                                   "8.0");
2303
2304        RegisterOption("OspTree.useCostHeuristics",
2305                                   optBool,
2306                                   "osp_use_cost_heuristics=",
2307                                   "true");
2308
2309        RegisterOption("OspTree.subdivisionStats",
2310                                        optString,
2311                                        "osp_subdivision_stats=",
2312                                        "ospSubdivisionStats.log");
2313
2314        RegisterOption("OspTree.Construction.splitBorder",
2315                                        optFloat,
2316                                        "osp_construction_split_border=",
2317                                        "0.01");
2318
2319        RegisterOption("OspTree.Construction.renderCostDecreaseWeight",
2320                                   optFloat,
2321                                   "osp_construction_render_cost_decrease_weight=",
2322                                   "0.99");
2323
2324
2325
2326/**********************************************************************/
2327/*            Bounding Volume Hierarchy related options               */
2328/**********************************************************************/
2329
2330        RegisterOption("BvHierarchy.Construction.randomize",
2331                                        optBool,
2332                                        "bvh_construction_randomize=",
2333                                        "false");
2334
2335        RegisterOption("BvHierarchy.Termination.maxDepth",
2336                                        optInt,
2337                                        "bvh_term_max_depth=",
2338                                        "30");
2339       
2340        RegisterOption("BvHierarchy.Termination.maxLeaves",
2341                                        optInt,
2342                                        "bvh_term_max_leaves=",
2343                                        "1000");
2344       
2345        RegisterOption("BvHierarchy.Termination.minObjects",
2346                                        optInt,
2347                                        "bvh_term_min_objects=",
2348                                        "1");
2349
2350        RegisterOption("BvHierarchy.Termination.minProbability",
2351                                        optFloat,
2352                                        "bvh_term_min_objects=",
2353                                        "0.00001");
2354
2355        RegisterOption("BvHierarchy.Termination.minRays",
2356                                        optInt,
2357                                        "bvh_term_min_rays=",
2358                                        "0");
2359
2360        RegisterOption("BvHierarchy.Termination.missTolerance",
2361                                        optInt,
2362                                        "osp_term_miss_tolerance=",
2363                                        "8");
2364
2365        RegisterOption("BvHierarchy.Termination.maxCostRatio",
2366                                        optFloat,
2367                                        "bvh_term_max_cost_ratio=",
2368                                        "0.99");
2369
2370        RegisterOption("BvHierarchy.Termination.minGlobalCostRatio",
2371                                        optFloat,
2372                                        "bvh_term_min_global_cost_ratio=",
2373                                        "0.00001");
2374
2375        RegisterOption("BvHierarchy.Termination.globalCostMissTolerance",
2376                                        optInt,
2377                                        "bvh_term_global_cost_miss_tolerance=",
2378                                        "4");
2379
2380        // if only the driving axis is used for axis aligned split
2381        RegisterOption("BvHierarchy.splitUseOnlyDrivingAxis",
2382                                   optBool,
2383                                   "bvh_split_only_driving_axis=",
2384                                   "false");
2385
2386        RegisterOption("BvHierarchy.maxStaticMemory",
2387                                   optFloat,
2388                                   "bvh_max_static_mem=",
2389                                   "8.0");
2390
2391        RegisterOption("BvHierarchy.useCostHeuristics",
2392                                   optBool,
2393                                   "bvh_use_cost_heuristics=",
2394                                   "true");
2395
2396        RegisterOption("BvHierarchy.subdivisionStats",
2397                                        optString,
2398                                        "bvh_subdivision_stats=",
2399                                        "bvhSubdivisionStats.log");
2400
2401        RegisterOption("BvHierarchy.Construction.renderCostDecreaseWeight",
2402                                   optFloat,
2403                                   "bvh_construction_render_cost_decrease_weight=",
2404                                   "0.99");
2405       
2406        RegisterOption("BvHierarchy.Construction.useGlobalSorting",
2407                                        optBool,
2408                                        "bvh_construction_use_global_sorting=",
2409                                        "false");
2410
2411       
2412        /*******************************************************************/
2413        /*               Hierarchy Manager related options                 */
2414        /*******************************************************************/
2415
2416        RegisterOption("Hierarchy.subdivisionStats",
2417                           optString,
2418                                   "hierarchy_subdivision_stats=",
2419                                   "hierarchySubdivisionStats.log");
2420
2421        RegisterOption("Hierarchy.type",
2422                           optString,
2423                                   "hierarchy_type=",
2424                                   "bvh");
2425
2426        RegisterOption("Hierarchy.Termination.minGlobalCostRatio",
2427                                        optFloat,
2428                                        "hierarchy_term_min_global_cost_ratio=",
2429                                        "0.00001");
2430
2431        RegisterOption("Hierarchy.Termination.globalCostMissTolerance",
2432                                        optInt,
2433                                        "hierarchy_term_global_cost_miss_tolerance=",
2434                                        "4");
2435
2436        RegisterOption("Hierarchy.Termination.maxLeaves",
2437                                        optInt,
2438                                        "hierarchy_term_max_leaves=",
2439                                        "1000");
2440       
2441        RegisterOption("Hierarchy.Construction.type",
2442                                        optInt,
2443                                        "hierarchy_construction_type=",
2444                                        "0");
2445
2446        RegisterOption("Hierarchy.Construction.minDepthForOsp",
2447                                        optInt,
2448                                        "hierarchy_construction_min_depth_for_osp=",
2449                                        "-1");
2450
2451        RegisterOption("Hierarchy.Construction.startWithObjectSpace",
2452                                        optBool,
2453                                        "hierarchy_construction_start_with_osp=",
2454                                        "true");
2455
2456        RegisterOption("Hierarchy.Construction.repairQueue",
2457                                        optBool,
2458                                        "hierarchy_construction_repair_queue=",
2459                                        "true");
2460
2461        RegisterOption("Hierarchy.Construction.minDepthForVsp",
2462                                        optInt,
2463                                        "hierarchy_construction_min_depth_for_vsp=",
2464                                        "-1");
2465
2466        //////////////////////////////////////////////////////////////////////////////////
2467}
2468
2469void
2470Environment::SetStaticOptions()
2471{
2472 
2473  // get Global option values
2474  GetRealValue("Limits.threshold", Limits::Threshold);
2475  GetRealValue("Limits.small", Limits::Small);
2476  GetRealValue("Limits.infinity", Limits::Infinity);
2477
2478
2479}
2480
2481bool
2482Environment::Parse(const int argc, char **argv, bool useExePath)
2483{
2484  bool result = true;
2485  // Read the names of the scene, environment and output files
2486  ReadCmdlineParams(argc, argv, "");
2487
2488  char *envFilename = new char[128];
2489
2490  char filename[64];
2491
2492  // Get the environment file name
2493  if (!GetParam(' ', 0, filename)) {
2494    // user didn't specified environment file explicitly, so
2495    strcpy(filename, "default.env");
2496  }
2497 
2498  if (useExePath) {
2499    char *path = GetPath(argv[0]);
2500    if (*path != 0)
2501      sprintf(envFilename, "%s/%s", path, filename);
2502    else
2503      strcpy(envFilename, filename);
2504   
2505    delete path;
2506  }
2507  else
2508    strcpy(envFilename, filename);
2509
2510 
2511  // Now it's time to read in environment file.
2512  if (!ReadEnvFile(envFilename)) {
2513    // error - bad input file name specified ?
2514    cerr<<"Error parsing environment file "<<envFilename<<endl;
2515        result = false;
2516  }
2517  delete envFilename;
2518
2519  // Parse the command line; options given on the command line subsume
2520  // stuff specified in the input environment file.
2521  ParseCmdline(argc, argv, 0);
2522
2523  SetStaticOptions();
2524
2525  // Check for request for help
2526  if (CheckForSwitch(argc, argv, '?')) {
2527    PrintUsage(cout);
2528    exit(0);
2529  }
2530 
2531  return true;
2532}
2533
2534}
Note: See TracBrowser for help on using the repository browser.