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

Revision 2686, 76.8 KB checked in by mattausch, 16 years ago (diff)

fixed several problems

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
541bool
542Environment::GetStringValue(const char *name,
543                            string &stringVariable,
544                            const bool isFatal) const
545{
546  int i = FindOption(name, isFatal);
547
548  if (i<0)
549    return false;
550
551 
552  if (options[i].value != NULL) {
553    // option was not read, so use the default
554    stringVariable = options[i].value;
555  }
556  else {
557    // option was explicitly specified
558    stringVariable = options[i].defaultValue;
559  }
560  return true;
561}
562
563
564void
565Environment::SetInt(const char *name, const int value)
566{
567
568  int i = FindOption(name);
569  if (i<0)
570    return;
571
572  if (options[i].type == optInt) {
573    delete options[i].value;
574    options[i].value = new char[16];
575    sprintf(options[i].value, "%.15d", value);
576  }
577  else {
578    Debug << "Internal error: Trying to set non-integer option " << name
579          << " to integral value.\n" << flush;
580    exit(1);
581  }
582}
583
584void
585Environment::SetFloat(const char *name, const Real value)
586{
587  int i = FindOption(name);
588  if (i<0)
589    return;
590
591  if (options[i].type == optFloat) {
592    delete options[i].value;
593    options[i].value = new char[25];
594    sprintf(options[i].value, "%.15e", value);
595  }
596  else {
597    Debug << "Internal error: Trying to set non-Real option " << name
598          << " to Real value.\n" << flush;
599    exit(1);
600  }
601}
602
603void
604Environment::SetBool(const char *name, const bool value)
605{
606  int i = FindOption(name);
607  if (i<0)
608    return;
609
610  if (options[i].type == optBool) {
611    delete options[i].value;
612    options[i].value = new char[6];
613    if (value)
614      sprintf(options[i].value, "true");
615    else
616      sprintf(options[i].value, "false");
617  }
618  else {
619    Debug << "Internal error: Trying to set non-bool option " << name
620          << " to boolean value.\n" << flush;
621    exit(1);
622  }
623}
624
625void
626Environment::SetVector(const char *name,
627                       const Vector3 &v)
628{
629  int i = FindOption(name);
630  if (i<0)
631    return;
632
633  if (options[i].type == optVector) {
634    delete options[i].value;
635    options[i].value = new char[128];
636    sprintf(options[i].value, "%.15e,%.15e,%.15e", v.x, v.y, v.z);
637  }
638  else {
639    Debug << "Internal error: Trying to set non-vector option " << name
640          << " to vector value.\n" << flush;
641    exit(1);
642  }
643}
644
645void
646Environment::SetString(const char *name, const char *value)
647{
648  int i = FindOption(name);
649  if (i<0)
650    return;
651
652  if (options[i].type == optString) {
653    delete options[i].value;
654        options[i].value = ::strdup(value);
655  }
656  else {
657    Debug << "Internal error: Trying to set non-string option " << name
658          << " to string value.\n" << flush;
659    exit(1);
660  }
661}
662
663void
664Environment::ParseCmdline(const int argc,
665                                                  char **argv,
666                                                  const int index)
667{
668  int curIndex = -1;
669
670  for (int i = 1; i < argc; i++) {
671    // if this parameter is non-optional, skip it and increment the counter
672    if (argv[i][0] != '-') {
673      curIndex++;
674      continue;
675    }
676    // make sure to skip all non-optional parameters
677    char *t = strchr(optionalParams, argv[i][1]);
678    if (t != NULL)
679      continue;
680
681    // if we are in the scope of the current parameter, parse it
682    if (curIndex == -1 || curIndex == index) {
683      if (argv[i][1] == 'D') {
684        // it's a full name definition
685        bool found = false;
686        int j;
687
688        char *t = strchr(argv[i] + 2, '=');
689        if (t == NULL) {
690          Debug << "Error: Missing '=' in option. "
691                << "Syntax is -D<name>=<value>.\n" << flush;
692          exit(1);
693        }
694        for (j = 0; j < numOptions; j++)
695          if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) &&
696              (unsigned)(t - argv[i] - 2) == strlen(options[j].name)) {
697            found = true;
698            break;
699          }
700        if (!found) {
701          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
702          //  exit(1);
703        }
704        if (found) {
705          if (!CheckType(t + 1, options[j].type)) {
706            Debug << "Error: invalid type of value " << t + 1 << " in option "
707                  << options[j].name << ".\n";
708            exit(1);
709          }
710          if (options[j].value != NULL)
711            delete options[j].value;
712          options[j].value = strdup(t + 1);
713        }
714      }
715      else {
716        // it's an abbreviation
717        bool found = false;
718        int j;
719       
720        for (j = 0; j < numOptions; j++)
721          if (options[j].abbrev != NULL &&
722              !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev))) {
723            found = true;
724            break;
725          }
726        if (!found) {
727          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
728          //          exit(1);
729        }
730        if (found) {
731          if (!CheckType(argv[i] + 1 + strlen(options[j].abbrev), options[j].type)) {
732            Debug << "Error: invalid type of value "
733                  << argv[i] + 1 + strlen(options[j].abbrev) << "in option "
734                  << options[j].name << ".\n";
735            exit(1);
736          }
737          if (options[j].value != NULL)
738            delete options[j].value;
739          options[j].value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
740        }
741      }
742    }
743  }
744#ifdef _DEBUG_PARAMS
745  // write out the options table
746  cerr << "Options table for " << numOptions << " options:\n";
747  for (int j = 0; j < numOptions; j++) {
748    cerr << options[j];
749    cerr << "\n";
750  }
751  cerr << "Options done.\n" << flush;
752#endif // _DEBUG_PARAMS
753}
754
755
756char *
757Environment::ParseString(char *buffer, char *string) const
758{
759  char *s = buffer;
760  char *t = string + strlen(string);
761
762  // skip leading whitespaces
763  while (*s == ' ' || *s == '\t')
764    s++;
765  if (*s == '\0')
766    return NULL;
767  while ((*s >= 'a' && *s <= 'z') ||
768         (*s >= 'A' && *s <= 'Z') ||
769         (*s >= '0' && *s <= '9') ||
770         *s == '_')
771    *t++ = *s++;
772  *t = '\0';
773  // skip trailing whitespaces
774  while (*s == ' ' || *s == '\t')
775    s++;
776  return s;
777}
778
779const char code[] = "JIDHipewhfdhyd74387hHO&{WK:DOKQEIDKJPQ*H#@USX:#FWCQ*EJMQAHPQP(@G#RD";
780
781void
782Environment::DecodeString(char *buff, int max)
783{
784  buff[max] = 0;
785  char *p = buff;
786  const char *cp = code;
787  for (; *p; p++) {
788    if (*p != '\n')
789      *p = *p ^ *cp;
790    ++cp;
791    if (*cp == 0)
792      cp = code;
793  }
794}
795
796void
797Environment::CodeString(char *buff, int max)
798{
799  buff[max] = 0;
800  char *p = buff;
801  const char *cp = code;
802  for (; *p; p++) {
803    if (*p != '\n')
804      *p = *p ^ *cp;
805    ++cp;
806    if (*cp == 0)
807      cp = code;
808  }
809}
810
811void
812Environment::SaveCodedFile(char *filenameText,
813                            char *filenameCoded)
814{
815  ifstream envStream(filenameText);
816 
817  // some error had occured
818  if (envStream.fail()) {
819    cerr << "Error: Can't open file " << filenameText << " for reading (err. "
820         << envStream.rdstate() << ").\n";
821    return;
822  }
823
824  char buff[256];
825  envStream.getline(buff, 255);
826  buff[8] = 0;
827  if (strcmp(buff, "CGX_CF10") == 0)
828    return;
829
830  ofstream cStream(filenameCoded);
831  cStream<<"CGX_CF10";
832 
833  // main loop
834  for (;;) {
835    // read in one line
836    envStream.getline(buff, 255);
837    if (!envStream)
838      break;
839    CodeString(buff, 255);
840    cStream<<buff;
841  }
842 
843}
844
845bool
846Environment::ReadEnvFile(const char *envFilename)
847{
848  char buff[MaxStringLength], name[MaxStringLength];
849  char *s, *t;
850  int i, line = 0;
851  bool found;
852  igzstream envStream(envFilename);
853
854  // some error had occured
855  if (envStream.fail()) {
856    cerr << "Error: Can't open file " << envFilename << " for reading (err. "
857         << envStream.rdstate() << ").\n";
858    return false;
859  }
860
861  name[0] = '\0';
862
863//    bool coded;
864//    envStream.getline(buff, 255);
865//    buff[8] = 0;
866//    if (strcmp(buff, "CGX_CF10") == 0)
867//      coded = true;
868//    else {
869//      coded = false;
870//      envStream.Rewind();
871//    }
872 
873  // main loop
874  for (;;) {
875    // read in one line
876    envStream.getline(buff, MaxStringLength-1);
877   
878    if (!envStream)
879      break;
880
881//      if (coded)
882//        DecodeString(buff, 255);
883
884    line++;
885    // get rid of comments
886    s = strchr(buff, '#');
887    if (s != NULL)
888      *s = '\0';
889
890    // get one identifier
891    s = ParseString(buff, name);
892    // parse line
893    while (s != NULL) {
894      // it's a group name - make the full name
895      if (*s == '{') {
896        strcat(name, ".");
897        s++;
898        s = ParseString(s, name);
899        continue;
900      }
901      // end of group
902      if (*s == '}') {
903        if (strlen(name) == 0) {
904          cerr << "Error: unpaired } in " << envFilename << " (line "
905               << line << ").\n";
906          envStream.close();
907          return false;
908        }
909        name[strlen(name) - 1] = '\0';
910        t = strrchr(name, '.');
911        if (t == NULL)
912          name[0] = '\0';
913        else
914          *(t + 1) = '\0';
915        s++;
916        s = ParseString(s, name);
917        continue;
918      }
919      // find variable name in the table
920      found = false;
921      for (i = 0; i < numOptions; i++)
922        if (!strcmp(name, options[i].name)) {
923          found = true;
924          break;
925        }
926      if (!found) {
927        cerr << "Warning: unknown option " << name << " in environment file "
928             << envFilename << " (line " << line << ").\n";
929      } else
930        switch (options[i].type) {
931        case optInt: {
932          strtol(s, &t, 10);
933          if (t == s || (*t != ' ' && *t != '\t' &&
934                         *t != '\0' && *t != '}')) {
935            cerr << "Error: Mismatch in int variable " << name << " in "
936                 << "environment file " << envFilename << " (line "
937                 << line << ").\n";
938            envStream.close();
939            return false;
940          }
941          if (options[i].value != NULL)
942            delete options[i].value;
943          options[i].value = new char[t - s + 1];
944          strncpy(options[i].value, s, t - s);
945          options[i].value[t - s] = '\0';
946          s = t;
947          break;
948        }
949        case optFloat: {
950          strtod(s, &t);
951          if (t == s || (*t != ' ' && *t != '\t' &&
952                         *t != '\0' && *t != '}')) {
953            cerr << "Error: Mismatch in Real variable " << name << " in "
954                 << "environment file " << envFilename << " (line "
955                 << line << ").\n";
956            envStream.close();
957            return false;
958          }
959          if (options[i].value != NULL)
960            delete options[i].value;
961          options[i].value = new char[t - s + 1];
962          strncpy(options[i].value, s, t - s);
963          options[i].value[t - s] = '\0';
964          s = t;
965          break;
966        }
967        case optBool: {
968          t = s;
969          while ((*t >= 'a' && *t <= 'z') ||
970                 (*t >= 'A' && *t <= 'Z') ||
971                 *t == '+' || *t == '-')
972            t++;
973          if (((!strncasecmp(s, "true", t - s)  && t - s == 4) ||
974               (!strncasecmp(s, "false", t - s) && t - s == 5) ||
975               (!strncasecmp(s, "YES", t -s)    && t - s == 3) ||
976               (!strncasecmp(s, "NO", t - s)    && t - s == 2) ||
977               (!strncasecmp(s, "ON", t - s)    && t - s == 2) ||
978               (!strncasecmp(s, "OFF", t - s)   && t - s == 3) ||
979               (t - s == 1 && (*s == '+' || *s == '-'))) &&
980              (*t == ' ' || *t == '\t' || *t == '\0' || *t == '}')) {
981            if (options[i].value != NULL)
982              delete options[i].value;
983            options[i].value = new char[t - s + 1];
984            strncpy(options[i].value, s, t - s);
985            options[i].value[t - s] = '\0';
986            s = t;
987          }
988          else {
989            cerr << "Error: Mismatch in bool variable " << name << " in "
990                 << "environment file " << envFilename << " (line "
991                 << line << ").\n";
992            envStream.close();
993            return false;
994          }
995          break;
996        }
997        case optVector:{
998          strtod(s, &t);
999          if (*t == ' ' || *t == '\t') {
1000            while (*t == ' ' || *t == '\t')
1001              t++;
1002            if (*t != ',')
1003              t--;
1004          }
1005          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
1006            cerr << "Error: Mismatch in vector variable " << name << " in "
1007                 << "environment file " << envFilename << " (line "
1008                 << line << ").\n";
1009            envStream.close();
1010            return false;
1011          }
1012          char *u;
1013          strtod(t, &u);
1014          t = u;
1015          if (*t == ' ' || *t == '\t') {
1016            while (*t == ' ' || *t == '\t')
1017              t++;
1018            if (*t != ',')
1019              t--;
1020          }
1021          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
1022            cerr << "Error: Mismatch in vector variable " << name << " in "
1023                 << "environment file " << envFilename << " (line "
1024                 << line << ").\n";
1025            envStream.close();
1026            return false;
1027          }
1028          strtod(t, &u);
1029          t = u;
1030          if (t == s || (*t != ' ' && *t != '\t' &&
1031                         *t != '\0' && *t != '}')) {
1032            cerr << "Error: Mismatch in vector variable " << name << " in "
1033                 << "environment file " << envFilename << " (line "
1034                 << line << ").\n";
1035            envStream.close();
1036            return false;
1037          }
1038          if (options[i].value != NULL)
1039            delete options[i].value;
1040          options[i].value = new char[t - s + 1];
1041          strncpy(options[i].value, s, t - s);
1042          options[i].value[t - s] = '\0';
1043          s = t;
1044          break;
1045        }
1046        case optString: {
1047          if (options[i].value != NULL)
1048            delete options[i].value;
1049          options[i].value = new char[strlen(s) + 1];
1050          strcpy(options[i].value, s);
1051          s += strlen(s);
1052          break;
1053        }
1054        default: {
1055          Debug << "Internal error: Unknown type of option.\n" << flush;
1056          exit(1);
1057        }
1058      }
1059      // prepare the variable name for next pass
1060      t = strrchr(name, '.');
1061      if (t == NULL)
1062        name[0] = '\0';
1063      else
1064        *(t + 1) = '\0';
1065      // get next identifier
1066      s = ParseString(s, name);
1067    }
1068  }
1069  envStream.close();
1070  return true;
1071}
1072
1073void
1074Environment::PrintUsage(ostream &s) const
1075{
1076  // Print out all environment variable names
1077  s << "Registered options:\n";
1078  for (int j = 0; j < numOptions; j++)
1079    s << options[j] << "\n";
1080  s << flush;
1081}
1082
1083  /**
1084         Input scene filename. Currently simplified X3D (.x3d), Unigraphics (.dat),
1085         and UNC (.ply) formats are supported.
1086  */
1087
1088Environment::Environment()
1089{
1090  optionalParams = NULL;
1091  paramRows = 0;
1092  numParams = 0;
1093  params = NULL;
1094  maxOptions = 600;
1095
1096 
1097// this is maximal nuber of options.
1098  numOptions = 0;
1099
1100  options = new COption[maxOptions];
1101
1102  if (options == NULL ) {
1103    Debug << "Error: Memory allocation failed.\n";
1104    exit(1);
1105  }
1106 
1107  // register all basic options
1108
1109  RegisterOption("Limits.threshold", optFloat, NULL, "0.01");
1110  RegisterOption("Limits.small", optFloat, NULL, "1e-6");
1111  RegisterOption("Limits.infinity", optFloat, NULL, "1e6");
1112
1113  RegisterOption("Scene.filename",
1114                                 optString,
1115                                 "scene_filename=",
1116                                 "atlanta2.x3d");
1117
1118  RegisterOption("Unigraphics.meshGrouping",
1119                                 optInt,
1120                                 "unigraphics_mesh_grouping=",
1121                                 "0");
1122 
1123   RegisterOption("ObjParser.meshGrouping",
1124                                 optInt,
1125                                 "objparser_mesh_grouping=",
1126                                 "0");
1127
1128  RegisterOption("KdTree.Termination.minCost",
1129                                 optInt,
1130                                 "kd_term_min_cost=",
1131                                 "10");
1132 
1133  RegisterOption("KdTree.Termination.maxNodes",
1134                                 optInt,
1135                                 "kd_term_max_nodes=",
1136                                 "200000");
1137 
1138  RegisterOption("KdTree.Termination.maxDepth",
1139                                 optInt,
1140                                 "kd_term_max_depth=",
1141                                 "20");
1142
1143  RegisterOption("KdTree.Termination.maxCostRatio",
1144                                 optFloat,
1145                                 "kd_term_max_cost_ratio=",
1146                                 "1.5");
1147
1148  RegisterOption("KdTree.Termination.ct_div_ci",
1149                                 optFloat,
1150                                 "kd_term_ct_div_ci=",
1151                                 "1.0");
1152
1153  RegisterOption("KdTree.splitMethod",
1154                                 optString,
1155                                 "kd_split_method=",
1156                                 "spatialMedian");
1157 
1158  RegisterOption("KdTree.pvsArea",
1159                                 optFloat,
1160                                 "kd_pvs_area=",
1161                                 "1e-5");
1162
1163  RegisterOption("KdTree.splitBorder",
1164                 optFloat,
1165                 "kd_split_border=",
1166                 "0.1");
1167
1168  RegisterOption("KdTree.sahUseFaces",
1169                 optBool,
1170                 "kd_sah_use_faces=",
1171                 "true");
1172
1173  RegisterOption("MeshKdTree.Termination.minCost",
1174                 optInt,
1175                 "kd_term_min_cost=",
1176                 "10");
1177 
1178  RegisterOption("MeshKdTree.Termination.maxDepth",
1179                 optInt,
1180                 "kd_term_max_depth=",
1181                 "20");
1182
1183  RegisterOption("MeshKdTree.Termination.maxCostRatio",
1184                 optFloat,
1185                 "kd_term_max_cost_ratio=",
1186                 "1.5");
1187
1188  RegisterOption("MeshKdTree.Termination.ct_div_ci",
1189                 optFloat,
1190                 "kd_term_ct_div_ci=",
1191                 "1.0");
1192
1193  RegisterOption("MeshKdTree.splitMethod",
1194                 optString,
1195                 "kd_split_method=",
1196                 "spatialMedian");
1197
1198  RegisterOption("MeshKdTree.splitBorder",
1199                 optFloat,
1200                 "kd_split_border=",
1201                 "0.1");
1202
1203  RegisterOption("Preprocessor.totalSamples",
1204                                 optInt,
1205                                 "total_samples=",
1206                                 "10000000");
1207
1208  RegisterOption("Preprocessor.totalTime",
1209                                 optInt,
1210                                 "total_time=",
1211                                 "-1");
1212
1213  RegisterOption("Preprocessor.samplesPerPass",
1214                                 optInt,
1215                                 "samples_per_pass=",
1216                                 "100000");
1217 
1218  RegisterOption("Preprocessor.samplesPerEvaluation",
1219                                 optInt,
1220                                 "samples_per_evaluation=",
1221                                 "1000000");
1222
1223  RegisterOption("Preprocessor.useHwGlobalLines",
1224                                 optBool,
1225                                 "preprocessor_use_hw_global_lines=",
1226                                 "false");
1227
1228   RegisterOption("Preprocessor.HwGlobalLines.texHeight",
1229                                  optInt,
1230                                  "preprocessor_hw_global_lines_texheight=",
1231                                  "128");
1232
1233    RegisterOption("Preprocessor.HwGlobalLines.texWidth",
1234                                   optInt,
1235                                   "preprocessor_hw_global_lines_texwidth=",
1236                                   "128");
1237
1238        RegisterOption("Preprocessor.HwGlobalLines.stepSize",
1239                                   optFloat,
1240                                   "preprocessor_hw_global_lines_stepsize=",
1241                                   "0.0001");
1242
1243        RegisterOption("Preprocessor.HwGlobalLines.maxDepth",
1244                                   optInt,
1245                                   "preprocessor_hw_global_lines_max_depth=",
1246                                   "50");
1247
1248        RegisterOption("Preprocessor.HwGlobalLines.sampleReverse",
1249                                   optBool,
1250                                   "preprocessor_hw_global_lines_sample_reverse=",
1251                                   "true");
1252
1253  RegisterOption("RenderSampler.samples",
1254                                 optInt,
1255                                 "render_sampler_samples=",
1256                                 "1000");
1257
1258  RegisterOption("RenderSampler.visibleThreshold",
1259                                 optInt,
1260                                 "render_sampler_visible_threshold=",
1261                                 "0");
1262
1263   RegisterOption("RenderSampler.useOcclusionQueries",
1264                                 optBool,
1265                                 "render_sampler_use_occlusion_queries=",
1266                                 "true");
1267 
1268  RegisterOption("VssPreprocessor.testBeamSampling",
1269                                optBool,
1270                                "vss_beam_sampling=",
1271                                "false");
1272
1273  RegisterOption("VssPreprocessor.useImportanceSampling",
1274                                 optBool,
1275                                 "vss_use_importance=",
1276                                 "true");
1277
1278 
1279   RegisterOption("VssPreprocessor.enlargeViewSpace",
1280                                 optBool,
1281                                 "vss_enlarge_viewspace=",
1282                                 "false");
1283
1284   RegisterOption("VssPreprocessor.loadInitialSamples",
1285          optBool,
1286          "vss_load_loadInitialSamples=",
1287          "false");
1288
1289   RegisterOption("VssPreprocessor.storeInitialSamples",
1290          optBool,
1291          "vss_store_storedInitialSamples=",
1292          "false");
1293 
1294
1295
1296   /*************************************************************************/
1297   /*    Mutation strategy related options                                  */
1298   /*************************************************************************/
1299   
1300   RegisterOption("Mutation.bufferSize",
1301                                  optInt,
1302                                  "mutation_buffer_size=",
1303                                  "500000");
1304
1305   RegisterOption("Mutation.radiusOrigin",
1306                                  optFloat,
1307                                  "mutation_radius_origin=",
1308                                  "0.5");
1309
1310   RegisterOption("Mutation.radiusTermination",
1311                                  optFloat,
1312                                  "mutation_radius_termination=",
1313                                  "0.5");
1314
1315   RegisterOption("Mutation.useReverseSamples",
1316                                  optBool,
1317                                  "mutation_use_reverse_samples",
1318                                  "true");
1319
1320   RegisterOption("Mutation.reverseSamplesDistance",
1321                                  optFloat,
1322                                  "mutation_reverse_samples_distance=",
1323                                  "3.0");
1324
1325   RegisterOption("Mutation.useSilhouetteSamples",
1326                                  optBool,
1327                                  "mutation_use_silhouette_samples",
1328                                  "true");
1329
1330   RegisterOption("Mutation.silhouetteSearchSteps",
1331                                  optInt,
1332                                  "mutation_silhouette_search_steps=",
1333                                  "3");
1334
1335   RegisterOption("Mutation.silhouetteProb",
1336                                  optFloat,
1337                                  "mutation_silhouette_prob=",
1338                                  "0.8");
1339
1340   RegisterOption("Mutation.usePassImportance",
1341                                  optBool,
1342                                  "mutation_use_pass_importance",
1343                                  "true");
1344
1345   RegisterOption("Mutation.useUnsuccCountImportance",
1346                                  optBool,
1347                                  "mutation_use_unsucc_count_importance",
1348                                  "false");
1349   
1350   
1351   /*************************************************************************/
1352   /*                       GvsPrerpocessor related options                 */
1353   /*************************************************************************/
1354
1355
1356   RegisterOption("GvsPreprocessor.totalSamples",
1357                 optInt,
1358                 "gvs_total_samples=",
1359                 "1000000");
1360   
1361   RegisterOption("GvsPreprocessor.gvsSamplesPerPass",
1362                 optInt,
1363                 "gvs_samples_per_pass=",
1364                 "100000");
1365   
1366   RegisterOption("GvsPreprocessor.initialSamples",
1367                 optInt,
1368                 "gvs_initial_samples=",
1369                 "256");
1370
1371   RegisterOption("GvsPreprocessor.epsilon",
1372                 optFloat,
1373                 "gvs_epsilon=",
1374                 "0.00001");
1375
1376    RegisterOption("GvsPreprocessor.threshold",
1377                 optFloat,
1378                 "gvs_threshold=",
1379                 "1.5");
1380
1381        RegisterOption("GvsPreprocessor.perViewCell",
1382                optBool,
1383                "gvs_per_viewcell=",
1384                "true");
1385
1386        RegisterOption("GvsPreprocessor.stats",
1387                optString,
1388                "gvs_stats=",
1389                "gvsStats.log");
1390
1391        RegisterOption("GvsPreprocessor.minContribution",
1392                 optInt,
1393                 "gvs_min_contribution=",
1394                 "50");
1395
1396         RegisterOption("GvsPreprocessor.maxViewCells",
1397                 optInt,
1398                 "gvs_max_viewcells=",
1399                 "5");
1400
1401
1402  /**********************************************************************/
1403  /*                     View cells related options                     */
1404  /**********************************************************************/
1405
1406
1407        RegisterOption("ViewCells.type",
1408                                        optString,
1409                                        "view_cells_type=",
1410                                        "vspBspTree");
1411
1412        RegisterOption("ViewCells.samplingType",
1413                                        optString,
1414                                        "view_cells_sampling_type=",
1415                                        "box");
1416
1417        RegisterOption("ViewCells.mergeStats",
1418                                        optString,
1419                                        "view_cells_merge_stats=",
1420                                        "mergeStats.log");
1421
1422        RegisterOption("ViewCells.Evaluation.statsPrefix",
1423                                        optString,
1424                                        "view_cells_evaluation_stats_prefix=",
1425                                        "viewCells");
1426
1427        RegisterOption("ViewCells.Evaluation.histogram",
1428                                        optBool,
1429                                        "view_cells_evaluation_histogram=",
1430                                        "false");
1431
1432        RegisterOption("ViewCells.Evaluation.histoStepSize",
1433                                        optInt,
1434                                        "view_cells_evaluation_histo_step_size=",
1435                                        "5000");
1436
1437        RegisterOption("ViewCells.Evaluation.histoMem",
1438                                        optInt,
1439                                        "view_cells_evaluation_histo_mem=",
1440                                        "50");
1441
1442        RegisterOption("ViewCells.active",
1443                                        optInt,
1444                                        "view_cells_active=",
1445                                        "1000");
1446
1447        RegisterOption("ViewCells.Construction.samples",
1448                                        optInt,
1449                                        "view_cells_construction_samples=",
1450                                        "0");
1451
1452        RegisterOption("ViewCells.Construction.samplesPerPass",
1453                                        optInt,
1454                                        "view_cells_construction_samples_per_pass=",
1455                                        "500000");
1456
1457        RegisterOption("ViewCells.PostProcess.samples",
1458                                        optInt,
1459                                        "view_cells_post_process_samples=",
1460                                        "0");
1461
1462        RegisterOption("ViewCells.Visualization.samples",
1463                                        optInt,
1464                                        "view_cells_visualization_samples=",
1465                                        "0");
1466
1467        RegisterOption("ViewCells.Visualization.maxOutput",
1468                                        optInt,
1469                                        "view_cells_visualization_max_output=",
1470                                        "20");
1471
1472        RegisterOption("ViewCells.Filter.maxSize",
1473                                        optInt,
1474                                        "view_cells_filter_max_size=",
1475                                        "4");
1476
1477        RegisterOption("ViewCells.Filter.width",
1478                                        optFloat,
1479                                        "view_cells_filter_width=",
1480                                        "1.0");
1481
1482        RegisterOption("ViewCells.loadFromFile",
1483                                        optBool,
1484                                        "view_cells_load_from_file=",
1485                                        "false");
1486
1487        RegisterOption("ViewCells.PostProcess.refine",
1488                                        optBool,
1489                                        "view_cells_refine=",
1490                                        "false");
1491
1492        RegisterOption("ViewCells.PostProcess.compress",
1493                                        optBool,
1494                                        "view_cells_post_process_compress=",
1495                                        "false");
1496
1497        RegisterOption("ViewCells.Evaluation.samples",
1498                                        optInt,
1499                                        "view_cells_evaluation_samples=",
1500                                        "8000000");
1501
1502        RegisterOption("ViewCells.Evaluation.samplingType",
1503                                        optString,
1504                                        "view_cells_evaluation_sampling_type=",
1505                                        "box");
1506
1507        RegisterOption("ViewCells.Evaluation.samplesPerPass",
1508                                        optInt,
1509                                        "view_cells_evaluation_samples_per_pass=",
1510                                        "300000");
1511
1512        RegisterOption("ViewCells.Evaluation.samplesForStats",
1513                                        optInt,
1514                                        "view_cells_evaluation_samples_for_stats=",
1515                                        "300000");
1516
1517        RegisterOption("ViewCells.exportToFile",
1518                                        optBool,
1519                                        "view_cells_export_to_file=",
1520                                        "false");
1521
1522        RegisterOption("ViewCells.exportPvs",
1523                                        optBool,
1524                                        "view_cells_export_pvs=",
1525                                        "false");
1526
1527        RegisterOption("ViewCells.exportBboxesForPvs",
1528                                        optBool,
1529                                        "view_cells_export_bounding_boxes=",
1530                                        "true");
1531       
1532        RegisterOption("ViewCells.boxesFilename",
1533                                        optString,
1534                                        "view_cells_boxes_filename=",
1535                                        "boxes.out");
1536
1537        RegisterOption("ViewCells.evaluateViewCells",
1538                                        optBool,
1539                                        "view_cells_evaluate=",
1540                                        "false");
1541
1542        RegisterOption("ViewCells.maxViewCells",
1543                                        optInt,
1544                                        "view_cells_max_view_cells=",
1545                                        "0");
1546
1547        RegisterOption("ViewCells.Evaluation.stepSize",
1548                                        optInt,
1549                                        "view_cells_evaluation_step_size=",
1550                                        "100");
1551
1552        RegisterOption("ViewCells.maxPvsRatio",
1553                                        optFloat,
1554                                        "view_cells_max_pvs_ratio=",
1555                                        "0.1");
1556
1557        RegisterOption("ViewCells.triangleWeight",
1558                                        optFloat,
1559                                        "view_cells_triangle_weight=",
1560                                        "1.0");
1561
1562        RegisterOption("ViewCells.objectWeight",
1563                                        optFloat,
1564                                        "view_cells_object_weight=",
1565                                        "0.0");
1566
1567        RegisterOption("ViewCells.filename",
1568                                        optString,
1569                                        "view_cells_filename=",
1570                                        "atlanta_viewcells_large.x3d");
1571
1572        RegisterOption("ViewCells.height",
1573                                        optFloat,
1574                                        "view_cells_height=",
1575                                        "5.0");
1576
1577        RegisterOption("ViewCells.Visualization.colorCode",
1578                                        optString,
1579                                        "view_cells_visualization_color_code=",
1580                                        "PVS");
1581
1582        RegisterOption("ViewCells.Visualization.clipPlanePos",
1583                                        optFloat,
1584                                        "view_cells_visualization_clip_plane_pos=",
1585                                        "0.35");
1586       
1587        RegisterOption("ViewCells.Visualization.exportGeometry",
1588                                        optBool,
1589                                        "view_cells_visualization_export_geometry=",
1590                                        "false");
1591
1592        RegisterOption("ViewCells.Visualization.exportRays",
1593                                        optBool,
1594                                        "view_cells_visualization_export_rays=",
1595                                        "false");
1596
1597        RegisterOption("ViewCells.processOnlyValidViewCells",
1598                                        optBool,
1599                                        "view_cells_process_only_valid_view_cells",
1600                                        "false");
1601
1602        RegisterOption("ViewCells.PostProcess.maxCostRatio",
1603                        optFloat,
1604                        "view_cells_post_process_max_cost_ratio=",
1605                        "0.9");
1606       
1607        RegisterOption("ViewCells.PostProcess.renderCostWeight",
1608                        optFloat,
1609                        "view_cells_post_process_render_cost_weight",
1610                        "0.5");
1611       
1612        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation",
1613                        optFloat,
1614                        "view_cells_avgcost_max_deviations",
1615                        "0.5");
1616
1617        RegisterOption("ViewCells.PostProcess.maxMergesPerPass",
1618                optInt,
1619                "view_cells_post_process_max_merges_per_pass=",
1620                "500");
1621
1622        RegisterOption("ViewCells.PostProcess.minViewCells",
1623                optInt,
1624                "view_cells_post_process_min_view_cells=",
1625                "1000");
1626
1627        RegisterOption("ViewCells.PostProcess.useRaysForMerge",
1628                optBool,
1629                "view_cells_post_process_use_rays_for_merge=",
1630                "false");
1631       
1632        RegisterOption("ViewCells.PostProcess.merge",
1633                optBool,
1634                "view_cells_post_process_merge=",
1635                "true");
1636
1637        RegisterOption("ViewCells.Visualization.exportMergedViewCells",
1638                optBool,
1639                "view_cells_viz_export_merged_viewcells=",
1640                "false");
1641
1642        RegisterOption("ViewCells.maxStaticMemory",
1643                optFloat,
1644                "view_cells_max_static_mem=",
1645                "8.0");
1646
1647        RegisterOption("ViewCells.Visualization.useClipPlane",
1648                optBool,
1649                "view_cells_viz_use_clip_plane=",
1650                "false");
1651       
1652        RegisterOption("ViewCells.showVisualization",
1653                optBool,
1654                "view_cells_show_visualization=",
1655                "false");
1656
1657        RegisterOption("ViewCells.Visualization.clipPlaneAxis",
1658                optInt,
1659                "view_cells_viz_clip_plane_axis=",
1660                "0");
1661
1662        RegisterOption("ViewCells.loadGeometry",
1663                optBool,
1664                "view_cells_load_geometry=",
1665                "false");
1666       
1667        RegisterOption("ViewCells.geometryFilename",
1668                optString,
1669                "view_cells_geometry_filename=",
1670                "viewCellsGeometry.x3d");
1671
1672        RegisterOption("ViewCells.useBaseTrianglesAsGeometry",
1673                optBool,
1674                "view_cells_use_base_triangles_as_geometry=",
1675                "false");
1676
1677        RegisterOption("ViewCells.compressObjects",
1678                optBool,
1679                "view_cells_compress_objects=",
1680                "false");
1681       
1682        RegisterOption("ViewCells.useKdPvs",
1683                optBool,
1684                "view_cells_use_kd_pvs",
1685                "false");
1686
1687        RegisterOption("ViewCells.useKdPvsAfterFiltering",
1688                                   optBool,
1689                                   "af_use_kd_pvs",
1690                                   "false");
1691
1692        RegisterOption("ViewCells.importRandomViewCells",
1693                                   optBool,
1694                                   "view_cells_import_random_viewcells",
1695                                   "false");
1696       
1697        RegisterOption("ViewCells.randomViewPointsList",
1698                optString,
1699                "view_cells_random_viewpoint_list=",
1700                "");
1701
1702
1703        RegisterOption("ViewCells.exportRandomViewCells",
1704                                   optBool,
1705                                   "view_cells_export_random_viewcells",
1706                                   "false");
1707
1708       
1709
1710
1711        /****************************************************************************/
1712        /*                     Render simulation related options                    */
1713        /****************************************************************************/
1714
1715
1716        RegisterOption("Simulation.objRenderCost",
1717                        optFloat,
1718                        "simulation_obj_render_cost",
1719                        "1.0");
1720
1721        RegisterOption("Simulation.vcOverhead",
1722                        optFloat,
1723                        "simulation_vc_overhead",
1724                        "0.05");
1725
1726        RegisterOption("Simulation.moveSpeed",
1727                        optFloat,
1728                        "simulation_moveSpeed",
1729                        "1.0");
1730
1731
1732
1733        /******************************************************************/
1734        /*                    Bsp tree related options                    */
1735        /******************************************************************/
1736
1737
1738        RegisterOption("BspTree.Construction.input",
1739                optString,
1740                "bsp_construction_input=",
1741                "fromViewCells");
1742       
1743        RegisterOption("BspTree.subdivisionStats",
1744                                        optString,
1745                                        "bsp_subdivision_stats=",
1746                                        "bspSubdivisionStats.log");
1747
1748        RegisterOption("BspTree.Construction.samples",
1749                optInt,
1750                "bsp_construction_samples=",
1751                "100000");
1752
1753        RegisterOption("BspTree.Construction.epsilon",
1754                optFloat,
1755                "bsp_construction_epsilon=",
1756                "0.002");
1757
1758        RegisterOption("BspTree.Termination.minPolygons",
1759                        optInt,
1760                        "bsp_term_min_polygons=",
1761                        "5");
1762
1763        RegisterOption("BspTree.Termination.minPvs",
1764                        optInt,
1765                        "bsp_term_min_pvs=",
1766                        "20");
1767
1768        RegisterOption("BspTree.Termination.minProbability",
1769                        optFloat,
1770                        "bsp_term_min_probability=",
1771                        "0.001");
1772
1773        RegisterOption("BspTree.Termination.maxRayContribution",
1774                        optFloat,
1775                        "bsp_term_ray_contribution=",
1776                        "0.005");
1777
1778        RegisterOption("BspTree.Termination.minAccRayLenght",
1779                        optFloat,
1780                        "bsp_term_min_acc_ray_length=",
1781                        "50");
1782
1783        RegisterOption("BspTree.Termination.minRays",
1784                        optInt,
1785                        "bsp_term_min_rays=",
1786                        "-1");
1787
1788        RegisterOption("BspTree.Termination.ct_div_ci",
1789                        optFloat,
1790                        "bsp_term_ct_div_ci=",
1791                        "0.0");
1792
1793        RegisterOption("BspTree.Termination.maxDepth",
1794                        optInt,
1795                        "bsp_term_max_depth=",
1796                        "100");
1797
1798        RegisterOption("BspTree.Termination.maxCostRatio",
1799                        optFloat,
1800                        "bsp_term_axis_aligned_max_cost_ratio=",
1801                        "1.5");
1802
1803        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1804                        optFloat,
1805                        "bsp_term_axis_aligned_ct_div_ci=",
1806                        "0.5");
1807
1808        RegisterOption("BspTree.AxisAligned.splitBorder",
1809                        optFloat,
1810                        "bsp__axis_aligned_split_border=",
1811                        "0.1");
1812
1813        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1814                        optInt,
1815                        "bsp_term_axis_aligned_max_polygons=",
1816                        "50");
1817
1818        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1819                        optInt,
1820                        "bsp_term_min_objects=",
1821                        "3");
1822
1823        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1824                        optInt,
1825                        "bsp_term_axis_aligned_min_rays=",
1826                        "-1");
1827
1828        RegisterOption("BspTree.splitPlaneStrategy",
1829                        optString,
1830                        "bsp_split_method=",
1831                        "leastSplits");
1832
1833        RegisterOption("BspTree.maxPolyCandidates",
1834                optInt,
1835                "bsp_max_poly_candidates=",
1836                "20");
1837
1838        RegisterOption("BspTree.maxRayCandidates",
1839                optInt,
1840                "bsp_max_plane_candidates=",
1841                "20");
1842
1843        RegisterOption("BspTree.maxTests",
1844                optInt,
1845                "bsp_max_tests=",
1846                "5000");
1847
1848        RegisterOption("BspTree.Termination.maxViewCells",
1849                optInt,
1850                "bsp_max_view_cells=",
1851                "5000");
1852
1853        RegisterOption("BspTree.Visualization.exportSplits",
1854                optBool,
1855                "bsp_visualization.export_splits=",
1856                "false");
1857
1858        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1859        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1860        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1861        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1862        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1863        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1864        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1865        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1866        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1867
1868
1869
1870
1871        /**********************************************************************/
1872        /*                     Preprocessor related options                   */
1873        /**********************************************************************/
1874
1875        RegisterOption("Preprocessor.type",
1876                                        optString,
1877                                        "preprocessor=",
1878                                        "sampling");
1879
1880        RegisterOption("Preprocessor.stats",
1881                                        optString,
1882                                        "preprocessor_stats=",
1883                                        "stats.log");
1884
1885        RegisterOption("Preprocessor.samplesFilename",
1886                                        optString,
1887                                        "preprocessor_samples_filename=",
1888                                        "rays.out");
1889
1890        RegisterOption("Preprocessor.loadMeshes",
1891                                        optBool,
1892                                        "preprocessor_load_meshes",
1893                                        "true");
1894
1895        RegisterOption("Preprocessor.evaluateFilter",
1896                                   optBool,
1897                                   "preprocessor_evaluate_filter",
1898                                   "false");
1899
1900        RegisterOption("Preprocessor.delayVisibilityComputation",
1901                                   optBool,
1902                                   "preprocessor_delay_computation",
1903                                   "true");
1904
1905        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1906                                   optInt,
1907                                   "preprocessor_pvs_rendererror_samples=",
1908                                   "10000");
1909       
1910        RegisterOption("Preprocessor.useGlRenderer",
1911                                        optBool,
1912                                        "preprocessor_use_gl_renderer",
1913                                        "false");
1914
1915        RegisterOption("Preprocessor.useGlDebugger",
1916                                        optBool,
1917                                        "preprocessor_use_gl_debugger",
1918                                        "false");
1919
1920        RegisterOption("Preprocessor.detectEmptyViewSpace",
1921                                   optBool,
1922                                   "preprocessor_detect_empty_viewspace",
1923                                   "false");
1924       
1925        RegisterOption("Preprocessor.quitOnFinish",
1926                                   optBool,
1927                                   "preprocessor_quit_on_finish",
1928                                   "true");
1929
1930        RegisterOption("Preprocessor.computeVisibility",
1931                                   optBool,
1932                                   "preprocessor_compute_visibility",
1933                                   "true");
1934
1935        RegisterOption("Preprocessor.exportVisibility",
1936                                   optBool,
1937                                   "preprocessor_export_visibility",
1938                                   "true");
1939
1940        RegisterOption("Preprocessor.visibilityFile",
1941                                   optString,
1942                                   "preprocessor_visibility_file=",
1943                                   "visibility.xml");
1944
1945        RegisterOption("Preprocessor.applyVisibilityFilter",
1946                                   optBool,
1947                                   "preprocessor_apply_filter",
1948                                   "false");
1949       
1950        RegisterOption("Preprocessor.evaluatePixelError",
1951                                   optBool,
1952                                   "preprocessor_evaluatePixelError",
1953                                   "false");
1954
1955        RegisterOption("Preprocessor.applyVisibilitySpatialFilter",
1956                                   optBool,
1957                                   "preprocessor_apply_spatial_filter",
1958                                   "false");
1959
1960        RegisterOption("Preprocessor.visibilityFilterWidth",
1961                                   optFloat,
1962                                   "preprocessor_visibility_filter_width=",
1963                                   "0.02");
1964
1965        RegisterOption("Preprocessor.histogram.maxValue",
1966                                        optInt,
1967                                        "preprocessor_histogram_max_value=",
1968                                        "1000");
1969
1970        RegisterOption("Preprocessor.rayCastMethod",
1971                                        optInt,
1972                                        "preprocessor_ray_cast_method=",
1973                                        "0");
1974
1975        RegisterOption("Preprocessor.histogram.intervals",
1976                                        optInt,
1977                                        "preprocessor_histogram_intervals=",
1978                                        "20");
1979
1980        RegisterOption("Preprocessor.histogram.file",
1981                                   optString,
1982                                   "preprocessor_histogram_file=",
1983                                   "histogram.log");
1984
1985        RegisterOption("Preprocessor.exportKdTree",
1986                                        optBool,
1987                                        "preprocessor_export_kd_tree=",
1988                                        "false");
1989
1990        RegisterOption("Preprocessor.loadKdTree",
1991                                        optBool,
1992                                        "preprocessor_load_kd_tree=",
1993                                        "false");
1994
1995        RegisterOption("Preprocessor.kdTreeFilename",
1996                                        optString,
1997                                        "preprocessor_kd_tree_filename=",
1998                                        "vienna_kdtree.bin.gz");
1999
2000        RegisterOption("Preprocessor.exportObj",
2001                                        optBool,
2002                                        "preprocessor_export_obj=",
2003                                        "false");
2004
2005   RegisterOption("Preprocessor.useViewSpaceBox",
2006                                        optBool,
2007                                        "preprocessor_use_viewspace_box=",
2008                                        "false");   
2009
2010   RegisterOption("Preprocessor.Export.rays", optBool, "export_rays", "false");
2011   RegisterOption("Preprocessor.Export.animation", optBool, "export_animation", "false");
2012   RegisterOption("Preprocessor.Export.numRays", optInt, "export_num_rays=", "5000");
2013   
2014        /*************************************************************************/
2015        /*             VSS Preprocessor cells related options                    */
2016        /*************************************************************************/
2017
2018        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
2019        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
2020        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
2021        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
2022        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
2023
2024        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
2025        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
2026        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
2027        RegisterOption("VssTree.splitType", optString, "split=", "queries");
2028        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
2029        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
2030        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
2031
2032        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
2033
2034        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
2035        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
2036
2037        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
2038
2039       
2040       
2041        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
2042        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false");
2043        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
2044        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
2045        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
2046        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
2047
2048        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
2049        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
2050
2051
2052//      RegisterOption("RssPreprocessor.initialSamples",
2053//                                                                      optInt,
2054//                                                                      "rss_initial_samples=",
2055//                                                                      "100000");
2056
2057//      RegisterOption("RssPreprocessor.vssSamples",
2058//                                      optInt,
2059//                                      "rss_vss_samples=",
2060//                                      "1000000");
2061
2062//      RegisterOption("RssPreprocessor.vssSamplesPerPass",
2063//                                      optInt,
2064//                                      "rss_vss_samples_per_pass=",
2065//                                      "1000");
2066
2067//      RegisterOption("RssPreprocessor.samplesPerPass",
2068//                                      optInt,
2069//                                      "rss_samples_per_pass=",
2070//                                      "100000");
2071
2072        RegisterOption("RssPreprocessor.useImportanceSampling",
2073                                        optBool,
2074                                        "rss_use_importance",
2075                                        "true");
2076
2077        RegisterOption("RssPreprocessor.useRssTree",
2078                                        optBool,
2079                                        "rss_use_rss_tree",
2080                                        "true");
2081
2082        RegisterOption("RssPreprocessor.objectBasedSampling",
2083                                        optBool,
2084                                        "rss_object_based_sampling",
2085                                        "true");
2086
2087        RegisterOption("RssPreprocessor.directionalSampling",
2088                                        optBool,
2089                                        "rss_directional_sampling",
2090                                        "false");
2091
2092        RegisterOption("RssPreprocessor.distributions",
2093                                   optString,
2094                                   "rss_distributions=",
2095                                   "rss+spatial+object");
2096       
2097        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10");
2098        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
2099        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
2100        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
2101        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
2102        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
2103
2104        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
2105        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
2106        RegisterOption("RssTree.randomize", optBool, "randomize=", "false");
2107        RegisterOption("RssTree.splitType", optString, "rss_split=", "queries");
2108        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
2109
2110        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
2111
2112        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
2113
2114        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
2115        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
2116
2117        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
2118
2119        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
2120        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
2121        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
2122        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
2123        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
2124        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
2125
2126        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true");
2127        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
2128        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true");
2129        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
2130
2131        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
2132
2133        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
2134        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
2135
2136        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
2137        RegisterOption("RssPreprocessor.updateSubdivision",
2138                                   optBool,
2139                                   "rss_update_subdivision=",
2140                                   "false");
2141
2142
2143/************************************************************************************/
2144/*                      Rss preprocessor related options                            */
2145/************************************************************************************/
2146
2147
2148        RegisterOption("RssPreprocessor.loadInitialSamples",
2149                                        optBool,
2150                                        "vss_load_loadInitialSamples=",
2151                                        "false");
2152
2153        RegisterOption("RssPreprocessor.storeInitialSamples",
2154                                        optBool,
2155                                        "vss_store_storeInitialSamples=",
2156                                        "false");
2157
2158
2159/************************************************************************************/
2160/*                 View space partition BSP tree related options                    */
2161/************************************************************************************/
2162
2163        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
2164                                        optFloat,
2165                                        "vsp_bsp_term_min_global_cost_ratio=",
2166                                        "0.0001");
2167
2168        RegisterOption("VspBspTree.useSplitCostQueue",
2169                                        optBool,
2170                                        "vsp_bsp_use_split_cost_queue=",
2171                                        "true");
2172
2173        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
2174                                        optInt,
2175                                        "vsp_bsp_term_global_cost_miss_tolerance=",
2176                                        "4");
2177
2178        RegisterOption("VspBspTree.Termination.minPolygons",
2179                                        optInt,
2180                                        "vsp_bsp_term_min_polygons=",
2181                                        "-1");
2182
2183        RegisterOption("VspBspTree.Termination.minPvs",
2184                                        optInt,
2185                                        "vsp_bsp_term_min_pvs=",
2186                                        "20");
2187
2188        RegisterOption("VspBspTree.Termination.minProbability",
2189                                        optFloat,
2190                                        "vsp_bsp_term_min_probability=",
2191                                        "0.001");
2192
2193        RegisterOption("VspBspTree.subdivisionStats",
2194                                        optString,
2195                                        "vsp_bsp_subdivision_stats=",
2196                                        "vspBspSubdivisionStats.log");
2197
2198        RegisterOption("VspBspTree.Termination.maxRayContribution",
2199                                        optFloat,
2200                                        "vsp_bsp_term_ray_contribution=",
2201                                        "2");
2202
2203        RegisterOption("VspBspTree.Termination.minAccRayLenght",
2204                                        optFloat,
2205                                        "vsp_bsp_term_min_acc_ray_length=",
2206                                        "50");
2207
2208        RegisterOption("VspBspTree.Termination.minRays",
2209                                        optInt,
2210                                        "vsp_bsp_term_min_rays=",
2211                                        "-1");
2212
2213        RegisterOption("VspBspTree.Termination.ct_div_ci",
2214                                        optFloat,
2215                                        "vsp_bsp_term_ct_div_ci=",
2216                                        "0.0");
2217
2218        RegisterOption("VspBspTree.Termination.maxDepth",
2219                                        optInt,
2220                                        "vsp_bsp_term_max_depth=",
2221                                        "50");
2222
2223        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
2224                                        optFloat,
2225                                        "vsp_bsp_term_axis_aligned_max_cost_ratio=",
2226                                        "1.5");
2227
2228        RegisterOption("VspBspTree.useCostHeuristics",
2229                                        optBool,
2230                                        "vsp_bsp_use_cost_heuristics=",
2231                                        "false");
2232
2233        RegisterOption("VspBspTree.Termination.maxViewCells",
2234                                        optInt,
2235                                        "vsp_bsp_term_max_view_cells=",
2236                                        "10000");
2237
2238        RegisterOption("VspBspTree.Termination.maxCostRatio",
2239                                        optFloat,
2240                                        "vsp_bsp_term_max_cost_ratio=",
2241                                        "1.5");
2242
2243        RegisterOption("VspBspTree.Termination.missTolerance",
2244                                        optInt,
2245                                        "vsp_bsp_term_miss_tolerance=",
2246                                        "4");
2247
2248        RegisterOption("VspBspTree.splitPlaneStrategy",
2249                                        optInt,
2250                                        "vsp_bsp_split_method=",
2251                                        "1026");
2252
2253        RegisterOption("VspBspTree.maxPolyCandidates",
2254                                        optInt,
2255                                        "vsp_bsp_max_poly_candidates=",
2256                                        "20");
2257
2258        RegisterOption("VspBspTree.maxRayCandidates",
2259                                        optInt,
2260                                        "vsp_bsp_max_plane_candidates=",
2261                                        "20");
2262
2263        RegisterOption("VspBspTree.maxTests",
2264                                        optInt,
2265                                        "vsp_bsp_max_tests=",
2266                                        "5000");
2267
2268        RegisterOption("VspBspTree.Construction.samples",
2269                                        optInt,
2270                                        "vsp_bsp_construction_samples=",
2271                                        "100000");
2272
2273        RegisterOption("VspBspTree.Construction.minBand",
2274                                        optFloat,
2275                                        "vsp_bsp_construction_min_band=",
2276                                        "0.01");
2277
2278        RegisterOption("VspBspTree.Construction.maxBand",
2279                                        optFloat,
2280                                        "vsp_bsp_construction_max_band=",
2281                                        "0.99");
2282
2283        RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost",
2284                                        optBool,
2285                                        "vsp_bsp_construction_use_drivingaxis_for_maxcost=",
2286                                        "false");
2287
2288        RegisterOption("VspBspTree.Construction.epsilon",
2289                                        optFloat,
2290                                        "vsp_bsp_construction_epsilon=",
2291                                        "0.002");
2292
2293        RegisterOption("VspBspTree.Visualization.exportSplits",
2294                                        optBool,
2295                                        "vsp_bsp_visualization.export_splits",
2296                                        "false");
2297
2298        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
2299                                        optBool,
2300                                        "vsp_bsp_split_only_driving_axis=",
2301                                        "false");
2302
2303        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
2304                                        optBool,
2305                    "vsp_bsp_usePolygonSplitIfAvailable=",
2306                                        "false");
2307
2308        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
2309                        optInt,
2310                        "bsp_term_axis_aligned_min_rays=",
2311                        "0");
2312       
2313        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
2314                        optFloat,
2315                        "bsp_term_axis_aligned_min_rays=",
2316                        "2");
2317
2318        RegisterOption("VspBspTree.Factor.leastRaySplits",
2319                                        optFloat,
2320                                        "vsp_bsp_factor_least_ray_splits=",
2321                                        "1.0");
2322
2323        RegisterOption("VspBspTree.Factor.balancedRays",
2324                                        optFloat,
2325                                        "vsp_bsp_factor_balanced_rays=",
2326                                        "1.0");
2327
2328        RegisterOption("VspBspTree.Factor.pvs",
2329                                        optFloat,
2330                                        "vsp_bsp_factor_pvs=",
2331                                        "1.0");
2332       
2333        RegisterOption("VspBspTree.Construction.renderCostWeight",
2334                        optFloat,
2335                        "vsp_bsp_post_process_render_cost_weight=",
2336                        "1.0");
2337
2338        RegisterOption("VspBspTree.Construction.renderCostDecreaseWeight",
2339                        optFloat,
2340                        "vsp_bsp_construction_render_cost_decrease_weight=",
2341                        "0.99");
2342
2343        RegisterOption("VspBspTree.Construction.randomize",
2344                optBool,
2345                "vsp_bsp_construction_randomize=",
2346                "false");
2347
2348        RegisterOption("VspBspTree.simulateOctree",
2349                optBool,
2350                "vsp_bsp_simulate_octree=",
2351                "false");
2352
2353        RegisterOption("VspBspTree.nodePriorityQueueType",
2354                optInt,
2355                "vsp_bsp_node_queue_type=",
2356                "0");
2357
2358        RegisterOption("VspBspTree.useRandomAxis",
2359                optBool,
2360                "-vsp_bsp_use_random_axis=",
2361                "false");
2362
2363        RegisterOption("VspBspTree.maxTotalMemory",
2364                optFloat,
2365                "vsp_bsp_max_total_mem=",
2366                "60.0");
2367
2368        RegisterOption("VspBspTree.maxStaticMemory",
2369                optFloat,
2370                "vsp_bsp_max_static_mem=",
2371                "8.0");
2372
2373
2374
2375/***************************************************************************/
2376/*                 View space partition tree related options               */
2377/***************************************************************************/
2378
2379       
2380        RegisterOption("VspTree.Construction.samples",
2381                                        optInt,
2382                                        "vsp_construction_samples=",
2383                                        "10000");
2384
2385        RegisterOption("VspTree.Construction.renderCostDecreaseWeight",
2386                                optFloat,
2387                                "vsp_construction_render_cost_decrease_weight=",
2388                                "0.99");
2389
2390        RegisterOption("VspTree.Termination.maxDepth",
2391                                        optInt,
2392                                        "vsp_term_max_depth=",
2393                                        "100");
2394
2395        RegisterOption("VspTree.Termination.minRays",
2396                                        optInt,
2397                                        "vsp_term_min_rays=",
2398                                        "-1");
2399
2400
2401        RegisterOption("VspTree.Termination.minPvs",
2402                                        optInt,
2403                                        "vsp_term_min_pvs=",
2404                                        "20");
2405
2406        RegisterOption("VspTree.Termination.minProbability",
2407                                        optFloat,
2408                                        "vsp_term_min_probability=",
2409                                        "0.0000001");
2410
2411        RegisterOption("VspTree.Termination.maxRayContribution",
2412                                optFloat,
2413                                "vsp_term_ray_contribution=",
2414                                "0.9");
2415       
2416        RegisterOption("VspTree.Termination.maxCostRatio",
2417                                optFloat,
2418                                "vsp_term_max_cost_ratio=",
2419                                "1.5");
2420       
2421        RegisterOption("VspTree.Termination.maxViewCells",
2422                                optInt,
2423                                "vsp_term_max_view_cells=",
2424                                "10000");
2425       
2426        RegisterOption("VspTree.Termination.missTolerance",
2427                                optInt,
2428                                "vsp_term_miss_tolerance=",
2429                                "4");
2430
2431        RegisterOption("VspTree.Termination.minGlobalCostRatio",
2432                                        optFloat,
2433                                        "vsp_term_min_global_cost_ratio=",
2434                                        "0.0001");
2435
2436        RegisterOption("VspTree.Termination.globalCostMissTolerance",
2437                                        optInt,
2438                                        "vsp_term_global_cost_miss_tolerance=",
2439                                        "4");
2440
2441        RegisterOption("VspTree.Termination.ct_div_ci",
2442                                        optFloat,
2443                                        "vsp_term_ct_div_ci=",
2444                                        "0.0");
2445
2446        RegisterOption("VspTree.Construction.epsilon",
2447                                        optFloat,
2448                                        "vsp_construction_epsilon=",
2449                                        "0.002");
2450
2451        RegisterOption("VspTree.splitUseOnlyDrivingAxis",
2452                                        optBool,
2453                                        "vsp_split_only_driving_axis=",
2454                                        "false");
2455
2456        RegisterOption("VspTree.maxStaticMemory",
2457                                        optFloat,
2458                                        "vsp_max_static_mem=",
2459                                        "8.0");
2460
2461        RegisterOption("VspTree.useCostHeuristics",
2462                                        optBool,
2463                                        "vsp_use_cost_heuristics=",
2464                                        "false");
2465
2466        RegisterOption("VspTree.simulateOctree",
2467                                        optBool,
2468                                        "vsp_simulate_octree=",
2469                                        "false");
2470
2471        RegisterOption("VspTree.Construction.randomize",
2472                                        optBool,
2473                                        "vsp_construction_randomize=",
2474                                        "false");
2475
2476        RegisterOption("VspTree.subdivisionStats",
2477                                        optString,
2478                                        "vsp_subdivision_stats=",
2479                                        "vspSubdivisionStats.log");
2480
2481        RegisterOption("VspTree.Construction.minBand",
2482                                        optFloat,
2483                                        "vsp_construction_min_band=",
2484                                        "0.01");
2485
2486        RegisterOption("VspTree.Construction.maxBand",
2487                                        optFloat,
2488                                        "vsp_construction_max_band=",
2489                                        "0.99");
2490       
2491        RegisterOption("VspTree.maxTests",
2492                                        optInt,
2493                                        "vsp_max_tests=",
2494                                        "5000");
2495
2496
2497
2498/***********************************************************************/
2499/*           Object space partition tree related options               */
2500/***********************************************************************/
2501
2502
2503        RegisterOption("OspTree.Construction.randomize",
2504                                        optBool,
2505                                        "osp_construction_randomize=",
2506                                        "false");
2507
2508        RegisterOption("OspTree.Termination.maxDepth",
2509                                        optInt,
2510                                        "osp_term_max_depth=",
2511                                        "30");
2512       
2513        RegisterOption("OspTree.Termination.maxLeaves",
2514                                        optInt,
2515                                        "osp_term_max_leaves=",
2516                                        "1000");
2517       
2518        RegisterOption("OspTree.Termination.minObjects",
2519                                        optInt,
2520                                        "osp_term_min_objects=",
2521                                        "1");
2522
2523        RegisterOption("OspTree.Termination.minProbability",
2524                                        optFloat,
2525                                        "osp_term_min_objects=",
2526                                        "0.00001");
2527
2528        RegisterOption("OspTree.Termination.missTolerance",
2529                                        optInt,
2530                                        "osp_term_miss_tolerance=",
2531                                        "8");
2532
2533        RegisterOption("OspTree.Termination.maxCostRatio",
2534                                        optFloat,
2535                                        "osp_term_max_cost_ratio=",
2536                                        "0.99");
2537
2538        RegisterOption("OspTree.Termination.minGlobalCostRatio",
2539                                        optFloat,
2540                                        "osp_term_min_global_cost_ratio=",
2541                                        "0.00001");
2542
2543        RegisterOption("OspTree.Termination.globalCostMissTolerance",
2544                                        optInt,
2545                                        "osp_term_global_cost_miss_tolerance=",
2546                                        "4");
2547
2548        RegisterOption("OspTree.Termination.ct_div_ci",
2549                                        optFloat,
2550                                        "osp_term_ct_div_ci=",
2551                                        "0");
2552       
2553        RegisterOption("OspTree.Construction.epsilon",
2554                                   optFloat,
2555                                   "osp_construction_epsilon=",
2556                                   "0.00001");
2557       
2558        // if only the driving axis is used for axis aligned split
2559        RegisterOption("OspTree.splitUseOnlyDrivingAxis",
2560                                   optBool,
2561                                   "osp_split_only_driving_axis=",
2562                                   "false");
2563
2564        RegisterOption("OspTree.maxStaticMemory",
2565                                   optFloat,
2566                                   "osp_max_static_mem=",
2567                                   "8.0");
2568
2569        RegisterOption("OspTree.useCostHeuristics",
2570                                   optBool,
2571                                   "osp_use_cost_heuristics=",
2572                                   "true");
2573
2574        RegisterOption("OspTree.subdivisionStats",
2575                                        optString,
2576                                        "osp_subdivision_stats=",
2577                                        "ospSubdivisionStats.log");
2578
2579        RegisterOption("OspTree.Construction.splitBorder",
2580                                        optFloat,
2581                                        "osp_construction_split_border=",
2582                                        "0.01");
2583
2584        RegisterOption("OspTree.Construction.renderCostDecreaseWeight",
2585                                   optFloat,
2586                                   "osp_construction_render_cost_decrease_weight=",
2587                                   "0.99");
2588
2589
2590
2591/**********************************************************************/
2592/*            Bounding Volume Hierarchy related options               */
2593/**********************************************************************/
2594
2595        RegisterOption("BvHierarchy.Construction.randomize",
2596                                        optBool,
2597                                        "bvh_construction_randomize=",
2598                                        "false");
2599
2600        RegisterOption("BvHierarchy.Termination.maxDepth",
2601                                        optInt,
2602                                        "bvh_term_max_depth=",
2603                                        "30");
2604       
2605        RegisterOption("BvHierarchy.Termination.maxLeaves",
2606                                        optInt,
2607                                        "bvh_term_max_leaves=",
2608                                        "1000");
2609       
2610        RegisterOption("BvHierarchy.Termination.minObjects",
2611                                        optInt,
2612                                        "bvh_term_min_objects=",
2613                                        "1");
2614
2615        RegisterOption("BvHierarchy.Termination.minProbability",
2616                                        optFloat,
2617                                        "bvh_term_min_objects=",
2618                                        "0.0000001");
2619
2620        RegisterOption("BvHierarchy.Termination.minRays",
2621                                        optInt,
2622                                        "bvh_term_min_rays=",
2623                                        "0");
2624
2625        RegisterOption("BvHierarchy.Termination.missTolerance",
2626                                        optInt,
2627                                        "osp_term_miss_tolerance=",
2628                                        "8");
2629
2630        RegisterOption("BvHierarchy.Termination.maxCostRatio",
2631                                        optFloat,
2632                                        "bvh_term_max_cost_ratio=",
2633                                        "0.99");
2634
2635        RegisterOption("BvHierarchy.Termination.minGlobalCostRatio",
2636                                        optFloat,
2637                                        "bvh_term_min_global_cost_ratio=",
2638                                        "0.00001");
2639
2640        RegisterOption("BvHierarchy.Termination.globalCostMissTolerance",
2641                                        optInt,
2642                                        "bvh_term_global_cost_miss_tolerance=",
2643                                        "4");
2644
2645        // if only the driving axis is used for axis aligned split
2646        RegisterOption("BvHierarchy.splitUseOnlyDrivingAxis",
2647                                   optBool,
2648                                   "bvh_split_only_driving_axis=",
2649                                   "false");
2650
2651        RegisterOption("BvHierarchy.maxStaticMemory",
2652                                   optFloat,
2653                                   "bvh_max_static_mem=",
2654                                   "8.0");
2655
2656        RegisterOption("BvHierarchy.useCostHeuristics",
2657                                   optBool,
2658                                   "bvh_use_cost_heuristics=",
2659                                   "true");
2660       
2661        RegisterOption("BvHierarchy.useSah",
2662                                   optBool,
2663                                   "bvh_use_sah=",
2664                                   "false");
2665
2666        RegisterOption("BvHierarchy.subdivisionStats",
2667                                        optString,
2668                                        "bvh_subdivision_stats=",
2669                                        "bvhSubdivisionStats.log");
2670
2671        RegisterOption("BvHierarchy.Construction.renderCostDecreaseWeight",
2672                                   optFloat,
2673                                   "bvh_construction_render_cost_decrease_weight=",
2674                                   "0.99");
2675       
2676        RegisterOption("BvHierarchy.Construction.useGlobalSorting",
2677                                        optBool,
2678                                        "bvh_construction_use_global_sorting=",
2679                                        "true");
2680       
2681        RegisterOption("BvHierarchy.Construction.useInitialSubdivision",
2682                                        optBool,
2683                                        "bvh_construction_use_initial_subdivision=",
2684                                        "false");
2685
2686        RegisterOption("BvHierarchy.Construction.Initial.minObjects",
2687                                        optInt,
2688                                        "bvh_construction_use_initial_min_objects=",
2689                                        "100000");
2690
2691        RegisterOption("BvHierarchy.Construction.Initial.minArea",
2692                                        optFloat,
2693                                        "bvh_construction_use_initial_min_area=",
2694                                        "0.0001");
2695
2696        RegisterOption("BvHierarchy.Construction.Initial.maxAreaRatio",
2697                                        optFloat,
2698                                        "bvh_construction_use_initial_max_area_ratio=",
2699                                        "0.9");
2700
2701        RegisterOption("BvHierarchy.minRaysForVisibility",
2702                                        optInt,
2703                                        "bvh_min_rays_for_vis=",
2704                                        "0");
2705
2706        RegisterOption("BvHierarchy.maxTests",
2707                                        optInt,
2708                                        "bvh_max_tests=",
2709                                        "50000");
2710
2711
2712        /*******************************************************************/
2713        /*               Hierarchy Manager related options                 */
2714        /*******************************************************************/
2715
2716        RegisterOption("Hierarchy.Construction.samples",
2717                                        optInt,
2718                                        "hierarchy_construction_samples=",
2719                                        "100000");
2720
2721        RegisterOption("Hierarchy.minRenderCost",
2722                                        optFloat,
2723                                        "hierarchy_minRenderCost=",
2724                                        "0");
2725
2726        RegisterOption("Hierarchy.subdivisionStats",
2727                           optString,
2728                                   "hierarchy_subdivision_stats=",
2729                                   "hierarchySubdivisionStats.log");
2730
2731        RegisterOption("Hierarchy.type",
2732                           optString,
2733                                   "hierarchy_type=",
2734                                   "bvh");
2735
2736        RegisterOption("Hierarchy.Termination.minGlobalCostRatio",
2737                                        optFloat,
2738                                        "hierarchy_term_min_global_cost_ratio=",
2739                                        "0.000000001");
2740
2741        RegisterOption("Hierarchy.Termination.globalCostMissTolerance",
2742                                        optInt,
2743                                        "hierarchy_term_global_cost_miss_tolerance=",
2744                                        "4");
2745
2746        RegisterOption("Hierarchy.Termination.maxLeaves",
2747                                        optInt,
2748                                        "hierarchy_term_max_leaves=",
2749                                        "1000");
2750       
2751        RegisterOption("Hierarchy.Construction.type",
2752                                        optInt,
2753                                        "hierarchy_construction_type=",
2754                                        "0");
2755
2756        RegisterOption("Hierarchy.Construction.minDepthForOsp",
2757                                        optInt,
2758                                        "hierarchy_construction_min_depth_for_osp=",
2759                                        "-1");
2760
2761        RegisterOption("Hierarchy.Construction.startWithObjectSpace",
2762                                        optBool,
2763                                        "hierarchy_construction_start_with_osp=",
2764                                        "true");
2765
2766        RegisterOption("Hierarchy.Construction.considerMemory",
2767                                        optBool,
2768                                        "hierarchy_construction_consider_memory=",
2769                                        "true");
2770
2771        RegisterOption("Hierarchy.Construction.repairQueue",
2772                                        optBool,
2773                                        "hierarchy_construction_repair_queue=",
2774                                        "true");
2775
2776        RegisterOption("Hierarchy.Construction.minDepthForVsp",
2777                                        optInt,
2778                                        "hierarchy_construction_min_depth_for_vsp=",
2779                                        "-1");
2780
2781        RegisterOption("Hierarchy.Termination.maxMemory",
2782                                        optFloat,
2783                                        "hierarchy_term_max_memory=",
2784                                        "1");
2785
2786        RegisterOption("Hierarchy.Termination.memoryConst",
2787                                        optFloat,
2788                                        "hierarchy_term_memory_const=",
2789                                        "1.0");
2790
2791        RegisterOption("Hierarchy.Construction.useMultiLevel",
2792                                        optBool,
2793                                        "hierarchy_construction_multilevel=",
2794                                        "false");
2795
2796        RegisterOption("Hierarchy.Construction.levels",
2797                                        optInt,
2798                                        "hierarchy_construction_levels=",
2799                                        "4");
2800
2801        RegisterOption("Hierarchy.Construction.maxRepairs",
2802                                        optInt,
2803                                        "hierarchy_construction_max_repairs=",
2804                                        "1000");
2805
2806        RegisterOption("Hierarchy.Construction.minStepsOfSameType",
2807                                        optInt,
2808                                        "hierarchy_construction_min_steps_same_type=",
2809                                        "200");
2810
2811        RegisterOption("Hierarchy.Construction.maxStepsOfSameType",
2812                                        optInt,
2813                                        "hierarchy_construction_max_steps_same_type=",
2814                                        "700");
2815
2816        RegisterOption("Hierarchy.Construction.recomputeSplitPlaneOnRepair",
2817                                        optBool,
2818                                        "hierarchy_construction_recompute_split_on_repair=",
2819                                        "true");
2820
2821        RegisterOption("Hierarchy.Construction.maxAvgRaysPerObject",
2822                                        optFloat,
2823                                        "hierarchy_construction_max_avg_rays_per_object=",
2824                                        "0");
2825       
2826        RegisterOption("Hierarchy.Construction.minAvgRaysPerObject",
2827                                        optFloat,
2828                                        "hierarchy_construction_min_avg_rays_per_object=",
2829                                        "0");
2830       
2831        RegisterOption("Hierarchy.useTraversalTree",
2832                                        optBool,
2833                                        "hierarchy_use_traversal_tree=",
2834                                        "false");
2835
2836        ///////////////////////////////////////////////////////
2837
2838         RegisterOption("TraversalTree.Termination.minCost",
2839                                 optInt,
2840                                 "kd_term_min_cost=",
2841                                 "1");
2842 
2843  RegisterOption("TraversalTree.Termination.maxNodes",
2844                                 optInt,
2845                                 "kd_term_max_nodes=",
2846                                 "200000");
2847 
2848  RegisterOption("TraversalTree.Termination.maxDepth",
2849                                 optInt,
2850                                 "kd_term_max_depth=",
2851                                 "20");
2852
2853  RegisterOption("TraversalTree.Termination.maxCostRatio",
2854                                 optFloat,
2855                                 "kd_term_max_cost_ratio=",
2856                                 "1.5");
2857
2858  RegisterOption("TraversalTree.Termination.ct_div_ci",
2859                                 optFloat,
2860                                 "kd_term_ct_div_ci=",
2861                                 "1.0");
2862
2863  RegisterOption("TraversalTree.splitMethod",
2864                                 optString,
2865                                 "kd_split_method=",
2866                                 "spatialMedian");
2867
2868  RegisterOption("TraversalTree.splitBorder",
2869                                 optFloat,
2870                                 "kd_split_border=",
2871                                 "0.1");
2872
2873  RegisterOption("TraversalTree.sahUseFaces",
2874                                 optBool,
2875                                 "kd_sah_use_faces=",
2876                                 "true");
2877
2878  /////////////////////////////////////////////////////////////////
2879  // By Vlastimil Havran
2880  RegisterOption("BSP.splitclip", optBool,
2881                 "kd_splitclip=", "false");
2882  RegisterOption("BSP.emptyCut", optBool,
2883                 "kd_emptycut=", "true");
2884  RegisterOption("BSP.termCrit", optString,
2885                 "kd_termcrit=", "auto");
2886  RegisterOption("BSP.maxDepthAllowed", optInt,
2887                 "kd_maxDepth=", "16");
2888  RegisterOption("BSP.maxEmptyCutDepth", optInt,
2889                 "kd_maxEmptyCutDepth=", "4");
2890  RegisterOption("BSP.absMaxAllowedDepth", optInt,
2891                 "kd_absMaxAllowedDepth=", "20");
2892  RegisterOption("BSP.maxListLength", optInt,
2893                 "kd_maxListLength=", "16");
2894  RegisterOption("BSP.useRadixSort", optBool,
2895                 "kd_useRadixSort=", "false");
2896  RegisterOption("BSP.printCuts", optBool,
2897                 "kd_printCuts=", "false");
2898  RegisterOption("BSP.algAutoTermination", optInt,
2899                 "kd_algAutoTermination=", "0");
2900  RegisterOption("BSP.axisSelectionAlg", optInt,
2901                 "kd_axisSelectAlg=", "0");
2902 
2903  RegisterOption("BSP.decisionCost", optFloat,
2904                 "kd_decCost=", "0.3");
2905  RegisterOption("BSP.intersectionCost", optFloat,
2906                 "kd_intersectCost=", "0.9");
2907  RegisterOption("BSP.traversalCost", optFloat,
2908                 "kd_travCost=", "0.2");
2909  RegisterOption("BSP.biasFreeCuts", optFloat,
2910                 "kd_biasFreeCuts=", "0.9");
2911
2912  RegisterOption("BSP.minBoxes.use", optBool,
2913                 "kd_minBoxesUse=", "false");
2914  RegisterOption("BSP.minBoxes.tight", optBool,
2915                 "kd_minBoxesTight=", "false");
2916  RegisterOption("BSP.minBoxes.minObjects", optInt,
2917                 "kd_minBoxesMinObjects=", "10");
2918  RegisterOption("BSP.minBoxes.minDepthDistance", optInt,
2919                 "kd_minBoxesMinDist=", "3");
2920  RegisterOption("BSP.minBoxes.minSA2ratio", optFloat,
2921                 "kd_minBoxesSA2ratio=", "1.0");
2922
2923  // The object used for testing
2924  RegisterOption("Rays.file",
2925                 optString,
2926                 "rays_filename=",
2927                 "data/fileRays_arena.txt");
2928  RegisterOption("Rays.cnt",
2929                 optInt,
2930                 "rays_cnt=", "100000");
2931 
2932  RegisterOption("TestDoubleRays", optBool,
2933                 "test_doublrays=", "false");
2934
2935  /////////////////////////////////////////////////////////////////
2936}
2937
2938void
2939Environment::SetStaticOptions()
2940{
2941 
2942  // get Global option values
2943  GetRealValue("Limits.threshold", Limits::Threshold);
2944  GetRealValue("Limits.small", Limits::Small);
2945  GetRealValue("Limits.infinity", Limits::Infinity);
2946
2947
2948}
2949
2950bool
2951Environment::Parse(const int argc, char **argv, bool useExePath)
2952{
2953  bool result = true;
2954  // Read the names of the scene, environment and output files
2955  ReadCmdlineParams(argc, argv, "");
2956
2957  char *envFilename = new char[128];
2958
2959  char filename[64];
2960
2961  // Get the environment file name
2962  if (!GetParam(' ', 0, filename)) {
2963    // user didn't specified environment file explicitly, so
2964    strcpy(filename, "default.env");
2965  }
2966
2967 
2968  if (useExePath) {
2969    char *path = GetPath(argv[0]);
2970    if (*path != 0)
2971      sprintf(envFilename, "%s/%s", path, filename);
2972    else
2973      strcpy(envFilename, filename);
2974   
2975    delete path;
2976  }
2977  else
2978    strcpy(envFilename, filename);
2979
2980 
2981  // Now it's time to read in environment file.
2982  if (!ReadEnvFile(envFilename)) {
2983    // error - bad input file name specified ?
2984    cerr<<"Error parsing environment file "<<envFilename<<endl;
2985        result = false;
2986  }
2987  delete [] envFilename;
2988
2989  // Parse the command line; options given on the command line subsume
2990  // stuff specified in the input environment file.
2991  ParseCmdline(argc, argv, 0);
2992
2993  SetStaticOptions();
2994
2995  // Check for request for help
2996  if (CheckForSwitch(argc, argv, '?')) {
2997    PrintUsage(cout);
2998    exit(0);
2999  }
3000 
3001  return true;
3002}
3003
3004}
Note: See TracBrowser for help on using the repository browser.