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

Revision 1001, 57.8 KB checked in by mattausch, 18 years ago (diff)

added mesh instance support
improved support for occlusion queries + other extensions

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("RenderSampler.visibleThreshold",
1171                                 optInt,
1172                                 "render_sampler_visible_threshold=",
1173                                 "0");
1174
1175
1176   RegisterOption("RenderSampler.useOcclusionQueries",
1177                                 optBool,
1178                                 "render_sampler_use_occlusion_queries=",
1179                                 "true");
1180
1181   RegisterOption("VssPreprocessor.initialSamples",
1182                                 optInt,
1183                                 "initial_samples=",
1184                                 "100000");
1185 
1186  RegisterOption("VssPreprocessor.testBeamSampling",
1187                                optBool,
1188                                "beam_sampling",
1189                                "false");
1190
1191  RegisterOption("VssPreprocessor.vssSamples",
1192                                 optInt,
1193                                 "vss_samples=",
1194                                 "1000000");
1195       
1196  RegisterOption("VssPreprocessor.vssSamplesPerPass",
1197                                 optInt,
1198                                 "vss_samples_per_pass=",
1199                                 "1000");
1200 
1201  RegisterOption("VssPreprocessor.samplesPerPass",
1202                                 optInt,
1203                                 "samples_per_pass=",
1204                                 "100000");
1205
1206  RegisterOption("VssPreprocessor.useImportanceSampling",
1207                                 optBool,
1208                                 "vss_use_importance=",
1209                                 "true");
1210
1211   RegisterOption("VssPreprocessor.enlargeViewSpace",
1212                                 optBool,
1213                                 "vss_enlarge_viewspace=",
1214                                 "false");
1215
1216   RegisterOption("VssPreprocessor.loadInitialSamples",
1217          optBool,
1218          "vss_load_loadInitialSamples=",
1219          "false");
1220
1221   RegisterOption("VssPreprocessor.storeInitialSamples",
1222          optBool,
1223          "vss_store_storedInitialSamples=",
1224          "false");
1225   
1226
1227    RegisterOption("VssPreprocessor.useViewSpaceBox",
1228          optBool,
1229          "vss_use_viewspace_box=",
1230          "false");
1231   
1232
1233  /************************************************************************************/
1234  /*                         View cells related options                               */
1235  /************************************************************************************/
1236
1237
1238        RegisterOption("ViewCells.type",
1239                        optString,
1240                        "view_cells_type=",
1241                        "vspBspTree");
1242
1243        RegisterOption("ViewCells.samplingType",
1244                        optString,
1245                        "view_cells_sampling_type=",
1246                        "box");
1247
1248        RegisterOption("ViewCells.mergeStats",
1249                                        optString,
1250                                        "view_cells_merge_stats=",
1251                                        "mergeStats.log");
1252
1253        RegisterOption("ViewCells.Evaluation.statsPrefix",
1254                                        optString,
1255                                        "view_cells_evaluation_stats_prefix=",
1256                                        "viewCells");
1257
1258        RegisterOption("ViewCells.Evaluation.histogram",
1259                                        optBool,
1260                                        "view_cells_evaluation_histogram=",
1261                                        "false");
1262
1263        RegisterOption("ViewCells.Evaluation.histoStepSize",
1264                                        optInt,
1265                                        "view_cells_evaluation_histo_step_size=",
1266                                        "5000");
1267
1268        RegisterOption("ViewCells.renderCostEvaluationType",
1269                                        optString,
1270                                        "view_cells_render_cost_evaluation=",
1271                                        "perobject");
1272
1273        RegisterOption("ViewCells.active",
1274                                        optInt,
1275                                        "view_cells_active=",
1276                                        "1000");
1277
1278        RegisterOption("ViewCells.Construction.samples",
1279                                        optInt,
1280                                        "view_cells_construction_samples=",
1281                                        "5000000");
1282
1283        RegisterOption("ViewCells.Construction.samplesPerPass",
1284                                        optInt,
1285                                        "view_cells_construction_samples_per_pass=",
1286                                        "500000");
1287
1288        RegisterOption("ViewCells.PostProcess.samples",
1289                                        optInt,
1290                                        "view_cells_post_process_samples=",
1291                                        "200000");
1292
1293        RegisterOption("ViewCells.Visualization.samples",
1294                                        optInt,
1295                                        "view_cells_visualization_samples=",
1296                                        "20000");
1297
1298        RegisterOption("ViewCells.Filter.maxSize",
1299                                        optInt,
1300                                        "view_cells_filter_max_size=",
1301                                        "4");
1302
1303        RegisterOption("ViewCells.Filter.width",
1304                                        optFloat,
1305                                        "view_cells_filter_width=",
1306                                        "200.0");
1307
1308        RegisterOption("ViewCells.loadFromFile",
1309                                        optBool,
1310                                        "view_cells_load_from_file=",
1311                                        "false");
1312
1313        RegisterOption("ViewCells.PostProcess.refine",
1314                                        optBool,
1315                                        "view_cells_refine=",
1316                                        "false");
1317
1318        RegisterOption("ViewCells.PostProcess.compress",
1319                                        optBool,
1320                                        "view_cells_post_process_compress=",
1321                                        "false");
1322
1323        RegisterOption("ViewCells.Evaluation.samples",
1324                                        optInt,
1325                                        "view_cells_evaluation_samples=",
1326                                        "8000000");
1327
1328        RegisterOption("ViewCells.Evaluation.samplingType",
1329                                        optString,
1330                                        "view_cells_evaluation_sampling_type=",
1331                                        "box");
1332
1333        RegisterOption("ViewCells.Evaluation.samplesPerPass",
1334                                        optInt,
1335                                        "view_cells_evaluation_samples_per_pass=",
1336                                        "300000");
1337
1338        RegisterOption("ViewCells.exportToFile",
1339                                        optBool,
1340                                        "view_cells_export_to_file=",
1341                                        "false");
1342
1343        RegisterOption("ViewCells.exportPvs",
1344                                        optBool,
1345                                        "view_cells_export_pvs=",
1346                                        "false");
1347
1348        RegisterOption("ViewCells.exportBboxesForPvs",
1349                                        optBool,
1350                                        "view_cells_export_bounding_boxes=",
1351                                        "true");
1352       
1353        RegisterOption("ViewCells.boxesFilename",
1354                                        optString,
1355                                        "view_cells_boxes_filename=",
1356                                        "boxes.out");
1357
1358        RegisterOption("ViewCells.PostProcess.emptyViewCellsMerge",
1359                                        optBool,
1360                                        "view_cells_merge_empty=",
1361                                        "true");
1362
1363        RegisterOption("ViewCells.evaluateViewCells",
1364                                        optBool,
1365                                        "view_cells_evaluate=",
1366                                        "false");
1367
1368        RegisterOption("ViewCells.maxViewCells",
1369                                        optInt,
1370                                        "view_cells_max_view_cells=",
1371                                        "0");
1372
1373        RegisterOption("ViewCells.maxPvsRatio",
1374                                        optFloat,
1375                                        "view_cells_max_pvs_ratio=",
1376                                        "0.1");
1377
1378        RegisterOption("ViewCells.filename",
1379                                        optString,
1380                                        "view_cells_filename=",
1381                                        "atlanta_viewcells_large.x3d");
1382
1383        RegisterOption("ViewCells.height",
1384                                        optFloat,
1385                                        "view_cells_height=",
1386                                        "5.0");
1387
1388        RegisterOption("ViewCells.Visualization.colorCode",
1389                                        optString,
1390                                        "view_cells_visualization_color_code=",
1391                                        "PVS");
1392
1393        RegisterOption("ViewCells.Visualization.clipPlanePos",
1394                                        optFloat,
1395                                        "view_cells_visualization_clip_plane_pos=",
1396                                        "0.35");
1397       
1398        RegisterOption("ViewCells.Visualization.exportGeometry",
1399                                        optBool,
1400                                        "view_cells_visualization_export_geometry=",
1401                                        "false");
1402
1403        RegisterOption("ViewCells.Visualization.exportRays",
1404                                        optBool,
1405                                        "view_cells_visualization_export_rays=",
1406                                        "false");
1407
1408        RegisterOption("ViewCells.pruneEmptyViewCells",
1409                                        optBool,
1410                                        "view_cells_prune_empty=",
1411                                        "false");
1412
1413        RegisterOption("ViewCells.processOnlyValidViewCells",
1414                                        optBool,
1415                                        "view_cells_process_only_valid_view_cells=",
1416                                        "false");
1417
1418       
1419        RegisterOption("ViewCells.PostProcess.maxCostRatio",
1420                        optFloat,
1421                        "view_cells_post_process_max_cost_ratio=",
1422                        "0.9");
1423       
1424        RegisterOption("ViewCells.PostProcess.renderCostWeight",
1425                        optFloat,
1426                        "view_cells_post_process_render_cost_weight",
1427                        "0.5");
1428       
1429        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation",
1430                        optFloat,
1431                        "vsp_bsp_avgcost_max_deviations",
1432                        "0.5");
1433
1434        RegisterOption("ViewCells.PostProcess.maxMergesPerPass",
1435                optInt,
1436                "view_cells_post_process_max_merges_per_pass=",
1437                "500");
1438
1439        RegisterOption("ViewCells.PostProcess.minViewCells",
1440                optInt,
1441                "view_cells_post_process_min_view_cells=",
1442                "1000");
1443
1444        RegisterOption("ViewCells.PostProcess.useRaysForMerge",
1445                optBool,
1446                "view_cells_post_process_use_rays_for_merge=",
1447                "false");
1448       
1449        RegisterOption("ViewCells.PostProcess.merge",
1450                optBool,
1451                "view_cells_post_process_merge=",
1452                "true");
1453
1454        RegisterOption("ViewCells.Visualization.exportMergedViewCells",
1455                optBool,
1456                "view_cells_viz_export_merged_viewcells=",
1457                "false");
1458
1459        RegisterOption("ViewCells.maxStaticMemory",
1460                optFloat,
1461                "view_cells_max_static_mem=",
1462                "8.0");
1463
1464        RegisterOption("ViewCells.Visualization.useClipPlane",
1465                optBool,
1466                "view_cells_viz_use_clip_plane=",
1467                "false");
1468       
1469        RegisterOption("ViewCells.showVisualization",
1470                optBool,
1471                "view_cells_show_visualization=",
1472                "false");
1473
1474        RegisterOption("ViewCells.Visualization.clipPlaneAxis",
1475                optInt,
1476                "view_cells_viz_clip_plane_axis=",
1477                "0");
1478
1479
1480        /************************************************************************************/
1481        /*                         Render simulation related options                        */
1482        /************************************************************************************/
1483
1484
1485        RegisterOption("Simulation.objRenderCost",
1486                        optFloat,
1487                        "simulation_obj_render_cost",
1488                        "1.0");
1489
1490        RegisterOption("Simulation.vcOverhead",
1491                        optFloat,
1492                        "simulation_vc_overhead",
1493                        "0.05");
1494
1495        RegisterOption("Simulation.moveSpeed",
1496                        optFloat,
1497                        "simulation_moveSpeed",
1498                        "1.0");
1499
1500
1501
1502
1503        /************************************************************************************/
1504        /*                         Bsp tree related options                                 */
1505        /************************************************************************************/
1506
1507
1508        RegisterOption("BspTree.Construction.input",
1509                optString,
1510                "bsp_construction_input=",
1511                "fromViewCells");
1512
1513        RegisterOption("BspTree.subdivisionStats",
1514                                        optString,
1515                                        "bsp_subdivision_stats=",
1516                                        "bspSubdivisionStats.log");
1517
1518        RegisterOption("BspTree.Construction.samples",
1519                optInt,
1520                "bsp_construction_samples=",
1521                "100000");
1522
1523        RegisterOption("BspTree.Construction.epsilon",
1524                optFloat,
1525                "bsp_construction_side_tolerance=",
1526                "0.002");
1527
1528        RegisterOption("BspTree.Termination.minPolygons",
1529                        optInt,
1530                        "bsp_term_min_polygons=",
1531                        "5");
1532
1533        RegisterOption("BspTree.Termination.minPvs",
1534                        optInt,
1535                        "bsp_term_min_pvs=",
1536                        "20");
1537
1538        RegisterOption("BspTree.Termination.minProbability",
1539                        optFloat,
1540                        "bsp_term_min_probability=",
1541                        "0.001");
1542
1543        RegisterOption("BspTree.Termination.maxRayContribution",
1544                        optFloat,
1545                        "bsp_term_ray_contribution=",
1546                        "0.005");
1547
1548        RegisterOption("BspTree.Termination.minAccRayLenght",
1549                        optFloat,
1550                        "bsp_term_min_acc_ray_length=",
1551                        "50");
1552
1553        RegisterOption("BspTree.Termination.minRays",
1554                        optInt,
1555                        "bsp_term_min_rays=",
1556                        "-1");
1557
1558        RegisterOption("BspTree.Termination.ct_div_ci",
1559                        optFloat,
1560                        "bsp_term_ct_div_ci=",
1561                        "0.0");
1562
1563        RegisterOption("BspTree.Termination.maxDepth",
1564                        optInt,
1565                        "bsp_term_max_depth=",
1566                        "100");
1567
1568        RegisterOption("BspTree.Termination.maxCostRatio",
1569                        optFloat,
1570                        "bsp_term_axis_aligned_max_cost_ratio=",
1571                        "1.5");
1572
1573        RegisterOption("BspTree.Termination.AxisAligned.ct_div_ci",
1574                        optFloat,
1575                        "bsp_term_axis_aligned_ct_div_ci=",
1576                        "0.5");
1577
1578        RegisterOption("BspTree.AxisAligned.splitBorder",
1579                        optFloat,
1580                        "bsp__axis_aligned_split_border=",
1581                        "0.1");
1582
1583        RegisterOption("BspTree.Termination.AxisAligned.minPolys",
1584                        optInt,
1585                        "bsp_term_axis_aligned_max_polygons=",
1586                        "50");
1587
1588        RegisterOption("BspTree.Termination.AxisAligned.minObjects",
1589                        optInt,
1590                        "bsp_term_min_objects=",
1591                        "3");
1592
1593        RegisterOption("BspTree.Termination.AxisAligned.minRays",
1594                        optInt,
1595                        "bsp_term_axis_aligned_min_rays=",
1596                        "-1");
1597
1598        RegisterOption("BspTree.splitPlaneStrategy",
1599                        optString,
1600                        "bsp_split_method=",
1601                        "leastSplits");
1602
1603        RegisterOption("BspTree.maxPolyCandidates",
1604                optInt,
1605                "bsp_max_poly_candidates=",
1606                "20");
1607
1608        RegisterOption("BspTree.maxRayCandidates",
1609                optInt,
1610                "bsp_max_plane_candidates=",
1611                "20");
1612
1613        RegisterOption("BspTree.maxTests",
1614                optInt,
1615                "bsp_max_tests=",
1616                "5000");
1617
1618        RegisterOption("BspTree.Termination.maxViewCells",
1619                optInt,
1620                "bsp_max_view_cells=",
1621                "5000");
1622
1623        RegisterOption("BspTree.Visualization.exportSplits",
1624                optBool,
1625                "bsp_visualization.export_splits",
1626                "false");
1627
1628        RegisterOption("BspTree.Factor.verticalSplits", optFloat, "bsp_factor_vertical=", "1.0");
1629        RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "bsp_factor_largest_poly=", "1.0");
1630        RegisterOption("BspTree.Factor.blockedRays", optFloat, "bsp_factor_blocked=", "1.0");
1631        RegisterOption("BspTree.Factor.leastSplits", optFloat, "bsp_factor_least_splits=", "1.0");
1632        RegisterOption("BspTree.Factor.balancedPolys", optFloat, "bsp_factor_balanced_polys=", "1.0");
1633        RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "bsp_factor_balanced_view_cells=", "1.0");
1634        RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "bsp_factor_least_ray_splits=", "1.0");
1635        RegisterOption("BspTree.Factor.balancedRays", optFloat, "bsp_factor_balanced_rays=", "1.0");
1636        RegisterOption("BspTree.Factor.pvs", optFloat, "bsp_factor_pvs=", "1.0");
1637
1638        /************************************************************************************/
1639        /*                         Preprocessor related options                             */
1640        /************************************************************************************/
1641
1642        RegisterOption("Preprocessor.type",
1643                                        optString,
1644                                        "preprocessor=",
1645                                        "sampling");
1646
1647        RegisterOption("Preprocessor.samplesFilename",
1648                                        optString,
1649                                        "preprocessor_samples_filename=",
1650                                        "rays.out");
1651
1652        RegisterOption("Preprocessor.loadPolygonsAsMeshes",
1653                                        optBool,
1654                                        "loadPolygonsAsMeshes=",
1655                                        "false");
1656
1657        RegisterOption("Preprocessor.pvsRenderErrorSamples",
1658                                   optInt,
1659                                   "pvsRenderErrorSamples=",
1660                                   "10000");
1661       
1662        RegisterOption("Preprocessor.useGlRenderer",
1663                                        optBool,
1664                                        "preprocessor_use_gl_renderer=",
1665                                        "false");
1666
1667        RegisterOption("Preprocessor.useGlDebugger",
1668                                        optBool,
1669                                        "preprocessor_use_gl_debugger=",
1670                                        "false");
1671
1672        RegisterOption("Preprocessor.detectEmptyViewSpace",
1673                                   optBool,
1674                                   "preprocessor_detect_empty_viewspace=",
1675                                   "false");
1676       
1677        RegisterOption("Preprocessor.quitOnFinish",
1678                                   optBool,
1679                                   "preprocessor_quit_on_finish=",
1680                                   "true");
1681
1682        RegisterOption("Preprocessor.computeVisibility",
1683                                   optBool,
1684                                   "preprocessor_compute_visibility=",
1685                                   "true");
1686
1687        RegisterOption("Preprocessor.exportVisibility",
1688                                   optBool,
1689                                   "preprocessor_export_visibility=",
1690                                   "true");
1691
1692        RegisterOption("Preprocessor.visibilityFile",
1693                                   optString,
1694                                   "preprocessor_visibility_file=",
1695                                   "visibility.xml");
1696
1697        RegisterOption("Preprocessor.applyVisibilityFilter",
1698                                   optBool,
1699                                   "preprocessor_apply_filter=",
1700                                   "true");
1701       
1702        RegisterOption("Preprocessor.applyVisibilitySpatialFilter",
1703                                   optBool,
1704                                   "preprocessor_apply_spatial_filter=",
1705                                   "true");
1706
1707        RegisterOption("Preprocessor.visibilityFilterWidth",
1708                                   optFloat,
1709                                   "preprocessor_visibility_filter_width=",
1710                                   "0.02");
1711
1712        RegisterOption("Preprocessor.histogram.maxValue",
1713                                        optInt,
1714                                        "preprocessor_histogram_max_value=",
1715                                        "1000");
1716
1717        RegisterOption("Preprocessor.histogram.intervals",
1718                                        optInt,
1719                                        "preprocessor_histogram_intervals=",
1720                                        "20");
1721
1722
1723        /**************************************************************************************/
1724        /*                  View space partition KD tree related options                      */
1725        /**************************************************************************************/
1726
1727        RegisterOption("VspKdTree.Construction.samples",
1728                                        optInt,
1729                                        "vsp_kd_construction_samples=",
1730                                        "100000");
1731
1732        RegisterOption("VspKdTree.Termination.maxDepth",
1733                optInt,
1734                "vsp_term_maxdepth=",
1735                "30");
1736
1737        RegisterOption("VspKdTree.Termination.minPvs",
1738                optInt,
1739                "vsp_minpvs=",
1740                "1");
1741
1742        RegisterOption("VspKdTree.Termination.minRays",
1743                optInt,
1744                "vsp_term_minrays=",
1745                "10");
1746
1747        RegisterOption("VspKdTree.Termination.minSize",
1748                optFloat,
1749                "vsp_term_minsize=",
1750                "0.001");
1751
1752        RegisterOption("VspKdTree.Termination.maxCostRatio",
1753                optFloat,
1754                "vsp_term_maxcost=",
1755                "0.95");
1756
1757        RegisterOption("VspKdTree.Termination.maxRayContribution",
1758                optFloat,
1759                "vsp_term_max_ray_contrib=",
1760                "0.5");
1761
1762        RegisterOption("VspKdTree.epsilon",
1763                optFloat,
1764                "kd_eps=",
1765                "1e-6");
1766
1767        RegisterOption("VspKdTree.ct_div_ci",
1768                optFloat,
1769                "vsp_ctdivci=", "1.0");
1770
1771        RegisterOption("VspKdTree.splitType",
1772                optString,
1773                "split=",
1774                "queries");
1775
1776        RegisterOption("VspKdTree.splitAxis",
1777                optString,
1778                "split=",
1779                "drivingAxis");
1780
1781        RegisterOption("VspKdTree.splitUseOnlyDrivingAxis",
1782                optBool,
1783                "vsp_kd_splitdriving=",
1784                "false");
1785
1786        RegisterOption("VspKdTree.numberOfEndPointDomains",
1787                optInt,
1788                "endpoints=",
1789                "10000");
1790
1791        RegisterOption("VspKdTree.maxTotalMemory",
1792                optFloat,
1793                "vsp_max_total_mem=",
1794                "60.0");
1795
1796        RegisterOption("VspKdTree.maxStaticMemory",
1797                optFloat,
1798                "vsp_max_static_mem=",
1799                "8.0");
1800
1801        RegisterOption("VspKdTree.queryType",
1802                optString,
1803                "qtype=",
1804                "static");
1805
1806        RegisterOption("VspKdTree.queryPosWeight",
1807                optFloat,
1808                "vsp_kd_qposweight=",
1809                "0.0");
1810
1811        RegisterOption("VspKdTree.accessTimeThreshold",
1812                optInt,
1813                "vsp_kd_accesstime=",
1814                "1000");
1815
1816        RegisterOption("VspKdTree.minCollapseDepth",
1817                optInt,
1818                "vsp_kd_min_colldepth=",
1819                "4");
1820
1821        RegisterOption("VspKdTree.PostProcess.maxCostRatio",
1822                        optFloat,
1823                        "vsp_kd_post_process_max_cost_ratio=",
1824                        "0.9");
1825
1826        RegisterOption("VspKdTree.PostProcess.minViewCells",
1827                optInt,
1828                "vsp_kd_term_post_process_min_view_cells=",
1829                "1000");
1830
1831        RegisterOption("VspKdTree.Termination.maxViewCells",
1832                optInt,
1833                "vsp_kd_term_post_process_min_view_cells=",
1834                "300");
1835
1836        RegisterOption("VspKdTree.PostProcess.maxPvsSize",
1837                optInt,
1838                "vsp_kd_term_post_process_max_pvs_size=",
1839                "100");
1840
1841        RegisterOption("VspKdTree.Termination.missTolerance",
1842                        optInt,
1843                        "vsp_kd_term_miss_tolerance=",
1844                        "4");
1845
1846        /************************************************************************************/
1847        /*                   VSS Preprocessor cells related options                         */
1848        /************************************************************************************/
1849
1850        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
1851        RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
1852        RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
1853        RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1854        RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1855
1856        RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1857        RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1858        RegisterOption("VssTree.randomize", optBool, "randomize", "false");
1859        RegisterOption("VssTree.splitType", optString, "split=", "queries");
1860        RegisterOption("VssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1861        RegisterOption("VssTree.useRss", optBool, "rss=", "false");
1862        RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1863
1864        RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001");
1865
1866        RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1867        RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1868
1869        RegisterOption("VssTree.queryType", optString, "qtype=", "static");
1870
1871       
1872       
1873        RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1874        RegisterOption("VssTree.useRefDirSplits", optBool, "refdir=", "false");
1875        RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10");
1876        RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1877        RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1878        RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
1879
1880        RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
1881        RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1882
1883
1884        RegisterOption("RssPreprocessor.initialSamples",
1885                                                                        optInt,
1886                                                                        "initial_samples=",
1887                                                                        "100000");
1888
1889        RegisterOption("RssPreprocessor.vssSamples",
1890                                        optInt,
1891                                        "rss_vss_samples=",
1892                                        "1000000");
1893
1894        RegisterOption("RssPreprocessor.vssSamplesPerPass",
1895                                        optInt,
1896                                        "rss_vss_samples_per_pass=",
1897                                        "1000");
1898
1899        RegisterOption("RssPreprocessor.samplesPerPass",
1900                                        optInt,
1901                                        "rss_samples_per_pass=",
1902                                        "100000");
1903
1904        RegisterOption("RssPreprocessor.useImportanceSampling",
1905                                        optBool,
1906                                        "rss_use_importance=",
1907                                        "true");
1908
1909        RegisterOption("RssPreprocessor.objectBasedSampling",
1910                                        optBool,
1911                                        "rss_object_based_sampling=",
1912                                        "true");
1913
1914        RegisterOption("RssPreprocessor.directionalSampling",
1915                                        optBool,
1916                                        "rss_directional_sampling=",
1917                                        "false");
1918
1919        RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12");
1920        RegisterOption("RssTree.minPvs", optInt, "kd_minpvs=", "1");
1921        RegisterOption("RssTree.minRays", optInt, "kd_minrays=", "10");
1922        RegisterOption("RssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
1923        RegisterOption("RssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
1924
1925        RegisterOption("RssTree.epsilon", optFloat, "kd_eps=", "1e-6");
1926        RegisterOption("RssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
1927        RegisterOption("RssTree.randomize", optBool, "randomize=", "false");
1928        RegisterOption("RssTree.splitType", optString, "split=", "queries");
1929        RegisterOption("RssTree.splitUseOnlyDrivingAxis", optBool, "splitdriving=", "false");
1930
1931        RegisterOption("RssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
1932
1933        RegisterOption("RssTree.minSize", optFloat, "minsize=", "0.001");
1934
1935        RegisterOption("RssTree.maxTotalMemory", optFloat, "mem=", "60.0");
1936        RegisterOption("RssTree.maxStaticMemory", optFloat, "statmem=", "8.0");
1937
1938        RegisterOption("RssTree.queryType", optString, "qtype=", "static");
1939
1940        RegisterOption("RssTree.queryPosWeight", optFloat, "qposweight=", "0.0");
1941        RegisterOption("RssTree.useRefDirSplits", optBool, "refdir", "false");
1942        RegisterOption("RssTree.refDirAngle", optFloat, "refangle=", "10");
1943        RegisterOption("RssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1");
1944        RegisterOption("RssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
1945        RegisterOption("RssTree.minCollapseDepth", optInt, "colldepth=", "4");
1946
1947        RegisterOption("RssTree.interleaveDirSplits", optBool, "interleavedirsplits=", "true");
1948        RegisterOption("RssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
1949        RegisterOption("RssTree.importanceBasedCost", optBool, "importance_based_cost=", "true");
1950        RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
1951
1952        RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
1953
1954        RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
1955        RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
1956        RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays=", "false");
1957        RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000");
1958        RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
1959        RegisterOption("RssPreprocessor.updateSubdivision",
1960                                   optBool,
1961                                   "rss_update_subdivision=",
1962                                   "false");
1963
1964
1965/************************************************************************************/
1966/*               View space partition BSP tree related options                      */
1967/************************************************************************************/
1968
1969
1970        RegisterOption("RssPreprocessor.loadInitialSamples",
1971                                        optBool,
1972                                        "vss_load_loadInitialSamples=",
1973                                        "false");
1974
1975        RegisterOption("RssPreprocessor.storeInitialSamples",
1976                                        optBool,
1977                                        "vss_store_storeInitialSamples=",
1978                                        "false");
1979
1980
1981/************************************************************************************/
1982/*               View space partition BSP tree related options                      */
1983/************************************************************************************/
1984
1985        RegisterOption("VspBspTree.Termination.minGlobalCostRatio",
1986                                        optFloat,
1987                                        "vsp_bsp_term_min_global_cost_ratio=",
1988                                        "0.0001");
1989
1990        RegisterOption("VspBspTree.useSplitCostQueue",
1991                optBool,
1992                "vsp_bsp_use_split_cost_queue=",
1993                "true");
1994
1995        RegisterOption("VspBspTree.Termination.globalCostMissTolerance",
1996                                        optInt,
1997                                        "vsp_bsp_term_global_cost_miss_tolerance=",
1998                                        "4");
1999
2000        RegisterOption("VspBspTree.Termination.minPolygons",
2001                                        optInt,
2002                                        "vsp_bsp_term_min_polygons=",
2003                                        "5");
2004
2005        RegisterOption("VspBspTree.Termination.minPvs",
2006                                        optInt,
2007                                        "vsp_bsp_term_min_pvs=",
2008                                        "20");
2009
2010        RegisterOption("VspBspTree.Termination.minProbability",
2011                                        optFloat,
2012                                        "vsp_bsp_term_min_probability=",
2013                                        "0.001");
2014
2015        RegisterOption("VspBspTree.subdivisionStats",
2016                                        optString,
2017                                        "vsp_bsp_subdivision_stats=",
2018                                        "vspBspSubdivisionStats.log");
2019
2020        RegisterOption("VspBspTree.Termination.maxRayContribution",
2021                                        optFloat,
2022                                        "vsp_bsp_term_ray_contribution=",
2023                                        "0.005");
2024
2025        RegisterOption("VspBspTree.Termination.minAccRayLenght",
2026                                        optFloat,
2027                                        "vsp_bsp_term_min_acc_ray_length=",
2028                                        "50");
2029
2030        RegisterOption("VspBspTree.Termination.minRays",
2031                                        optInt,
2032                                        "vsp_bsp_term_min_rays=",
2033                                        "-1");
2034
2035        RegisterOption("VspBspTree.Termination.ct_div_ci",
2036                                        optFloat,
2037                                        "vsp_bsp_term_ct_div_ci=",
2038                                        "0.0");
2039
2040        RegisterOption("VspBspTree.Termination.maxDepth",
2041                                        optInt,
2042                                        "vsp_bsp_term_max_depth=",
2043                                        "100");
2044
2045        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
2046                optFloat,
2047                "vsp_bsp_term_axis_aligned_max_cost_ratio=",
2048                "1.5");
2049
2050        RegisterOption("VspBspTree.useCostHeuristics",
2051                optBool,
2052                "vsp_bsp_use_cost_heuristics=",
2053                "false");
2054
2055        RegisterOption("VspBspTree.Termination.maxViewCells",
2056                optInt,
2057                "vsp_bsp_term_max_view_cells=",
2058                "10000");
2059
2060        RegisterOption("VspBspTree.Termination.maxCostRatio",
2061                optFloat,
2062                "vsp_bsp_term_max_cost_ratio=",
2063                "1.5");
2064
2065        RegisterOption("VspBspTree.Termination.missTolerance",
2066                optInt,
2067                "vsp_bsp_term_miss_tolerance=",
2068                "4");
2069
2070        RegisterOption("VspBspTree.splitPlaneStrategy",
2071                                        optString,
2072                                        "vsp_bsp_split_method=",
2073                                        "leastSplits");
2074
2075        RegisterOption("VspBspTree.maxPolyCandidates",
2076                                        optInt,
2077                                        "vsp_bsp_max_poly_candidates=",
2078                                        "20");
2079        RegisterOption("VspBspTree.maxRayCandidates",
2080                                        optInt,
2081                                        "vsp_bsp_max_plane_candidates=",
2082                                        "20");
2083
2084        RegisterOption("VspBspTree.maxTests",
2085                                        optInt,
2086                                        "vsp_bsp_max_tests=",
2087                                        "5000");
2088
2089        RegisterOption("VspBspTree.Construction.samples",
2090                                        optInt,
2091                                        "vsp_bsp_construction_samples=",
2092                                        "100000");
2093
2094        RegisterOption("VspBspTree.Construction.minBand",
2095                                        optFloat,
2096                                        "vsp_bsp_construction_min_band=",
2097                                        "0.1");
2098
2099        RegisterOption("VspBspTree.Construction.maxBand",
2100                                        optFloat,
2101                                        "vsp_bsp_construction_min_band=",
2102                                        "0.9");
2103
2104        RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost",
2105                                        optBool,
2106                                        "vsp_bsp_construction_use_drivingaxis_for_maxcost=",
2107                                        "false");
2108
2109        RegisterOption("VspBspTree.Construction.epsilon",
2110                                        optFloat,
2111                                        "vsp_bsp_construction_side_tolerance=",
2112                                        "0.002");
2113
2114        RegisterOption("VspBspTree.Visualization.exportSplits",
2115                                        optBool,
2116                                        "vsp_bsp_visualization.export_splits",
2117                                        "false");
2118
2119        RegisterOption("VspBspTree.splitUseOnlyDrivingAxis",
2120                                        optBool,
2121                                        "vsp_bsp_split_only_driving_axis=",
2122                                        "false");
2123
2124        RegisterOption("VspBspTree.usePolygonSplitIfAvailable",
2125                                        optBool,
2126                    "vsp_bsp_usePolygonSplitIfAvailable=",
2127                                        "false");
2128
2129        RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
2130                        optInt,
2131                        "bsp_term_axis_aligned_min_rays=",
2132                        "100");
2133       
2134        RegisterOption("VspBspTree.Termination.AxisAligned.maxRayContribution",
2135                        optFloat,
2136                        "bsp_term_axis_aligned_min_rays=",
2137                        "0.1");
2138
2139        RegisterOption("VspBspTree.Factor.leastRaySplits",
2140                                        optFloat,
2141                                        "vsp_bsp_factor_least_ray_splits=",
2142                                        "1.0");
2143
2144        RegisterOption("VspBspTree.Factor.balancedRays",
2145                                        optFloat,
2146                                        "vsp_bsp_factor_balanced_rays=",
2147                                        "1.0");
2148
2149        RegisterOption("VspBspTree.Factor.pvs",
2150                                        optFloat,
2151                                        "vsp_bsp_factor_pvs=",
2152                                        "1.0");
2153       
2154        RegisterOption("VspBspTree.Construction.renderCostWeight",
2155                        optFloat,
2156                        "-vsp_bsp_post_process_render_cost_weight",
2157                        "0.5");
2158
2159        RegisterOption("VspBspTree.Construction.randomize",
2160                optBool,
2161                "vsp_bsp_construction_randomize=",
2162                "false");
2163
2164        RegisterOption("VspBspTree.simulateOctree",
2165                optBool,
2166                "vsp_bsp_simulate_octree=",
2167                "false");
2168
2169        RegisterOption("VspBspTree.nodePriorityQueueType",
2170                optInt,
2171                "vsp_bsp_node_queue_type=",
2172                "0");
2173
2174        RegisterOption("VspBspTree.useRandomAxis",
2175                optBool,
2176                "-vsp_bsp_use_random_axis=",
2177                "false");
2178
2179        RegisterOption("VspBspTree.maxTotalMemory",
2180                optFloat,
2181                "vsp_bsp_max_total_mem=",
2182                "60.0");
2183
2184        RegisterOption("VspBspTree.maxStaticMemory",
2185                optFloat,
2186                "vsp_bsp_max_static_mem=",
2187                "8.0");
2188
2189       
2190       
2191
2192        //////////////////////////////////////////////////////////////////////////////////
2193}
2194
2195void
2196Environment::SetStaticOptions()
2197{
2198 
2199  // get Global option values
2200  GetRealValue("Limits.threshold", Limits::Threshold);
2201  GetRealValue("Limits.small", Limits::Small);
2202  GetRealValue("Limits.infinity", Limits::Infinity);
2203
2204
2205}
2206
2207bool
2208Environment::Parse(const int argc, char **argv, bool useExePath)
2209{
2210  bool result = true;
2211  // Read the names of the scene, environment and output files
2212  ReadCmdlineParams(argc, argv, "");
2213
2214  char *envFilename = new char[128];
2215
2216  char filename[64];
2217
2218  // Get the environment file name
2219  if (!GetParam(' ', 0, filename)) {
2220    // user didn't specified environment file explicitly, so
2221    strcpy(filename, "default.env");
2222  }
2223 
2224  if (useExePath) {
2225    char *path = GetPath(argv[0]);
2226    if (*path != 0)
2227      sprintf(envFilename, "%s/%s", path, filename);
2228    else
2229      strcpy(envFilename, filename);
2230   
2231    delete path;
2232  }
2233  else
2234    strcpy(envFilename, filename);
2235
2236 
2237  // Now it's time to read in environment file.
2238  if (!ReadEnvFile(envFilename)) {
2239    // error - bad input file name specified ?
2240    cerr<<"Error parsing environment file "<<envFilename<<endl;
2241        result = false;
2242  }
2243  delete envFilename;
2244
2245  // Parse the command line; options given on the command line subsume
2246  // stuff specified in the input environment file.
2247  ParseCmdline(argc, argv, 0);
2248
2249  SetStaticOptions();
2250
2251  // Check for request for help
2252  if (CheckForSwitch(argc, argv, '?')) {
2253    PrintUsage(cout);
2254    exit(0);
2255  }
2256 
2257  return true;
2258}
2259
2260}
Note: See TracBrowser for help on using the repository browser.