Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shade with debug colors for inf/nan values #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/polyscope/scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class ScalarQuantity {
QuantityT* setColorMap(std::string val);
std::string getColorMap();

// Substitute colors for inf and nan
QuantityT* setInfColor(glm::vec3 val);
glm::vec3 getInfColor();
QuantityT* setNaNColor(glm::vec3 val);
glm::vec3 getNaNColor();

// Data limits mapped in to colormap
QuantityT* setMapRange(std::pair<double, double> val);
std::pair<double, double> getMapRange();
Expand Down Expand Up @@ -74,6 +80,8 @@ class ScalarQuantity {

// Parameters
PersistentValue<std::string> cMap;
PersistentValue<glm::vec3> infColor;
PersistentValue<glm::vec3> nanColor;
PersistentValue<bool> isolinesEnabled;
PersistentValue<ScaledValue<float>> isolineWidth;
PersistentValue<float> isolineDarkness;
Expand Down
32 changes: 32 additions & 0 deletions include/polyscope/scalar_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ScalarQuantity<QuantityT>::ScalarQuantity(QuantityT& quantity_, const std::vecto
vizRangeMin(quantity.uniquePrefix() + "vizRangeMin", -777.), // set later,
vizRangeMax(quantity.uniquePrefix() + "vizRangeMax", -777.), // including clearing cache
cMap(quantity.uniquePrefix() + "cmap", defaultColorMap(dataType)),
infColor(quantity.uniquePrefix() + "infColor", glm::vec3(1., 0., 1.)),
nanColor(quantity.uniquePrefix() + "nanColor", glm::vec3(1., 0., 0.)),
isolinesEnabled(quantity.uniquePrefix() + "isolinesEnabled", false),
isolineWidth(quantity.uniquePrefix() + "isolineWidth",
absoluteValue((dataRange.second - dataRange.first) * 0.02)),
Expand Down Expand Up @@ -166,6 +168,12 @@ template <typename QuantityT>
void ScalarQuantity<QuantityT>::buildScalarOptionsUI() {
if (ImGui::MenuItem("Reset colormap range")) resetMapRange();
if (ImGui::MenuItem("Enable isolines", NULL, isolinesEnabled.get())) setIsolinesEnabled(!isolinesEnabled.get());
if (ImGui::ColorEdit3("Color for +-Inf values", &infColor.get()[0], ImGuiColorEditFlags_NoInputs)) {
setInfColor(getInfColor());
}
if (ImGui::ColorEdit3("Color for NaN values", &nanColor.get()[0], ImGuiColorEditFlags_NoInputs)) {
setNaNColor(getNaNColor());
}
}

template <typename QuantityT>
Expand All @@ -182,6 +190,8 @@ template <typename QuantityT>
void ScalarQuantity<QuantityT>::setScalarUniforms(render::ShaderProgram& p) {
p.setUniform("u_rangeLow", vizRangeMin.get());
p.setUniform("u_rangeHigh", vizRangeMax.get());
p.setUniform("u_infColor", infColor.get());
p.setUniform("u_nanColor", nanColor.get());

if (isolinesEnabled.get()) {
p.setUniform("u_modLen", getIsolineWidth());
Expand Down Expand Up @@ -236,6 +246,28 @@ std::string ScalarQuantity<QuantityT>::getColorMap() {
return cMap.get();
}

template <typename QuantityT>
QuantityT* ScalarQuantity<QuantityT>::setInfColor(glm::vec3 val) {
infColor = val;
requestRedraw();
return &quantity;
}
template <typename QuantityT>
glm::vec3 ScalarQuantity<QuantityT>::getInfColor() {
return infColor.get();
}

template <typename QuantityT>
QuantityT* ScalarQuantity<QuantityT>::setNaNColor(glm::vec3 val) {
nanColor = val;
requestRedraw();
return &quantity;
}
template <typename QuantityT>
glm::vec3 ScalarQuantity<QuantityT>::getNaNColor() {
return nanColor.get();
}

template <typename QuantityT>
QuantityT* ScalarQuantity<QuantityT>::setMapRange(std::pair<double, double> val) {
vizRangeMin = val.first;
Expand Down
17 changes: 14 additions & 3 deletions src/render/opengl/shaders/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,27 @@ const ShaderReplacementRule SHADE_COLORMAP_VALUE(
uniform float u_rangeHigh;
uniform float u_rangeLow;
uniform sampler1D t_colormap;
uniform vec3 u_infColor;
uniform vec3 u_nanColor;
)"},
{"GENERATE_SHADE_COLOR", R"(
float rangeTVal = (shadeValue - u_rangeLow) / (u_rangeHigh - u_rangeLow);
rangeTVal = clamp(rangeTVal, 0.f, 1.f);
vec3 albedoColor = texture(t_colormap, rangeTVal).rgb;
vec3 albedoColor = vec3(0., 0., 0.);
if (isnan(shadeValue)) {
albedoColor = u_nanColor;
} else if(isinf(shadeValue)) {
albedoColor = u_infColor;
} else {
float rangeTVal = (shadeValue - u_rangeLow) / (u_rangeHigh - u_rangeLow);
rangeTVal = clamp(rangeTVal, 0.f, 1.f);
albedoColor = texture(t_colormap, rangeTVal).rgb;
}
)"}
},
/* uniforms */ {
{"u_rangeLow", RenderDataType::Float},
{"u_rangeHigh", RenderDataType::Float},
{"u_infColor", RenderDataType::Vector3Float},
{"u_nanColor", RenderDataType::Vector3Float},
},
/* attributes */ {},
/* textures */ {
Expand Down
Loading