Tornado-Visualization/datenvisualisierung_sose2024/flowdatasource.cpp

109 lines
3.5 KiB
C++

#include "flowdatasource.h"
#include "tornadoSrc.c"
#include <iostream>
#include <cmath>
FlowDataSource::FlowDataSource() {
// The Constructor
num_x = 0;
num_y = 0;
num_z = 0;
cartesianDataGrid = new float[1];
}
FlowDataSource::~FlowDataSource() {
// The Destructor
delete cartesianDataGrid;
std::cout << "SOURCE DESTRUCTOR CALLED\n";
}
void FlowDataSource::createData(int x, int y, int z, int t) {
// We creare a 3D grid of points, where each point is a 3D-vector
// representing the wind speeds. We generate the wind speeds with
// tornadoSrc by Roger A. Crawfis. We generate the points at t=t.
num_x = x;
num_y = y;
num_z = z;
ct = t;
delete[] cartesianDataGrid; // Prevents data leaks
cartesianDataGrid = new float[3*x*y*z];
gen_tornado(num_x, num_y, num_z, ct, cartesianDataGrid);
}
void FlowDataSource::updateT() {
ct++;
gen_tornado(num_x, num_y, num_z, ct, cartesianDataGrid);
}
void FlowDataSource::decreaseT() {
if (ct > 0) {
ct--;
}
gen_tornado(num_x, num_y, num_z, ct, cartesianDataGrid);
}
void FlowDataSource::resetT() {
ct=0;
gen_tornado(num_x, num_y, num_z, ct, cartesianDataGrid);
}
float FlowDataSource::getDataValue(int iz, int iy, int ix, int ic) {
// We get the value located at a specific grid point and of a specific
// Wind-speed-vector component.
return cartesianDataGrid[iz*num_x*num_y*3 + iy*num_x*3 + ix*3 + ic];
}
void FlowDataSource::printValuesOfHorizontalSlice(int iz, int ic) {
// We print a whole level of the the grid, specifically the ic-th component
// of the Wind-speed-vector. We print all the columns and then all the rows
for (int j = 0; j < num_y; j++) {
for (int i = 0; i < num_x; i++) {
std::cout << cartesianDataGrid[iz*num_x*num_y*3 + j*num_x*3 + i*3 + ic] << "\n";
}
}
}
float FlowDataSource::totalWindSpeed(int iz, int iy, int ix) {
// Calculate the norm of a vector
// Fast inverse square calling???
float x = cartesianDataGrid[iz*num_x*num_y*3 + iy*num_x*3 + ix*3];
float y = cartesianDataGrid[iz*num_x*num_y*3 + iy*num_x*3 + ix*3 +1];
float z = cartesianDataGrid[iz*num_x*num_y*3 + iy*num_x*3 + ix*3 + 2];
return sqrt(x*x + y*y + z*z);
}
void FlowDataSource::printSpeedValuesOfHorizontalSlice(int iz) {
// We print a whole level of the the grid, specifically the ic-th component
// of the Wind-speed-vector. We print all the columns and then all the rows
float largest_speed = 0.0;
for (int j = 0; j < num_y; j++) {
for (int i = 0; i < num_x; i++) {
float speed = FlowDataSource::totalWindSpeed(iz, j, i);
std::cout << speed << "\n";
if (largest_speed < speed) {
largest_speed = speed;
}
}
}
std::cout << "\n The largest speed measured was:" << largest_speed;
}
void FlowDataSource::printLargestSpeed(int iz) {
// We print a whole level of the the grid, specifically the ic-th component
// of the Wind-speed-vector. We print all the columns and then all the rows
float largest_speed = 0.0;
for (int j = 0; j < num_y; j++) {
for (int i = 0; i < num_x; i++) {
float speed = FlowDataSource::totalWindSpeed(iz, j, i);
if (largest_speed < speed) {
largest_speed = speed;
}
}
}
std::cout << "\n The largest speed measured was:" << largest_speed;
}
float* FlowDataSource::returnSource() {
return cartesianDataGrid;
}