Open3D (C++ API)
0.19.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp
open3d
utility
ProgressReporters.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
// - Open3D: www.open3d.org -
3
// ----------------------------------------------------------------------------
4
// Copyright (c) 2018-2024 www.open3d.org
5
// SPDX-License-Identifier: MIT
6
// ----------------------------------------------------------------------------
7
8
#pragma once
9
10
#include <functional>
11
#include <string>
12
13
#include "
open3d/utility/ProgressBar.h
"
14
15
namespace
open3d
{
16
namespace
utility
{
17
22
class
CountingProgressReporter
{
23
public
:
24
CountingProgressReporter
(std::function<
bool
(
double
)> f) {
25
update_progress_ = f;
26
}
27
void
SetTotal
(int64_t total) { total_ = total; }
28
bool
Update
(int64_t count) {
29
if
(!update_progress_)
return
true
;
30
last_count_ = count;
31
double
percent = 0;
32
if
(total_ > 0) {
33
if
(count < total_) {
34
percent = count * 100.0 / total_;
35
}
else
{
36
percent = 100.0;
37
}
38
}
39
return
CallUpdate(percent);
40
}
41
void
Finish
() { CallUpdate(100); }
42
// for compatibility with ProgressBar
43
void
operator++
() {
Update
(last_count_ + 1); }
44
45
private
:
46
bool
CallUpdate(
double
percent) {
47
if
(update_progress_) {
48
return
update_progress_(percent);
49
}
50
return
true
;
51
}
52
std::function<bool(
double
)> update_progress_;
53
int64_t total_ = -1;
54
int64_t last_count_ = -1;
55
};
56
58
struct
ConsoleProgressUpdater
{
59
ConsoleProgressUpdater
(
const
std::string &progress_info,
60
bool
active =
false
)
61
: progress_bar_(100, progress_info, active) {}
62
bool
operator()
(
double
pct) {
63
while
(last_pct_ < pct) {
64
++last_pct_;
65
++progress_bar_;
66
}
67
return
true
;
68
}
69
70
private
:
71
utility::ProgressBar
progress_bar_;
72
int
last_pct_ = 0;
73
};
74
75
}
// namespace utility
76
}
// namespace open3d
open3d::utility::CountingProgressReporter::SetTotal
void SetTotal(int64_t total)
Definition
ProgressReporters.h:27
open3d::utility::CountingProgressReporter::operator++
void operator++()
Definition
ProgressReporters.h:43
open3d::utility::CountingProgressReporter::Update
bool Update(int64_t count)
Definition
ProgressReporters.h:28
open3d::utility::CountingProgressReporter::CountingProgressReporter
CountingProgressReporter(std::function< bool(double)> f)
Definition
ProgressReporters.h:24
open3d::utility::CountingProgressReporter::Finish
void Finish()
Definition
ProgressReporters.h:41
open3d::utility::ProgressBar
Definition
ProgressBar.h:15
open3d::utility
Definition
Dispatch.h:91
open3d
Definition
PinholeCameraIntrinsic.cpp:16
open3d::utility::ConsoleProgressUpdater::operator()
bool operator()(double pct)
Definition
ProgressReporters.h:62
open3d::utility::ConsoleProgressUpdater::ConsoleProgressUpdater
ConsoleProgressUpdater(const std::string &progress_info, bool active=false)
Definition
ProgressReporters.h:59
ProgressBar.h
Generated by
1.17.0