Berkeley SfM
progress_bar.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 - Erik Nelson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 //
22 // The ProgressBar class prints a progress bar to the console, with percentage
23 // complete and estimated time remaining.
24 //
25 ///////////////////////////////////////////////////////////////////////////////
26 
27 #ifndef BSFM_UTIL_PROGRESS_BAR_H
28 #define BSFM_UTIL_PROGRESS_BAR_H
29 
30 #include <cmath>
31 #include <iomanip>
32 #include <sstream>
33 #include <string.h>
34 
35 #include "timer.h"
36 
37 namespace bsfm {
38 namespace util {
39 
40 class ProgressBar {
41 public:
42  // Initialize a new progress bar with a print message and a maximum number
43  // of items that we are tracking towards. The bar will print 100% when we
44  // our progress reaches 'max'.
45  ProgressBar(const std::string& message, double max);
46  ~ProgressBar();
47 
48  // Update the progress bar with our current value.
49  std::string Update(double progress);
50 
51  // Reset out progress with a new maximum.
52  void Reset(double max);
53 
54  // Getters.
55  double GetMax() const;
56  double GetProgress() const;
57  double GetPercentage() const;
58  double GetRemainingSeconds();
59 
60 private:
61  // Convert from an elapsed time to a remaining amount of time, based on how
62  // long it has taken so far to get to our current progress.
63  double ElapsedToRemaining(double elapsed) const;
64 
65  // Formatting and string functions.
66  std::string FormatRemaining(double elapsed) const;
67  std::string ProgressBarString() const;
68  std::string PrintProgress(double elapsed);
69 
70  // Private members used for storing internal state, such as last message
71  // length, time, etc.
73  std::string message_;
74 
75  double progress_;
76  double max_;
77 
79  static const size_t bar_length_ = 40;
80 
81 }; //\class ProgressBar
82 
83 } //\namespace util
84 } //\namespace bsfm
85 
86 #endif
double GetMax() const
std::string ProgressBarString() const
static const size_t bar_length_
Definition: progress_bar.h:79
std::string PrintProgress(double elapsed)
void Reset(double max)
double GetPercentage() const
double GetProgress() const
std::string FormatRemaining(double elapsed) const
std::string Update(double progress)
ProgressBar(const std::string &message, double max)
Definition: camera.cpp:50
double ElapsedToRemaining(double elapsed) const