riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
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 
28 namespace chc = std::chrono;
29 typedef 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 
37 public:
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
46  size_t fr_total; // Total number of frames
48  ProgressMonitor &operator+=(int step);
49  void reset_flags();
50  explicit ProgressMonitor(size_t fr_total, bool b_bar = true, float report_interval = 250.0, std::ostream &out = std::cerr);
51 
52 private:
53  bool b_bar; // Print progress bar
54  std::ostream *out; // Output stream
55 
56  float fr; // Frequncy per frame
57  float fr_avg; // Average frequency
58  float report_interval; // Update interval
59  std::atomic<int> fr_count_a; // Count measured points for averaging
60 
61  chc::time_point<chc::high_resolution_clock> time_stamp;
62 
63  const char *unit;
64  const char *unit_bar;
65  const char *unit_space;
66 
67  inline void Report(size_t idx, float print_val);
68  inline void ClearBarField();
69  inline int GetBarLength();
70 };
71 
72 #endif // _PROGRESS_MONITOR_
chc::duration< float, std::milli > float_ms
ProgressMonitor & operator+=(int step)
std::atomic< bool > report_set
std::atomic< size_t > fr_count_i
static const int DEFAULT_WIDTH
ProgressMonitor(size_t fr_total, bool b_bar=true, float report_interval=250.0, std::ostream &out=std::cerr)
ProgressMonitor & operator++()
std::atomic< size_t > fr_count
std::atomic< bool > report_set_public