-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfig.cpp
More file actions
133 lines (117 loc) · 5.79 KB
/
Config.cpp
File metadata and controls
133 lines (117 loc) · 5.79 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "Config.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <QStringList>
#include <iostream>
#include <QFile>
#include <QDir>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
#include <QStandardPaths>
template<typename Stream>
Stream& operator>>(Stream& s, QString& q)
{
std::string tmp;
s >> tmp;
q = tmp.data();
return s;
}
template<typename Stream>
Stream& operator<<(Stream& s, QString const& q)
{
return s << q.toStdString();
}
void Config::load(QString dir, QString file)
{
using namespace boost::property_tree;
auto tree = ptree{};
QDir d(dir);
d.mkpath(dir);
QFile fin(dir + "/" + file);
if (!fin.exists()) {
fin.open(QIODevice::ReadWrite);
fin.close();
}
read_ini((dir + "/" + file).toStdString(), tree);
Config* config = this;
std::string globalPrefix = "General.";
config->EnableView = tree.get<int>(globalPrefix + "EnableView",
config->EnableView);
config->EnableMove = tree.get<int>(globalPrefix + "EnableMove",
config->EnableMove);
config->EnableRemove = tree.get<int>(globalPrefix + "EnableRemove",
config->EnableRemove);
config->EnableSwap = tree.get<int>(globalPrefix + "EnableSwap",
config->EnableSwap);
config->EnableAdd = tree.get<int>(globalPrefix + "EnableAdd",
config->EnableAdd);
config->EnableRotate = tree.get<int>(globalPrefix + "EnableRotate",
config->EnableRotate);
config->UseAbsoluteDifference = tree.get<bool>(
globalPrefix + "UseAbsoluteDifference",
config->UseAbsoluteDifference);
config->BinarizationThreshold = tree.get<int>(
globalPrefix + "BinarizationThreshold",
config->BinarizationThreshold);
config->MaximumImageValue = tree.get<int>(globalPrefix +
"MaximumImageValue",
config->MaximumImageValue);
config->OpeningErosionSize = tree.get<int>(globalPrefix +
"OpeningErosionSize",
config->OpeningErosionSize);
config->OpeningDilationSize = tree.get<int>(globalPrefix +
"OpeningDilationSize",
config->OpeningDilationSize);
config->ClosingDilationSize = tree.get<int>(globalPrefix +
"ClosingDilationSize",
config->ClosingDilationSize);
config->ClosingErosionSize = tree.get<int>(globalPrefix +
"ClosingErosionSize",
config->ClosingErosionSize);
config->MinBlobSize = tree.get<int>(globalPrefix + "MinBlobSize",
config->MinBlobSize);
config->MaxBlobSize = tree.get<int>(globalPrefix + "MaxBlobSize",
config->MaxBlobSize);
config->LearningRate = tree.get<double>(globalPrefix + "LearningRate",
config->LearningRate);
config->DoNetwork = tree.get<int>(globalPrefix + "DoNetwork",
config->DoNetwork);
config->NetworkPort = tree.get<int>(globalPrefix + "NetworkPort",
config->NetworkPort);
config->DoBackground = tree.get<int>(globalPrefix + "DoBackground",
config->DoBackground);
config->ResetBackground = tree.get<int>(globalPrefix + "ResetBackground",
config->ResetBackground);
}
void Config::save(QString dir, QString file)
{
using namespace boost::property_tree;
auto tree = ptree{};
Config* config = this;
std::string globalPrefix = "General.";
tree.put(globalPrefix + "EnableView", config->EnableView);
tree.put(globalPrefix + "EnableMove", config->EnableMove);
tree.put(globalPrefix + "EnableRemove", config->EnableRemove);
tree.put(globalPrefix + "EnableSwap", config->EnableSwap);
tree.put(globalPrefix + "EnableAdd", config->EnableAdd);
tree.put(globalPrefix + "EnableRotate", config->EnableRotate);
tree.put(globalPrefix + "UseAbsoluteDifference",
config->UseAbsoluteDifference);
tree.put(globalPrefix + "BinarizationThreshold",
config->BinarizationThreshold);
tree.put(globalPrefix + "MaximumImageValue", config->MaximumImageValue);
tree.put(globalPrefix + "OpeningErosionSize", config->OpeningErosionSize);
tree.put(globalPrefix + "OpeningDilationSize",
config->OpeningDilationSize);
tree.put(globalPrefix + "ClosingDilationSize",
config->ClosingDilationSize);
tree.put(globalPrefix + "ClosingErosionSize", config->ClosingErosionSize);
tree.put(globalPrefix + "MinBlobSize", config->MinBlobSize);
tree.put(globalPrefix + "MaxBlobSize", config->MaxBlobSize);
tree.put(globalPrefix + "LearningRate", config->LearningRate);
tree.put(globalPrefix + "DoNetwork", config->DoNetwork);
tree.put(globalPrefix + "NetworkPort", config->NetworkPort);
tree.put(globalPrefix + "DoBackground", config->DoBackground);
tree.put(globalPrefix + "ResetBackground", config->ResetBackground);
write_ini((dir + "/" + file).toStdString(), tree);
}