OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ConfigurationParser.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
26 #define INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
27 
28 // Internal Includes
29 #include "GetOptionalParameter.h"
30 #include "OptionalStream.h"
31 #include "Types.h"
32 #include <ParseBlobParams.h>
33 
34 // Library/third-party includes
35 #include <boost/optional.hpp>
36 #include <json/value.h>
37 
38 // Standard includes
39 #include <initializer_list>
40 #include <iostream>
41 
42 namespace osvr {
43 namespace vbtracker {
44  inline const char *getConfigStringForTargetSet(BuiltInTargetSets target) {
45  switch (target) {
46  case osvr::vbtracker::BuiltInTargetSets::HDK1xChassis:
47  return "HDK1x";
48  break;
49  case osvr::vbtracker::BuiltInTargetSets::HDK2Chassis:
50  return "HDK2";
51  break;
52  }
53  }
54  static const std::initializer_list<BuiltInTargetSets> AllBuiltInTargetSets =
55  {BuiltInTargetSets::HDK1xChassis, BuiltInTargetSets::HDK2Chassis};
56  template <typename EnumType, typename StringifyFunctor>
57  inline std::pair<boost::optional<EnumType>, boost::optional<std::string>>
58  getEnumFromStringParameter(
59  Json::Value const &root, const char memberName[],
60  StringifyFunctor &&stringifyEnum,
61  std::initializer_list<EnumType> const &possibleValues) {
62  using ReturnType =
63  std::pair<boost::optional<EnumType>, boost::optional<std::string>>;
64  ReturnType ret;
65  if (!root.isMember(memberName)) {
66  return ret;
67  }
68  auto &member = root[memberName];
69  if (!member.isString()) {
70  return ret;
71  }
72  std::string str = member.asString();
73  ret.second = str;
74  for (auto enumVal : possibleValues) {
75  if (str == stringifyEnum(enumVal)) {
77  ret.first = enumVal;
78  return ret;
79  }
80  }
81  // didn't find it. But, they get a string back anyway.
82  return ret;
83  }
84 
85  static const auto MESSAGE_PREFIX =
86  "[Unified Tracker] Configuration Parsing WARNING: ";
87 #define PARAMNAME(X) "'" << X << "'"
88  inline ConfigParams parseConfigParams(Json::Value const &root) {
89  ConfigParams config;
90  config.debug = root.get("showDebug", false).asBool();
91 
92  // Target set, first and foremost.
93  auto targetSet = getEnumFromStringParameter(root, "targetSet",
94  getConfigStringForTargetSet,
95  AllBuiltInTargetSets);
96  if (targetSet.first) {
97  config.targetSet = *targetSet.first;
98  } else if (targetSet.second) {
99  // some string that we couldn't turn into an enum
101  // right now, we just warn
102  std::cout << MESSAGE_PREFIX << PARAMNAME("targetSet")
103  << " contained a string, \"" << *(targetSet.second)
104  << "\", that was not recognized as a known target set. "
105  "Using the default instead."
106  << std::endl;
107  }
108 
109  getOptionalParameter(config.backPanelMeasurementError, root,
110  "backPanelMeasurementError");
111 
113  getOptionalParameter(config.includeRearPanel, root, "includeRearPanel");
114  getOptionalParameter(config.headCircumference, root,
115  "headCircumference");
116  getOptionalParameter(config.headToFrontBeaconOriginDistance, root,
117  "headToFrontBeaconOriginDistance");
118  getOptionalParameter(config.backPanelMeasurementError, root,
119  "backPanelMeasurementError");
120 
121  // If we include the rear panel, we default to not offsetting to
122  // centroid since it causes strange tracking.
123  if (config.includeRearPanel) {
124  config.offsetToCentroid = false;
125  }
126 
128  getOptionalParameter(config.logRawBlobs, root, "logRawBlobs");
129  if (config.logRawBlobs) {
130  std::cout << MESSAGE_PREFIX << PARAMNAME("logRawBlobs")
131  << " is enabled - existing raw blob data file will be "
132  "overwritten, and there is a slight chance of "
133  "performance impacts."
134  << std::endl;
135  }
136  getOptionalParameter(config.logUsableLeds, root, "logUsableLeds");
137  if (config.logUsableLeds) {
138  std::cout << MESSAGE_PREFIX << PARAMNAME("logUsableLeds")
139  << " is enabled - existing 'usable LED' data file will "
140  "be overwritten, and there is a slight chance of "
141  "performance impacts."
142  << std::endl;
143  }
144 
145  getOptionalParameter(config.continuousReporting, root,
146  "continuousReporting");
147  getOptionalParameter(config.extraVerbose, root, "extraVerbose");
148  getOptionalParameter(config.highGain, root, "highGain");
149  getOptionalParameter(config.calibrationFile, root, "calibrationFile");
150 
151  getOptionalParameter(config.additionalPrediction, root,
152  "additionalPrediction");
153  getOptionalParameter(config.maxResidual, root, "maxResidual");
154  getOptionalParameter(config.initialBeaconError, root,
155  "initialBeaconError");
156  getOptionalParameter(config.blobMoveThreshold, root,
157  "blobMoveThreshold");
158  getOptionalParameter(config.blobsKeepIdentity, root,
159  "blobsKeepIdentity");
160  getOptionalParameter(config.numThreads, root, "numThreads");
161  getOptionalParameter(config.cameraMicrosecondsOffset, root,
162  "cameraMicrosecondsOffset");
163  getOptionalParameter(config.streamBeaconDebugInfo, root,
164  "streamBeaconDebugInfo");
165 
166  getOptionalParameter(config.offsetToCentroid, root, "offsetToCentroid");
167  if (!config.offsetToCentroid) {
168  getOptionalParameter(config.manualBeaconOffset, root,
169  "manualBeaconOffset");
170  }
171 
173  getOptionalParameter(config.cameraPosition, root, "cameraPosition");
174  getOptionalParameter(config.cameraIsForward, root, "cameraIsForward");
175  outputUnless(std::cout, root["eyeHeight"].isNull())
176  << MESSAGE_PREFIX << PARAMNAME("eyeHeight")
177  << " is deprecated/ignored: use 'cameraPosition' for similar "
178  "effects with this plugin.";
179 
181  getOptionalParameter(config.permitKalman, root, "permitKalman");
182  getOptionalParameter(config.beaconProcessNoise, root,
183  "beaconProcessNoise");
184  getOptionalParameter(config.processNoiseAutocorrelation, root,
185  "processNoiseAutocorrelation");
186  getOptionalParameter(config.linearVelocityDecayCoefficient, root,
187  "linearVelocityDecayCoefficient");
188  getOptionalParameter(config.angularVelocityDecayCoefficient, root,
189  "angularVelocityDecayCoefficient");
190  getOptionalParameter(config.noBeaconLinearVelocityDecayCoefficient,
191  root, "noBeaconLinearVelocityDecayCoefficient");
192  getOptionalParameter(config.measurementVarianceScaleFactor, root,
193  "measurementVarianceScaleFactor");
194  getOptionalParameter(config.highResidualVariancePenalty, root,
195  "highResidualVariancePenalty");
196 #if 0
197  getOptionalParameter(config.boundingBoxFilterRatio, root,
198  "boundingBoxFilterRatio");
199 #else
200  outputUnless(std::cout, root["boundingBoxFilterRatio"].isNull())
201  << MESSAGE_PREFIX << PARAMNAME("boundingBoxFilterRatio")
202  << " parameter not actively used";
203 #endif
204  getOptionalParameter(config.maxZComponent, root, "maxZComponent");
205  getOptionalParameter(config.shouldSkipBrightLeds, root,
206  "shouldSkipBrightLeds");
207  getOptionalParameter(config.brightLedVariancePenalty, root,
208  "brightLedVariancePenalty");
209 
211  getOptionalParameter(config.softResets, root, "softResets");
212  getOptionalParameter(config.softResetPositionVarianceScale, root,
213  "softResetPositionVarianceScale");
214  getOptionalParameter(config.softResetOrientationVariance, root,
215  "softResetOrientationVariance");
216 
218  if (root.isMember("blobParams")) {
219  parseBlobParams(root["blobParams"], config.blobParams);
220 
221  // We'll just combine them into one JSON object here.
222  parseEdgeHoleExtractorParams(root["blobParams"],
223  config.extractParams);
224  }
225 
227  if (root.isMember("imu")) {
228  Json::Value const &imu = root["imu"];
229  getOptionalParameter(config.imu.path, imu, "path");
230  getOptionalParameter(config.imu.calibrateAnyway, imu,
231  "calibrateAnyway");
232  getOptionalParameter(config.imu.useOrientation, imu,
233  "useOrientation");
234  getOptionalParameter(config.imu.orientationVariance, imu,
235  "orientationVariance");
236  getOptionalParameter(config.imu.orientationMicrosecondsOffset, imu,
237  "orientationMicrosecondsOffset");
238  getOptionalParameter(config.imu.useAngularVelocity, imu,
239  "useAngularVelocity");
240  getOptionalParameter(config.imu.angularVelocityVariance, imu,
241  "angularVelocityVariance");
242  getOptionalParameter(config.imu.angularVelocityMicrosecondsOffset,
243  imu, "angularVelocityMicrosecondsOffset");
244  }
245 
246  return config;
247  }
248 #undef PARAMNAME
249 } // End namespace vbtracker
250 } // End namespace osvr
251 #endif // INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
Header.
bool isNull(PathElement const &elt)
Returns true if the path element provided is a NullElement.
bool debug
Whether to show the debug windows and debug messages.
Definition: ConfigParams.h:137