OSVR-Core
IdentifierHelpers.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_IdentifierHelpers_h_GUID_B6F81E02_BE7B_4382_12E5_87296135997D
26 #define INCLUDED_IdentifierHelpers_h_GUID_B6F81E02_BE7B_4382_12E5_87296135997D
27 
28 // Internal Includes
29 #include "BasicTypes.h"
30 
31 // Library/third-party includes
32 #include <boost/assert.hpp>
33 
34 // Standard includes
35 #include <algorithm>
36 #include <iterator>
37 
38 namespace osvr {
39 namespace vbtracker {
40 
43  inline void truncateBrightnessListTo(BrightnessList &brightnesses,
44  size_t n) {
46  auto currentSize = brightnesses.size();
47  if (currentSize > n) {
48  auto excess = currentSize - n;
49  auto newBegin = brightnesses.begin();
50  std::advance(newBegin, excess);
51  brightnesses.erase(brightnesses.begin(), newBegin);
52  if (brightnesses.size() > n) {
53  throw std::logic_error("MATH FAIL");
54  }
55  }
56 #if 0
57  while (brightnesses.size() > n) {
58  brightnesses.pop_front();
59  }
60 #endif
61  }
62 
65  inline BrightnessMinMax
66  findMinMaxBrightness(const BrightnessList &brightnesses) {
67 
68  BOOST_ASSERT_MSG(!brightnesses.empty(), "Must be a non-empty list!");
69  auto extremaIterators =
70  std::minmax_element(begin(brightnesses), end(brightnesses));
71  return std::make_pair(*extremaIterators.first,
72  *extremaIterators.second);
73  }
74 
78  inline LedPatternWrapped
79  getBitsUsingThreshold(const BrightnessList &brightnesses, float threshold) {
81  // Allocate output space for our transform.
82  ret.resize(brightnesses.size());
83 
84  // Transform the brightnesses into a string with '.' for dim
85  // and '*' for bright.
86  std::transform(begin(brightnesses), end(brightnesses), begin(ret),
87  [threshold](Brightness val) {
88  if (val >= threshold) {
89  return '*';
90  } else {
91  return '.';
92  }
93  });
94 
95  return ret;
96  }
97 } // End namespace vbtracker
98 } // End namespace osvr
99 
100 #endif // INCLUDED_IdentifierHelpers_h_GUID_B6F81E02_BE7B_4382_12E5_87296135997D
LedPatternWrapped getBitsUsingThreshold(const BrightnessList &brightnesses, float threshold)
Helper for implementations of LedIdentifier to turn a brightness list into a boolean list based on th...
Definition: IdentifierHelpers.h:79
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
void truncateBrightnessListTo(BrightnessList &brightnesses, size_t n)
Helper for implementations of LedIdentifier to truncate the passed-in brightness list to the maximum ...
Definition: IdentifierHelpers.h:43
t_< detail::transform_< List, Fun >> transform
Given a list and an alias class, apply the alias class to each element in the list and return the res...
Definition: Transform.h:54
std::string LedPatternWrapped
Pattern repeated almost twice.
Definition: BasicTypes.h:48
Header.
BrightnessMinMax findMinMaxBrightness(const BrightnessList &brightnesses)
Helper function for implementations of LedIdentifier to find the minimum and maximum values in a non-...
Definition: IdentifierHelpers.h:66