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

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