OSVR-Core
CVTwoStepProgressBar.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_CVTwoStepProgressBar_h_GUID_259E874E_85B4_4AAD_0FDE_BA90B5D9DCD4
26 #define INCLUDED_CVTwoStepProgressBar_h_GUID_259E874E_85B4_4AAD_0FDE_BA90B5D9DCD4
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <opencv2/core/core.hpp>
33 #include <opencv2/imgproc/imgproc.hpp>
34 
35 // Standard includes
36 #include <tuple>
37 
38 namespace osvr {
39 namespace vbtracker {
40  void drawTwoStepProgressBar(cv::Mat &image, cv::Point location,
41  cv::Size size, std::size_t complete,
42  std::size_t partial, std::size_t incomplete) {
43  static const auto RED = cv::Vec3b{0, 0, 255};
44  static const auto YELLOW = cv::Vec3b{0, 255, 255};
45  static const auto GREEN = cv::Vec3b{0, 255, 0};
46 
47  auto totalUnits = complete + partial + incomplete;
48  double totalWidth = size.width;
49 
52 
55  auto drawBar = [&](int width, cv::Vec3b const &color) {
56  cv::rectangle(image, location,
57  location + cv::Point(width, size.height),
58  cv::Scalar(color), CV_FILLED);
59  };
60 
63  auto drawFraction = [&](std::size_t portionOfTotal,
64  cv::Vec3b const &color) {
65  auto width = double(portionOfTotal) / totalUnits * totalWidth;
66  drawBar(static_cast<int>(width), color);
67  };
68 
72  bool haveBaseBar = false;
73  auto drawBaseBar = [&](cv::Vec3b const &color) {
74  drawBar(size.width, color);
75  haveBaseBar = true;
76  };
77 
78  using std::make_tuple;
81  auto layers = {
82  make_tuple(incomplete, incomplete + partial + complete, RED),
83  make_tuple(partial, partial + complete, YELLOW),
84  make_tuple(complete, complete, GREEN)};
85 
87  for (auto &layer : layers) {
88  std::size_t portionOfTotal;
89  std::size_t cumulative;
90  cv::Vec3b color;
91  std::tie(portionOfTotal, cumulative, color) = layer;
92  if (portionOfTotal == 0) {
94  continue;
95  }
96 
97  if (haveBaseBar) {
98  // Can just draw the fraction if we already have a base
99  // Drawing the cumulative fraction, though, since we overlap.
100  drawFraction(cumulative, color);
101  } else {
102  // Otherwise we get to draw the base.
103  drawBaseBar(color);
104  }
105  }
106  }
107 
108 } // namespace vbtracker
109 } // namespace osvr
110 #endif // INCLUDED_CVTwoStepProgressBar_h_GUID_259E874E_85B4_4AAD_0FDE_BA90B5D9DCD4
void drawTwoStepProgressBar(cv::Mat &image, cv::Point location, cv::Size size, std::size_t complete, std::size_t partial, std::size_t incomplete)
Definition: CVTwoStepProgressBar.h:40
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48