riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
src
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
18
static
std::string version(
"0.0.4-beta"
);
19
20
// Forward Declarations
21
int
run_cli
(
int
argc,
char
*argv[],
Ricom
*ricom);
22
int
run_gui
(
Ricom
*ricom);
23
void
log2file
(
Ricom
*ricom);
24
25
# ifdef __linux__
26
#include <sys/utsname.h>
27
std::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
62
int
main
(
int
argc,
char
*argv[])
63
{
64
65
Ricom
ricom;
66
67
if
(argc == 1)
68
{
69
#ifdef _WIN32
70
FreeConsole();
71
#endif
72
log2file
(&ricom);
73
return
run_gui
(&ricom);
74
}
75
else
76
{
77
return
run_cli
(argc, argv, &ricom);
78
}
79
}
80
81
// Redirect all output of cout into a log-file for GUI mode
82
void
log2file
(
Ricom
*ricom)
83
{
84
if
(freopen(
"ricom.log"
,
"a"
, stdout) == NULL)
85
{
86
std::cout <<
"Error redirecting output to log file"
<< std::endl;
87
}
88
if
(freopen(
"ricom.log"
,
"a"
, stderr) == NULL)
89
{
90
std::cout <<
"Error redirecting error output to log file"
<< std::endl;
91
}
92
ricom->
b_print2file
=
true
;
93
auto
t = std::time(
nullptr
);
94
auto
tm = *std::localtime(&t);
95
std::cout << std::endl;
96
std::cout <<
"Ricom version "
<< version <<
" started at "
<< std::put_time(&tm,
"%d/%m/%Y %H:%M:%S"
) << std::endl;
97
std::cout <<
"OS: "
<<
get_os
() << std::endl;
98
}
Camera.h
Ricom.h
Ricom
Definition:
Ricom.h:154
Ricom::b_print2file
bool b_print2file
Definition:
Ricom.h:222
main
int main(int argc, char *argv[])
Definition:
main.cpp:62
get_os
std::string get_os()
Definition:
main.cpp:59
run_gui
int run_gui(Ricom *ricom)
Definition:
RunGUI.cpp:67
log2file
void log2file(Ricom *ricom)
Definition:
main.cpp:82
run_cli
int run_cli(int argc, char *argv[], Ricom *ricom)
Definition:
RunCLI.cpp:21
Generated by
1.9.1