-
Notifications
You must be signed in to change notification settings - Fork 12
/
ba_stats.hpp
89 lines (76 loc) · 1.88 KB
/
ba_stats.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef SLAM_BA_STATS_H_
#define SLAM_BA_STATS_H_
#include "../util/logging.hpp"
namespace slam {
namespace {
class BaStats {
public:
enum class Ba {
NONE,
POSE,
NEIGHBOR,
LOCAL,
GLOBAL,
// Marker for iteration.
LAST
};
private:
const int last = static_cast<int>(Ba::LAST);
bool enabled;
std::map<Ba, int> bas;
std::map<Ba, int> totalBas;
public:
BaStats(bool enabled) :
enabled(enabled)
{
if (!enabled) return;
for (int i = 0; i < last; ++i) {
Ba l = static_cast<Ba>(i);
bas.emplace(l, 0);
totalBas.emplace(l, 0);
}
}
void update(Ba ba) {
if (!enabled) return;
++bas.at(ba);
}
void finishFrame() {
if (!enabled) return;
int count = 0;
for (int i = 0; i < last; ++i) {
Ba t = static_cast<Ba>(i);
totalBas.at(t) += bas.at(t);
count += bas.at(t);
}
if (count == 0) {
bas.at(Ba::NONE) += 1;
totalBas.at(Ba::NONE) += 1;
}
const char *names[6] = {
"none ",
"pose ",
"neighbor ",
"local ",
"global ",
"TOTAL ",
};
log_info("");
log_info("TYPE \tNUM\tTOTAL");
int sum = 0;
int totalSum = 0;
for (int i = 0; i < last; ++i) {
Ba t = static_cast<Ba>(i);
sum += bas.at(t);
totalSum += totalBas.at(t);
log_info("%s\t%d\t%d", names[i], bas.at(t), totalBas.at(t));
}
log_info("%s\t%d\t%d", names[last], sum, totalSum);
for (int i = 0; i < last; ++i) {
Ba t = static_cast<Ba>(i);
bas.at(t) = 0;
}
}
};
} // anonymous namespace
} // namespace slam
#endif // SLAM_BA_STATS_H_