...
 
Commits (2)
//
// CPlot.hpp
// dlibxx
//
// Created by 蒋志平 on 2017/12/6.
//
//
// CPlot.hpp
// dlibxx
//
// Created by 蒋志平 on 2017/12/6.
//
#ifndef CPlot_h
#define CPlot_h
......@@ -58,10 +58,8 @@ public:
//±flΩÁ¥Û–°
int border_size;
template<class T>
void plot(T *y, size_t Cnt, CvScalar color, char type = '*', bool is_need_lined = true);
template<class T>
void plot(T *x, T *y, size_t Cnt, CvScalar color, char type = '*', bool is_need_lined = true);
template<class T> void plot(T *y, size_t Cnt, CvScalar color, char type = '*', bool is_need_lined = true);
template<class T> void plot(T *x, T *y, size_t Cnt, CvScalar color, char type = '*', bool is_need_lined = true);
void xlabel(string xlabel_name, CvScalar label_color);
void ylabel(string ylabel_name, CvScalar label_color);
......@@ -74,5 +72,52 @@ public:
};
//∑∂–Յ˺∆
template<class T>
void CPlot::plot(T *X, T *Y, size_t Cnt, CvScalar color, char type, bool is_need_lined)
{
//∂‘ ˝æ›Ω¯––¥Ê¥¢
T tempX, tempY;
vector<CvPoint2D64f>data;
for (int i = 0; i < Cnt; i++)
{
tempX = X[i];
tempY = Y[i];
data.push_back(cvPoint2D64f((double)tempX, (double)tempY));
}
this->dataset.push_back(data);
LineType LT;
LT.type = type;
LT.color = color;
LT.is_need_lined = is_need_lined;
this->lineTypeSet.push_back(LT);
//printf("data count:%d\n", this->dataset.size());
this->DrawData(this->Figure); //√ø¥Œ∂º «÷ÿ–¬ªÊ÷∆
}
template<class T>
void CPlot::plot(T *Y, size_t Cnt, CvScalar color, char type, bool is_need_lined)
{
//∂‘ ˝æ›Ω¯––¥Ê¥¢
T tempX, tempY;
vector<CvPoint2D64f>data;
for (int i = 0; i < Cnt; i++)
{
tempX = i;
tempY = Y[i];
data.push_back(cvPoint2D64f((double)tempX, (double)tempY));
}
this->dataset.push_back(data);
LineType LT;
LT.type = type;
LT.color = color;
LT.is_need_lined = is_need_lined;
this->lineTypeSet.push_back(LT);
this->DrawData(this->Figure);
}
#endif /* CPlot_h */
......@@ -9,23 +9,56 @@
#include "TickTockTimer.h"
namespace cve {
void TickTockTimer::tick() {
startTime = system_clock::now();
std::map<std::string, TickTockTimer *> TickTockTimer::instanceMap;
TickTockTimer & TickTockTimer::tick() {
startTime = steady_clock::now();
return *this;
}
void TickTockTimer::tock() {
time_point<system_clock> endTime = system_clock::now();
TickTockTimer & TickTockTimer::tock() {
time_point<steady_clock> endTime = steady_clock::now();
duration<double> elipsed_seconds = endTime - startTime;
durations.push_back(elipsed_seconds.count());
auto duration_double = elipsed_seconds.count();
durations.push_back(duration_double);
if (durations.size() > durationLength) {
durations.pop_front();
}
auto averageDuration = [&] () {
return std::accumulate(durations.begin(), durations.end(), 0.0) / durations.size();
}();
std::printf("Timer(%s) %.4fs %.1ffps\n", timerName.c_str(), averageDuration, 1.0/averageDuration);
return *this;
}
TickTockTimer & TickTockTimer::getInstance(const std::string &timerName, int timerLength) {
if (instanceMap.find(timerName) != instanceMap.end()) {
return *instanceMap[timerName];
} else {
auto newTimer = new TickTockTimer(timerName, timerLength);
instanceMap[timerName] = newTimer;
return *instanceMap[timerName];
}
}
TickTockTimer &TickTockTimer::tock_instant() {
time_point<steady_clock> endTime = steady_clock::now();
duration<double> elipsed_seconds = endTime - startTime;
auto duration_double = elipsed_seconds.count();
std::printf("Instant Timer(%s) %.9fs \n", timerName.c_str(), duration_double);
return *this;
}
TickTockTimer &TickTockTimer::tickTockLambda(std::function<void(void)> codeBlock) {
this->tick();
codeBlock();
this->tock_instant();
return *this;
}
}
......@@ -11,23 +11,29 @@
#include <iostream>
#include <chrono>
#include <thread>
#include <numeric>
#include <deque>
#include <map>
#include <string>
using namespace std::chrono;
namespace cve {
class TickTockTimer {
private:
static std::map<std::string, TickTockTimer *> instanceMap;
std::string timerName;
std::deque<double> durations;
int durationLength = 50;
time_point<system_clock> startTime;
time_point<steady_clock> startTime;
public:
TickTockTimer(const std::string & timerName, int timerLength = 50): timerName{timerName}, durationLength{timerLength} {}
void tick();
void tock();
static TickTockTimer & getInstance(const std::string & timerName, int timerLength = 50);
TickTockTimer & tick();
TickTockTimer & tock();
TickTockTimer & tock_instant();
TickTockTimer & tickTockLambda(std::function<void(void)> codeBlock);
};
}
......