-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
98 lines (79 loc) · 2.32 KB
/
utils.cpp
File metadata and controls
98 lines (79 loc) · 2.32 KB
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
#include "utils.h"
bool TCPUtils::startWith(const std::string& str, const std::string& start)
{
return str.rfind(start, 0) == 0;
}
bool TCPUtils::endWith(const std::string& str, const std::string& end)
{
if (str.length() >= end.length())
{
return (0 == str.compare(str.length() - end.length(), end.length(), end));
}
return false;
}
bool TCPUtils::contains(const std::string& str, const std::string& sub)
{
return str.find(sub) != std::string::npos;
}
std::vector<std::string> TCPUtils::split(const std::string& str, const std::string& delimiter)
{
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do
{
pos = str.find(delimiter, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos - prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delimiter.length();
} while (pos < str.length() && prev < str.length());
return tokens;
}
ArucoTag::ArucoTag(int id, std::string name, std::array<float, 2> pos, std::array<float, 3> rot) : _id(id), _name(std::move(name)), _pos(pos), _rot(rot) {}
int ArucoTag::id() const {
return _id;
}
std::string ArucoTag::name() const {
return _name;
}
std::array<float, 2> ArucoTag::pos() const {
return _pos;
}
std::array<float, 3> ArucoTag::rot() const {
return _rot;
}
void ArucoTag::setId(int id) {
_id = id;
}
void ArucoTag::setName(const std::string& name) {
_name = name;
}
void ArucoTag::setPos(float x, float y) {
this->_pos[0] = x;
this->_pos[1] = y;
}
void ArucoTag::setRot(float x, float y, float z) {
this->_rot[0] = x;
this->_rot[1] = y;
this->_rot[2] = z;
}
ArucoTag& ArucoTag::operator=(const ArucoTag& tag) {
_id = tag.id();
_name = tag.name();
_pos = tag.pos();
_rot = tag.rot();
return *this;
}
void ArucoTag::find() {
nbFind++;
}
int ArucoTag::getNbFind() const {
return nbFind;
}
std::ostream& operator<<(std::ostream& os, const ArucoTag& tag) {
os << "ArucoTag{id=" << tag.id() << ", name=" << tag.name() << ", pos=[" << tag.pos()[0] << ", " << tag.pos()[1] << "], rot=[" << tag.rot()[0] << ", " << tag.rot()[1] << ", " << tag.rot()[2] << "]}";
return os;
}
double distanceToTag(const ArucoTag& tag) {
return std::sqrt(pow(tag.pos()[0], 2) + pow(tag.pos()[1], 2));
}