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

Revision 1902, 69.6 KB checked in by mattausch, 17 years ago (diff)

added kd pvs as option to view cells manager to avoid errors when updating the svn from jiri

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