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

Revision 2582, 76.7 KB checked in by bittner, 16 years ago (diff)

Havran Ray Caster compiles and links, but still does not work

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-4");
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.exportRandomViewCells",
1698                                   optBool,
1699                                   "view_cells_export_random_viewcells=",
1700                                   "false");
1701
1702
1703
1704        /****************************************************************************/
1705        /*                     Render simulation related options                    */
1706        /****************************************************************************/
1707
1708
1709        RegisterOption("Simulation.objRenderCost",
1710                        optFloat,
1711                        "simulation_obj_render_cost",
1712                        "1.0");
1713
1714        RegisterOption("Simulation.vcOverhead",
1715                        optFloat,
1716                        "simulation_vc_overhead",
1717                        "0.05");
1718
1719        RegisterOption("Simulation.moveSpeed",
1720                        optFloat,
1721                        "simulation_moveSpeed",
1722                        "1.0");
1723
1724
1725
1726        /******************************************************************/
1727        /*                    Bsp tree related options                    */
1728        /******************************************************************/
1729
1730
1731        RegisterOption("BspTree.Construction.input",
1732                optString,
1733                "bsp_construction_input=",
1734                "fromViewCells");
1735       
1736        RegisterOption("BspTree.subdivisionStats",
1737                                        optString,
1738                                        "bsp_subdivision_stats=",
1739                                        "bspSubdivisionStats.log");
1740
1741        RegisterOption("BspTree.Construction.samples",
1742                optInt,
1743                "bsp_construction_samples=",
1744                "100000");
1745
1746        RegisterOption("BspTree.Construction.epsilon",
1747                optFloat,
1748                "bsp_construction_epsilon=",
1749                "0.002");
1750
1751        RegisterOption("BspTree.Termination.minPolygons",
1752                        optInt,
1753                        "bsp_term_min_polygons=",
1754                        "5");
1755
1756        RegisterOption("BspTree.Termination.minPvs",
1757                        optInt,
1758                        "bsp_term_min_pvs=",
1759                        "20");
1760
1761        RegisterOption("BspTree.Termination.minProbability",
1762                        optFloat,
1763                        "bsp_term_min_probability=",
1764                        "0.001");
1765
1766        RegisterOption("BspTree.Termination.maxRayContribution",
1767                        optFloat,
1768                        "bsp_term_ray_contribution=",
1769                        "0.005");
1770
1771        RegisterOption("BspTree.Termination.minAccRayLenght",
1772                        optFloat,
1773                        "bsp_term_min_acc_ray_length=",
1774                        "50");
1775
1776        RegisterOption("BspTree.Termination.minRays",
1777                        optInt,
1778                        "bsp_term_min_rays=",
1779                        "-1");
1780
1781        RegisterOption("BspTree.Termination.ct_div_ci",
1782                        optFloat,
1783                        "bsp_term_ct_div_ci=",
1784                        "0.0");
1785
1786        RegisterOption("BspTree.Termination.maxDepth",
1787                        optInt,
1788                        "bsp_term_max_depth=",
1789                        "100");
1790
1791        RegisterOption("BspTree.Termination.maxCostRatio",
1792                        optFloat,
1793                        "bsp_term_axis_aligned_max_cost_ratio=",
1794                        "1.5");
1795
1796        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1797                        optFloat,
1798                        "bsp_term_axis_aligned_ct_div_ci=",
1799                        "0.5");
1800
1801        RegisterOption("BspTree.AxisAligned.splitBorder",
1802                        optFloat,
1803                        "bsp__axis_aligned_split_border=",
1804                        "0.1");
1805
1806        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1807                        optInt,
1808                        "bsp_term_axis_aligned_max_polygons=",
1809                        "50");
1810
1811        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1812                        optInt,
1813                        "bsp_term_min_objects=",
1814                        "3");
1815
1816        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1817                        optInt,
1818                        "bsp_term_axis_aligned_min_rays=",
1819                        "-1");
1820
1821        RegisterOption("BspTree.splitPlaneStrategy",
1822                        optString,
1823                        "bsp_split_method=",
1824                        "leastSplits");
1825
1826        RegisterOption("BspTree.maxPolyCandidates",
1827                optInt,
1828                "bsp_max_poly_candidates=",
1829                "20");
1830
1831        RegisterOption("BspTree.maxRayCandidates",
1832                optInt,
1833                "bsp_max_plane_candidates=",
1834                "20");
1835
1836        RegisterOption("BspTree.maxTests",
1837                optInt,
1838                "bsp_max_tests=",
1839                "5000");
1840
1841        RegisterOption("BspTree.Termination.maxViewCells",
1842                optInt,
1843                "bsp_max_view_cells=",
1844                "5000");
1845
1846        RegisterOption("BspTree.Visualization.exportSplits",
1847                optBool,
1848                "bsp_visualization.export_splits=",
1849                "false");
1850
1851        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1852        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1853        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1854        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1855        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1856        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1857        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1858        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1859        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1860
1861
1862
1863
1864        /**********************************************************************/
1865        /*                     Preprocessor related options                   */
1866        /**********************************************************************/
1867
1868        RegisterOption("Preprocessor.type",
1869                                        optString,
1870                                        "preprocessor=",
1871                                        "sampling");
1872
1873        RegisterOption("Preprocessor.stats",
1874                                        optString,
1875                                        "preprocessor_stats=",
1876                                        "stats.log");
1877
1878        RegisterOption("Preprocessor.samplesFilename",
1879                                        optString,
1880                                        "preprocessor_samples_filename=",
1881                                        "rays.out");
1882
1883        RegisterOption("Preprocessor.loadMeshes",
1884                                        optBool,
1885                                        "preprocessor_load_meshes",
1886                                        "true");
1887
1888        RegisterOption("Preprocessor.evaluateFilter",
1889                                   optBool,
1890                                   "preprocessor_evaluate_filter",
1891                                   "false");
1892
1893        RegisterOption("Preprocessor.delayVisibilityComputation",
1894                                   optBool,
1895                                   "preprocessor_delay_computation",
1896                                   "true");
1897
1898        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1899                                   optInt,
1900                                   "preprocessor_pvs_rendererror_samples=",
1901                                   "10000");
1902       
1903        RegisterOption("Preprocessor.useGlRenderer",
1904                                        optBool,
1905                                        "preprocessor_use_gl_renderer",
1906                                        "false");
1907
1908        RegisterOption("Preprocessor.useGlDebugger",
1909                                        optBool,
1910                                        "preprocessor_use_gl_debugger",
1911                                        "false");
1912
1913        RegisterOption("Preprocessor.detectEmptyViewSpace",
1914                                   optBool,
1915                                   "preprocessor_detect_empty_viewspace",
1916                                   "false");
1917       
1918        RegisterOption("Preprocessor.quitOnFinish",
1919                                   optBool,
1920                                   "preprocessor_quit_on_finish",
1921                                   "true");
1922
1923        RegisterOption("Preprocessor.computeVisibility",
1924                                   optBool,
1925                                   "preprocessor_compute_visibility",
1926                                   "true");
1927
1928        RegisterOption("Preprocessor.exportVisibility",
1929                                   optBool,
1930                                   "preprocessor_export_visibility",
1931                                   "true");
1932
1933        RegisterOption("Preprocessor.visibilityFile",
1934                                   optString,
1935                                   "preprocessor_visibility_file=",
1936                                   "visibility.xml");
1937
1938        RegisterOption("Preprocessor.applyVisibilityFilter",
1939                                   optBool,
1940                                   "preprocessor_apply_filter",
1941                                   "false");
1942       
1943        RegisterOption("Preprocessor.evaluatePixelError",
1944                                   optBool,
1945                                   "preprocessor_evaluatePixelError",
1946                                   "false");
1947
1948        RegisterOption("Preprocessor.applyVisibilitySpatialFilter",
1949                                   optBool,
1950                                   "preprocessor_apply_spatial_filter",
1951                                   "false");
1952
1953        RegisterOption("Preprocessor.visibilityFilterWidth",
1954                                   optFloat,
1955                                   "preprocessor_visibility_filter_width=",
1956                                   "0.02");
1957
1958        RegisterOption("Preprocessor.histogram.maxValue",
1959                                        optInt,
1960                                        "preprocessor_histogram_max_value=",
1961                                        "1000");
1962
1963        RegisterOption("Preprocessor.rayCastMethod",
1964                                        optInt,
1965                                        "preprocessor_ray_cast_method=",
1966                                        "0");
1967
1968        RegisterOption("Preprocessor.histogram.intervals",
1969                                        optInt,
1970                                        "preprocessor_histogram_intervals=",
1971                                        "20");
1972
1973        RegisterOption("Preprocessor.histogram.file",
1974                                   optString,
1975                                   "preprocessor_histogram_file=",
1976                                   "histogram.log");
1977
1978        RegisterOption("Preprocessor.exportKdTree",
1979                                        optBool,
1980                                        "preprocessor_export_kd_tree=",
1981                                        "false");
1982
1983        RegisterOption("Preprocessor.loadKdTree",
1984                                        optBool,
1985                                        "preprocessor_load_kd_tree=",
1986                                        "false");
1987
1988        RegisterOption("Preprocessor.kdTreeFilename",
1989                                        optString,
1990                                        "preprocessor_kd_tree_filename=",
1991                                        "vienna_kdtree.bin.gz");
1992
1993        RegisterOption("Preprocessor.exportObj",
1994                                        optBool,
1995                                        "preprocessor_export_obj=",
1996                                        "false");
1997
1998   RegisterOption("Preprocessor.useViewSpaceBox",
1999                                        optBool,
2000                                        "preprocessor_use_viewspace_box=",
2001                                        "false");   
2002
2003   RegisterOption("Preprocessor.Export.rays", optBool, "export_rays", "false");
2004   RegisterOption("Preprocessor.Export.animation", optBool, "export_animation", "false");
2005   RegisterOption("Preprocessor.Export.numRays", optInt, "export_num_rays=", "5000");
2006   
2007        /*************************************************************************/
2008        /*             VSS Preprocessor cells related options                    */
2009        /*************************************************************************/
2010
2011        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
2012        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
2013        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
2014        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
2015        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
2016
2017        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
2018        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
2019        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
2020        RegisterOption("VssTree.splitType", optString, "split=", "queries");
2021        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
2022        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
2023        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
2024
2025        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
2026
2027        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
2028        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
2029
2030        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
2031
2032       
2033       
2034        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
2035        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false");
2036        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
2037        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
2038        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
2039        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
2040
2041        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
2042        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
2043
2044
2045//      RegisterOption("RssPreprocessor.initialSamples",
2046//                                                                      optInt,
2047//                                                                      "rss_initial_samples=",
2048//                                                                      "100000");
2049
2050//      RegisterOption("RssPreprocessor.vssSamples",
2051//                                      optInt,
2052//                                      "rss_vss_samples=",
2053//                                      "1000000");
2054
2055//      RegisterOption("RssPreprocessor.vssSamplesPerPass",
2056//                                      optInt,
2057//                                      "rss_vss_samples_per_pass=",
2058//                                      "1000");
2059
2060//      RegisterOption("RssPreprocessor.samplesPerPass",
2061//                                      optInt,
2062//                                      "rss_samples_per_pass=",
2063//                                      "100000");
2064
2065        RegisterOption("RssPreprocessor.useImportanceSampling",
2066                                        optBool,
2067                                        "rss_use_importance",
2068                                        "true");
2069
2070        RegisterOption("RssPreprocessor.useRssTree",
2071                                        optBool,
2072                                        "rss_use_rss_tree",
2073                                        "true");
2074
2075        RegisterOption("RssPreprocessor.objectBasedSampling",
2076                                        optBool,
2077                                        "rss_object_based_sampling",
2078                                        "true");
2079
2080        RegisterOption("RssPreprocessor.directionalSampling",
2081                                        optBool,
2082                                        "rss_directional_sampling",
2083                                        "false");
2084
2085        RegisterOption("RssPreprocessor.distributions",
2086                                   optString,
2087                                   "rss_distributions=",
2088                                   "rss+spatial+object");
2089       
2090        RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10");
2091        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
2092        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
2093        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
2094        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
2095        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
2096
2097        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
2098        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
2099        RegisterOption("RssTree.randomize", optBool, "randomize=", "false");
2100        RegisterOption("RssTree.splitType", optString, "rss_split=", "queries");
2101        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
2102
2103        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
2104
2105        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
2106
2107        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
2108        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
2109
2110        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
2111
2112        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
2113        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
2114        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
2115        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
2116        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
2117        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
2118
2119        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true");
2120        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
2121        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true");
2122        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
2123
2124        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
2125
2126        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
2127        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
2128
2129        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
2130        RegisterOption("RssPreprocessor.updateSubdivision",
2131                                   optBool,
2132                                   "rss_update_subdivision=",
2133                                   "false");
2134
2135
2136/************************************************************************************/
2137/*                      Rss preprocessor related options                            */
2138/************************************************************************************/
2139
2140
2141        RegisterOption("RssPreprocessor.loadInitialSamples",
2142                                        optBool,
2143                                        "vss_load_loadInitialSamples=",
2144                                        "false");
2145
2146        RegisterOption("RssPreprocessor.storeInitialSamples",
2147                                        optBool,
2148                                        "vss_store_storeInitialSamples=",
2149                                        "false");
2150
2151
2152/************************************************************************************/
2153/*                 View space partition BSP tree related options                    */
2154/************************************************************************************/
2155
2156        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
2157                                        optFloat,
2158                                        "vsp_bsp_term_min_global_cost_ratio=",
2159                                        "0.0001");
2160
2161        RegisterOption("VspBspTree.useSplitCostQueue",
2162                                        optBool,
2163                                        "vsp_bsp_use_split_cost_queue=",
2164                                        "true");
2165
2166        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
2167                                        optInt,
2168                                        "vsp_bsp_term_global_cost_miss_tolerance=",
2169                                        "4");
2170
2171        RegisterOption("VspBspTree.Termination.minPolygons",
2172                                        optInt,
2173                                        "vsp_bsp_term_min_polygons=",
2174                                        "-1");
2175
2176        RegisterOption("VspBspTree.Termination.minPvs",
2177                                        optInt,
2178                                        "vsp_bsp_term_min_pvs=",
2179                                        "20");
2180
2181        RegisterOption("VspBspTree.Termination.minProbability",
2182                                        optFloat,
2183                                        "vsp_bsp_term_min_probability=",
2184                                        "0.001");
2185
2186        RegisterOption("VspBspTree.subdivisionStats",
2187                                        optString,
2188                                        "vsp_bsp_subdivision_stats=",
2189                                        "vspBspSubdivisionStats.log");
2190
2191        RegisterOption("VspBspTree.Termination.maxRayContribution",
2192                                        optFloat,
2193                                        "vsp_bsp_term_ray_contribution=",
2194                                        "2");
2195
2196        RegisterOption("VspBspTree.Termination.minAccRayLenght",
2197                                        optFloat,
2198                                        "vsp_bsp_term_min_acc_ray_length=",
2199                                        "50");
2200
2201        RegisterOption("VspBspTree.Termination.minRays",
2202                                        optInt,
2203                                        "vsp_bsp_term_min_rays=",
2204                                        "-1");
2205
2206        RegisterOption("VspBspTree.Termination.ct_div_ci",
2207                                        optFloat,
2208                                        "vsp_bsp_term_ct_div_ci=",
2209                                        "0.0");
2210
2211        RegisterOption("VspBspTree.Termination.maxDepth",
2212                                        optInt,
2213                                        "vsp_bsp_term_max_depth=",
2214                                        "50");
2215
2216        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
2217                                        optFloat,
2218                                        "vsp_bsp_term_axis_aligned_max_cost_ratio=",
2219                                        "1.5");
2220
2221        RegisterOption("VspBspTree.useCostHeuristics",
2222                                        optBool,
2223                                        "vsp_bsp_use_cost_heuristics=",
2224                                        "false");
2225
2226        RegisterOption("VspBspTree.Termination.maxViewCells",
2227                                        optInt,
2228                                        "vsp_bsp_term_max_view_cells=",
2229                                        "10000");
2230
2231        RegisterOption("VspBspTree.Termination.maxCostRatio",
2232                                        optFloat,
2233                                        "vsp_bsp_term_max_cost_ratio=",
2234                                        "1.5");
2235
2236        RegisterOption("VspBspTree.Termination.missTolerance",
2237                                        optInt,
2238                                        "vsp_bsp_term_miss_tolerance=",
2239                                        "4");
2240
2241        RegisterOption("VspBspTree.splitPlaneStrategy",
2242                                        optInt,
2243                                        "vsp_bsp_split_method=",
2244                                        "1026");
2245
2246        RegisterOption("VspBspTree.maxPolyCandidates",
2247                                        optInt,
2248                                        "vsp_bsp_max_poly_candidates=",
2249                                        "20");
2250
2251        RegisterOption("VspBspTree.maxRayCandidates",
2252                                        optInt,
2253                                        "vsp_bsp_max_plane_candidates=",
2254                                        "20");
2255
2256        RegisterOption("VspBspTree.maxTests",
2257                                        optInt,
2258                                        "vsp_bsp_max_tests=",
2259                                        "5000");
2260
2261        RegisterOption("VspBspTree.Construction.samples",
2262                                        optInt,
2263                                        "vsp_bsp_construction_samples=",
2264                                        "100000");
2265
2266        RegisterOption("VspBspTree.Construction.minBand",
2267                                        optFloat,
2268                                        "vsp_bsp_construction_min_band=",
2269                                        "0.01");
2270
2271        RegisterOption("VspBspTree.Construction.maxBand",
2272                                        optFloat,
2273                                        "vsp_bsp_construction_max_band=",
2274                                        "0.99");
2275
2276        RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost",
2277                                        optBool,
2278                                        "vsp_bsp_construction_use_drivingaxis_for_maxcost=",
2279                                        "false");
2280
2281        RegisterOption("VspBspTree.Construction.epsilon",
2282                                        optFloat,
2283                                        "vsp_bsp_construction_epsilon=",
2284                                        "0.002");
2285
2286        RegisterOption("VspBspTree.Visualization.exportSplits",
2287                                        optBool,
2288                                        "vsp_bsp_visualization.export_splits",
2289                                        "false");
2290
2291        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
2292                                        optBool,
2293                                        "vsp_bsp_split_only_driving_axis=",
2294                                        "false");
2295
2296        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
2297                                        optBool,
2298                    "vsp_bsp_usePolygonSplitIfAvailable=",
2299                                        "false");
2300
2301        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
2302                        optInt,
2303                        "bsp_term_axis_aligned_min_rays=",
2304                        "0");
2305       
2306        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
2307                        optFloat,
2308                        "bsp_term_axis_aligned_min_rays=",
2309                        "2");
2310
2311        RegisterOption("VspBspTree.Factor.leastRaySplits",
2312                                        optFloat,
2313                                        "vsp_bsp_factor_least_ray_splits=",
2314                                        "1.0");
2315
2316        RegisterOption("VspBspTree.Factor.balancedRays",
2317                                        optFloat,
2318                                        "vsp_bsp_factor_balanced_rays=",
2319                                        "1.0");
2320
2321        RegisterOption("VspBspTree.Factor.pvs",
2322                                        optFloat,
2323                                        "vsp_bsp_factor_pvs=",
2324                                        "1.0");
2325       
2326        RegisterOption("VspBspTree.Construction.renderCostWeight",
2327                        optFloat,
2328                        "vsp_bsp_post_process_render_cost_weight=",
2329                        "1.0");
2330
2331        RegisterOption("VspBspTree.Construction.renderCostDecreaseWeight",
2332                        optFloat,
2333                        "vsp_bsp_construction_render_cost_decrease_weight=",
2334                        "0.99");
2335
2336        RegisterOption("VspBspTree.Construction.randomize",
2337                optBool,
2338                "vsp_bsp_construction_randomize=",
2339                "false");
2340
2341        RegisterOption("VspBspTree.simulateOctree",
2342                optBool,
2343                "vsp_bsp_simulate_octree=",
2344                "false");
2345
2346        RegisterOption("VspBspTree.nodePriorityQueueType",
2347                optInt,
2348                "vsp_bsp_node_queue_type=",
2349                "0");
2350
2351        RegisterOption("VspBspTree.useRandomAxis",
2352                optBool,
2353                "-vsp_bsp_use_random_axis=",
2354                "false");
2355
2356        RegisterOption("VspBspTree.maxTotalMemory",
2357                optFloat,
2358                "vsp_bsp_max_total_mem=",
2359                "60.0");
2360
2361        RegisterOption("VspBspTree.maxStaticMemory",
2362                optFloat,
2363                "vsp_bsp_max_static_mem=",
2364                "8.0");
2365
2366
2367
2368/***************************************************************************/
2369/*                 View space partition tree related options               */
2370/***************************************************************************/
2371
2372       
2373        RegisterOption("VspTree.Construction.samples",
2374                                        optInt,
2375                                        "vsp_construction_samples=",
2376                                        "10000");
2377
2378        RegisterOption("VspTree.Construction.renderCostDecreaseWeight",
2379                                optFloat,
2380                                "vsp_construction_render_cost_decrease_weight=",
2381                                "0.99");
2382
2383        RegisterOption("VspTree.Termination.maxDepth",
2384                                        optInt,
2385                                        "vsp_term_max_depth=",
2386                                        "100");
2387
2388        RegisterOption("VspTree.Termination.minRays",
2389                                        optInt,
2390                                        "vsp_term_min_rays=",
2391                                        "-1");
2392
2393
2394        RegisterOption("VspTree.Termination.minPvs",
2395                                        optInt,
2396                                        "vsp_term_min_pvs=",
2397                                        "20");
2398
2399        RegisterOption("VspTree.Termination.minProbability",
2400                                        optFloat,
2401                                        "vsp_term_min_probability=",
2402                                        "0.0000001");
2403
2404        RegisterOption("VspTree.Termination.maxRayContribution",
2405                                optFloat,
2406                                "vsp_term_ray_contribution=",
2407                                "0.9");
2408       
2409        RegisterOption("VspTree.Termination.maxCostRatio",
2410                                optFloat,
2411                                "vsp_term_max_cost_ratio=",
2412                                "1.5");
2413       
2414        RegisterOption("VspTree.Termination.maxViewCells",
2415                                optInt,
2416                                "vsp_term_max_view_cells=",
2417                                "10000");
2418       
2419        RegisterOption("VspTree.Termination.missTolerance",
2420                                optInt,
2421                                "vsp_term_miss_tolerance=",
2422                                "4");
2423
2424        RegisterOption("VspTree.Termination.minGlobalCostRatio",
2425                                        optFloat,
2426                                        "vsp_term_min_global_cost_ratio=",
2427                                        "0.0001");
2428
2429        RegisterOption("VspTree.Termination.globalCostMissTolerance",
2430                                        optInt,
2431                                        "vsp_term_global_cost_miss_tolerance=",
2432                                        "4");
2433
2434        RegisterOption("VspTree.Termination.ct_div_ci",
2435                                        optFloat,
2436                                        "vsp_term_ct_div_ci=",
2437                                        "0.0");
2438
2439        RegisterOption("VspTree.Construction.epsilon",
2440                                        optFloat,
2441                                        "vsp_construction_epsilon=",
2442                                        "0.002");
2443
2444        RegisterOption("VspTree.splitUseOnlyDrivingAxis",
2445                                        optBool,
2446                                        "vsp_split_only_driving_axis=",
2447                                        "false");
2448
2449        RegisterOption("VspTree.maxStaticMemory",
2450                                        optFloat,
2451                                        "vsp_max_static_mem=",
2452                                        "8.0");
2453
2454        RegisterOption("VspTree.useCostHeuristics",
2455                                        optBool,
2456                                        "vsp_use_cost_heuristics=",
2457                                        "false");
2458
2459        RegisterOption("VspTree.simulateOctree",
2460                                        optBool,
2461                                        "vsp_simulate_octree=",
2462                                        "false");
2463
2464        RegisterOption("VspTree.Construction.randomize",
2465                                        optBool,
2466                                        "vsp_construction_randomize=",
2467                                        "false");
2468
2469        RegisterOption("VspTree.subdivisionStats",
2470                                        optString,
2471                                        "vsp_subdivision_stats=",
2472                                        "vspSubdivisionStats.log");
2473
2474        RegisterOption("VspTree.Construction.minBand",
2475                                        optFloat,
2476                                        "vsp_construction_min_band=",
2477                                        "0.01");
2478
2479        RegisterOption("VspTree.Construction.maxBand",
2480                                        optFloat,
2481                                        "vsp_construction_max_band=",
2482                                        "0.99");
2483       
2484        RegisterOption("VspTree.maxTests",
2485                                        optInt,
2486                                        "vsp_max_tests=",
2487                                        "5000");
2488
2489
2490
2491/***********************************************************************/
2492/*           Object space partition tree related options               */
2493/***********************************************************************/
2494
2495
2496        RegisterOption("OspTree.Construction.randomize",
2497                                        optBool,
2498                                        "osp_construction_randomize=",
2499                                        "false");
2500
2501        RegisterOption("OspTree.Termination.maxDepth",
2502                                        optInt,
2503                                        "osp_term_max_depth=",
2504                                        "30");
2505       
2506        RegisterOption("OspTree.Termination.maxLeaves",
2507                                        optInt,
2508                                        "osp_term_max_leaves=",
2509                                        "1000");
2510       
2511        RegisterOption("OspTree.Termination.minObjects",
2512                                        optInt,
2513                                        "osp_term_min_objects=",
2514                                        "1");
2515
2516        RegisterOption("OspTree.Termination.minProbability",
2517                                        optFloat,
2518                                        "osp_term_min_objects=",
2519                                        "0.00001");
2520
2521        RegisterOption("OspTree.Termination.missTolerance",
2522                                        optInt,
2523                                        "osp_term_miss_tolerance=",
2524                                        "8");
2525
2526        RegisterOption("OspTree.Termination.maxCostRatio",
2527                                        optFloat,
2528                                        "osp_term_max_cost_ratio=",
2529                                        "0.99");
2530
2531        RegisterOption("OspTree.Termination.minGlobalCostRatio",
2532                                        optFloat,
2533                                        "osp_term_min_global_cost_ratio=",
2534                                        "0.00001");
2535
2536        RegisterOption("OspTree.Termination.globalCostMissTolerance",
2537                                        optInt,
2538                                        "osp_term_global_cost_miss_tolerance=",
2539                                        "4");
2540
2541        RegisterOption("OspTree.Termination.ct_div_ci",
2542                                        optFloat,
2543                                        "osp_term_ct_div_ci=",
2544                                        "0");
2545       
2546        RegisterOption("OspTree.Construction.epsilon",
2547                                   optFloat,
2548                                   "osp_construction_epsilon=",
2549                                   "0.00001");
2550       
2551        // if only the driving axis is used for axis aligned split
2552        RegisterOption("OspTree.splitUseOnlyDrivingAxis",
2553                                   optBool,
2554                                   "osp_split_only_driving_axis=",
2555                                   "false");
2556
2557        RegisterOption("OspTree.maxStaticMemory",
2558                                   optFloat,
2559                                   "osp_max_static_mem=",
2560                                   "8.0");
2561
2562        RegisterOption("OspTree.useCostHeuristics",
2563                                   optBool,
2564                                   "osp_use_cost_heuristics=",
2565                                   "true");
2566
2567        RegisterOption("OspTree.subdivisionStats",
2568                                        optString,
2569                                        "osp_subdivision_stats=",
2570                                        "ospSubdivisionStats.log");
2571
2572        RegisterOption("OspTree.Construction.splitBorder",
2573                                        optFloat,
2574                                        "osp_construction_split_border=",
2575                                        "0.01");
2576
2577        RegisterOption("OspTree.Construction.renderCostDecreaseWeight",
2578                                   optFloat,
2579                                   "osp_construction_render_cost_decrease_weight=",
2580                                   "0.99");
2581
2582
2583
2584/**********************************************************************/
2585/*            Bounding Volume Hierarchy related options               */
2586/**********************************************************************/
2587
2588        RegisterOption("BvHierarchy.Construction.randomize",
2589                                        optBool,
2590                                        "bvh_construction_randomize=",
2591                                        "false");
2592
2593        RegisterOption("BvHierarchy.Termination.maxDepth",
2594                                        optInt,
2595                                        "bvh_term_max_depth=",
2596                                        "30");
2597       
2598        RegisterOption("BvHierarchy.Termination.maxLeaves",
2599                                        optInt,
2600                                        "bvh_term_max_leaves=",
2601                                        "1000");
2602       
2603        RegisterOption("BvHierarchy.Termination.minObjects",
2604                                        optInt,
2605                                        "bvh_term_min_objects=",
2606                                        "1");
2607
2608        RegisterOption("BvHierarchy.Termination.minProbability",
2609                                        optFloat,
2610                                        "bvh_term_min_objects=",
2611                                        "0.0000001");
2612
2613        RegisterOption("BvHierarchy.Termination.minRays",
2614                                        optInt,
2615                                        "bvh_term_min_rays=",
2616                                        "0");
2617
2618        RegisterOption("BvHierarchy.Termination.missTolerance",
2619                                        optInt,
2620                                        "osp_term_miss_tolerance=",
2621                                        "8");
2622
2623        RegisterOption("BvHierarchy.Termination.maxCostRatio",
2624                                        optFloat,
2625                                        "bvh_term_max_cost_ratio=",
2626                                        "0.99");
2627
2628        RegisterOption("BvHierarchy.Termination.minGlobalCostRatio",
2629                                        optFloat,
2630                                        "bvh_term_min_global_cost_ratio=",
2631                                        "0.00001");
2632
2633        RegisterOption("BvHierarchy.Termination.globalCostMissTolerance",
2634                                        optInt,
2635                                        "bvh_term_global_cost_miss_tolerance=",
2636                                        "4");
2637
2638        // if only the driving axis is used for axis aligned split
2639        RegisterOption("BvHierarchy.splitUseOnlyDrivingAxis",
2640                                   optBool,
2641                                   "bvh_split_only_driving_axis=",
2642                                   "false");
2643
2644        RegisterOption("BvHierarchy.maxStaticMemory",
2645                                   optFloat,
2646                                   "bvh_max_static_mem=",
2647                                   "8.0");
2648
2649        RegisterOption("BvHierarchy.useCostHeuristics",
2650                                   optBool,
2651                                   "bvh_use_cost_heuristics=",
2652                                   "true");
2653       
2654        RegisterOption("BvHierarchy.useSah",
2655                                   optBool,
2656                                   "bvh_use_sah=",
2657                                   "false");
2658
2659        RegisterOption("BvHierarchy.subdivisionStats",
2660                                        optString,
2661                                        "bvh_subdivision_stats=",
2662                                        "bvhSubdivisionStats.log");
2663
2664        RegisterOption("BvHierarchy.Construction.renderCostDecreaseWeight",
2665                                   optFloat,
2666                                   "bvh_construction_render_cost_decrease_weight=",
2667                                   "0.99");
2668       
2669        RegisterOption("BvHierarchy.Construction.useGlobalSorting",
2670                                        optBool,
2671                                        "bvh_construction_use_global_sorting=",
2672                                        "true");
2673       
2674        RegisterOption("BvHierarchy.Construction.useInitialSubdivision",
2675                                        optBool,
2676                                        "bvh_construction_use_initial_subdivision=",
2677                                        "false");
2678
2679        RegisterOption("BvHierarchy.Construction.Initial.minObjects",
2680                                        optInt,
2681                                        "bvh_construction_use_initial_min_objects=",
2682                                        "100000");
2683
2684        RegisterOption("BvHierarchy.Construction.Initial.minArea",
2685                                        optFloat,
2686                                        "bvh_construction_use_initial_min_area=",
2687                                        "0.0001");
2688
2689        RegisterOption("BvHierarchy.Construction.Initial.maxAreaRatio",
2690                                        optFloat,
2691                                        "bvh_construction_use_initial_max_area_ratio=",
2692                                        "0.9");
2693
2694        RegisterOption("BvHierarchy.minRaysForVisibility",
2695                                        optInt,
2696                                        "bvh_min_rays_for_vis=",
2697                                        "0");
2698
2699        RegisterOption("BvHierarchy.maxTests",
2700                                        optInt,
2701                                        "bvh_max_tests=",
2702                                        "50000");
2703
2704
2705        /*******************************************************************/
2706        /*               Hierarchy Manager related options                 */
2707        /*******************************************************************/
2708
2709        RegisterOption("Hierarchy.Construction.samples",
2710                                        optInt,
2711                                        "hierarchy_construction_samples=",
2712                                        "100000");
2713
2714        RegisterOption("Hierarchy.minRenderCost",
2715                                        optFloat,
2716                                        "hierarchy_minRenderCost=",
2717                                        "0");
2718
2719        RegisterOption("Hierarchy.subdivisionStats",
2720                           optString,
2721                                   "hierarchy_subdivision_stats=",
2722                                   "hierarchySubdivisionStats.log");
2723
2724        RegisterOption("Hierarchy.type",
2725                           optString,
2726                                   "hierarchy_type=",
2727                                   "bvh");
2728
2729        RegisterOption("Hierarchy.Termination.minGlobalCostRatio",
2730                                        optFloat,
2731                                        "hierarchy_term_min_global_cost_ratio=",
2732                                        "0.000000001");
2733
2734        RegisterOption("Hierarchy.Termination.globalCostMissTolerance",
2735                                        optInt,
2736                                        "hierarchy_term_global_cost_miss_tolerance=",
2737                                        "4");
2738
2739        RegisterOption("Hierarchy.Termination.maxLeaves",
2740                                        optInt,
2741                                        "hierarchy_term_max_leaves=",
2742                                        "1000");
2743       
2744        RegisterOption("Hierarchy.Construction.type",
2745                                        optInt,
2746                                        "hierarchy_construction_type=",
2747                                        "0");
2748
2749        RegisterOption("Hierarchy.Construction.minDepthForOsp",
2750                                        optInt,
2751                                        "hierarchy_construction_min_depth_for_osp=",
2752                                        "-1");
2753
2754        RegisterOption("Hierarchy.Construction.startWithObjectSpace",
2755                                        optBool,
2756                                        "hierarchy_construction_start_with_osp=",
2757                                        "true");
2758
2759        RegisterOption("Hierarchy.Construction.considerMemory",
2760                                        optBool,
2761                                        "hierarchy_construction_consider_memory=",
2762                                        "true");
2763
2764        RegisterOption("Hierarchy.Construction.repairQueue",
2765                                        optBool,
2766                                        "hierarchy_construction_repair_queue=",
2767                                        "true");
2768
2769        RegisterOption("Hierarchy.Construction.minDepthForVsp",
2770                                        optInt,
2771                                        "hierarchy_construction_min_depth_for_vsp=",
2772                                        "-1");
2773
2774        RegisterOption("Hierarchy.Termination.maxMemory",
2775                                        optFloat,
2776                                        "hierarchy_term_max_memory=",
2777                                        "1");
2778
2779        RegisterOption("Hierarchy.Termination.memoryConst",
2780                                        optFloat,
2781                                        "hierarchy_term_memory_const=",
2782                                        "1.0");
2783
2784        RegisterOption("Hierarchy.Construction.useMultiLevel",
2785                                        optBool,
2786                                        "hierarchy_construction_multilevel=",
2787                                        "false");
2788
2789        RegisterOption("Hierarchy.Construction.levels",
2790                                        optInt,
2791                                        "hierarchy_construction_levels=",
2792                                        "4");
2793
2794        RegisterOption("Hierarchy.Construction.maxRepairs",
2795                                        optInt,
2796                                        "hierarchy_construction_max_repairs=",
2797                                        "1000");
2798
2799        RegisterOption("Hierarchy.Construction.minStepsOfSameType",
2800                                        optInt,
2801                                        "hierarchy_construction_min_steps_same_type=",
2802                                        "200");
2803
2804        RegisterOption("Hierarchy.Construction.maxStepsOfSameType",
2805                                        optInt,
2806                                        "hierarchy_construction_max_steps_same_type=",
2807                                        "700");
2808
2809        RegisterOption("Hierarchy.Construction.recomputeSplitPlaneOnRepair",
2810                                        optBool,
2811                                        "hierarchy_construction_recompute_split_on_repair=",
2812                                        "true");
2813
2814        RegisterOption("Hierarchy.Construction.maxAvgRaysPerObject",
2815                                        optFloat,
2816                                        "hierarchy_construction_max_avg_rays_per_object=",
2817                                        "0");
2818       
2819        RegisterOption("Hierarchy.Construction.minAvgRaysPerObject",
2820                                        optFloat,
2821                                        "hierarchy_construction_min_avg_rays_per_object=",
2822                                        "0");
2823       
2824        RegisterOption("Hierarchy.useTraversalTree",
2825                                        optBool,
2826                                        "hierarchy_use_traversal_tree=",
2827                                        "false");
2828
2829        ///////////////////////////////////////////////////////
2830
2831         RegisterOption("TraversalTree.Termination.minCost",
2832                                 optInt,
2833                                 "kd_term_min_cost=",
2834                                 "1");
2835 
2836  RegisterOption("TraversalTree.Termination.maxNodes",
2837                                 optInt,
2838                                 "kd_term_max_nodes=",
2839                                 "200000");
2840 
2841  RegisterOption("TraversalTree.Termination.maxDepth",
2842                                 optInt,
2843                                 "kd_term_max_depth=",
2844                                 "20");
2845
2846  RegisterOption("TraversalTree.Termination.maxCostRatio",
2847                                 optFloat,
2848                                 "kd_term_max_cost_ratio=",
2849                                 "1.5");
2850
2851  RegisterOption("TraversalTree.Termination.ct_div_ci",
2852                                 optFloat,
2853                                 "kd_term_ct_div_ci=",
2854                                 "1.0");
2855
2856  RegisterOption("TraversalTree.splitMethod",
2857                                 optString,
2858                                 "kd_split_method=",
2859                                 "spatialMedian");
2860
2861  RegisterOption("TraversalTree.splitBorder",
2862                                 optFloat,
2863                                 "kd_split_border=",
2864                                 "0.1");
2865
2866  RegisterOption("TraversalTree.sahUseFaces",
2867                                 optBool,
2868                                 "kd_sah_use_faces=",
2869                                 "true");
2870
2871  /////////////////////////////////////////////////////////////////
2872  // By Vlastimil Havran
2873  RegisterOption("BSP.splitclip", optBool,
2874                 "kd_splitclip=", "false");
2875  RegisterOption("BSP.emptyCut", optBool,
2876                 "kd_emptycut=", "true");
2877  RegisterOption("BSP.termCrit", optString,
2878                 "kd_termcrit=", "auto");
2879  RegisterOption("BSP.maxDepthAllowed", optInt,
2880                 "kd_maxDepth=", "16");
2881  RegisterOption("BSP.maxEmptyCutDepth", optInt,
2882                 "kd_maxEmptyCutDepth=", "4");
2883  RegisterOption("BSP.absMaxAllowedDepth", optInt,
2884                 "kd_absMaxAllowedDepth=", "20");
2885  RegisterOption("BSP.maxListLength", optInt,
2886                 "kd_maxListLength=", "16");
2887  RegisterOption("BSP.useRadixSort", optBool,
2888                 "kd_useRadixSort=", "false");
2889  RegisterOption("BSP.printCuts", optBool,
2890                 "kd_printCuts=", "false");
2891  RegisterOption("BSP.algAutoTermination", optInt,
2892                 "kd_algAutoTermination=", "0");
2893  RegisterOption("BSP.axisSelectionAlg", optInt,
2894                 "kd_axisSelectAlg=", "0");
2895 
2896  RegisterOption("BSP.decisionCost", optFloat,
2897                 "kd_decCost=", "0.3");
2898  RegisterOption("BSP.intersectionCost", optFloat,
2899                 "kd_intersectCost=", "0.9");
2900  RegisterOption("BSP.traversalCost", optFloat,
2901                 "kd_travCost=", "0.2");
2902  RegisterOption("BSP.biasFreeCuts", optFloat,
2903                 "kd_biasFreeCuts=", "0.9");
2904
2905  RegisterOption("BSP.minBoxes.use", optBool,
2906                 "kd_minBoxesUse=", "false");
2907  RegisterOption("BSP.minBoxes.tight", optBool,
2908                 "kd_minBoxesTight=", "false");
2909  RegisterOption("BSP.minBoxes.minObjects", optInt,
2910                 "kd_minBoxesMinObjects=", "10");
2911  RegisterOption("BSP.minBoxes.minDepthDistance", optInt,
2912                 "kd_minBoxesMinDist=", "3");
2913  RegisterOption("BSP.minBoxes.minSA2ratio", optFloat,
2914                 "kd_minBoxesSA2ratio=", "1.0");
2915
2916  // The object used for testing
2917  RegisterOption("Rays.file",
2918                 optString,
2919                 "rays_filename=",
2920                 "data/fileRays_arena.txt");
2921  RegisterOption("Rays.cnt",
2922                 optInt,
2923                 "rays_cnt=", "100000");
2924 
2925  RegisterOption("TestDoubleRays", optBool,
2926                 "test_doublrays=", "false");
2927
2928  /////////////////////////////////////////////////////////////////
2929}
2930
2931void
2932Environment::SetStaticOptions()
2933{
2934 
2935  // get Global option values
2936  GetRealValue("Limits.threshold", Limits::Threshold);
2937  GetRealValue("Limits.small", Limits::Small);
2938  GetRealValue("Limits.infinity", Limits::Infinity);
2939
2940
2941}
2942
2943bool
2944Environment::Parse(const int argc, char **argv, bool useExePath)
2945{
2946  bool result = true;
2947  // Read the names of the scene, environment and output files
2948  ReadCmdlineParams(argc, argv, "");
2949
2950  char *envFilename = new char[128];
2951
2952  char filename[64];
2953
2954  // Get the environment file name
2955  if (!GetParam(' ', 0, filename)) {
2956    // user didn't specified environment file explicitly, so
2957    strcpy(filename, "default.env");
2958  }
2959
2960 
2961  if (useExePath) {
2962    char *path = GetPath(argv[0]);
2963    if (*path != 0)
2964      sprintf(envFilename, "%s/%s", path, filename);
2965    else
2966      strcpy(envFilename, filename);
2967   
2968    delete path;
2969  }
2970  else
2971    strcpy(envFilename, filename);
2972
2973 
2974  // Now it's time to read in environment file.
2975  if (!ReadEnvFile(envFilename)) {
2976    // error - bad input file name specified ?
2977    cerr<<"Error parsing environment file "<<envFilename<<endl;
2978        result = false;
2979  }
2980  delete [] envFilename;
2981
2982  // Parse the command line; options given on the command line subsume
2983  // stuff specified in the input environment file.
2984  ParseCmdline(argc, argv, 0);
2985
2986  SetStaticOptions();
2987
2988  // Check for request for help
2989  if (CheckForSwitch(argc, argv, '?')) {
2990    PrintUsage(cout);
2991    exit(0);
2992  }
2993 
2994  return true;
2995}
2996
2997}
Note: See TracBrowser for help on using the repository browser.