wip: dataloading feature
This commit is contained in:
parent
f4588913ea
commit
48e92596e6
|
|
@ -60,7 +60,7 @@ include_directories("${CUDA_INCLUDE_DIRS}")
|
||||||
|
|
||||||
# netcdf
|
# netcdf
|
||||||
find_package(netCDF REQUIRED)
|
find_package(netCDF REQUIRED)
|
||||||
message(STATUS "Found netcdf in ${GLFW3_INCLUDE_DIR}")
|
message(STATUS "Found netcdf in ${NETCDF_INCLUDE_DIR}")
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND nc-config --includedir
|
COMMAND nc-config --includedir
|
||||||
|
|
|
||||||
|
|
@ -76,4 +76,5 @@ extern __constant__ ColorStop d_stopsBluePurleRed[3];
|
||||||
// --------------------------- Functions for handling external constants ---------------------------
|
// --------------------------- Functions for handling external constants ---------------------------
|
||||||
void copyConstantsToDevice();
|
void copyConstantsToDevice();
|
||||||
|
|
||||||
|
|
||||||
#endif // CONSTS_H
|
#endif // CONSTS_H
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,6 @@
|
||||||
#include "input/Widget.h"
|
#include "input/Widget.h"
|
||||||
|
|
||||||
|
|
||||||
// TODO: Delete
|
|
||||||
void saveImage2(const char* filename, unsigned char* framebuffer, int width, int height) { // TODO: Figure out a better way to do this
|
|
||||||
std::ofstream imageFile(filename, std::ios::out | std::ios::binary);
|
|
||||||
imageFile << "P6\n" << width << " " << height << "\n255\n";
|
|
||||||
for (int i = 0; i < width * height * 3; i++) {
|
|
||||||
imageFile << framebuffer[i];
|
|
||||||
}
|
|
||||||
imageFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::Window(unsigned int w, unsigned int h) {
|
Window::Window(unsigned int w, unsigned int h) {
|
||||||
this->w = w;
|
this->w = w;
|
||||||
this->h = h;
|
this->h = h;
|
||||||
|
|
@ -65,18 +55,10 @@ int Window::init(float* data) {
|
||||||
// init imGUI
|
// init imGUI
|
||||||
this->widget = new Widget(this->window);
|
this->widget = new Widget(this->window);
|
||||||
|
|
||||||
|
// loop function for draw calls etc.
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
Window::tick();
|
Window::tick();
|
||||||
}
|
}
|
||||||
// TODO: Remove this, this was just for ray-casting debug
|
|
||||||
// Window::tick();
|
|
||||||
// Window::tick();
|
|
||||||
// // Save the image
|
|
||||||
// unsigned char* pixels = new unsigned char[this->w * this->h * 3];
|
|
||||||
// glReadPixels(0, 0, this->w, this->h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
|
||||||
// saveImage2("output.ppm", pixels, this->w, this->h);
|
|
||||||
// delete[] pixels;
|
|
||||||
|
|
||||||
Window::free(data);
|
Window::free(data);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -116,6 +98,10 @@ void Window::tick() {
|
||||||
|
|
||||||
// input
|
// input
|
||||||
this->widget->tick(1000.0/diff);
|
this->widget->tick(1000.0/diff);
|
||||||
|
if (this->widget->dateChanged) {
|
||||||
|
// TODO: Load new date file here
|
||||||
|
this->widget->dateChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
// tick render
|
// tick render
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,63 @@
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
// probably not the cleanest way to do this but it works
|
||||||
|
void parseDate(char* string, int dayOfYear) {
|
||||||
|
switch (dayOfYear) {
|
||||||
|
case 1 ... 31:
|
||||||
|
sprintf(string, "Jan %d", dayOfYear);
|
||||||
|
break;
|
||||||
|
case 32 ... 60:
|
||||||
|
sprintf(string, "Feb %d", dayOfYear-31);
|
||||||
|
break;
|
||||||
|
case 61 ... 91:
|
||||||
|
sprintf(string, "Mar %d", dayOfYear-60);
|
||||||
|
break;
|
||||||
|
case 92 ... 121:
|
||||||
|
sprintf(string, "Apr %d", dayOfYear-91);
|
||||||
|
break;
|
||||||
|
case 122 ... 152:
|
||||||
|
sprintf(string, "May %d", dayOfYear-121);
|
||||||
|
break;
|
||||||
|
case 153 ... 182:
|
||||||
|
sprintf(string, "Jun %d", dayOfYear-152);
|
||||||
|
break;
|
||||||
|
case 183 ... 213:
|
||||||
|
sprintf(string, "Jul %d", dayOfYear-182);
|
||||||
|
break;
|
||||||
|
case 214 ... 244:
|
||||||
|
sprintf(string, "Aug %d", dayOfYear-213);
|
||||||
|
break;
|
||||||
|
case 245 ... 274:
|
||||||
|
sprintf(string, "Sep %d", dayOfYear-244);
|
||||||
|
break;
|
||||||
|
case 275 ... 305:
|
||||||
|
sprintf(string, "Oct %d", dayOfYear-274);
|
||||||
|
break;
|
||||||
|
case 306 ... 335:
|
||||||
|
sprintf(string, "Nov %d", dayOfYear-305);
|
||||||
|
break;
|
||||||
|
case 336 ... 366:
|
||||||
|
sprintf(string, "Dec %d", dayOfYear-335);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sprintf(string, "∞");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget::Widget(GLFWwindow* window) {
|
Widget::Widget(GLFWwindow* window) :
|
||||||
|
opacityK(0),
|
||||||
|
sigmoidOne(0.5f),
|
||||||
|
sigmoidTwo(-250.0f),
|
||||||
|
tfComboSelected(0),
|
||||||
|
dateChanged(false),
|
||||||
|
paused(true),
|
||||||
|
renderOnce(false),
|
||||||
|
bgColor(Color3::init(0.1f, 0.1f, 0.1f)),
|
||||||
|
date(0)
|
||||||
|
{
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
this->io = ImGui::GetIO();
|
this->io = ImGui::GetIO();
|
||||||
|
|
@ -13,23 +67,12 @@ Widget::Widget(GLFWwindow* window) {
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
ImGui_ImplOpenGL3_Init();
|
ImGui_ImplOpenGL3_Init();
|
||||||
|
|
||||||
this->cameraPos = Point3::init(50.0f, -50.0f, -75.0f); // Camera for partially trimmed data set
|
|
||||||
// this->cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
|
||||||
|
|
||||||
Vec3 h_center = Vec3::init((float)VOLUME_WIDTH/2.0f, (float)VOLUME_HEIGHT/2.0f, (float)VOLUME_DEPTH/2.0f);
|
|
||||||
this->cameraDir = (h_center - this->cameraPos).normalize();
|
|
||||||
|
|
||||||
this->bgColor = Color3::init(0.1f, 0.1f, 0.1f);
|
|
||||||
this->lightPos = Point3::init(1.5, 2.0, -1.0);
|
|
||||||
|
|
||||||
this->fps = (char*)malloc(512*sizeof(char));
|
this->fps = (char*)malloc(512*sizeof(char));
|
||||||
this->paused = true;
|
this->dateString = (char*)malloc(512*sizeof(char));
|
||||||
this->renderOnce = false;
|
sprintf(this->dateString, "January 1st");
|
||||||
|
|
||||||
this->opacityK = 0;
|
resetCamera();
|
||||||
this->sigmoidOne = 0.5f;
|
resetLight();
|
||||||
this->sigmoidTwo = -250.0f;
|
|
||||||
this->tfComboSelected = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// REFACTOR: should probably not have all the logic in one function; something like a list of ImplementedWidgets with each a Render() function (a la interface) would be better.
|
// REFACTOR: should probably not have all the logic in one function; something like a list of ImplementedWidgets with each a Render() function (a la interface) would be better.
|
||||||
|
|
@ -45,8 +88,6 @@ void Widget::tick(double fps) {
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
// input widgets
|
|
||||||
float min = -1, max = 1;
|
|
||||||
|
|
||||||
ImGui::Begin("Transfer Function Controls");
|
ImGui::Begin("Transfer Function Controls");
|
||||||
ImGui::DragInt("k (log [1e-10, 1])", &this->opacityK, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp);
|
ImGui::DragInt("k (log [1e-10, 1])", &this->opacityK, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp);
|
||||||
|
|
@ -71,13 +112,17 @@ void Widget::tick(double fps) {
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
float min = -1, max = 1;
|
||||||
ImGui::Begin("Light Controls");
|
ImGui::Begin("Light Controls");
|
||||||
ImGui::DragScalar("X coordinate", ImGuiDataType_Double, &this->lightPos.x, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("X coordinate", ImGuiDataType_Double, &this->lightPos.x, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Y coordinate", ImGuiDataType_Double, &this->lightPos.z, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Y coordinate", ImGuiDataType_Double, &this->lightPos.z, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Z coordinate", ImGuiDataType_Double, &this->lightPos.y, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Z coordinate", ImGuiDataType_Double, &this->lightPos.y, 0.5f, &min, &max, "%.3f");
|
||||||
|
if (ImGui::Button("Reset light")) resetLight();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Begin("Miscellaneous");
|
|
||||||
|
ImGui::Begin("Simulation Controls");
|
||||||
if (ImGui::Button(this->paused ? "Unpause" : "Pause")) this->paused = !this->paused;
|
if (ImGui::Button(this->paused ? "Unpause" : "Pause")) this->paused = !this->paused;
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Render once")) {
|
if (ImGui::Button("Render once")) {
|
||||||
|
|
@ -86,15 +131,26 @@ void Widget::tick(double fps) {
|
||||||
}
|
}
|
||||||
sprintf(this->fps, "%.3f fps\n", fps);
|
sprintf(this->fps, "%.3f fps\n", fps);
|
||||||
ImGui::Text(this->fps);
|
ImGui::Text(this->fps);
|
||||||
|
|
||||||
|
// we have data from 2012-01-01 til 2012-09-11 == 255 days
|
||||||
|
ImGui::SetNextItemWidth(20.0f * ImGui::GetFontSize());
|
||||||
|
if (ImGui::SliderInt("Day of year", &this->date, 1, 255, "%d", ImGuiSliderFlags_NoInput)) {
|
||||||
|
this->dateChanged = true;
|
||||||
|
parseDate(this->dateString, this->date);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text(this->dateString);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
ImGui::Begin("Camera Controls");
|
ImGui::Begin("Camera Controls");
|
||||||
ImGui::DragScalar("X position", ImGuiDataType_Double, &this->cameraPos.x, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("X position", ImGuiDataType_Double, &this->cameraPos.x, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Y position", ImGuiDataType_Double, &this->cameraPos.z, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Y position", ImGuiDataType_Double, &this->cameraPos.z, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Z position", ImGuiDataType_Double, &this->cameraPos.y, 0.5f, &min, &max, "%.3f");
|
ImGui::DragScalar("Z position", ImGuiDataType_Double, &this->cameraPos.y, 0.5f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f");
|
ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f"); // TODO: should wrap around once fully rotated
|
||||||
ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
||||||
ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
||||||
|
if (ImGui::Button("Reset camera")) resetCamera();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
copyToDevice();
|
copyToDevice();
|
||||||
|
|
@ -105,6 +161,19 @@ void Widget::render() {
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::resetCamera() {
|
||||||
|
this->cameraPos = Point3::init(50.0f, -50.0f, -75.0f); // Camera for partially trimmed data set
|
||||||
|
// this->cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
||||||
|
|
||||||
|
Vec3 h_center = Vec3::init((float)VOLUME_WIDTH/2.0f, (float)VOLUME_HEIGHT/2.0f, (float)VOLUME_DEPTH/2.0f);
|
||||||
|
this->cameraDir = (h_center - this->cameraPos).normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Widget::resetLight() {
|
||||||
|
this->lightPos = Point3::init(1.5, 2.0, -1.0);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::copyToDevice() {
|
void Widget::copyToDevice() {
|
||||||
cudaMemcpyToSymbol(&d_cameraPos, &this->cameraPos, sizeof(Point3));
|
cudaMemcpyToSymbol(&d_cameraPos, &this->cameraPos, sizeof(Point3));
|
||||||
cudaMemcpyToSymbol(&d_cameraDir, &this->cameraDir, sizeof(Vec3));
|
cudaMemcpyToSymbol(&d_cameraDir, &this->cameraDir, sizeof(Vec3));
|
||||||
|
|
@ -125,4 +194,5 @@ Widget::~Widget() {
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
free(this->fps);
|
free(this->fps);
|
||||||
|
free(this->dateString);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,33 +5,47 @@
|
||||||
#include "../include/imgui/backends/imgui_impl_glfw.h"
|
#include "../include/imgui/backends/imgui_impl_glfw.h"
|
||||||
#include "../include/imgui/backends/imgui_impl_opengl3.h"
|
#include "../include/imgui/backends/imgui_impl_opengl3.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <string>
|
||||||
#include "linalg/linalg.h"
|
#include "linalg/linalg.h"
|
||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
public:
|
public:
|
||||||
|
bool paused;
|
||||||
|
bool dateChanged;
|
||||||
|
int date;
|
||||||
|
|
||||||
|
void tick(double fps);
|
||||||
|
void render();
|
||||||
|
|
||||||
|
Widget(GLFWwindow* window);
|
||||||
|
~Widget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// camera controls
|
||||||
Point3 cameraDir;
|
Point3 cameraDir;
|
||||||
Vec3 cameraPos;
|
Vec3 cameraPos;
|
||||||
Point3 lightPos;
|
|
||||||
Color3 bgColor; // TODO: widget
|
|
||||||
|
|
||||||
bool paused;
|
// simulation cotnrols
|
||||||
bool renderOnce;
|
bool renderOnce;
|
||||||
char* fps;
|
char* fps;
|
||||||
|
ImGuiIO io;
|
||||||
|
char *dateString;
|
||||||
|
|
||||||
|
// transfer function controls
|
||||||
int tfComboSelected;
|
int tfComboSelected;
|
||||||
int opacityK;
|
int opacityK;
|
||||||
float opacityKReal;
|
float opacityKReal;
|
||||||
float sigmoidOne;
|
float sigmoidOne;
|
||||||
float sigmoidTwo;
|
float sigmoidTwo;
|
||||||
|
|
||||||
ImGuiIO io;
|
// miscellaneous
|
||||||
|
Point3 lightPos;
|
||||||
|
Color3 bgColor; // TODO: widget
|
||||||
|
|
||||||
void tick(double fps);
|
|
||||||
void render();
|
|
||||||
void copyToDevice();
|
void copyToDevice();
|
||||||
|
void resetCamera();
|
||||||
|
void resetLight();
|
||||||
|
|
||||||
Widget(GLFWwindow* window);
|
|
||||||
~Widget();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue