diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 351611d..ded2d7d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,14 +1,71 @@ #include "MainWindow.h" +#include "hurricanedata/datareader.h" #include "cuda_runtime.h" #include #include #include +#include +#include "consts.h" #include "Shader.h" #include "input/Widget.h" #include "cuda_error.h" +// FIXME: this is the worst code in this project - very ad hoc +// this is a blocking operation, and really does not follow any practices of code design +// should really be a proper class like GpuBufferHandler. +void loadData(float* d_data, const int idx) { + std::cout << "hi\n"; + + std::vector h_data; + std::cout << "hi\n"; + std::string path = "data/trimmed"; + std::cout << "hi\n"; + std::string variable = "T"; + std::cout << "hi\n"; + + DataReader dataReader(path, variable); + std::cout << "hi\n"; + + size_t dataLength = dataReader.fileLength(idx); + std::cout << "hi\n"; + + h_data.resize(dataLength); + std::cout << "hi\n"; + + dataReader.loadFile(h_data.data(), idx); + std::cout << "hi\n"; + + // getTemperature(h_data, idx); + // getSpeed(h_data, idx); + + float* hostVolume = new float[VOLUME_WIDTH * VOLUME_HEIGHT * VOLUME_DEPTH]; + for (int i = 0; i < VOLUME_WIDTH * VOLUME_HEIGHT * VOLUME_DEPTH; i++) { + hostVolume[i] = h_data[i + 0*VOLUME_DEPTH*VOLUME_HEIGHT*VOLUME_WIDTH]; + // Discard missing values + if (h_data[i + 0*VOLUME_DEPTH*VOLUME_HEIGHT*VOLUME_WIDTH] + epsilon >= infty) hostVolume[i] = -infty; + } + std::cout << "hi\n"; + + // Reverse the order of hostVolume - why is it upside down anyway? + for (int i = 0; i < VOLUME_WIDTH; i++) { + for (int j = 0; j < VOLUME_HEIGHT; j++) { + for (int k = 0; k < VOLUME_DEPTH/2; k++) { + float temp = hostVolume[i + j*VOLUME_WIDTH + k*VOLUME_WIDTH*VOLUME_HEIGHT]; + hostVolume[i + j*VOLUME_WIDTH + k*VOLUME_WIDTH*VOLUME_HEIGHT] = hostVolume[i + j*VOLUME_WIDTH + (VOLUME_DEPTH - 1 - k)*VOLUME_WIDTH*VOLUME_HEIGHT]; + hostVolume[i + j*VOLUME_WIDTH + (VOLUME_DEPTH - 1 - k)*VOLUME_WIDTH*VOLUME_HEIGHT] = temp; + } + } + } + std::cout << "hi\n"; + + // Allocate + copy data to GPU + size_t volumeSize = sizeof(float) * VOLUME_WIDTH * VOLUME_HEIGHT * VOLUME_DEPTH; + std::cout << "hi\n"; + cudaMemcpy(d_data, hostVolume, volumeSize, cudaMemcpyHostToDevice); + std::cout << "hi\n"; +} void Window::saveImage() { unsigned char* pixels = new unsigned char[this->w * this->h * 3]; @@ -41,6 +98,8 @@ void framebuffer_size_callback(GLFWwindow* window, int w, int h) { } int Window::init(float* data) { + this->data = data; + // init glfw glfwInit(); // requesting context version 1.0 makes glfw try to provide the latest version if possible @@ -124,6 +183,7 @@ void Window::tick() { this->widget->tick(1000.0/diff); if (this->widget->dateChanged) { // TODO: Load new date file here + loadData(this->data, this->widget->date); this->widget->dateChanged = false; } if (this->widget->saveImage) { diff --git a/src/gui/input/Widget.cpp b/src/gui/input/Widget.cpp index d72243e..bcc42e2 100644 --- a/src/gui/input/Widget.cpp +++ b/src/gui/input/Widget.cpp @@ -107,7 +107,6 @@ void Widget::tick(double fps) { ImGui::DragFloat("Alpha accum. limit", &this->alphaAcumLimit, 0.01f, 0.0f, 1.0f, "%.2f"); ImGui::DragInt("Opacity const. (log [1e-5, 1])", &this->opacityConst, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp); ImGui::DragFloat("Levoy Width", &this->levoyWidth, 0.01f, 0.0f, 100.0f, "%.2f"); - // ImGui::DragFloat("Levoy Focus", &this->levoyFocus, 0.01f, 250.0f, 350.0f, "%.2f"); ImGui::DragFloat("Levoy Focus", &this->levoyFocus, 0.01f, 0.0f, 1.0f, "%.2f"); // the items[] contains the entries for the combobox. The selected index is stored as an int on this->tfComboSelected @@ -115,9 +114,7 @@ void Widget::tick(double fps) { // whatever value is selected here is available on the gpu as d_tfComboSelected. const char* items[] = {"Opacity - gradient", "Opacity - sigmoid", "Opacity - constant", "Opacity - levoy"}; if (ImGui::BeginCombo("Transfer function", items[this->tfComboSelected])) { - // std::cout << "hello???\n"; for (int n = 0; n < IM_ARRAYSIZE(items); n++) { - // std::cout << "letsssssa a asdfa???\n"; const bool is_selected = (this->tfComboSelected == n); if (ImGui::Selectable(items[n], is_selected)) this->tfComboSelected = n; diff --git a/src/main.cu b/src/main.cu index e01eb2d..7bf3789 100644 --- a/src/main.cu +++ b/src/main.cu @@ -43,8 +43,8 @@ void getSpeed(std::vector& speedData, int idx = 0) { int main() { std::vector data; - // getTemperature(data, 254); // 20121028 - getSpeed(data, 254); // 20121028 + getTemperature(data, 254); // 20121028 + // getSpeed(data, 254); // 20121028 std::cout << "DATA size: " << data.size() << std::endl;