diff --git a/README.md b/README.md index 8cde199..86906ce 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ First, initialize the imGui submodule: ```bash -git submodule init imgui -git submodule update imgui +git submodule update --init ``` Then, compile using cmake: diff --git a/src/consts.cu b/src/consts.cu index 30e201f..2252c36 100644 --- a/src/consts.cu +++ b/src/consts.cu @@ -51,3 +51,4 @@ void copyConstantsToDevice() { __device__ float d_opacityK; __device__ float d_sigmoidOne; __device__ float d_sigmoidTwo; +__device__ int d_tfComboSelected; diff --git a/src/consts.h b/src/consts.h index 4790915..7e6faad 100644 --- a/src/consts.h +++ b/src/consts.h @@ -63,6 +63,8 @@ extern __device__ float d_opacityK; // sigmoid function variables extern __device__ float d_sigmoidOne; extern __device__ float d_sigmoidTwo; +// combo box index +extern __device__ int d_tfComboSelected; const int lenStopsPythonLike = 5; const int lenStopsGrayscale = 2; diff --git a/src/gui/input/Widget.cpp b/src/gui/input/Widget.cpp index e57d9a1..92001ef 100644 --- a/src/gui/input/Widget.cpp +++ b/src/gui/input/Widget.cpp @@ -29,9 +29,12 @@ Widget::Widget(GLFWwindow* window) { this->opacityK = 0; this->sigmoidOne = 0.5f; this->sigmoidTwo = -250.0f; + this->tfComboSelected = 0; }; -// TODO: can be marginally improvement by only copying changed values to device - however we're dealing with individual floats here so i dont think the benefit would be all that obvious. +// 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. +// TODO: can be marginally improved by only copying changed values to device - however we're dealing with individual floats here so i dont think the benefit would be all that obvious. +// TODO: wrap basically all ImGui calls in if statements; better form + allows for checking return values / errors. void Widget::tick(double fps) { if (this->renderOnce) { this->renderOnce = false; @@ -49,6 +52,23 @@ void Widget::tick(double fps) { ImGui::DragInt("k (log [1e-10, 1])", &this->opacityK, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp); ImGui::DragFloat("sigmoidOne", &this->sigmoidOne, 0.01f, 0.0f, 1.0f, "%.2f"); ImGui::InputFloat("sigmoidTwo", &this->sigmoidTwo, 10.0f, 100.0f, "%.0f"); + + // the items[] contains the entries for the combobox. The selected index is stored as an int on this->tfComboSelected + // the default entry is set in the constructor, so if you want that to be a specific entry just change it + // whatever value is selected here is available on the gpu as d_tfComboSelected. + const char* items[] = {"First option", "Another option", "this is the third option", "..."}; + if (ImGui::BeginCombo("ComboBox for transferFunction", items[this->tfComboSelected])) + { + for (int n = 0; n < IM_ARRAYSIZE(items); n++) + { + const bool is_selected = (this->tfComboSelected == n); + if (ImGui::Selectable(items[n], is_selected)) + this->tfComboSelected = n; + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } ImGui::End(); ImGui::Begin("Light Controls"); @@ -97,6 +117,7 @@ void Widget::copyToDevice() { cudaMemcpyToSymbol(&d_sigmoidOne, &this->sigmoidOne, sizeof(float)); cudaMemcpyToSymbol(&d_sigmoidTwo, &this->sigmoidTwo, sizeof(float)); + cudaMemcpyToSymbol(&d_tfComboSelected, &this->tfComboSelected, sizeof(float)); } Widget::~Widget() { diff --git a/src/gui/input/Widget.h b/src/gui/input/Widget.h index 21440f9..15370c7 100644 --- a/src/gui/input/Widget.h +++ b/src/gui/input/Widget.h @@ -18,6 +18,7 @@ public: bool renderOnce; char* fps; + int tfComboSelected; int opacityK; float opacityKReal; float sigmoidOne;