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

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