OSVR-Core
BeaconSetupData.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_BeaconSetupData_h_GUID_AEDF8B01_FC4D_4388_2C88_0351E5E7FD83
26 #define INCLUDED_BeaconSetupData_h_GUID_AEDF8B01_FC4D_4388_2C88_0351E5E7FD83
27 
28 // Internal Includes
29 #include "BeaconIdTypes.h"
30 #include "Types.h"
31 
32 // Library/third-party includes
33 #include <opencv2/core/core.hpp>
34 
35 // Standard includes
36 #include <string>
37 #include <vector>
38 
39 namespace osvr {
40 namespace vbtracker {
41  using EmissionDirectionVec = ::cv::Vec3d;
42  using LocationPoint = ::cv::Point3f;
43 
45  std::vector<OneBasedBeaconId> disabledByPattern;
46  std::vector<OneBasedBeaconId> disabledByEmptyPattern;
47  std::vector<std::pair<OneBasedBeaconId, std::string>> errors;
48  std::vector<OneBasedBeaconId> validBeacons;
49  };
50 
53  struct TargetSetupData {
54  std::vector<std::string> patterns;
55  Point3Vector locations;
56  Vec3Vector emissionDirections;
57  std::vector<double> baseMeasurementVariances;
58  std::vector<double> initialAutocalibrationErrors;
59  std::vector<bool> isFixed;
60 
61  using size_type = std::vector<double>::size_type;
62 
63  size_type numBeacons() const { return locations.size(); }
64 
67  static LocationPoint getBogusLocation() {
68  return LocationPoint(-10000.f, -10000.f, -87314159.f);
69  }
74  void setBeaconCount(std::size_t numBeacons,
75  double baseMeasurementVariance,
76  double initialAutocalibrationError) {
77  patterns.resize(numBeacons);
78  locations.resize(numBeacons, getBogusLocation());
79  // these are invalid directions and must be populated!
80  emissionDirections.resize(numBeacons,
81  EmissionDirectionVec(0, 0, 0));
82  baseMeasurementVariances.resize(numBeacons,
83  baseMeasurementVariance);
84  initialAutocalibrationErrors.resize(numBeacons,
85  initialAutocalibrationError);
86  isFixed.resize(numBeacons, false);
87  }
88 
91  isFixed.at(beacon.value()) = true;
92  initialAutocalibrationErrors.at(beacon.value()) = 0;
93  }
96  markBeaconFixed(makeZeroBased(beacon));
97  }
98 
100  bool isBeaconActive(OneBasedBeaconId beacon);
101 
102  void markBeaconInactive(ZeroBasedBeaconId beacon);
103  void markBeaconInactive(OneBasedBeaconId beacon) {
104  markBeaconInactive(makeZeroBased(beacon));
105  }
106 
107  TargetDataSummary cleanAndValidate(bool silent = false);
108  };
109 
111  template <typename Stream>
112  inline Stream &operator<<(Stream &os, TargetDataSummary const &summary) {
113  os << "\n\nTarget Data Summary:\n";
114  os << "\nBeacons disabled by their pattern:\n";
115  for (auto id : summary.disabledByPattern) {
116  os << id.value() << "\n";
117  }
118  os << "\nBeacons disabled by empty pattern:\n";
119  for (auto id : summary.disabledByEmptyPattern) {
120  os << id.value() << "\n";
121  }
122  os << "\nBeacons with errors:\n";
123  for (auto &err : summary.errors) {
124  os << err.first.value() << ": " << err.second << "\n";
125  }
126  os << "\nValid beacons:\n";
127  for (auto id : summary.validBeacons) {
128  os << id.value() << " ";
129  }
130  os << "\n\n";
131  return os;
132  }
133 } // namespace vbtracker
134 } // namespace osvr
135 
136 #endif // INCLUDED_BeaconSetupData_h_GUID_AEDF8B01_FC4D_4388_2C88_0351E5E7FD83
ZeroBasedBeaconId makeZeroBased(OneBasedBeaconId id)
Overloaded conversion function to turn any beacon ID into zero-based, respecting the convention that ...
Definition: BeaconIdTypes.h:99
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
static LocationPoint getBogusLocation()
This is both an entirely unlikely out of bounds value and a specific sentinel value.
Definition: BeaconSetupData.h:67
Header.
void markBeaconFixed(ZeroBasedBeaconId beacon)
Mark a beacon, by zero-based ID, as being fixed.
Definition: BeaconSetupData.h:90
void markBeaconFixed(OneBasedBeaconId beacon)
Mark a beacon, by one-based ID, as being fixed.
Definition: BeaconSetupData.h:95
Definition: BeaconSetupData.h:44
Data for a full target (all the beacons), unswizzled into a "struct of vectors".
Definition: BeaconSetupData.h:53
void setBeaconCount(std::size_t numBeacons, double baseMeasurementVariance, double initialAutocalibrationError)
Resizes all arrays to the numBeacons.
Definition: BeaconSetupData.h:74