Commit 9cf029b5c304f71170c1649984486577b2a0a87b
1 parent
f4927d54
Added a convenience toTime function
Showing
4 changed files
with
17 additions
and
10 deletions
openbr/core/qtutils.cpp
| @@ -429,6 +429,17 @@ QString toString(const QVariant &variant) | @@ -429,6 +429,17 @@ QString toString(const QVariant &variant) | ||
| 429 | return QString(); | 429 | return QString(); |
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | +QString toTime(int s) | ||
| 433 | +{ | ||
| 434 | + int h = s / (60*60); | ||
| 435 | + int m = (s - h*60*60) / 60; | ||
| 436 | + s = (s - h*60*60 - m*60); | ||
| 437 | + | ||
| 438 | + const QChar fillChar = QLatin1Char('0'); | ||
| 439 | + | ||
| 440 | + return QString("%1:%2:%3").arg(h,2,10,fillChar).arg(m,2,10,fillChar).arg(s,2,10,fillChar); | ||
| 441 | +} | ||
| 442 | + | ||
| 432 | float euclideanLength(const QPointF &point) | 443 | float euclideanLength(const QPointF &point) |
| 433 | { | 444 | { |
| 434 | return sqrt(pow(point.x(), 2) + pow(point.y(), 2)); | 445 | return sqrt(pow(point.x(), 2) + pow(point.y(), 2)); |
openbr/core/qtutils.h
| @@ -65,6 +65,7 @@ namespace QtUtils | @@ -65,6 +65,7 @@ namespace QtUtils | ||
| 65 | QPointF toPoint(const QString &string, bool *ok = NULL); | 65 | QPointF toPoint(const QString &string, bool *ok = NULL); |
| 66 | QRectF toRect(const QString &string, bool *ok = NULL); | 66 | QRectF toRect(const QString &string, bool *ok = NULL); |
| 67 | QStringList naturalSort(const QStringList &strings); | 67 | QStringList naturalSort(const QStringList &strings); |
| 68 | + QString toTime(int s); | ||
| 68 | 69 | ||
| 69 | /**** Process Utilities ****/ | 70 | /**** Process Utilities ****/ |
| 70 | bool runRScript(const QString &file); | 71 | bool runRScript(const QString &file); |
openbr/openbr_plugin.cpp
| @@ -845,10 +845,7 @@ void br::Context::printStatus() | @@ -845,10 +845,7 @@ void br::Context::printStatus() | ||
| 845 | const float p = progress(); | 845 | const float p = progress(); |
| 846 | if (p < 1) { | 846 | if (p < 1) { |
| 847 | int s = timeRemaining(); | 847 | int s = timeRemaining(); |
| 848 | - int h = s / (60*60); | ||
| 849 | - int m = (s - h*60*60) / 60; | ||
| 850 | - s = (s - h*60*60 - m*60); | ||
| 851 | - fprintf(stderr, "%05.2f%% REMAINING=%02d:%02d:%02d COUNT=%g \r", 100 * p, h, m, s, totalSteps); | 848 | + fprintf(stderr, "%05.2f%% REMAINING=%s COUNT=%g \r", 100 * p, QtUtils::toTime(s/1000.0f).toStdString().c_str(), totalSteps); |
| 852 | } | 849 | } |
| 853 | } | 850 | } |
| 854 | 851 |
openbr/plugins/misc.cpp
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | #include <opencv2/highgui/highgui.hpp> | 19 | #include <opencv2/highgui/highgui.hpp> |
| 20 | #include "openbr_internal.h" | 20 | #include "openbr_internal.h" |
| 21 | #include "openbr/core/opencvutils.h" | 21 | #include "openbr/core/opencvutils.h" |
| 22 | +#include "openbr/core/qtutils.h" | ||
| 22 | 23 | ||
| 23 | using namespace cv; | 24 | using namespace cv; |
| 24 | 25 | ||
| @@ -579,12 +580,7 @@ class ProgressCounterTransform : public TimeVaryingTransform | @@ -579,12 +580,7 @@ class ProgressCounterTransform : public TimeVaryingTransform | ||
| 579 | // seconds remaining | 580 | // seconds remaining |
| 580 | int s = float(remaining) / speed; | 581 | int s = float(remaining) / speed; |
| 581 | 582 | ||
| 582 | - int h = s / (60*60); | ||
| 583 | - int m = (s - h*60*60) / 60; | ||
| 584 | - s = (s - h*60*60 - m*60); | ||
| 585 | - | ||
| 586 | - // hours:minutes:seconds | ||
| 587 | - fprintf(stderr, "%05.2f%% REMAINING=%02d:%02d:%02d COUNT=%g \r", p, h, m, s, float(calls)); | 583 | + fprintf(stderr, "%05.2f%% ELAPSED=%s REMAINING=%s COUNT=%g \r", p, QtUtils::toTime(Globals->startTime.elapsed()/1000.0f).toStdString().c_str(), QtUtils::toTime(s).toStdString().c_str(), float(calls)); |
| 588 | 584 | ||
| 589 | timer.start(); | 585 | timer.start(); |
| 590 | set_calls = 0; | 586 | set_calls = 0; |
| @@ -603,11 +599,13 @@ class ProgressCounterTransform : public TimeVaryingTransform | @@ -603,11 +599,13 @@ class ProgressCounterTransform : public TimeVaryingTransform | ||
| 603 | { | 599 | { |
| 604 | (void) data; | 600 | (void) data; |
| 605 | } | 601 | } |
| 602 | + | ||
| 606 | void init() | 603 | void init() |
| 607 | { | 604 | { |
| 608 | calls = 0; | 605 | calls = 0; |
| 609 | set_calls = 0; | 606 | set_calls = 0; |
| 610 | timer.start(); | 607 | timer.start(); |
| 608 | + Globals->startTime.start(); | ||
| 611 | } | 609 | } |
| 612 | 610 | ||
| 613 | public: | 611 | public: |