riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/* Copyright (C) 2021 Thomas Friedrich, Chu-Ping Yu,
2 * University of Antwerp - All Rights Reserved.
3 * You may use, distribute and modify
4 * this code under the terms of the GPL3 license.
5 * You should have received a copy of the GPL3 license with
6 * this file. If not, please visit:
7 * https://www.gnu.org/licenses/gpl-3.0.en.html
8 *
9 * Authors:
10 * Thomas Friedrich <thomas.friedrich@uantwerpen.be>
11 * Chu-Ping Yu <chu-ping.yu@uantwerpen.be>
12 */
13
14#include <string>
15#include "Ricom.h"
16#include "Camera.h"
17
18static std::string version("0.0.4-beta");
19
20// Forward Declarations
21int run_cli(int argc, char *argv[], Ricom *ricom, CAMERA::Default_configurations &hardware_configurations);
22int run_gui(Ricom *ricom, CAMERA::Default_configurations &hardware_configurations);
23void log2file(Ricom *ricom);
24
25# ifdef __linux__
26#include <sys/utsname.h>
27std::string get_os()
28{
29 struct utsname uts;
30 uname(&uts);
31 return std::string(uts.sysname) + " Kernel : " + std::string(uts.version);
32}
33#elif defined(_WIN32) || defined(WIN32)
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <windows.h>
37
38 typedef LONG NTSTATUS, *PNTSTATUS;
39 #define STATUS_SUCCESS (0x00000000)
40
41 typedef NTSTATUS (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
42
43 std::string get_os() {
44 HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
45 if (hMod) {
46 RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
47 if (fxPtr != nullptr) {
48 RTL_OSVERSIONINFOW rovi = { 0 };
49 rovi.dwOSVersionInfoSize = sizeof(rovi);
50 if ( STATUS_SUCCESS == fxPtr(&rovi) ) {
51 return "Windows " + std::to_string(rovi.dwMajorVersion) + "." + std::to_string(rovi.dwMinorVersion) ;
52 }
53 }
54 }
55 RTL_OSVERSIONINFOW rovi = { 0 };
56 return "Windows";
57}
58#else
59 std::string get_os() {return "Unknown"};
60#endif
61
62int main(int argc, char *argv[])
63{
64
65 Ricom ricom;
66 CAMERA::Default_configurations hardware_configurations;
67
68 if (argc == 1)
69 {
70#ifdef _WIN32
71 FreeConsole();
72#endif
73 log2file(&ricom);
74 return run_gui(&ricom, hardware_configurations);
75 }
76 else
77 {
78 return run_cli(argc, argv, &ricom, hardware_configurations);
79 }
80}
81
82// Redirect all output of cout into a log-file for GUI mode
83void log2file(Ricom *ricom)
84{
85 if (freopen("ricom.log", "a", stdout) == NULL)
86 {
87 std::cout << "Error redirecting output to log file" << std::endl;
88 }
89 if (freopen("ricom.log", "a", stderr) == NULL)
90 {
91 std::cout << "Error redirecting error output to log file" << std::endl;
92 }
93 ricom->b_print2file = true;
94 auto t = std::time(nullptr);
95 auto tm = *std::localtime(&t);
96 std::cout << std::endl;
97 std::cout << "Ricom version " << version << " started at " << std::put_time(&tm, "%d/%m/%Y %H:%M:%S") << std::endl;
98 std::cout << "OS: " << get_os() << std::endl;
99}
Definition Ricom.h:152
bool b_print2file
Definition Ricom.h:220
int main(int argc, char *argv[])
Definition main.cpp:62
int run_gui(Ricom *ricom, CAMERA::Default_configurations &hardware_configurations)
Definition RunGUI.cpp:68
std::string get_os()
Definition main.cpp:59
int run_cli(int argc, char *argv[], Ricom *ricom, CAMERA::Default_configurations &hardware_configurations)
Definition RunCLI.cpp:21
void log2file(Ricom *ricom)
Definition main.cpp:83