Tornado-Visualization/datenvisualisierung_sose2024/horizontalslicetoimagemapper.cpp

90 lines
2.6 KiB
C++

#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() {
// 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
//std::cout << xs << " hier kommt noch ys:" << ys << std::endl;
QImage image(xs, ys, QImage::Format_RGB32);
QRgb colour;
int value;
if (!magnitudeBool) {
for (int i = 0; i < xs; i++) {
for (int j = 0; j < ys; j++) {
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 {
for (int i = 0; i < xs; i++) {
for (int j = 0; j < ys; j++) {
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
// maps the UHH logo to a frame
QImage image;
if (!image.load(fileName)) {
std::cout << "ERROR! Image could not be read!" << std::endl;
}
return image;
}