2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
11 * folded-ctf is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
27 #include "progress_bar.h"
29 ProgressBar::ProgressBar() : _visible(false), _value_max(-1) { }
31 void ProgressBar::set_visible(bool visible) {
35 void ProgressBar::init(ostream *out, scalar_t value_max) {
36 _value_max = value_max;
42 void ProgressBar::refresh(ostream *out, scalar_t value) {
43 if(_visible && _value_max > 0) {
44 int step = int((value * 40) / _value_max);
46 if(1 || step > _last_step) {
47 char buffer[width + 1], date_buffer[buffer_size];
49 j = sprintf(buffer, "Timer: ");
51 for(i = 0; i < step; i++) buffer[j + i] = 'X';
52 for(; i < 40; i++) buffer[j + i] = (i%4 == 0) ? '+' : '-';
55 time_t current_time; time(¤t_time);
56 int rt = int(((current_time - _initial_time)/scalar_t(value)) * scalar_t(_value_max - value));
63 strftime(date_buffer, buffer_size, "%a %b %e %H:%M", localtime(¤t));
64 j += snprintf(buffer + j, width - j - 1, " (end ~ %s)", date_buffer);
66 int hours = rt/3600, min = (rt%3600)/60, sec = rt%60;
68 j += snprintf(buffer + j, width - j - 1, " (~%dh%dmin left)", hours, min);
70 j += snprintf(buffer + j, width - j - 1, " (~%dmin%ds left)", min, sec);
72 j += snprintf(buffer + j, width - j - 1, " (~%ds left)", sec);
76 for(; j < width; j++) buffer[j] = ' ';
78 (*out) << buffer << "\r";
85 void ProgressBar::finish(ostream *out) {
87 char buffer[width + 1];
89 time_t current_time; time(¤t_time);
90 int rt = int(current_time - _initial_time);
91 int min = rt/60, sec = rt%60;
92 j = sprintf(buffer, "Timer: Total %dmin%ds", min, sec);
93 for(; j < width; j++) buffer[j] = ' ';
95 (*out) << buffer << endl;