Implemented picker for color map

This commit is contained in:
Martin Opat 2025-01-15 19:44:16 +01:00
parent 33365a26a7
commit 4b95bb728d
5 changed files with 44 additions and 6 deletions

View File

@ -52,4 +52,5 @@ __device__ float d_opacityK;
__device__ float d_sigmoidShift; __device__ float d_sigmoidShift;
__device__ float d_sigmoidExp; __device__ float d_sigmoidExp;
__device__ int d_tfComboSelected; __device__ int d_tfComboSelected;
__device__ int d_tfComboSelectedColor;
__device__ float d_opacityConst; __device__ float d_opacityConst;

View File

@ -69,6 +69,7 @@ extern __device__ float d_sigmoidShift;
extern __device__ float d_sigmoidExp; extern __device__ float d_sigmoidExp;
// combo box index // combo box index
extern __device__ int d_tfComboSelected; extern __device__ int d_tfComboSelected;
extern __device__ int d_tfComboSelectedColor;
// constant opacity option // constant opacity option
extern __device__ float d_opacityConst; extern __device__ float d_opacityConst;

View File

@ -71,6 +71,21 @@ void Widget::tick(double fps) {
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
// Same comments as above apply
const char* items2[] = {"Python-like", "BPR", "Greyscale", "..."};
if (ImGui::BeginCombo("ComboBox for color map", items2[this->tfComboSelectedColor]))
{
for (int n = 0; n < IM_ARRAYSIZE(items2); n++)
{
const bool is_selected = (this->tfComboSelectedColor == n);
if (ImGui::Selectable(items2[n], is_selected))
this->tfComboSelectedColor = n;
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::End(); ImGui::End();
ImGui::Begin("Light Controls"); ImGui::Begin("Light Controls");
@ -119,10 +134,12 @@ void Widget::copyToDevice() {
cudaMemcpyToSymbol(&d_sigmoidShift, &this->sigmoidShift, sizeof(float)); cudaMemcpyToSymbol(&d_sigmoidShift, &this->sigmoidShift, sizeof(float));
cudaMemcpyToSymbol(&d_sigmoidExp, &this->sigmoidExp, sizeof(float)); cudaMemcpyToSymbol(&d_sigmoidExp, &this->sigmoidExp, sizeof(float));
cudaMemcpyToSymbol(&d_tfComboSelected, &this->tfComboSelected, sizeof(float)); cudaMemcpyToSymbol(&d_tfComboSelected, &this->tfComboSelected, sizeof(int));
this->opacityConstReal = std::pow(10.0f, (-5 + 0.05 * this->opacityConst)); this->opacityConstReal = std::pow(10.0f, (-5 + 0.05 * this->opacityConst));
cudaMemcpyToSymbol(&d_opacityConst, &this->opacityConstReal, sizeof(float)); cudaMemcpyToSymbol(&d_opacityConst, &this->opacityConstReal, sizeof(float));
cudaMemcpyToSymbol(&d_tfComboSelectedColor, &this->tfComboSelectedColor, sizeof(int));
} }
Widget::~Widget() { Widget::~Widget() {

View File

@ -19,6 +19,7 @@ public:
char* fps; char* fps;
int tfComboSelected; int tfComboSelected;
int tfComboSelectedColor;
int opacityK; int opacityK;
float opacityKReal; float opacityKReal;
float sigmoidShift; float sigmoidShift;

View File

@ -40,17 +40,35 @@ __device__ float4 transferFunction(float density, const Vec3& grad, const Point3
// --------------------------- Sample the volume --------------------------- // --------------------------- Sample the volume ---------------------------
// TODO: Somehow pick if to use temp of speed normalization ... or pass extremas as params. // TODO: Somehow pick if to use temp of speed normalization ... or pass extremas as params.
float normDensity = (density - MIN_TEMP) / (MAX_TEMP - MIN_TEMP); // float normDensity = (density - MIN_TEMP) / (MAX_TEMP - MIN_TEMP);
float normDensity = (density - 273) / (MAX_TEMP - MIN_TEMP)+16.f/21.f; // Make zero match Celsius zero
// float normDensity = (density - MIN_SPEED) / (MAX_SPEED - MIN_SPEED); // float normDensity = (density - MIN_SPEED) / (MAX_SPEED - MIN_SPEED);
normDensity = clamp(normDensity, 0.0f, 1.0f); normDensity = clamp(normDensity, 0.0f, 1.0f);
// --------------------------- Map density to color --------------------------- // --------------------------- Map density to color ---------------------------
// TODO: Add a way to pick stops here // Pick color map
Color3 baseColor = colorMap(normDensity, d_stopsPythonLike, lenStopsPythonLike); Color3 baseColor;
switch (d_tfComboSelectedColor) {
case 0:
baseColor = colorMap(normDensity, d_stopsPythonLike, lenStopsPythonLike);
break;
case 1:
baseColor = colorMap(normDensity, d_stopsBluePurleRed, lenStopsBluePurpleRed);
break;
// TODO: This is a Gui select element case 2:
// TODO: Add a way to pick different function for alpha baseColor = colorMap(normDensity, d_stopsGrayscale, lenStopsGrayscale);
break;
default:
baseColor = colorMap(normDensity, d_stopsPythonLike, lenStopsPythonLike);
break;
}
// Pick opacity function
float alpha; float alpha;
switch (d_tfComboSelected) { switch (d_tfComboSelected) {
case 0: case 0: