parent
74aba4f4fa
commit
e7230714f3
@ -0,0 +1,37 @@
|
|||||||
|
#include "colorattributer.h"
|
||||||
|
|
||||||
|
Q_INVOKABLE QColor ColorAttributer::encode(const float& value) {
|
||||||
|
if(myColors.size() < 2)
|
||||||
|
return QColor();
|
||||||
|
|
||||||
|
float normalizedValue = (value - minValue) / (maxValue - minValue);
|
||||||
|
|
||||||
|
auto upper = myColors.lower_bound(normalizedValue);
|
||||||
|
auto lower = upper;
|
||||||
|
if(upper == myColors.begin()) {
|
||||||
|
return upper->second;
|
||||||
|
}
|
||||||
|
else if(upper == myColors.end()) {
|
||||||
|
--lower;
|
||||||
|
return lower->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
--lower;
|
||||||
|
|
||||||
|
float fraction = (normalizedValue - lower->first) / (upper->first - lower->first);
|
||||||
|
|
||||||
|
return QColor::fromRgbF(
|
||||||
|
lower->second.redF() + fraction * (upper->second.redF() - lower->second.redF()),
|
||||||
|
lower->second.greenF() + fraction * (upper->second.greenF() - lower->second.greenF()),
|
||||||
|
lower->second.blueF() + fraction * (upper->second.blueF() - lower->second.blueF())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorAttributer::addColor(const float& value, const QColor& color) {
|
||||||
|
if (value >= 0.0 && value <= 1.0) {
|
||||||
|
myColors[value] = color;
|
||||||
|
} else {
|
||||||
|
return; //invalid color mapping (0->1)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef COLORATTRIBUTER_H
|
||||||
|
#define COLORATTRIBUTER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class ColorAttributer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
std::map<float, QColor> myColors;
|
||||||
|
float minValue, maxValue;
|
||||||
|
QString myName;
|
||||||
|
public:
|
||||||
|
ColorAttributer(QString name, const float& minValue = -3000000.0f, const float& maxValue = -1000000.0f) : minValue(minValue), maxValue(maxValue), myName(name) {}
|
||||||
|
Q_INVOKABLE inline QString getName() const {return myName;}
|
||||||
|
Q_INVOKABLE void addColor(const float& value, const QColor& color);
|
||||||
|
Q_INVOKABLE QColor encode(const float& value);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLORATTRIBUTER_H
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "perlin.h"
|
||||||
|
|
||||||
|
Perlin::Perlin()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef PERLIN_H
|
||||||
|
#define PERLIN_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <math.h>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
class Perlin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Perlin();
|
||||||
|
float interpolate(float a, float b, float x) {
|
||||||
|
float ft = x * 3.1415927;
|
||||||
|
float f = (1 - cos(ft)) * 0.5;
|
||||||
|
return a * (1 - f) + b * f;
|
||||||
|
}
|
||||||
|
float noise(int x, int y, float t, int seed) {
|
||||||
|
int n = x + y * 57 + int(t) * 131 + seed;
|
||||||
|
n = (n << 13) ^ n;
|
||||||
|
return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float perlinNoise(float x, float y, float t, int seed) {
|
||||||
|
int wholePartX = (int)x;
|
||||||
|
float fractionalPartX = x - wholePartX;
|
||||||
|
|
||||||
|
int wholePartY = (int)y;
|
||||||
|
float fractionalPartY = y - wholePartY;
|
||||||
|
|
||||||
|
float v1 = noise(wholePartX, wholePartY, t, seed);
|
||||||
|
float v2 = noise(wholePartX + 1, wholePartY, t, seed);
|
||||||
|
float v3 = noise(wholePartX, wholePartY + 1, t, seed);
|
||||||
|
float v4 = noise(wholePartX + 1, wholePartY + 1, t, seed);
|
||||||
|
|
||||||
|
float i1 = interpolate(v1, v2, fractionalPartX);
|
||||||
|
float i2 = interpolate(v3, v4, fractionalPartX);
|
||||||
|
|
||||||
|
return interpolate(i1, i2, fractionalPartY);
|
||||||
|
}
|
||||||
|
void fillWithPerlinNoise(QVector<float>& vector, int width, int height, int seed) {
|
||||||
|
float t = 0.0f;
|
||||||
|
for (int y = 0; y < height; ++y) {
|
||||||
|
for (int x = 0; x < width; ++x) {
|
||||||
|
float noise = perlinNoise(x / (float)width, y / (float)height, t, seed);
|
||||||
|
vector[(y * width + x)] = noise;
|
||||||
|
}
|
||||||
|
t += 0.01f; // flow speed variable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PERLIN_H
|
@ -1,24 +1,36 @@
|
|||||||
#include "pollingtimer.h"
|
#include "pollingtimer.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
|
#include "pollingtimer.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
void PollingTimer::doLoop() {
|
||||||
|
while (shouldRun) {
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
_c->exec();
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||||
|
if (elapsed < this->timeout) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(this->timeout - elapsed));
|
||||||
|
}
|
||||||
|
fprintf(stderr, "time elapsed: %lld",elapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PollingTimer::start() {
|
void PollingTimer::start() {
|
||||||
|
if (myThread != nullptr) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
shouldRun = true;
|
shouldRun = true;
|
||||||
|
myThread = new std::thread([this]() { this->doLoop(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void PollingTimer::stop() {
|
void PollingTimer::stop() {
|
||||||
|
if (myThread != nullptr) {
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
myThread->join();
|
||||||
|
delete myThread;
|
||||||
void PollingTimer::doLoop(){
|
myThread = nullptr;
|
||||||
std::chrono::steady_clock::time_point begin;
|
|
||||||
std::chrono::steady_clock::time_point end;
|
|
||||||
|
|
||||||
while(shouldRun){
|
|
||||||
begin = std::chrono::steady_clock::now();
|
|
||||||
_c->exec();
|
|
||||||
end = std::chrono::steady_clock::now();
|
|
||||||
std::this_thread::sleep_for(
|
|
||||||
std::chrono::microseconds((this->timeout)
|
|
||||||
- std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,23 @@
|
|||||||
#include "thermaldatarenderer.h"
|
#include "thermaldatarenderer.h"
|
||||||
|
#include <chrono>
|
||||||
|
void ThermalDataRenderer::receiveNewData(QVector<float> data) {
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
//fprintf(stderr, "in renderer");
|
||||||
|
//fprintf(stderr, "renderer received data of length: %d\n",data.length());
|
||||||
|
|
||||||
ThermalDataRenderer::ThermalDataRenderer()
|
if(activeAttributer >= attributers.size()){
|
||||||
{
|
fprintf(stderr, "attr size mismatch: %d; %d",activeAttributer,attributers.size());
|
||||||
|
activeAttributer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(renderBuffer.size() < data.size())
|
||||||
|
renderBuffer = QVector<QColor>(data.size()+1);
|
||||||
|
|
||||||
|
for (int i = 0; i < data.size() && i < renderBuffer.size(); ++i) {
|
||||||
|
renderBuffer[i] = attributers[activeAttributer]->encode(data[i]);
|
||||||
|
}
|
||||||
|
emit dataChanged();
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||||
|
//fprintf(stderr,"renderer time: %lld\n",elapsed);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue