Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ProgressReporters.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <functional>
30 #include <string>
31 
33 
34 namespace open3d {
35 namespace utility {
36 
42 public:
43  CountingProgressReporter(std::function<bool(double)> f) {
44  update_progress_ = f;
45  }
46  void SetTotal(int64_t total) { total_ = total; }
47  bool Update(int64_t count) {
48  if (!update_progress_) return true;
49  last_count_ = count;
50  double percent = 0;
51  if (total_ > 0) {
52  if (count < total_) {
53  percent = count * 100.0 / total_;
54  } else {
55  percent = 100.0;
56  }
57  }
58  return CallUpdate(percent);
59  }
60  void Finish() { CallUpdate(100); }
61  // for compatibility with ProgressBar
62  void operator++() { Update(last_count_ + 1); }
63 
64 private:
65  bool CallUpdate(double percent) {
66  if (update_progress_) {
67  return update_progress_(percent);
68  }
69  return true;
70  }
71  std::function<bool(double)> update_progress_;
72  int64_t total_ = -1;
73  int64_t last_count_ = -1;
74 };
75 
78  ConsoleProgressUpdater(const std::string &progress_info,
79  bool active = false)
80  : progress_bar_(100, progress_info, active) {}
81  bool operator()(double pct) {
82  while (last_pct_ < pct) {
83  ++last_pct_;
84  ++progress_bar_;
85  }
86  return true;
87  }
88 
89 private:
90  utility::ProgressBar progress_bar_;
91  int last_pct_ = 0;
92 };
93 
94 } // namespace utility
95 } // namespace open3d
void SetTotal(int64_t total)
Definition: ProgressReporters.h:46
void operator++()
Definition: ProgressReporters.h:62
void Finish()
Definition: ProgressReporters.h:60
int count
Definition: FilePCD.cpp:61
bool Update(int64_t count)
Definition: ProgressReporters.h:47
Definition: ProgressBar.h:34
CountingProgressReporter(std::function< bool(double)> f)
Definition: ProgressReporters.h:43
update_progress(double percent) functor for ProgressBar
Definition: ProgressReporters.h:77
Definition: PinholeCameraIntrinsic.cpp:35
ConsoleProgressUpdater(const std::string &progress_info, bool active=false)
Definition: ProgressReporters.h:78
Definition: ProgressReporters.h:41
bool operator()(double pct)
Definition: ProgressReporters.h:81