-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (99 loc) · 3.85 KB
/
main.cpp
File metadata and controls
117 lines (99 loc) · 3.85 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
#include <QApplication>
#include "BioTracker3App.h"
#include "GuiContext.h"
#include "opencv2/core/core.hpp"
#include <boost/filesystem.hpp>
#include <QVector>
#include <QStandardPaths>
#include <QTextStream>
#include <QFile>
#include "Model/MediaPlayerStateMachine/PlayerParameters.h"
#include "util/types.h"
#include "util/camera/base.h"
#include "util/CLIcommands.h"
#include "Interfaces/IModel/IModelTrackedComponent.h"
#include "util/Config.h"
#include <QDir>
#include <boost/filesystem.hpp>
#if HAS_PYLON
#include <GenApi/GenApi.h>
#endif
// This will hide the console.
// See
// https://stackoverflow.com/questions/2139637/hide-console-of-windows-application
#ifdef _WIN32
//#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#endif
// Get the default Qt message handler.
static const QtMessageHandler QT_DEFAULT_MESSAGE_HANDLER =
qInstallMessageHandler(0);
void myMessageOutput(QtMsgType type,
const QMessageLogContext& context,
const QString& msg)
{
if (type == QtMsgType::QtInfoMsg)
return;
QString fmsg = qFormatLogMessage(type, context, msg);
QString outf = IConfig::dataLocation + "/log.txt";
std::string debugs = outf.toStdString();
QFile outFile(outf);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << fmsg << endl;
(*QT_DEFAULT_MESSAGE_HANDLER)(type, context, msg);
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
app.setOrganizationName("FU Berlin");
app.setApplicationName("BioTracker");
IConfig::configLocation = QStandardPaths::writableLocation(
QStandardPaths::AppConfigLocation);
IConfig::dataLocation = QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation);
Config* cfg = new Config();
CLI::optionParser(argc, argv, cfg);
QString cfgLoc = cfg->CfgCustomLocation.isEmpty() ? Config::configLocation
: cfg->CfgCustomLocation;
cfg->load(cfgLoc, "config.ini");
cfg->save(cfgLoc, "config.ini");
#if HAS_PYLON
const auto cache = boost::filesystem::path{
QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
.toStdString()};
const auto genicamCache = cache / "genicam_xml_cache";
boost::filesystem::create_directories(genicamCache);
GenICam::SetGenICamCacheFolder(GenICam::gcstring{genicamCache.c_str()});
qputenv(GENICAM_CACHE_VERSION,
QByteArray::fromStdString(genicamCache.string()));
#endif
qRegisterMetaType<cv::Mat>("cv::Mat");
qRegisterMetaType<std::size_t>("std::size_t");
qRegisterMetaType<size_t>("size_t");
qRegisterMetaType<std::vector<boost::filesystem::path>>(
"std::vector<boost::filesystem::path>");
qRegisterMetaType<BiotrackerTypes::AreaType>("BiotrackerTypes::AreaType");
qRegisterMetaType<QVector<bool>>("QVector<bool>");
qRegisterMetaType<QVector<QString>>("QVector<QString>");
qRegisterMetaType<QMap<QString, cv::Mat>>("QMap<QString, cv::Mat>");
qRegisterMetaType<std::shared_ptr<const playerParameters>>(
"std::shared_ptr<const playerParameters>");
qRegisterMetaType<CameraConfiguration>("CameraConfiguration");
qRegisterMetaTypeStreamOperators<QList<IModelTrackedComponent*>>(
"QList<IModelTrackedComponent*>");
qInstallMessageHandler(myMessageOutput);
QDir qd;
qd.mkpath(IConfig::configLocation);
qd.mkpath(IConfig::dataLocation);
qd.mkpath(cfg->DirPlugins);
qd.mkpath(cfg->DirVideos);
qd.mkpath(cfg->DirTracks);
qd.mkpath(cfg->DirTrials);
qd.mkpath(cfg->DirScreenshots);
qd.mkpath(cfg->DirTemp);
BioTracker3App bioTracker3(&app);
GuiContext context(&bioTracker3, cfg);
bioTracker3.setBioTrackerContext(&context);
bioTracker3.runBioTracker();
app.exec();
}