forked from LIDS-UNICAMP/MISe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markerinformation.h
107 lines (90 loc) · 2.66 KB
/
markerinformation.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef MARKERINFORMATION_H
#define MARKERINFORMATION_H
#include <QObject>
#include "ift.h"
class MarkerInformation : public QObject
{
Q_OBJECT
public:
MarkerInformation(int label, QString name = "");
MarkerInformation(const MarkerInformation &other);
MarkerInformation &operator =(const MarkerInformation &other);
int label() const;
iftColor color() const;
bool isVisible() const;
bool isActive() const;
QString name() const;
void setColor(iftColor color);
void setLabel(int label);
void activate();
void deactivate();
void setVisible(bool visibility);
void setName(QString name);
static iftColor defaultColor(int label);
signals:
private:
int _label;
iftColor _color;
bool _visible, _active;
QString _name;
bool _useDefaultColor;
};
class MarkerInformationVector : public QVector<MarkerInformation> {
public:
int lastActive() {
return _lastActive;
}
void activate(int label) {
for (MarkerInformation &markerInfo: *this) {
if (label == markerInfo.label())
markerInfo.activate();
else
markerInfo.deactivate();
}
_lastActive = label;
}
void deactivate() {
for (MarkerInformation &markerInfo: *this) {
markerInfo.deactivate();
}
}
MarkerInformation getActive() {
for (MarkerInformation &markerInfo: *this) {
if (markerInfo.isActive())
return markerInfo;
}
return MarkerInformation(-1);
}
bool hasLabel(int label) const {
auto it = std::find_if(begin(), end(),
[label] (const MarkerInformation& m) -> bool { return label == m.label(); });
return it != end();
}
int maxLabel() const {
int max = -1;
for (MarkerInformation mi: *this) {
if (mi.label() > max)
max = mi.label();
}
return max;
}
iftColorTable *generateColorTable() {
if (size() == 0)
return nullptr;
iftColorTable *t = iftCreateColorTable(this->maxLabel() + 1);
for (int i = 0; i < t->ncolors; i++) {
t->color[i] = iftRGBtoYCbCr({{255,255,255},0},255);
}
//TODO this returns all values, it shouldnt
for (MarkerInformation &markerInfo: *this) {
int l = markerInfo.label();
t->color[l].val[0] = markerInfo.color().val[0];
t->color[l].val[1] = markerInfo.color().val[1];
t->color[l].val[2] = markerInfo.color().val[2];
}
return t;
}
private:
int _lastActive = 0;
};
#endif // MARKERINFORMATION_H