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

Warn color range clamping #303

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions include/polyscope/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ inline std::string to_string(const glm::vec3& v) {
}
inline std::string to_string_short(const glm::vec3& v) { return str_printf("<%1.3f, %1.3f, %1.3f>", v[0], v[1], v[2]); }

// Warn when provided color ranges are not [0, 1], so they will be clamped in shader
void checkColorRanges(const std::vector<glm::vec3>& colors);

// === Index management
const size_t INVALID_IND = std::numeric_limits<size_t>::max();
const uint32_t INVALID_IND_32 = std::numeric_limits<uint32_t>::max();
Expand Down
2 changes: 2 additions & 0 deletions src/curve_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void CurveNetworkQuantity::buildEdgeInfoGUI(size_t edgeInd) {}
CurveNetworkNodeColorQuantity* CurveNetwork::addNodeColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
CurveNetworkNodeColorQuantity* q = new CurveNetworkNodeColorQuantity(name, colors, *this);
addQuantity(q);
return q;
Expand All @@ -521,6 +522,7 @@ CurveNetworkNodeColorQuantity* CurveNetwork::addNodeColorQuantityImpl(std::strin
CurveNetworkEdgeColorQuantity* CurveNetwork::addEdgeColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
CurveNetworkEdgeColorQuantity* q = new CurveNetworkEdgeColorQuantity(name, colors, *this);
addQuantity(q);
return q;
Expand Down
1 change: 1 addition & 0 deletions src/point_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ void PointCloudQuantity::buildInfoGUI(size_t pointInd) {}

PointCloudColorQuantity* PointCloud::addColorQuantityImpl(std::string name, const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
PointCloudColorQuantity* q = new PointCloudColorQuantity(name, colors, *this);
addQuantity(q);
return q;
Expand Down
3 changes: 3 additions & 0 deletions src/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ MeshShadeStyle SurfaceMesh::getShadeStyle() { return shadeStyle.get(); }
SurfaceVertexColorQuantity* SurfaceMesh::addVertexColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
SurfaceVertexColorQuantity* q = new SurfaceVertexColorQuantity(name, *this, colors);
addQuantity(q);
return q;
Expand All @@ -1585,6 +1586,7 @@ SurfaceVertexColorQuantity* SurfaceMesh::addVertexColorQuantityImpl(std::string
SurfaceFaceColorQuantity* SurfaceMesh::addFaceColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
SurfaceFaceColorQuantity* q = new SurfaceFaceColorQuantity(name, *this, colors);
addQuantity(q);
return q;
Expand All @@ -1594,6 +1596,7 @@ SurfaceTextureColorQuantity*
SurfaceMesh::addTextureColorQuantityImpl(std::string name, SurfaceParameterizationQuantity& param, size_t dimX,
size_t dimY, const std::vector<glm::vec3>& colors, ImageOrigin imageOrigin) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
SurfaceTextureColorQuantity* q = new SurfaceTextureColorQuantity(name, *this, param, dimX, dimY, colors, imageOrigin);
addQuantity(q);
return q;
Expand Down
11 changes: 11 additions & 0 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ std::string prettyPrintCount(size_t count) {
}
}

void checkColorRanges(const std::vector<glm::vec3>& colors) {
for (glm::vec3 color : colors){
for (float c : color){
if(c<0.0 || c>1.0){
warning("Colors should be in range [0, 1], will be clamped");
return;
}
}
}
}

void ImGuiHelperMarker(const char* text) {
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered()) {
Expand Down
2 changes: 2 additions & 0 deletions src/volume_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ double VolumeMesh::getEdgeWidth() { return edgeWidth.get(); }
VolumeMeshVertexColorQuantity* VolumeMesh::addVertexColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
VolumeMeshVertexColorQuantity* q = new VolumeMeshVertexColorQuantity(name, *this, colors);
addQuantity(q);
return q;
Expand All @@ -1025,6 +1026,7 @@ VolumeMeshVertexColorQuantity* VolumeMesh::addVertexColorQuantityImpl(std::strin
VolumeMeshCellColorQuantity* VolumeMesh::addCellColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
checkColorRanges(colors);
VolumeMeshCellColorQuantity* q = new VolumeMeshCellColorQuantity(name, *this, colors);
addQuantity(q);
return q;
Expand Down