OSVR-Core
TrackedBody.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_TrackedBody_h_GUID_1FC60169_196A_4F89_551C_E1B41531BBC8
26 #define INCLUDED_TrackedBody_h_GUID_1FC60169_196A_4F89_551C_E1B41531BBC8
27 
28 // Internal Includes
29 #include "ConfigParams.h"
30 #include "BodyIdTypes.h"
31 #include "ModelTypes.h"
32 #include "CannedIMUMeasurement.h"
33 
34 // Library/third-party includes
36 #include <osvr/Util/TimeValue.h>
37 #include <boost/assert.hpp>
38 
39 // Standard includes
40 #include <memory>
41 
42 namespace osvr {
43 namespace vbtracker {
44  class TrackingSystem;
45  class TrackedBodyIMU;
46  class TrackedBodyTarget;
47  struct TargetSetupData;
48 
56  class TrackedBody {
57  public:
59  TrackedBody(TrackingSystem &system, BodyId id);
61  ~TrackedBody();
63  TrackedBody(TrackedBody const &) = delete;
65  TrackedBody &operator=(TrackedBody const &) = delete;
66  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
67 
84  createIntegratedIMU(double orientationVariance,
85  double angularVelocityVariance = 1.0);
86 
97  TrackedBodyTarget *createTarget(Eigen::Vector3d const &targetToBody,
98  TargetSetupData const &setupData);
100 
102  BodyId getId() const;
103 
105  ConfigParams const &getParams() const;
106 
107  BodyState const &getState() const { return m_state; }
108 
110  bool hasIMU() const { return static_cast<bool>(m_imu); }
111 
114  BOOST_ASSERT_MSG(m_imu, "getIMU() called when hasIMU() is false!");
115  return *m_imu;
116  }
117 
119  TrackedBodyIMU const &getIMU() const {
120  BOOST_ASSERT_MSG(m_imu, "getIMU() called when hasIMU() is false!");
121  return *m_imu;
122  }
123 
126  std::size_t getNumTargets() const { return m_target ? 1 : 0; }
127 
128  TrackedBodyTarget *getTarget(TargetId id) {
129  if (TargetId(0) == id) {
130  return m_target.get();
131  }
132  return nullptr;
133  }
134 
135  TrackedBodyTarget const *getTarget(TargetId id) const {
136  if (TargetId(0) == id) {
137  return m_target.get();
138  }
139  return nullptr;
140  }
141 
142  template <typename F> void forEachTarget(F &&f) {
143  if (m_target) {
144  std::forward<F>(f)(*m_target);
145  }
146  }
147 
148  template <typename F> void forEachTarget(F &&f) const {
149  if (m_target) {
150  std::forward<F>(f)(*m_target);
151  }
152  }
153 
155  bool hasPoseEstimate() const;
156 
157  bool hasEverHadPoseEstimate() const;
158 
182  bool getStateAtOrBefore(osvr::util::time::TimeValue const &desiredTime,
184  BodyState &outState);
185 
203  osvr::util::time::TimeValue const &newTime,
204  BodyState const &newState);
205 
208  void pruneHistory(OSVR_TimeValue const &videoTime);
209 
212 
213  BodyProcessModel &getProcessModel() { return m_processModel; }
214 
216  BodyState &getState() { return m_state; }
217 
221  CannedIMUMeasurement const &meas);
222 
223  TrackingSystem &getSystem() { return m_system; }
224  TrackingSystem const &getSystem() const { return m_system; }
225 
226  private:
230  void applyIMUMeasurement(util::time::TimeValue const &tv,
231  CannedIMUMeasurement const &meas);
234  void pushState();
235  TrackingSystem &m_system;
236  const BodyId m_id;
237 
238  util::time::TimeValue m_stateTime;
239  BodyState m_state;
240  BodyProcessModel m_processModel;
242  struct Impl;
243  std::unique_ptr<Impl> m_impl;
244  std::unique_ptr<TrackedBodyIMU> m_imu;
245  std::unique_ptr<TrackedBodyTarget> m_target;
246  };
247 } // namespace vbtracker
248 } // namespace osvr
249 
250 #endif // INCLUDED_TrackedBody_h_GUID_1FC60169_196A_4F89_551C_E1B41531BBC8
BodyId getId() const
Gets the body ID within the tracking system.
Definition: TrackedBody.cpp:100
bool hasPoseEstimate() const
Do we have a pose estimate for this body in general?
Definition: TrackedBody.cpp:241
TrackedBody(TrackingSystem &system, BodyId id)
Constructor.
Definition: TrackedBody.cpp:55
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
void pruneHistory(OSVR_TimeValue const &videoTime)
Clean histories of no-longer-needed historical state and measurements.
Definition: TrackedBody.cpp:134
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
void replaceStateSnapshot(osvr::util::time::TimeValue const &origTime, osvr::util::time::TimeValue const &newTime, BodyState const &newState)
This is the counterpart to getStateAtOrBefore() and should only be called subsequent to it...
Definition: TrackedBody.cpp:164
TrackedBodyIMU & getIMU()
Get the IMU - only valid if hasIMU is true.
Definition: TrackedBody.h:113
TrackedBodyTarget * createTarget(Eigen::Vector3d const &targetToBody, TargetSetupData const &setupData)
Creates a video-based tracking target (constellation of beacons) to add to this body.
Definition: TrackedBody.cpp:82
Definition: TrackingSystem.h:54
Corresponds to a rigid arrangements of discrete beacons detected by video-based tracking - typically ...
Definition: TrackedBodyTarget.h:77
A safe way to store and transport an orientation measurement or an angular velocity measurement witho...
Definition: CannedIMUMeasurement.h:44
TrackedBody & operator=(TrackedBody const &)=delete
Non-copy-assignable.
TrackedBodyIMU const & getIMU() const
Get the IMU - only valid if hasIMU is true.
Definition: TrackedBody.h:119
std::size_t getNumTargets() const
How many (if any) video-based tracking targets does this tracked body have?
Definition: TrackedBody.h:126
General configuration parameters.
Definition: ConfigParams.h:82
ConfigParams const & getParams() const
Definition: TrackedBody.cpp:96
Data for a full target (all the beacons), unswizzled into a "struct of vectors".
Definition: BeaconSetupData.h:53
Definition: TrackedBodyIMU.h:44
bool hasIMU() const
Does this tracked body have an IMU?
Definition: TrackedBody.h:110
Header providing a C++ wrapper around TimeValueC.h.
This is the class representing a tracked rigid body in the system.
Definition: TrackedBody.h:56
~TrackedBody()
Destructor - explicit so we can use unique_ptr for our pimpls.
Definition: TrackedBody.cpp:67
Definition: TrackedBody.cpp:49
Header.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
BodyState & getState()
Definition: TrackedBody.h:216
osvr::util::time::TimeValue getStateTime() const
Get timestamp associated with current state.
Definition: TrackedBody.cpp:101
bool getStateAtOrBefore(osvr::util::time::TimeValue const &desiredTime, osvr::util::time::TimeValue &outTime, BodyState &outState)
Requests a copy of (a possibly historical snapshot of) body state, as close to desiredTime without be...
Definition: TrackedBody.cpp:105
A basically-constant-velocity model, with the addition of some damping of the velocities inspired by ...
Definition: PoseSeparatelyDampedConstantVelocity.h:43
void incorporateNewMeasurementFromIMU(util::time::TimeValue const &tv, CannedIMUMeasurement const &meas)
Incorporates a brand-new measurement from the IMU into the state.
Definition: TrackedBody.cpp:199