2024-05-20 17:42:22 +00:00
|
|
|
#include "horizontalslicetoimagemapper.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
HorizontalSliceToImageMapper::HorizontalSliceToImageMapper()
|
|
|
|
{
|
|
|
|
magnitudeBool = false;
|
|
|
|
std::cout << "DEBUG: MAPPER CONSTRUCTOR CALLED" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
HorizontalSliceToImageMapper::~HorizontalSliceToImageMapper()
|
|
|
|
{
|
|
|
|
std::cout << "MAPPER DESTRUCTOR CALLED!\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void HorizontalSliceToImageMapper::getSlice(float *source, int x, int y) {
|
|
|
|
slice = source;
|
|
|
|
xs = x;
|
|
|
|
ys = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HorizontalSliceToImageMapper::getSlice(float *source) {
|
|
|
|
slice = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HorizontalSliceToImageMapper::setMagnitude(bool x) {
|
|
|
|
magnitudeBool = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
float HorizontalSliceToImageMapper::totalWindSpeed(float x, float y, float z) {
|
|
|
|
return sqrt(x*x + y*y + z*z);
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage HorizontalSliceToImageMapper::mapSliceToImage() {
|
2024-07-05 11:00:39 +00:00
|
|
|
// We loop through the windspeed value and map a red colour to it, if positive
|
|
|
|
// otherwise it's a blue colour, the brightness determines the intensity
|
|
|
|
// We amplify the intensity by a factor 3 for a better visualization
|
|
|
|
|
|
|
|
|
2024-05-20 17:42:22 +00:00
|
|
|
//std::cout << xs << " hier kommt noch ys:" << ys << std::endl;
|
|
|
|
QImage image(xs, ys, QImage::Format_RGB32);
|
|
|
|
QRgb colour;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
if (!magnitudeBool) {
|
2024-06-11 11:02:20 +00:00
|
|
|
for (int i = 0; i < xs; i++) {
|
|
|
|
for (int j = 0; j < ys; j++) {
|
2024-05-20 17:42:22 +00:00
|
|
|
value = int(255*slice[3*(j*xs+i)]);
|
|
|
|
//std::cout << slice[3*(i*xs+j)] << " ";
|
|
|
|
//std::cout << value << std::endl;
|
|
|
|
if (value >= 0) {
|
|
|
|
colour = qRgb(3*value, 20, 0);
|
|
|
|
} else {
|
|
|
|
colour = qRgb(0, 20, -3*value);
|
|
|
|
}
|
|
|
|
image.setPixel(j, i, colour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2024-06-11 11:02:20 +00:00
|
|
|
for (int i = 0; i < xs; i++) {
|
|
|
|
for (int j = 0; j < ys; j++) {
|
2024-05-20 17:42:22 +00:00
|
|
|
value = int(HorizontalSliceToImageMapper::totalWindSpeed(255*slice[3*(j*xs+i)+2], 255*slice[3*(j*xs+i)+1], 255*slice[3*(j*xs+i)]));
|
|
|
|
//std::cout << value << std::endl;
|
|
|
|
//always positive so no need for extra checks
|
|
|
|
colour = qRgb(3*value, 20, 20);
|
|
|
|
image.setPixel(j, i, colour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FOR DEBUG
|
|
|
|
if (image.isNull()) {
|
|
|
|
std::cout << "IMAGE LOADING ERROR IN MAPPER";
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage HorizontalSliceToImageMapper::mapSliceToImage(QString fileName) {
|
|
|
|
// CREATED FOR LEARNING PURPOSES
|
2024-07-05 11:00:39 +00:00
|
|
|
// maps the UHH logo to a frame
|
2024-05-20 17:42:22 +00:00
|
|
|
QImage image;
|
|
|
|
if (!image.load(fileName)) {
|
|
|
|
std::cout << "ERROR! Image could not be read!" << std::endl;
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|