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

fix indexing bug for surface textures from vertex param #255

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
4 changes: 3 additions & 1 deletion include/polyscope/surface_parameterization_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class SurfaceParameterizationQuantity : public SurfaceMeshQuantity,

public:
SurfaceParameterizationQuantity(std::string name, SurfaceMesh& mesh_, const std::vector<glm::vec2>& coords_,
ParamCoordsType type_, ParamVizStyle style_);
MeshElement definedOn, ParamCoordsType type_, ParamVizStyle style_);

virtual void draw() override;
virtual void refresh() override;
virtual void buildCustomUI() override;

const MeshElement definedOn;

// Set islands labels. Technically, this data is just any categorical integer labels per-face of the mesh.
// The intended use is to label islands (connected components in parameterization space) of the UV map.
// When style == CHECKER_ISLANDS, these will be use to visualize the islands with different colors.
Expand Down
15 changes: 14 additions & 1 deletion src/surface_color_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,20 @@ void SurfaceTextureColorQuantity::createProgram() {
// clang-format on

parent.setMeshGeometryAttributes(*program);
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));

// the indexing into the parameterization varies based on whether it is a corner or vertex quantity
switch (param.definedOn) {
case MeshElement::VERTEX:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
break;
case MeshElement::CORNER:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));
break;
default:
// nothing
break;
}

program->setTextureFromBuffer("t_color", colors.getRenderTextureBuffer().get());
render::engine->setMaterial(*program, parent.getMaterial());

Expand Down
10 changes: 6 additions & 4 deletions src/surface_parameterization_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace polyscope {

SurfaceParameterizationQuantity::SurfaceParameterizationQuantity(std::string name, SurfaceMesh& mesh_,
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_, ParamVizStyle style_)
: SurfaceMeshQuantity(name, mesh_, true), ParameterizationQuantity(*this, coords_, type_, style_) {
MeshElement definedOn_, ParamCoordsType type_,
ParamVizStyle style_)
: SurfaceMeshQuantity(name, mesh_, true), ParameterizationQuantity(*this, coords_, type_, style_),
definedOn(definedOn_) {

// sanity check, this should basically never happen, but this guards against weird edge cases such
// as persistent values restoring the style, device updates, etc
Expand Down Expand Up @@ -216,7 +218,7 @@ SurfaceCornerParameterizationQuantity::SurfaceCornerParameterizationQuantity(std
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_,
ParamVizStyle style_)
: SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {}
: SurfaceParameterizationQuantity(name, mesh_, coords_, MeshElement::CORNER, type_, style_) {}

std::string SurfaceCornerParameterizationQuantity::niceName() { return name + " (corner parameterization)"; }

Expand Down Expand Up @@ -244,7 +246,7 @@ SurfaceVertexParameterizationQuantity::SurfaceVertexParameterizationQuantity(std
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_,
ParamVizStyle style_)
: SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {}
: SurfaceParameterizationQuantity(name, mesh_, coords_, MeshElement::VERTEX, type_, style_) {}

std::string SurfaceVertexParameterizationQuantity::niceName() { return name + " (vertex parameterization)"; }

Expand Down
17 changes: 15 additions & 2 deletions src/surface_scalar_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ SurfaceTextureScalarQuantity::SurfaceTextureScalarQuantity(std::string name, Sur
SurfaceParameterizationQuantity& param_, size_t dimX_,
size_t dimY_, const std::vector<float>& values_,
ImageOrigin origin_, DataType dataType_)
: SurfaceScalarQuantity(name, mesh_, "texture", values_, dataType_), param(param_), dimX(dimX_), dimY(dimY_),
: SurfaceScalarQuantity(name, mesh_, "vertex", values_, dataType_), param(param_), dimX(dimX_), dimY(dimY_),
imageOrigin(origin_) {
values.setTextureSize(dimX, dimY);
values.ensureHostBufferPopulated();
Expand All @@ -298,7 +298,20 @@ void SurfaceTextureScalarQuantity::createProgram() {
// clang-format on

parent.setMeshGeometryAttributes(*program);
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));

// the indexing into the parameterization varies based on whether it is a corner or vertex quantity
switch (param.definedOn) {
case MeshElement::VERTEX:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
break;
case MeshElement::CORNER:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));
break;
default:
// nothing
break;
}

program->setTextureFromBuffer("t_scalar", values.getRenderTextureBuffer().get());
render::engine->setMaterial(*program, parent.getMaterial());
program->setTextureFromColormap("t_colormap", cMap.get());
Expand Down