25 #ifndef INCLUDED_SetupSensors_h_GUID_7F0F52BD_57B4_4ABB_0834_C61DB7C22132
26 #define INCLUDED_SetupSensors_h_GUID_7F0F52BD_57B4_4ABB_0834_C61DB7C22132
38 #include <json/reader.h>
39 #include <json/value.h>
49 static bool frontPanelFixedBeaconShared(
int id) {
50 return (
id == 16) || (
id == 17) || (
id == 19) || (
id == 20);
53 static bool backPanelFixedBeaconShared(
int) {
return true; }
56 inline void loadedCalibFileSuccessfully(ConfigParams
const &config) {
57 loadedCalibFileSuccessfully(config.calibrationFile);
60 inline void calibFileSpecifiedButNotLoaded(ConfigParams
const &config) {
61 calibFileSpecifiedButNotLoaded(config.calibrationFile);
65 using BeaconPredicate = std::function<bool(int)>;
68 inline float computeDistanceBetweenPanels(ConfigParams
const &config) {
69 return static_cast<float>(computeDistanceBetweenPanels(
70 config.headCircumference, config.headToFrontBeaconOriginDistance));
72 inline void addRearPanelBeaconLocations(
float distanceBetweenPanels,
73 Point3Vector &locations) {
78 for (
auto &pt : OsvrHdkLedLocations_SENSOR1) {
79 locations.emplace_back(-pt.x, pt.y, -pt.z - distanceBetweenPanels);
83 inline void addRearPanelBeaconLocations(ConfigParams
const &config,
84 Point3Vector &locations) {
85 addRearPanelBeaconLocations(computeDistanceBetweenPanels(config),
89 inline void setupSensorsIncludeRearPanel(
90 VideoBasedTracker &vbtracker, ConfigParams
const &config,
91 bool attemptToLoadCalib =
true,
92 BeaconPredicate &&beaconFixedPredicate = &frontPanelFixedBeaconShared) {
94 Point3Vector locations = OsvrHdkLedLocations_SENSOR0;
95 Vec3Vector directions = OsvrHdkLedDirections_SENSOR0;
96 std::vector<double> variances = OsvrHdkLedVariances_SENSOR0;
99 addRearPanelBeaconLocations(config, locations);
101 variances.insert(end(variances), OsvrHdkLedLocations_SENSOR1.size(),
102 config.backPanelMeasurementError);
104 for (
auto &vec : OsvrHdkLedDirections_SENSOR1) {
105 directions.emplace_back(-vec[0], vec[1], -vec[2]);
107 double autocalibScale = 1;
108 if (attemptToLoadCalib) {
109 auto calibLocations =
110 tryLoadingArrayOfPointsFromFile(config.calibrationFile);
111 bool gotCalib =
false;
112 if (calibLocations.size() == locations.size()) {
115 }
else if (calibLocations.size() == getNumHDKFrontPanelBeacons()) {
120 addRearPanelBeaconLocations(config, calibLocations);
125 messages::loadedCalibFileSuccessfully(config);
126 locations = calibLocations;
127 autocalibScale = BEACON_AUTOCALIB_ERROR_SCALE_IF_CALIBRATED;
129 }
else if (!config.calibrationFile.empty()) {
130 messages::calibFileSpecifiedButNotLoaded(config);
134 auto camParams = getHDKCameraParameters();
135 vbtracker.addSensor(createHDKUnifiedLedIdentifier(), camParams,
136 locations, directions, variances,
137 beaconFixedPredicate, 4, 0, autocalibScale);
141 setupSensorsWithoutRearPanel(VideoBasedTracker &vbtracker,
142 ConfigParams
const &config,
143 bool attemptToLoadCalib =
true,
144 BeaconPredicate &&frontBeaconFixedPredicate =
145 &frontPanelFixedBeaconShared,
146 BeaconPredicate &&backBeaconFixedPredicate =
147 &backPanelFixedBeaconShared) {
149 auto camParams = getHDKCameraParameters();
151 bool needFrontSensor =
true;
152 if (attemptToLoadCalib) {
153 auto calibLocations =
154 tryLoadingArrayOfPointsFromFile(config.calibrationFile);
155 if (calibLocations.size() == getNumHDKFrontPanelBeacons() ||
156 calibLocations.size() ==
157 getNumHDKFrontPanelBeacons() +
158 getNumHDKRearPanelBeacons()) {
160 calibLocations.resize(getNumHDKFrontPanelBeacons());
161 messages::loadedCalibFileSuccessfully(config);
162 needFrontSensor =
false;
164 createHDKLedIdentifier(0), camParams, calibLocations,
165 OsvrHdkLedDirections_SENSOR0, OsvrHdkLedVariances_SENSOR0,
166 frontBeaconFixedPredicate, 6, 0,
167 BEACON_AUTOCALIB_ERROR_SCALE_IF_CALIBRATED);
168 }
else if (!config.calibrationFile.empty()) {
169 messages::calibFileSpecifiedButNotLoaded(config);
172 if (needFrontSensor) {
174 createHDKLedIdentifier(0), camParams,
175 OsvrHdkLedLocations_SENSOR0, OsvrHdkLedDirections_SENSOR0,
176 OsvrHdkLedVariances_SENSOR0, frontBeaconFixedPredicate, 6, 0);
179 createHDKLedIdentifier(1), camParams, OsvrHdkLedLocations_SENSOR1,
180 OsvrHdkLedDirections_SENSOR1, backBeaconFixedPredicate, 4, 0);
185 #endif // INCLUDED_SetupSensors_h_GUID_7F0F52BD_57B4_4ABB_0834_C61DB7C22132