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

Revision 660, 53.3 KB checked in by mattausch, 18 years ago (diff)

adding function for testing purpose

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
22 
23Environment *environment = NULL;
24
25Environment::~Environment()
26{
27  int i, j;
28
29  // delete the params structure
30  for (i = 0; i < numParams; i++) {
31    for (j = 0; j < paramRows; j++)
32      if (params[i][j] != NULL)
33        delete[] params[i][j];
34    if (params[i] != NULL)
35      delete[] params[i];
36  }
37
38  if (params != NULL)
39    delete[] params;
40 
41  // delete the options structure
42  if (options != NULL)
43    delete[] options;
44 
45  if (optionalParams != NULL)
46    delete optionalParams;
47}
48
49bool
50Environment::CheckForSwitch(const int argc,
51                                                        char **argv,
52                                                        const char swtch) const
53{
54  for (int i = 1; i < argc; i++)
55    if ((argv[i][0] == '-') && (argv[i][1] == swtch))
56      return true;
57  return false;
58}
59
60bool
61Environment::CheckType(const char *value,
62                        const EOptType type) const
63{
64  char *s, *t, *u;
65
66  switch (type) {
67    case optInt: {
68      strtol(value, &t, 10);
69      if (value + strlen(value) != t)
70        return false;
71      else
72        return true;
73    }
74    case optFloat: {
75      strtod(value, &t);
76      if (value + strlen(value) != t)
77        return false;
78      else
79        return true;
80    }
81    case optBool: {
82      if (!strcasecmp(value, "true") ||
83          !strcasecmp(value, "false") ||
84          !strcasecmp(value, "YES") ||
85          !strcasecmp(value, "NO") ||
86          !strcmp(value, "+") ||
87          !strcmp(value, "-") ||
88          !strcasecmp(value, "ON") ||
89          !strcasecmp(value, "OFF"))
90        return true;
91      return false;
92    }
93    case optVector:{
94      strtod(value, &s);
95      if (*s == ' ' || *s == '\t') {
96        while (*s == ' ' || *s == '\t')
97          s++;
98        if (*s != ',')
99          s--;
100      }
101      if ((*s != ',' && *s != ' ' && *s != '\t') || value == s)
102        return false;
103      t = s;
104      strtod(s + 1, &u);
105      if (*u == ' ' || *u == '\t') {
106        while (*u == ' ' || *u == '\t')
107          u++;
108        if (*u != ',')
109          u--;
110      }
111      if ((*u != ',' && *s != ' ' && *s != '\t') || t == u)
112        return false;
113      t = u;
114      strtod(u + 1, &s);
115      if (t == s || value + strlen(value) != s)
116        return false;
117      return true;
118    }
119    case optString: {
120      return true;
121    }
122    default: {
123      Debug << "Internal error: Unknown type of option.\n" << flush;
124      exit(1);
125    }
126  }
127  return false;
128}
129
130void
131Environment::ReadCmdlineParams(const int argc,
132                                                           char **argv,
133                                                           const char *optParams)
134{
135  int i;
136
137  // Make sure we are called for the first time
138  if (optionalParams != NULL)
139    return;
140
141  numParams = (int)strlen(optParams) + 1;
142  optionalParams = new char[numParams];
143  strcpy(optionalParams, optParams);
144
145  // First, count all non-optional parameters on the command line
146  for (i = 1; i < argc; i++)
147    if (argv[i][0] != '-')
148      paramRows++;
149
150  // if there is no non-optional parameter add a default one...
151  if (paramRows == 0)
152    paramRows = 1;
153 
154  // allocate and initialize the table for parameters
155  params = new char **[numParams];
156  for (i = 0; i < numParams; i++) {
157    params[i] = new char *[paramRows];
158    for (int j = 0; j < paramRows; j++)
159      params[i][j] = NULL;
160  }
161  // Now read all non-optional and optional parameters into the table
162  curRow = -1;
163  for (i = 1; i < argc; i++) {
164    if (argv[i][0] != '-') {
165      // non-optional parameter encountered
166      curRow++;
167      params[0][curRow] = new char[strlen(argv[i]) + 1];
168      strcpy(params[0][curRow], argv[i]);
169    }
170    else {
171      // option encountered
172      char *t = strchr(optionalParams, argv[i][1]);
173      if (t != NULL) {
174        // this option is optional parameter
175        int index = t - optionalParams + 1;
176        if (curRow < 0) {
177          // it's a global parameter
178          for (int j = 0; j < paramRows; j++) {
179            params[index][j] = new char[strlen(argv[i] + 2) + 1];
180            strcpy(params[index][j], argv[i] + 2);
181          }
182        }
183        else {
184          // it's a scene parameter
185          if (params[index][curRow] != NULL) {
186            delete[] params[index][curRow];
187          }
188          params[index][curRow] = new char[strlen(argv[i] + 2) + 1];
189          strcpy(params[index][curRow], argv[i] + 2);
190        }
191      }
192    }
193  }
194  curRow = 0;
195
196#ifdef _DEBUG_PARAMS
197  // write out the parameter table
198  cerr << "Parameter table for " << numParams << " columns and "
199       << paramRows << " rows:\n";
200  for (int j = 0; j < paramRows; j++) {
201    for (i = 0; i < numParams; i++) {
202      if (params[i][j] != NULL)
203        cerr << params[i][j];
204      else
205        cerr << "NULL";
206      cerr << "\t";
207    }
208    cerr << "\n";
209  }
210  cerr << "Params done.\n" << flush;
211#endif // _DEBUG_PARAMS
212}
213
214bool
215Environment::GetParam(const char name,
216                       const int index,
217                       char *value) const
218{
219  int column;
220
221  if (index >= paramRows || index < 0)
222    return false;
223  if (name == ' ')
224    column = 0;
225  else {
226    char *t = strchr(optionalParams, name);
227
228    if (t == NULL)
229      return false;
230    column = t - optionalParams + 1;
231  }
232
233  if (params[column][index] == NULL)
234    return false;
235  //  value = new char[strlen(params[column][index]) + 1];
236  strcpy(value, params[column][index]);
237  return true;
238}
239
240void
241Environment::RegisterOption(const char *name,
242                             const EOptType type,
243                             const char *abbrev,
244                             const char *defValue)
245{
246  int i;
247
248  // make sure this option was not yet registered
249  for (i = 0; i < numOptions; i++)
250    if (!strcmp(name, options[i].name)) {
251      Debug << "Error: Option " << name << " registered twice.\n";
252      exit(1);
253    }
254  // make sure we have enough room in memory
255  if (numOptions >= maxOptions) {
256    Debug << "Error: Too many options. Try enlarge the maxOptions "
257          << "definition.\n";
258    exit(1);
259  }
260
261  // make sure the abbreviation doesn't start with 'D'
262  if (abbrev != NULL && (abbrev[0] == 'D' )) {
263    Debug << "Internal error: reserved switch " << abbrev
264         << " used as an abbreviation.\n";
265    exit(1);
266  }
267  // new option
268  options[numOptions].type = type;
269  options[numOptions].name = strdup(name);
270  // assign abbreviation, if requested
271  if (abbrev != NULL) {
272    options[numOptions].abbrev = strdup(abbrev);
273  }
274  // assign default value, if requested
275  if (defValue != NULL) {
276    options[numOptions].defaultValue = strdup(defValue);
277    if (!CheckType(defValue, type)) {
278      Debug << "Internal error: Inconsistent type and default value in option "
279           << name << ".\n";
280      exit(1);
281    }
282  }
283  // new option registered
284  numOptions++;
285}
286
287bool
288Environment::OptionPresent(const char *name) const
289{
290  bool found = false;
291  int i;
292
293  for (i = 0; i < numOptions; i++)
294    if (!strcmp(options[i].name, name)) {
295      found = true;
296      break;
297    }
298  if (!found) {
299    Debug << "Internal error: Option " << name << " not registered.\n" << flush;
300    exit(1);
301  }
302  if (options[i].value != NULL || options[i].defaultValue != NULL)
303    return true;
304  else
305    return false;
306}
307
308int
309Environment::FindOption(const char *name,
310                        const bool isFatal) const
311{
312  int i;
313  bool found = false;
314  // is this option registered ?
315  for (i = 0; i < numOptions; i++)
316    if (!strcmp(options[i].name, name)) {
317      found = true;
318      break;
319    }
320  if (!found) {
321    // no registration found
322    Debug << "Internal error: Required option " << name
323          << " not registered.\n" << flush;
324    exit(1);
325  }
326  if (options[i].value == NULL && options[i].defaultValue == NULL)
327    // this option was not initialised to some value
328    if (isFatal) {
329      Debug << "Error: Required option " << name << " not found.\n" << flush;
330      exit(1);
331    }
332    else {
333      Debug << "Error: Required option " << name << " not found.\n" << flush;
334      return -1;
335    }
336  return i;
337}
338
339bool
340Environment::GetIntValue(const char *name,
341                         int &value,
342                         const bool isFatal) const
343{
344  int i = FindOption(name, isFatal);
345
346  if (i<0)
347    return false;
348
349  if (options[i].value != NULL) {
350    // option was explicitly specified
351    value = strtol(options[i].value, NULL, 10);
352  } else {
353    // option was not read, so use the default
354    value = strtol(options[i].defaultValue, NULL, 10);
355  }
356
357  return true;
358}
359
360bool
361Environment::GetDoubleValue(const char *name,
362                            double &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 = strtod(options[i].value, NULL);
373  } else {
374    // option was not read, so use the default
375    value = strtod(options[i].defaultValue, NULL);
376  }
377  return true;
378}
379
380bool
381Environment::GetRealValue(const char *name,
382                          Real &value,
383                          const bool isFatal) const
384{
385  int i = FindOption(name, isFatal);
386 
387  if (i<0)
388    return false;
389
390  if (options[i].value != NULL) {
391    // option was explicitly specified
392    value = (Real)strtod(options[i].value, NULL);
393  } else {
394    // option was not read, so use the default
395    value = (Real)strtod(options[i].defaultValue, NULL);
396  }
397  return true;
398}
399
400bool
401Environment::GetFloatValue(const char *name,
402                           float &value,
403                           const bool isFatal) const
404{
405  int i = FindOption(name, isFatal);
406
407  if (i<0)
408    return false;
409
410  if (options[i].value != NULL) {
411    // option was explicitly specified
412    value = (float)strtod(options[i].value, NULL);
413  } else {
414    // option was not read, so use the default
415    value = (float)strtod(options[i].defaultValue, NULL);
416  }
417  return true;
418}
419
420bool
421Environment::GetBool(const char *name,
422                     const bool isFatal) const
423{
424  bool ret;
425  if (GetBoolValue(name, ret, isFatal))
426    return ret;
427  else
428    return false;
429}
430
431bool
432Environment::ParseBool(const char *name) const
433{
434
435  bool value = true;
436 
437  if (!strcasecmp(name, "false") ||
438      !strcasecmp(name, "NO") ||
439      !strcmp(name, "-") ||
440      !strcasecmp(name, "OFF"))
441    value = false;
442 
443  return value;
444}
445
446void
447Environment::ParseVector(const char *name, Vector3 &v) const
448{
449  // option was not read, so use the default
450  char *s, *t;
451 
452  v.x = (Real)strtod(name, &s);
453  v.y = (Real)strtod(s + 1, &t);
454  v.z = (Real)strtod(t + 1, NULL);
455
456}
457
458bool
459Environment::GetBoolValue(const char *name,
460                           bool &value,
461                           const bool isFatal) const
462{
463  int i = FindOption(name, isFatal);
464
465  if (i<0)
466    return false;
467
468 
469  if (options[i].value != NULL)
470    value = ParseBool(options[i].value);
471  else
472    value = ParseBool(options[i].defaultValue);
473
474  return true;
475}
476
477bool
478Environment::GetVectorValue(const char *name,
479                            Vector3 &v,
480                            const bool isFatal) const
481{
482  int i = FindOption(name, isFatal);
483  if (i<0)
484    return false;
485
486  if (options[i].value != NULL)
487
488   
489  if (options[i].value != NULL) {
490    ParseVector(options[i].value, v);
491  }
492  else {
493    ParseVector(options[i].defaultValue, v);
494  }
495  return true;
496}
497
498bool
499Environment::GetStringValue(const char *name,
500                            char *value,
501                            const bool isFatal) const
502{
503  int i = FindOption(name, isFatal);
504
505  if (i<0)
506    return false;
507
508 
509  if (options[i].value != NULL) {
510    // option was not read, so use the default
511    strcpy(value, options[i].value);
512  }
513  else {
514    // option was explicitly specified
515    strcpy(value, options[i].defaultValue);
516  }
517  return true;
518}
519
520void
521Environment::SetInt(const char *name, const int value)
522{
523
524  int i = FindOption(name);
525  if (i<0)
526    return;
527
528  if (options[i].type == optInt) {
529    delete options[i].value;
530    options[i].value = new char[16];
531    sprintf(options[i].value, "%.15d", value);
532  }
533  else {
534    Debug << "Internal error: Trying to set non-integer option " << name
535          << " to integral value.\n" << flush;
536    exit(1);
537  }
538}
539
540void
541Environment::SetFloat(const char *name, const Real value)
542{
543  int i = FindOption(name);
544  if (i<0)
545    return;
546
547  if (options[i].type == optFloat) {
548    delete options[i].value;
549    options[i].value = new char[25];
550    sprintf(options[i].value, "%.15e", value);
551  }
552  else {
553    Debug << "Internal error: Trying to set non-Real option " << name
554          << " to Real value.\n" << flush;
555    exit(1);
556  }
557}
558
559void
560Environment::SetBool(const char *name, const bool value)
561{
562  int i = FindOption(name);
563  if (i<0)
564    return;
565
566  if (options[i].type == optBool) {
567    delete options[i].value;
568    options[i].value = new char[6];
569    if (value)
570      sprintf(options[i].value, "true");
571    else
572      sprintf(options[i].value, "false");
573  }
574  else {
575    Debug << "Internal error: Trying to set non-bool option " << name
576          << " to boolean value.\n" << flush;
577    exit(1);
578  }
579}
580
581void
582Environment::SetVector(const char *name,
583                       const Vector3 &v)
584{
585  int i = FindOption(name);
586  if (i<0)
587    return;
588
589  if (options[i].type == optVector) {
590    delete options[i].value;
591    options[i].value = new char[128];
592    sprintf(options[i].value, "%.15e,%.15e,%.15e", v.x, v.y, v.z);
593  }
594  else {
595    Debug << "Internal error: Trying to set non-vector option " << name
596          << " to vector value.\n" << flush;
597    exit(1);
598  }
599}
600
601void
602Environment::SetString(const char *name, const char *value)
603{
604  int i = FindOption(name);
605  if (i<0)
606    return;
607
608  if (options[i].type == optString) {
609    delete options[i].value;
610    options[i].value = strdup(value);
611  }
612  else {
613    Debug << "Internal error: Trying to set non-string option " << name
614          << " to string value.\n" << flush;
615    exit(1);
616  }
617}
618
619void
620Environment::ParseCmdline(const int argc,
621                                                  char **argv,
622                                                  const int index)
623{
624  int curIndex = -1;
625
626  for (int i = 1; i < argc; i++) {
627    // if this parameter is non-optional, skip it and increment the counter
628    if (argv[i][0] != '-') {
629      curIndex++;
630      continue;
631    }
632    // make sure to skip all non-optional parameters
633    char *t = strchr(optionalParams, argv[i][1]);
634    if (t != NULL)
635      continue;
636
637    // if we are in the scope of the current parameter, parse it
638    if (curIndex == -1 || curIndex == index) {
639      if (argv[i][1] == 'D') {
640        // it's a full name definition
641        bool found = false;
642        int j;
643
644        char *t = strchr(argv[i] + 2, '=');
645        if (t == NULL) {
646          Debug << "Error: Missing '=' in option. "
647                << "Syntax is -D<name>=<value>.\n" << flush;
648          exit(1);
649        }
650        for (j = 0; j < numOptions; j++)
651          if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) &&
652              (unsigned)(t - argv[i] - 2) == strlen(options[j].name)) {
653            found = true;
654            break;
655          }
656        if (!found) {
657          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
658          //  exit(1);
659        }
660        if (found) {
661          if (!CheckType(t + 1, options[j].type)) {
662            Debug << "Error: invalid type of value " << t + 1 << " in option "
663                  << options[j].name << ".\n";
664            exit(1);
665          }
666          if (options[j].value != NULL)
667            delete options[j].value;
668          options[j].value = strdup(t + 1);
669        }
670      }
671      else {
672        // it's an abbreviation
673        bool found = false;
674        int j;
675       
676        for (j = 0; j < numOptions; j++)
677          if (options[j].abbrev != NULL &&
678              !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev))) {
679            found = true;
680            break;
681          }
682        if (!found) {
683          Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
684          //          exit(1);
685        }
686        if (found) {
687          if (!CheckType(argv[i] + 1 + strlen(options[j].abbrev), options[j].type)) {
688            Debug << "Error: invalid type of value "
689                  << argv[i] + 1 + strlen(options[j].abbrev) << "in option "
690                  << options[j].name << ".\n";
691            exit(1);
692          }
693          if (options[j].value != NULL)
694            delete options[j].value;
695          options[j].value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
696        }
697      }
698    }
699  }
700#ifdef _DEBUG_PARAMS
701  // write out the options table
702  cerr << "Options table for " << numOptions << " options:\n";
703  for (int j = 0; j < numOptions; j++) {
704    cerr << options[j];
705    cerr << "\n";
706  }
707  cerr << "Options done.\n" << flush;
708#endif // _DEBUG_PARAMS
709}
710
711
712char *
713Environment::ParseString(char *buffer, char *string) const
714{
715  char *s = buffer;
716  char *t = string + strlen(string);
717
718  // skip leading whitespaces
719  while (*s == ' ' || *s == '\t')
720    s++;
721  if (*s == '\0')
722    return NULL;
723  while ((*s >= 'a' && *s <= 'z') ||
724         (*s >= 'A' && *s <= 'Z') ||
725         (*s >= '0' && *s <= '9') ||
726         *s == '_')
727    *t++ = *s++;
728  *t = '\0';
729  // skip trailing whitespaces
730  while (*s == ' ' || *s == '\t')
731    s++;
732  return s;
733}
734
735const char code[] = "JIDHipewhfdhyd74387hHO&{WK:DOKQEIDKJPQ*H#@USX:#FWCQ*EJMQAHPQP(@G#RD";
736
737void
738Environment::DecodeString(char *buff, int max)
739{
740  buff[max] = 0;
741  char *p = buff;
742  const char *cp = code;
743  for (; *p; p++) {
744    if (*p != '\n')
745      *p = *p ^ *cp;
746    ++cp;
747    if (*cp == 0)
748      cp = code;
749  }
750}
751
752void
753Environment::CodeString(char *buff, int max)
754{
755  buff[max] = 0;
756  char *p = buff;
757  const char *cp = code;
758  for (; *p; p++) {
759    if (*p != '\n')
760      *p = *p ^ *cp;
761    ++cp;
762    if (*cp == 0)
763      cp = code;
764  }
765}
766
767void
768Environment::SaveCodedFile(char *filenameText,
769                            char *filenameCoded)
770{
771  ifstream envStream(filenameText);
772 
773  // some error had occured
774  if (envStream.fail()) {
775    cerr << "Error: Can't open file " << filenameText << " for reading (err. "
776         << envStream.rdstate() << ").\n";
777    return;
778  }
779  char buff[256];
780  envStream.getline(buff, 255);
781  buff[8] = 0;
782  if (strcmp(buff, "CGX_CF10") == 0)
783    return;
784
785  ofstream cStream(filenameCoded);
786  cStream<<"CGX_CF10";
787 
788  // main loop
789  for (;;) {
790    // read in one line
791    envStream.getline(buff, 255);
792    if (!envStream)
793      break;
794    CodeString(buff, 255);
795    cStream<<buff;
796  }
797 
798}
799
800bool
801Environment::ReadEnvFile(const char *envFilename)
802{
803  char buff[MaxStringLength], name[MaxStringLength];
804  char *s, *t;
805  int i, line = 0;
806  bool found;
807  igzstream envStream(envFilename);
808
809  // some error had occured
810  if (envStream.fail()) {
811    cerr << "Error: Can't open file " << envFilename << " for reading (err. "
812         << envStream.rdstate() << ").\n";
813    return false;
814  }
815 
816  name[0] = '\0';
817
818//    bool coded;
819//    envStream.getline(buff, 255);
820//    buff[8] = 0;
821//    if (strcmp(buff, "CGX_CF10") == 0)
822//      coded = true;
823//    else {
824//      coded = false;
825//      envStream.Rewind();
826//    }
827 
828  // main loop
829  for (;;) {
830    // read in one line
831    envStream.getline(buff, 255);
832   
833    if (!envStream)
834      break;
835
836//      if (coded)
837//        DecodeString(buff, 255);
838
839    line++;
840    // get rid of comments
841    s = strchr(buff, '#');
842    if (s != NULL)
843      *s = '\0';
844
845    // get one identifier
846    s = ParseString(buff, name);
847    // parse line
848    while (s != NULL) {
849      // it's a group name - make the full name
850      if (*s == '{') {
851        strcat(name, ".");
852        s++;
853        s = ParseString(s, name);
854        continue;
855      }
856      // end of group
857      if (*s == '}') {
858        if (strlen(name) == 0) {
859          cerr << "Error: unpaired } in " << envFilename << " (line "
860               << line << ").\n";
861          envStream.close();
862          return false;
863        }
864        name[strlen(name) - 1] = '\0';
865        t = strrchr(name, '.');
866        if (t == NULL)
867          name[0] = '\0';
868        else
869          *(t + 1) = '\0';
870        s++;
871        s = ParseString(s, name);
872        continue;
873      }
874      // find variable name in the table
875      found = false;
876      for (i = 0; i < numOptions; i++)
877        if (!strcmp(name, options[i].name)) {
878          found = true;
879          break;
880        }
881      if (!found) {
882        cerr << "Warning: unknown option " << name << " in environment file "
883             << envFilename << " (line " << line << ").\n";
884      } else
885        switch (options[i].type) {
886        case optInt: {
887          strtol(s, &t, 10);
888          if (t == s || (*t != ' ' && *t != '\t' &&
889                         *t != '\0' && *t != '}')) {
890            cerr << "Error: Mismatch in int variable " << name << " in "
891                 << "environment file " << envFilename << " (line "
892                 << line << ").\n";
893            envStream.close();
894            return false;
895          }
896          if (options[i].value != NULL)
897            delete options[i].value;
898          options[i].value = new char[t - s + 1];
899          strncpy(options[i].value, s, t - s);
900          options[i].value[t - s] = '\0';
901          s = t;
902          break;
903        }
904        case optFloat: {
905          strtod(s, &t);
906          if (t == s || (*t != ' ' && *t != '\t' &&
907                         *t != '\0' && *t != '}')) {
908            cerr << "Error: Mismatch in Real variable " << name << " in "
909                 << "environment file " << envFilename << " (line "
910                 << line << ").\n";
911            envStream.close();
912            return false;
913          }
914          if (options[i].value != NULL)
915            delete options[i].value;
916          options[i].value = new char[t - s + 1];
917          strncpy(options[i].value, s, t - s);
918          options[i].value[t - s] = '\0';
919          s = t;
920          break;
921        }
922        case optBool: {
923          t = s;
924          while ((*t >= 'a' && *t <= 'z') ||
925                 (*t >= 'A' && *t <= 'Z') ||
926                 *t == '+' || *t == '-')
927            t++;
928          if (((!strncasecmp(s, "true", t - s)  && t - s == 4) ||
929               (!strncasecmp(s, "false", t - s) && t - s == 5) ||
930               (!strncasecmp(s, "YES", t -s)    && t - s == 3) ||
931               (!strncasecmp(s, "NO", t - s)    && t - s == 2) ||
932               (!strncasecmp(s, "ON", t - s)    && t - s == 2) ||
933               (!strncasecmp(s, "OFF", t - s)   && t - s == 3) ||
934               (t - s == 1 && (*s == '+' || *s == '-'))) &&
935              (*t == ' ' || *t == '\t' || *t == '\0' || *t == '}')) {
936            if (options[i].value != NULL)
937              delete options[i].value;
938            options[i].value = new char[t - s + 1];
939            strncpy(options[i].value, s, t - s);
940            options[i].value[t - s] = '\0';
941            s = t;
942          }
943          else {
944            cerr << "Error: Mismatch in bool variable " << name << " in "
945                 << "environment file " << envFilename << " (line "
946                 << line << ").\n";
947            envStream.close();
948            return false;
949          }
950          break;
951        }
952        case optVector:{
953          strtod(s, &t);
954          if (*t == ' ' || *t == '\t') {
955            while (*t == ' ' || *t == '\t')
956              t++;
957            if (*t != ',')
958              t--;
959          }
960          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
961            cerr << "Error: Mismatch in vector variable " << name << " in "
962                 << "environment file " << envFilename << " (line "
963                 << line << ").\n";
964            envStream.close();
965            return false;
966          }
967          char *u;
968          strtod(t, &u);
969          t = u;
970          if (*t == ' ' || *t == '\t') {
971            while (*t == ' ' || *t == '\t')
972              t++;
973            if (*t != ',')
974              t--;
975          }
976          if (t == s || (*t != ' ' && *t != '\t' && *t != ',')) {
977            cerr << "Error: Mismatch in vector variable " << name << " in "
978                 << "environment file " << envFilename << " (line "
979                 << line << ").\n";
980            envStream.close();
981            return false;
982          }
983          strtod(t, &u);
984          t = u;
985          if (t == s || (*t != ' ' && *t != '\t' &&
986                         *t != '\0' && *t != '}')) {
987            cerr << "Error: Mismatch in vector variable " << name << " in "
988                 << "environment file " << envFilename << " (line "
989                 << line << ").\n";
990            envStream.close();
991            return false;
992          }
993          if (options[i].value != NULL)
994            delete options[i].value;
995          options[i].value = new char[t - s + 1];
996          strncpy(options[i].value, s, t - s);
997          options[i].value[t - s] = '\0';
998          s = t;
999          break;
1000        }
1001        case optString: {
1002          if (options[i].value != NULL)
1003            delete options[i].value;
1004          options[i].value = new char[strlen(s) + 1];
1005          strcpy(options[i].value, s);
1006          s += strlen(s);
1007          break;
1008        }
1009        default: {
1010          Debug << "Internal error: Unknown type of option.\n" << flush;
1011          exit(1);
1012        }
1013      }
1014      // prepare the variable name for next pass
1015      t = strrchr(name, '.');
1016      if (t == NULL)
1017        name[0] = '\0';
1018      else
1019        *(t + 1) = '\0';
1020      // get next identifier
1021      s = ParseString(s, name);
1022    }
1023  }
1024  envStream.close();
1025  return true;
1026}
1027
1028void
1029Environment::PrintUsage(ostream &s) const
1030{
1031  // Print out all environment variable names
1032  s << "Registered options:\n";
1033  for (int j = 0; j < numOptions; j++)
1034    s << options[j] << "\n";
1035  s << flush;
1036}
1037
1038
1039Environment::Environment()
1040{
1041  optionalParams = NULL;
1042  paramRows = 0;
1043  numParams = 0;
1044  params = NULL;
1045  maxOptions = 500;
1046
1047 
1048// this is maximal nuber of options.
1049  numOptions = 0;
1050
1051  options = new COption[maxOptions];
1052
1053  if (options == NULL ) {
1054    Debug << "Error: Memory allocation failed.\n";
1055    exit(1);
1056  }
1057 
1058  // register all basic options
1059
1060  RegisterOption("Limits.threshold", optFloat, NULL, "0.01");
1061  RegisterOption("Limits.small", optFloat, NULL, "1e-6");
1062  RegisterOption("Limits.infinity", optFloat, NULL, "1e6");
1063
1064
1065  RegisterOption("Scene.filename",
1066                                 optString,
1067                                 "scene_filename=",
1068                                 "atlanta2.x3d");
1069
1070  RegisterOption("Unigraphics.meshGrouping",
1071                                 optInt,
1072                                 "unigraphics_mesh_grouping=",
1073                                 "0");
1074 
1075
1076  RegisterOption("KdTree.Termination.minCost",
1077                                 optInt,
1078                                 "kd_term_min_cost=",
1079                                 "10");
1080 
1081  RegisterOption("KdTree.Termination.maxDepth",
1082                                 optInt,
1083                                 "kd_term_max_depth=",
1084                                 "20");
1085
1086  RegisterOption("KdTree.Termination.maxCostRatio",
1087                                 optFloat,
1088                                 "kd_term_max_cost_ratio=",
1089                                 "1.5");
1090
1091  RegisterOption("KdTree.Termination.ct_div_ci",
1092                                 optFloat,
1093                                 "kd_term_ct_div_ci=",
1094                                 "1.0");
1095
1096  RegisterOption("KdTree.splitMethod",
1097                                 optString,
1098                                 "kd_split_method=",
1099                                 "spatialMedian");
1100
1101  RegisterOption("KdTree.splitBorder",
1102                 optFloat,
1103                 "kd_split_border=",
1104                 "0.1");
1105
1106  RegisterOption("KdTree.sahUseFaces",
1107                 optBool,
1108                 "kd_sah_use_faces=",
1109                 "true");
1110
1111
1112  RegisterOption("MeshKdTree.Termination.minCost",
1113                 optInt,
1114                 "kd_term_min_cost=",
1115                 "10");
1116 
1117  RegisterOption("MeshKdTree.Termination.maxDepth",
1118                 optInt,
1119                 "kd_term_max_depth=",
1120                 "20");
1121
1122  RegisterOption("MeshKdTree.Termination.maxCostRatio",
1123                 optFloat,
1124                 "kd_term_max_cost_ratio=",
1125                 "1.5");
1126
1127  RegisterOption("MeshKdTree.Termination.ct_div_ci",
1128                 optFloat,
1129                 "kd_term_ct_div_ci=",
1130                 "1.0");
1131
1132  RegisterOption("MeshKdTree.splitMethod",
1133                 optString,
1134                 "kd_split_method=",
1135                 "spatialMedian");
1136
1137  RegisterOption("MeshKdTree.splitBorder",
1138                 optFloat,
1139                 "kd_split_border=",
1140                 "0.1");
1141
1142  RegisterOption("SamplingPreprocessor.totalSamples",
1143                 optInt,
1144                 "total_samples=",
1145                 "1000000");
1146
1147  RegisterOption("SamplingPreprocessor.samplesPerPass",
1148                 optInt,
1149                 "samples_per_pass=",
1150                 "10");
1151
1152  RegisterOption("VssPreprocessor.initialSamples",
1153                                 optInt,
1154                                 "initial_samples=",
1155                                 "100000");
1156 
1157  RegisterOption("VssPreprocessor.testBeamSampling", optBool, "beam_sampling", "false");
1158
1159  RegisterOption("VssPreprocessor.vssSamples",
1160                                 optInt,
1161                                 "vss_samples=",
1162                                 "1000000");
1163       
1164  RegisterOption("VssPreprocessor.vssSamplesPerPass",
1165                                 optInt,
1166                                 "vss_samples_per_pass=",
1167                                 "1000");
1168 
1169  RegisterOption("VssPreprocessor.samplesPerPass",
1170                                 optInt,
1171                                 "samples_per_pass=",
1172                                 "100000");
1173
1174
1175
1176  RegisterOption("VssPreprocessor.useImportanceSampling",
1177                                 optBool,
1178                                 "vss_use_importance=",
1179                                 "true");
1180
1181   RegisterOption("VssPreprocessor.loadInitialSamples",
1182          optBool,
1183          "-vss_load_loadInitialSamples=",
1184          "false");
1185
1186   RegisterOption("VssPreprocessor.storeInitialSamples",
1187          optBool,
1188          "-vss_store_storedInitialSamples=",
1189          "false");
1190   
1191
1192    RegisterOption("VssPreprocessor.useViewSpaceBox",
1193          optBool,
1194          "-vss_use_viewspace_box=",
1195          "false");
1196   
1197
1198  /************************************************************************************/
1199  /*                         View cells related options                               */
1200  /************************************************************************************/
1201
1202
1203        RegisterOption("ViewCells.type",
1204                        optString,
1205                        "view_cells_type",
1206                        "bspTree");
1207
1208        RegisterOption("ViewCells.stats",
1209                                        optString,
1210                                        "view_cells_stats=",
1211                                        "viewCellsStats.log");
1212
1213        RegisterOption("ViewCells.PostProcess.statsPrefix",
1214                                        optString,
1215                                        "view_cells_stats_prefix=",
1216                                        "viewCells");
1217
1218
1219        RegisterOption("ViewCells.active",
1220                                        optInt,
1221                                        "1000");
1222       
1223        RegisterOption("ViewCells.active",
1224                                        optInt,
1225                                        "1000");
1226
1227        RegisterOption("ViewCells.Construction.samples",
1228                                        optInt,
1229                                        "view_cells_construction_samples=",
1230                                        "5000000");
1231
1232        RegisterOption("ViewCells.Evaluation.samples",
1233                                        optInt,
1234                                        "view_cells_evaluation_samples=",
1235                                        "8000000");
1236
1237        RegisterOption("ViewCells.Evaluation.samplesPerPass",
1238                                        optInt,
1239                                        "view_cells_evaluation_samples_per_oass=",
1240                                        "300000");
1241
1242        RegisterOption("ViewCells.Construction.samplesPerPass",
1243                                        optInt,
1244                                        "view_cells_construction_samples_per_pass=",
1245                                        "500000");
1246
1247        RegisterOption("ViewCells.PostProcess.samples",
1248                                        optInt,
1249                                        "view_cells_postprocess_samples=",
1250                                        "200000");
1251
1252        RegisterOption("ViewCells.Visualization.samples",
1253                                        optInt,
1254                                        "view_cells_visualization_samples=",
1255                                        "20000");
1256
1257        RegisterOption("ViewCells.loadFromFile",
1258                                        optBool,
1259                                        "view_cells_load_from_file",
1260                                        "false");
1261
1262        RegisterOption("ViewCells.PostProcess.refine",
1263                                        optBool,
1264                                        "view_cells_refine",
1265                                        "false");
1266
1267
1268        RegisterOption("ViewCells.PostProcess.compress",
1269                                        optBool,
1270                                        "view_cells_compress",
1271                                        "false");
1272
1273        RegisterOption("ViewCells.exportToFile",
1274                                        optBool,
1275                                        "view_cells_export_to_file",
1276                                        "false");
1277
1278        RegisterOption("ViewCells.maxViewCells",
1279                        optInt,
1280                        "view_cells_max_view_cells=",
1281                        "0");
1282
1283        RegisterOption("ViewCells.maxPvsRatio",
1284                                        optFloat,
1285                                        "view_cells_max_pvs_ratio=",
1286                                        "0.1");
1287
1288        RegisterOption("ViewCells.filename",
1289                        optString,
1290                        "view_cells_filename=",
1291                        "atlanta_viewcells_large.x3d");
1292
1293        RegisterOption("ViewCells.height",
1294                        optFloat,
1295                        "view_cells_height=",
1296                        "5.0");
1297
1298        RegisterOption("ViewCells.Visualization.colorCode",
1299                optString,
1300                "-view_cells_visualization_color_code",
1301                "PVS");
1302
1303        RegisterOption("ViewCells.Visualization.exportRays",
1304                optBool,
1305                "-view_cells_delayed_construction",
1306                "false");
1307       
1308
1309        RegisterOption("ViewCells.Visualization.exportGeometry",
1310                optBool,
1311                "-view_cells_visualization_export_geometry",
1312                "false");
1313
1314        RegisterOption("ViewCells.pruneEmptyViewCells",
1315                optBool,
1316                "-view_cells_prune_empty_view_cells",
1317                "false");
1318
1319        RegisterOption("ViewCells.processOnlyValidViewCells",
1320                optBool,
1321                "-view_cells_process_only_valid_view_cells",
1322                "false");
1323
1324       
1325        RegisterOption("ViewCells.PostProcess.maxCostRatio",
1326                        optFloat,
1327                        "-view_cells_post_process_max_cost_ratio=",
1328                        "0.9");
1329       
1330        RegisterOption("ViewCells.PostProcess.renderCostWeight",
1331                        optFloat,
1332                        "-view_cells_post_process_render_cost_weight",
1333                        "0.5");
1334       
1335        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation",
1336                        optFloat,
1337                        "-vsp_bsp_avgcost_max_deviations",
1338                        "0.5");
1339
1340        RegisterOption("ViewCells.PostProcess.maxMergesPerPass",
1341                optInt,
1342                "vsp_bsp_term_max_merges_per_pass=",
1343                "500");
1344
1345        RegisterOption("ViewCells.PostProcess.minViewCells",
1346                optInt,
1347                "vsp_bsp_term_post_process_min_view_cells=",
1348                "1000");
1349
1350        RegisterOption("ViewCells.PostProcess.useRaysForMerge",
1351                optBool,
1352                "view_cells_post_process_use_rays_for_merge=",
1353                "false");
1354       
1355        RegisterOption("ViewCells.PostProcess.merge",
1356                optBool,
1357                "view_cells_post_merge=",
1358                "true");
1359
1360        RegisterOption("ViewCells.Visualization.exportMergedViewCells",
1361                optBool,
1362                "view_cells_viz_export_merged_viewcells=",
1363                "false");
1364
1365        RegisterOption("ViewCells.maxStaticMemory",
1366                optFloat,
1367                "view_cells_max_static_mem=",
1368                "8.0");
1369
1370        RegisterOption("ViewCells.Visualization.useClipPlane",
1371                optBool,
1372                "view_cells_viz_use_clip_plane=",
1373                "false");
1374       
1375        RegisterOption("ViewCells.Visualization.clipPlaneAxis",
1376                optInt,
1377                "view_cells_viz_clip_plane_axis=",
1378                "0");
1379
1380
1381        /************************************************************************************/
1382        /*                         Render simulation related options                        */
1383        /************************************************************************************/
1384
1385
1386        RegisterOption("Simulation.objRenderCost",
1387                        optFloat,
1388                        "simulation_obj_render_cost",
1389                        "1.0");
1390
1391        RegisterOption("Simulation.vcOverhead",
1392                        optFloat,
1393                        "simulation_vc_overhead",
1394                        "0.05");
1395
1396        RegisterOption("Simulation.moveSpeed",
1397                        optFloat,
1398                        "simulation_moveSpeed",
1399                        "1.0");
1400
1401
1402
1403
1404        /************************************************************************************/
1405        /*                         Bsp tree related options                                 */
1406        /************************************************************************************/
1407
1408
1409        RegisterOption("BspTree.Construction.input",
1410                optString,
1411                "bsp_construction_input=",
1412                "fromViewCells");
1413
1414        RegisterOption("BspTree.subdivisionStats",
1415                                        optString,
1416                                        "vsp_bsp_subdivision_stats=",
1417                                        "bspSubdivisionStats.log");
1418
1419        RegisterOption("BspTree.Construction.samples",
1420                optInt,
1421                "bsp_construction_samples=",
1422                "100000");
1423
1424        RegisterOption("BspTree.Construction.epsilon",
1425                optFloat,
1426                "bsp_construction_side_tolerance=",
1427                "0.002");
1428
1429        RegisterOption("BspTree.Termination.minPolygons",
1430                        optInt,
1431                        "bsp_term_min_polygons=",
1432                        "5");
1433
1434        RegisterOption("BspTree.Termination.minPvs",
1435                        optInt,
1436                        "bsp_term_min_pvs=",
1437                        "20");
1438
1439        RegisterOption("BspTree.Termination.minProbability",
1440                        optFloat,
1441                        "bsp_term_min_probability=",
1442                        "0.001");
1443
1444        RegisterOption("BspTree.Termination.maxRayContribution",
1445                        optFloat,
1446                        "bsp_term_ray_contribution=",
1447                        "0.005");
1448
1449        RegisterOption("BspTree.Termination.minAccRayLenght",
1450                        optFloat,
1451                        "bsp_term_min_acc_ray_length=",
1452                        "50");
1453
1454        RegisterOption("BspTree.Termination.minRays",
1455                        optInt,
1456                        "bsp_term_min_rays=",
1457                        "-1");
1458
1459        RegisterOption("BspTree.Termination.ct_div_ci",
1460                        optFloat,
1461                        "bsp_term_ct_div_ci=",
1462                        "0.0");
1463
1464        RegisterOption("BspTree.Termination.maxDepth",
1465                        optInt,
1466                        "bsp_term_max_depth=",
1467                        "100");
1468
1469        RegisterOption("BspTree.Termination.maxCostRatio",
1470                        optFloat,
1471                        "bsp_term_axis_aligned_max_cost_ratio=",
1472                        "1.5");
1473
1474        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1475                        optFloat,
1476                        "bsp_term_axis_aligned_ct_div_ci=",
1477                        "0.5");
1478
1479        RegisterOption("BspTree.AxisAligned.splitBorder",
1480                        optFloat,
1481                        "bsp__axis_aligned_split_border=",
1482                        "0.1");
1483
1484        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1485                        optInt,
1486                        "bsp_term_axis_aligned_max_polygons=",
1487                        "50");
1488
1489        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1490                        optInt,
1491                        "bsp_term_min_objects=",
1492                        "3");
1493
1494        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1495                        optInt,
1496                        "bsp_term_axis_aligned_min_rays=",
1497                        "-1");
1498
1499        RegisterOption("BspTree.splitPlaneStrategy",
1500                        optString,
1501                        "bsp_split_method=",
1502                        "leastSplits");
1503
1504        RegisterOption("BspTree.maxPolyCandidates",
1505                optInt,
1506                "bsp_max_poly_candidates=",
1507                "20");
1508
1509        RegisterOption("BspTree.maxRayCandidates",
1510                optInt,
1511                "bsp_max_plane_candidates=",
1512                "20");
1513
1514        RegisterOption("BspTree.maxTests",
1515                optInt,
1516                "bsp_max_tests=",
1517                "5000");
1518
1519        RegisterOption("BspTree.Termination.maxViewCells",
1520                optInt,
1521                "bsp_max_view_cells=",
1522                "5000");
1523
1524        RegisterOption("BspTree.Visualization.exportSplits",
1525                optBool,
1526                "bsp_visualization.export_splits",
1527                "false");
1528
1529        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1530        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1531        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1532        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1533        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1534        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1535        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1536        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1537        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1538
1539        /************************************************************************************/
1540        /*                         Preprocessor related options                             */
1541        /************************************************************************************/
1542
1543        RegisterOption("Preprocessor.type",
1544                                        optString,
1545                                        "preprocessor=",
1546                                        "sampling");
1547
1548        RegisterOption("Preprocessor.samplesFilename",
1549                                        optString,
1550                                        "-preprocessor_samples_filename=",
1551                                        "rays.out");
1552
1553        RegisterOption("Preprocessor.useGlRenderer",
1554                                        optBool,
1555                                        "useGlRenderer",
1556                                        "false");
1557
1558        RegisterOption("Preprocessor.loadPolygonsAsMeshes",
1559                                        optBool,
1560                                        "loadPolygonsAsMeshes=",
1561                                        "false");
1562
1563        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1564                                   optInt,
1565                                   "pvsRenderErrorSamples=",
1566                                   "10000");
1567
1568        RegisterOption("Preprocessor.useGlDebugger",
1569                                        optBool,
1570                                        "useGlDebugger",
1571                                        "false");
1572
1573        RegisterOption("Preprocessor.detectEmptyViewSpace",
1574                                   optBool,
1575                                   "detectEmptyViewSpace",
1576                                   "false");
1577       
1578        RegisterOption("Preprocessor.quitOnFinish",
1579                                   optBool,
1580                                   "quitOnFinish",
1581                                   "true");
1582
1583        /**************************************************************************************/
1584        /*                  View space partition KD tree related options                      */
1585        /**************************************************************************************/
1586
1587        RegisterOption("VspKdTree.Construction.samples",
1588                                        optInt,
1589                                        "vsp_kd_construction_samples=",
1590                                        "100000");
1591
1592        RegisterOption("VspKdTree.Termination.maxDepth",
1593                optInt,
1594                "vsp_term_maxdepth=", "30");
1595
1596        RegisterOption("VspKdTree.Termination.minPvs",
1597                optInt,
1598                "vsp_minpvs=",
1599                "1");
1600
1601        RegisterOption("VspKdTree.Termination.minRays",
1602                optInt,
1603                "vsp_term_minrays=",
1604                "10");
1605
1606        RegisterOption("VspKdTree.Termination.minSize",
1607                optFloat,
1608                "vsp_term_minsize=",
1609                "0.001");
1610
1611        RegisterOption("VspKdTree.Termination.maxCostRatio",
1612                optFloat,
1613                "vsp_term_maxcost=",
1614                "0.95");
1615
1616        RegisterOption("VspKdTree.Termination.maxRayContribution",
1617                optFloat,
1618                "vsp_term_max_ray_contrib=",
1619                "0.5");
1620
1621        RegisterOption("VspKdTree.epsilon",
1622                optFloat,
1623                "kd_eps=",
1624                "1e-6");
1625
1626        RegisterOption("VspKdTree.ct_div_ci",
1627                optFloat,
1628                "vsp_ctdivci=", "1.0");
1629
1630        RegisterOption("VspKdTree.splitType",
1631                optString,
1632                "split=",
1633                "queries");
1634
1635        RegisterOption("VspKdTree.splitAxis",
1636                optString,
1637                "split=",
1638                "drivingAxis");
1639
1640        RegisterOption("VspKdTree.splitUseOnlyDrivingAxis",
1641                optBool,
1642                "vsp_kd_splitdriving=",
1643                "false");
1644
1645        RegisterOption("VspKdTree.numberOfEndPointDomains",
1646                optInt,
1647                "endpoints=",
1648                "10000");
1649
1650        RegisterOption("VspKdTree.maxTotalMemory",
1651                optFloat,
1652                "vsp_max_total_mem=",
1653                "60.0");
1654
1655        RegisterOption("VspKdTree.maxStaticMemory",
1656                optFloat,
1657                "vsp_max_static_mem=",
1658                "8.0");
1659
1660        RegisterOption("VspKdTree.queryType",
1661                optString,
1662                "qtype=",
1663                "static");
1664
1665        RegisterOption("VspKdTree.queryPosWeight",
1666                optFloat,
1667                "vsp_kd_qposweight=",
1668                "0.0");
1669
1670        RegisterOption("VspKdTree.accessTimeThreshold",
1671                optInt,
1672                "vsp_kd_accesstime=",
1673                "1000");
1674
1675        RegisterOption("VspKdTree.minCollapseDepth",
1676                optInt,
1677                "vsp_kd_min_colldepth=",
1678                "4");
1679
1680        RegisterOption("VspKdTree.PostProcess.maxCostRatio",
1681                        optFloat,
1682                        "vsp_kd_post_process_max_cost_ratio=",
1683                        "0.9");
1684
1685        RegisterOption("VspKdTree.PostProcess.minViewCells",
1686                optInt,
1687                "vsp_kd_term_post_process_min_view_cells=",
1688                "1000");
1689
1690        RegisterOption("VspKdTree.Termination.maxViewCells",
1691                optInt,
1692                "vsp_kd_term_post_process_min_view_cells=",
1693                "300");
1694
1695        RegisterOption("VspKdTree.PostProcess.maxPvsSize",
1696                optInt,
1697                "vsp_kd_term_post_process_max_pvs_size=",
1698                "100");
1699
1700        RegisterOption("VspKdTree.Termination.missTolerance",
1701                        optInt,
1702                        "-vsp_kd_term_miss_tolerance=",
1703                        "4");
1704
1705        /************************************************************************************/
1706        /*                   VSS Preprocessor cells related options                         */
1707        /************************************************************************************/
1708
1709        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
1710        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
1711        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
1712        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1713        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1714
1715        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1716        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1717        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
1718        RegisterOption("VssTree.splitType", optString, "split=", "queries");
1719        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1720        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
1721        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1722
1723        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
1724
1725        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1726        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1727
1728        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
1729
1730       
1731       
1732        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1733        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir", "false");
1734        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
1735        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1736        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1737        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
1738
1739        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
1740        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1741
1742
1743        RegisterOption("RssPreprocessor.initialSamples",
1744                                                                        optInt,
1745                                                                        "initial_samples=",
1746                                                                        "100000");
1747
1748        RegisterOption("RssPreprocessor.vssSamples",
1749                                        optInt,
1750                                        "rss_vss_samples=",
1751                                        "1000000");
1752
1753        RegisterOption("RssPreprocessor.vssSamplesPerPass",
1754                                        optInt,
1755                                        "rss_vss_samples_per_pass=",
1756                                        "1000");
1757
1758        RegisterOption("RssPreprocessor.samplesPerPass",
1759                                        optInt,
1760                                        "rss_samples_per_pass=",
1761                                        "100000");
1762
1763        RegisterOption("RssPreprocessor.useImportanceSampling",
1764                                        optBool,
1765                                        "rss_use_importance",
1766                                        "true");
1767
1768        RegisterOption("RssPreprocessor.objectBasedSampling",
1769                                        optBool,
1770                                        "rss_object_based_sampling",
1771                                        "true");
1772
1773        RegisterOption("RssPreprocessor.directionalSampling",
1774                                        optBool,
1775                                        "rss_directional_sampling",
1776                                        "false");
1777
1778        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
1779        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
1780        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
1781        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1782        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1783
1784        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1785        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1786        RegisterOption("RssTree.randomize", optBool, "randomize", "false");
1787        RegisterOption("RssTree.splitType", optString, "split=", "queries");
1788        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1789
1790        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1791
1792        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
1793
1794        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1795        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1796
1797        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
1798
1799        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1800        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
1801        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
1802        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1803        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1804        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
1805
1806        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
1807        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1808        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost", "true");
1809        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
1810
1811        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
1812
1813        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs", "false");
1814        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree", "false");
1815        RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays", "false");
1816        RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000");
1817        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells", "false");
1818        RegisterOption("RssPreprocessor.updateSubdivision",
1819                                   optBool,
1820                                   "rss_update_subdivision",
1821                                   "false");
1822
1823
1824/************************************************************************************/
1825/*               View space partition BSP tree related options                      */
1826/************************************************************************************/
1827
1828
1829        RegisterOption("RssPreprocessor.loadInitialSamples",
1830                                        optBool,
1831                                        "vss_load_loadInitialSamples=",
1832                                        "false");
1833
1834        RegisterOption("RssPreprocessor.storeInitialSamples",
1835                                        optBool,
1836                                        "vss_store_storeInitialSamples=",
1837                                        "false");
1838
1839
1840/************************************************************************************/
1841/*               View space partition BSP tree related options                      */
1842/************************************************************************************/
1843
1844        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
1845                                        optFloat,
1846                                        "vsp_bsp_term_min_global_cost_ratio",
1847                                        "0.0001");
1848
1849        RegisterOption("VspBspTree.useSplitCostQueue",
1850                optBool,
1851                "-vsp_bsp_use_split_cost_queue=",
1852                "true");
1853
1854        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
1855                                        optInt,
1856                                        "vsp_bsp_term_global_cost_miss_tolerance",
1857                                        "4");
1858
1859        RegisterOption("VspBspTree.Termination.minPolygons",
1860                                        optInt,
1861                                        "vsp_bsp_term_min_polygons=",
1862                                        "5");
1863
1864        RegisterOption("VspBspTree.Termination.minPvs",
1865                                        optInt,
1866                                        "vsp_bsp_term_min_pvs=",
1867                                        "20");
1868
1869        RegisterOption("VspBspTree.Termination.minProbability",
1870                                        optFloat,
1871                                        "vsp_bsp_term_min_probability=",
1872                                        "0.001");
1873
1874        RegisterOption("VspBspTree.subdivisionStats",
1875                                        optString,
1876                                        "vsp_bsp_subdivision_stats=",
1877                                        "vspBspSubdivisionStats.log");
1878
1879        RegisterOption("VspBspTree.Termination.maxRayContribution",
1880                                        optFloat,
1881                                        "vsp_bsp_term_ray_contribution=",
1882                                        "0.005");
1883
1884        RegisterOption("VspBspTree.Termination.minAccRayLenght",
1885                                        optFloat,
1886                                        "vsp_bsp_term_min_acc_ray_length=",
1887                                        "50");
1888
1889        RegisterOption("VspBspTree.Termination.minRays",
1890                                        optInt,
1891                                        "vsp_bsp_term_min_rays=",
1892                                        "-1");
1893
1894        RegisterOption("VspBspTree.Termination.ct_div_ci",
1895                                        optFloat,
1896                                        "vsp_bsp_term_ct_div_ci=",
1897                                        "0.0");
1898
1899        RegisterOption("VspBspTree.Termination.maxDepth",
1900                                        optInt,
1901                                        "vsp_bsp_term_max_depth=",
1902                                        "100");
1903
1904        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
1905                optFloat,
1906                "-vsp_bsp_term_axis_aligned_max_cost_ratio=",
1907                "1.5");
1908
1909        RegisterOption("VspBspTree.useCostHeuristics",
1910                optBool,
1911                "-vsp_bsp_use_cost_heuristics=",
1912                "false");
1913
1914        RegisterOption("VspBspTree.Termination.maxViewCells",
1915                optInt,
1916                "-vsp_bsp_term_max_view_cells=",
1917                "1000");
1918
1919        RegisterOption("VspBspTree.Termination.maxCostRatio",
1920                optFloat,
1921                "-vsp_bsp_term_max_cost_ratio=",
1922                "1.5");
1923
1924        RegisterOption("VspBspTree.Termination.missTolerance",
1925                                        optInt,
1926                                        "vsp_bsp_term_miss_tolerance=",
1927                                        "4");
1928        RegisterOption("VspBspTree.splitPlaneStrategy",
1929                                        optString,
1930                                        "vsp_bsp_split_method=",
1931                                        "leastSplits");
1932
1933        RegisterOption("VspBspTree.maxPolyCandidates",
1934                                        optInt,
1935                                        "vsp_bsp_max_poly_candidates=",
1936                                        "20");
1937        RegisterOption("VspBspTree.maxRayCandidates",
1938                                        optInt,
1939                                        "vsp_bsp_max_plane_candidates=",
1940                                        "20");
1941
1942        RegisterOption("VspBspTree.maxTests",
1943                                        optInt,
1944                                        "vsp_bsp_max_tests=",
1945                                        "5000");
1946
1947        RegisterOption("VspBspTree.Construction.samples",
1948                                        optInt,
1949                                        "bsp_construction_samples=",
1950                                        "100000");
1951
1952        RegisterOption("VspBspTree.Construction.epsilon",
1953                                        optFloat,
1954                                        "vsp_bsp_construction_side_tolerance=",
1955                                        "0.002");
1956
1957        RegisterOption("VspBspTree.Visualization.exportSplits",
1958                                        optBool,
1959                                        "vsp_bsp_visualization.export_splits",
1960                                        "false");
1961
1962        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
1963                                        optBool,
1964                                        "vsp_bsp_splitdriving=",
1965                                        "false");
1966
1967        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
1968                                        optBool,
1969                    "vsp_bsp_usePolygonSplitIfAvailable=",
1970                                        "false");
1971
1972        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
1973                        optInt,
1974                        "bsp_term_axis_aligned_min_rays=",
1975                        "100");
1976       
1977        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
1978                        optFloat,
1979                        "bsp_term_axis_aligned_min_rays=",
1980                        "0.1");
1981
1982        RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0");
1983        RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0");
1984        RegisterOption("VspBspTree.Factor.pvs", optFloat, "-vsp_bsp_factor_pvs=", "1.0");
1985
1986
1987        RegisterOption("VspBspTree.Construction.renderCostWeight",
1988                        optFloat,
1989                        "-vsp_bsp_post_process_render_cost_weight",
1990                        "0.5");
1991
1992
1993        RegisterOption("VspBspTree.Construction.randomize",
1994                optBool,
1995                "vsp_bsp_construction_randomize=",
1996                "false");
1997
1998       
1999        RegisterOption("VspBspTree.maxTotalMemory",
2000                optFloat,
2001                "vsp_bsp_max_total_mem=",
2002                "60.0");
2003
2004        RegisterOption("VspBspTree.maxStaticMemory",
2005                optFloat,
2006                "vsp_bsp_max_static_mem=",
2007                "8.0");
2008
2009       
2010       
2011
2012        //////////////////////////////////////////////////////////////////////////////////
2013}
2014
2015void
2016Environment::SetStaticOptions()
2017{
2018 
2019  // get Global option values
2020  GetRealValue("Limits.threshold", Limits::Threshold);
2021  GetRealValue("Limits.small", Limits::Small);
2022  GetRealValue("Limits.infinity", Limits::Infinity);
2023
2024
2025}
2026
2027void
2028Environment::Parse(const int argc, char **argv, bool useExePath)
2029{
2030 
2031  // Read the names of the scene, environment and output files
2032  ReadCmdlineParams(argc, argv, "");
2033
2034  char *envFilename = new char[128];
2035
2036  char filename[64];
2037
2038  // Get the environment file name
2039  if (!GetParam(' ', 0, filename)) {
2040    // user didn't specified environment file explicitly, so
2041    strcpy(filename, "default.env");
2042  }
2043 
2044  if (useExePath) {
2045    char *path = GetPath(argv[0]);
2046    if (*path != 0)
2047      sprintf(envFilename, "%s/%s", path, filename);
2048    else
2049      strcpy(envFilename, filename);
2050   
2051    delete path;
2052  }
2053  else
2054    strcpy(envFilename, filename);
2055
2056 
2057  // Now it's time to read in environment file.
2058  if (!ReadEnvFile(envFilename)) {
2059    // error - bad input file name specified ?
2060    cerr<<"Error parsing environment file "<<envFilename<<endl;
2061  }
2062  delete envFilename;
2063
2064  // Parse the command line; options given on the command line subsume
2065  // stuff specified in the input environment file.
2066  ParseCmdline(argc, argv, 0);
2067
2068  SetStaticOptions();
2069
2070  // Check for request for help
2071  if (CheckForSwitch(argc, argv, '?')) {
2072    PrintUsage(cout);
2073    exit(0);
2074  }
2075
2076}
Note: See TracBrowser for help on using the repository browser.