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
ProgressMonitor.h
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#ifndef _PROGRESS_MONITOR_
15#define _PROGRESS_MONITOR_
16
17#ifndef _WIN32
18#include <sys/ioctl.h>
19#endif
20
21#include <iostream>
22#include <iomanip>
23#include <cstring>
24#include <atomic>
25#include <chrono>
26#include <cmath>
27
28namespace chc = std::chrono;
29typedef chc::duration<float, std::milli> float_ms;
30
31#define TOTAL_PERCENTAGE 100.0
32#define CHARACTER_WIDTH_PERCENTAGE 4
33#define TERMINAL_WIDTH 120
35{
36
37public:
38 const static int DEFAULT_WIDTH;
39
40 std::atomic<size_t> fr_count; // frame count
41 std::atomic<size_t> fr_count_i; // Frame count in interval
42 float fr_freq; // frame frequency
43 std::atomic<bool> report_set; // update flag (reset internally)
44 std::atomic<bool> report_set_public; // update flag (reset externally)
45 bool first_frame; // first frame flag
47 void reset_flags();
48 explicit ProgressMonitor(size_t fr_total, bool b_bar = true, float report_interval = 250.0, std::ostream &out = std::cerr);
49
50private:
51 bool b_bar; // Print progress bar
52 size_t fr_total; // Total number of frames
53 std::ostream *out; // Output stream
54
55 float fr; // Frequncy per frame
56 float fr_avg; // Average frequency
57 float report_interval; // Update interval
58 std::atomic<int> fr_count_a; // Count measured points for averaging
59
60 chc::time_point<chc::high_resolution_clock> time_stamp;
61
62 const char *unit;
63 const char *unit_bar;
64 const char *unit_space;
65
66 void Report(unsigned long idx, float print_val);
67 void ClearBarField();
68 int GetBarLength();
69};
70
71#endif // _PROGRESS_MONITOR_
chc::duration< float, std::milli > float_ms
std::atomic< bool > report_set
std::atomic< size_t > fr_count_i
static const int DEFAULT_WIDTH
ProgressMonitor & operator++()
std::atomic< size_t > fr_count
std::atomic< bool > report_set_public