-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToolBox.cpp
66 lines (52 loc) · 1.14 KB
/
ToolBox.cpp
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
#include "ToolBox.hpp"
#define NB_MIN_SELECTIONS 30
ToolBox::ToolBox() {}
Tool* ToolBox::findTheGoodOne(Tool& t) {
Tool* tool = NULL;
if(tools.empty()){
return NULL;
}
double currentConfidence = t.compare(tools[0].getFeatures());;
int theGoodOneIndex = -1;
double c = 0;
for(unsigned int i=1; i<tools.size(); i++)
{
c = t.compare(tools[i].getFeatures());
if(c >= currentConfidence && c >= 10)
{
theGoodOneIndex = i;
currentConfidence = c;
}
}
if(theGoodOneIndex != -1){
tool = (Tool*)(&tools[theGoodOneIndex]);
tools[theGoodOneIndex].hasBeenSelected();
}
return tool;
}
Tool* ToolBox::last() const {
if(tools.size() == 0){
return NULL;
}
return (Tool*)&tools.back();
}
bool ToolBox::empty() const {
return tools.empty();
}
void ToolBox::add(Tool& tool) {
tools.push_back(tool);
tool.setID(tools.size());
}
void ToolBox::clean() {
for(std::vector<Tool>::iterator it = tools.begin();
it != tools.end();
it++) {
if(it->getSelections() < NB_MIN_SELECTIONS) {
tools.erase(it);
}
}
}
int ToolBox::size() const
{
return tools.size();
}