OSVR-Core
ForEachTracked.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_ForEachTracked_h_GUID_8DA1845D_2D7F_4C8C_9424_C18D06339380
26 #define INCLUDED_ForEachTracked_h_GUID_8DA1845D_2D7F_4C8C_9424_C18D06339380
27 
28 // Internal Includes
29 #include "TrackingSystem.h"
30 #include "TrackedBody.h"
31 #include "TrackedBodyTarget.h"
32 
33 // Library/third-party includes
34 // - none
35 
36 // Standard includes
37 // - none
38 
39 namespace osvr {
40 namespace vbtracker {
42  template <typename F> inline void forEachBody(TrackingSystem &sys, F &&f) {
43  auto n = static_cast<BodyId::wrapped_type>(sys.getNumBodies());
44  for (BodyId::wrapped_type i = 0; i < n; ++i) {
45  f(sys.getBody(BodyId(i)));
46  }
47  }
48 
50  template <typename F>
51  inline void forEachBody(TrackingSystem const &sys, F &&f) {
52  auto n = static_cast<BodyId::wrapped_type>(sys.getNumBodies());
53  for (BodyId::wrapped_type i = 0; i < n; ++i) {
54  f(sys.getBody(BodyId(i)));
55  }
56  }
57 
61  template <typename F> inline void forEachTarget(TrackedBody &body, F &&f) {
62  body.forEachTarget(std::forward<F>(f));
63  }
64 
68  template <typename F>
69  inline void forEachTarget(TrackedBody const &body, F &&f) {
70  body.forEachTarget(std::forward<F>(f));
71  }
72 
74  template <typename F>
75  inline void forEachTarget(TrackingSystem &sys, F &&f) {
76  forEachBody(sys, [&](TrackedBody &body) {
77  forEachTarget(body, std::forward<F>(f));
78  });
79  }
80 
82  template <typename F>
83  inline void forEachTarget(TrackingSystem const &sys, F &&f) {
84  forEachBody(sys, [&](TrackedBody const &body) {
85  forEachTarget(body, std::forward<F>(f));
86  });
87  }
88 
90  template <typename F> inline void forEachIMU(TrackingSystem &sys, F &&f) {
91  forEachBody(sys, [&](TrackedBody &body) {
92  if (body.hasIMU()) {
93  f(body.getIMU());
94  }
95  });
96  }
97 
99  template <typename F>
100  inline void forEachIMU(TrackingSystem const &sys, F &&f) {
101  forEachBody(sys, [&](TrackedBody const &body) {
102  if (body.hasIMU()) {
103  f(body.getIMU());
104  }
105  });
106  }
107 } // namespace vbtracker
108 } // namespace osvr
109 #endif // INCLUDED_ForEachTracked_h_GUID_8DA1845D_2D7F_4C8C_9424_C18D06339380
void forEachBody(TrackingSystem &sys, F &&f)
For each body in a tracking system.
Definition: ForEachTracked.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
TrackedBodyIMU & getIMU()
Get the IMU - only valid if hasIMU is true.
Definition: TrackedBody.h:113
void forEachIMU(TrackingSystem &sys, F &&f)
For each IMU in a tracking system.
Definition: ForEachTracked.h:90
Definition: TrackingSystem.h:54
bool hasIMU() const
Does this tracked body have an IMU?
Definition: TrackedBody.h:110
This is the class representing a tracked rigid body in the system.
Definition: TrackedBody.h:56
void forEachTarget(TrackedBody &body, F &&f)
For each target belonging to a tracked body.
Definition: ForEachTracked.h:61