Skip to content

Commit

Permalink
templated texture options for scalars too
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Dec 24, 2024
1 parent 618f2b1 commit 8237674
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions include/polyscope/surface_scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "polyscope/render/engine.h"
#include "polyscope/scalar_quantity.h"
#include "polyscope/surface_mesh.h"
#include "polyscope/texture_map_quantity.h"

namespace polyscope {

Expand All @@ -25,6 +26,7 @@ class SurfaceScalarQuantity : public SurfaceMeshQuantity, public ScalarQuantity<

virtual void draw() override;
virtual void buildCustomUI() override;
virtual void buildSurfaceScalarOptionsUI() {};
virtual std::string niceName() override;
virtual void refresh() override;

Expand Down Expand Up @@ -117,20 +119,20 @@ class SurfaceCornerScalarQuantity : public SurfaceScalarQuantity {
// ========== Texture Scalar ==========
// ========================================================

class SurfaceTextureScalarQuantity : public SurfaceScalarQuantity {
class SurfaceTextureScalarQuantity : public SurfaceScalarQuantity,
public TextureMapQuantity<SurfaceTextureScalarQuantity> {
public:
SurfaceTextureScalarQuantity(std::string name, SurfaceMesh& mesh_, SurfaceParameterizationQuantity& param_,
size_t dimX, size_t dimY, const std::vector<float>& values_, ImageOrigin origin_,
DataType dataType_ = DataType::STANDARD);

virtual void createProgram() override;
virtual void buildSurfaceScalarOptionsUI() override;
virtual std::shared_ptr<render::AttributeBuffer> getAttributeBuffer() override;


protected:
SurfaceParameterizationQuantity& param;
size_t dimX, dimY;
ImageOrigin imageOrigin;
};

} // namespace polyscope
9 changes: 6 additions & 3 deletions src/surface_scalar_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void SurfaceScalarQuantity::buildCustomUI() {
if (ImGui::BeginPopup("OptionsPopup")) {

buildScalarOptionsUI();
buildSurfaceScalarOptionsUI();

ImGui::EndPopup();
}
Expand Down Expand Up @@ -293,8 +294,8 @@ 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_, "vertex", values_, dataType_), param(param_), dimX(dimX_), dimY(dimY_),
imageOrigin(origin_) {
: SurfaceScalarQuantity(name, mesh_, "vertex", values_, dataType_),
TextureMapQuantity(*this, dimX_, dimY_, origin_), param(param_) {
values.setTextureSize(dimX, dimY);
values.ensureHostBufferPopulated();
hist.buildHistogram(values.data);
Expand Down Expand Up @@ -334,9 +335,11 @@ void SurfaceTextureScalarQuantity::createProgram() {
render::engine->setMaterial(*program, parent.getMaterial());
program->setTextureFromColormap("t_colormap", cMap.get());

values.getRenderTextureBuffer()->setFilterMode(FilterMode::Linear);
values.getRenderTextureBuffer()->setFilterMode(filterMode.get());
}

void SurfaceTextureScalarQuantity::buildSurfaceScalarOptionsUI() { buildTextureMapOptionsUI(); }

std::shared_ptr<render::AttributeBuffer> SurfaceTextureScalarQuantity::getAttributeBuffer() {
exception("unsupported operation -- cannot get attribute buffer for texture scalar quantity [" + this->name + "]");
return std::shared_ptr<render::AttributeBuffer>(nullptr);
Expand Down

0 comments on commit 8237674

Please sign in to comment.