Skip to content

Commit db8c9ee

Browse files
authored
expose texture filtering options for surface mesh quantities (#310)
* initial implementation of texture filtering option * factor out texture map options * templated texture options for scalars too
1 parent 9f97b70 commit db8c9ee

13 files changed

+143
-17
lines changed

include/polyscope/color_quantity.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class ColorQuantity {
1717
public:
1818
ColorQuantity(QuantityT& parent, const std::vector<glm::vec3>& colors);
1919

20-
// Build the ImGUI UIs for scalars
20+
// Build the ImGUI UIs for colors
2121
void buildColorUI();
22+
virtual void buildColorOptionsUI(); // called inside of an options menu
2223

2324
// Add rules to rendering programs for scalars
2425
std::vector<std::string> addColorRules(std::vector<std::string> rules);

include/polyscope/color_quantity.ipp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ColorQuantity<QuantityT>::ColorQuantity(QuantityT& quantity_, const std::vector<
99
template <typename QuantityT>
1010
void ColorQuantity<QuantityT>::buildColorUI() {}
1111

12+
template <typename QuantityT>
13+
void ColorQuantity<QuantityT>::buildColorOptionsUI() {}
14+
1215
template <typename QuantityT>
1316
void ColorQuantity<QuantityT>::setColorUniforms(render::ShaderProgram& p) {}
1417

include/polyscope/persistent_value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ extern PersistentCache<std::vector<std::string>> persistentCache_vectorstring;
142142
extern PersistentCache<ParamVizStyle> persistentCache_paramVizStyle;
143143
extern PersistentCache<BackFacePolicy> persistentCache_BackFacePolicy;
144144
extern PersistentCache<MeshShadeStyle> persistentCache_MeshNormalType;
145+
extern PersistentCache<FilterMode> persistentCache_FilterMode;
145146

146147
template<> inline PersistentCache<double>& getPersistentCacheRef<double>() { return persistentCache_double; }
147148
template<> inline PersistentCache<float>& getPersistentCacheRef<float>() { return persistentCache_float; }
@@ -155,6 +156,7 @@ template<> inline PersistentCache<std::vector<std::string>>& getPersistentCacheR
155156
template<> inline PersistentCache<ParamVizStyle>& getPersistentCacheRef<ParamVizStyle>() { return persistentCache_paramVizStyle; }
156157
template<> inline PersistentCache<BackFacePolicy>& getPersistentCacheRef<BackFacePolicy>() { return persistentCache_BackFacePolicy; }
157158
template<> inline PersistentCache<MeshShadeStyle>& getPersistentCacheRef<MeshShadeStyle>() { return persistentCache_MeshNormalType; }
159+
template<> inline PersistentCache<FilterMode>& getPersistentCacheRef<FilterMode>() { return persistentCache_FilterMode; }
158160
}
159161
// clang-format on
160162

include/polyscope/render/engine.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ enum class DrawMode {
3636
TriangleStripInstanced,
3737
};
3838

39-
enum class FilterMode { Nearest = 0, Linear };
4039
enum class TextureFormat { RGB8 = 0, RGBA8, RG16F, RGB16F, RGBA16F, RGBA32F, RGB32F, R32F, R16F, DEPTH24 };
4140
enum class RenderBufferType { Color, ColorAlpha, Depth, Float4 };
4241
enum class DepthMode { Less, LEqual, LEqualReadOnly, Greater, Disable, PassReadOnly };
@@ -207,7 +206,7 @@ class RenderBuffer {
207206
public:
208207
// abstract class: use the factory methods from the Engine class
209208
RenderBuffer(RenderBufferType type_, unsigned int sizeX_, unsigned int sizeY_);
210-
virtual ~RenderBuffer(){};
209+
virtual ~RenderBuffer() {};
211210

212211
virtual void resize(unsigned int newX, unsigned int newY);
213212

@@ -228,7 +227,7 @@ class FrameBuffer {
228227
public:
229228
// abstract class: use the factory methods from the Engine class
230229
FrameBuffer();
231-
virtual ~FrameBuffer(){};
230+
virtual ~FrameBuffer() {};
232231

233232
virtual void bind() = 0;
234233
// Bind to this framebuffer so subsequent draw calls will go to it
@@ -347,7 +346,7 @@ class ShaderProgram {
347346

348347
public:
349348
ShaderProgram(DrawMode dm);
350-
virtual ~ShaderProgram(){};
349+
virtual ~ShaderProgram() {};
351350

352351

353352
// === Store data

include/polyscope/surface_color_quantity.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "polyscope/color_quantity.h"
66
#include "polyscope/render/engine.h"
77
#include "polyscope/surface_mesh.h"
8+
#include "polyscope/texture_map_quantity.h"
89

910
namespace polyscope {
1011

@@ -19,6 +20,7 @@ class SurfaceColorQuantity : public SurfaceMeshQuantity, public ColorQuantity<Su
1920
const std::vector<glm::vec3>& colorValues);
2021

2122
virtual void draw() override;
23+
virtual void buildCustomUI() override;
2224
virtual std::string niceName() override;
2325
virtual void refresh() override;
2426

@@ -40,6 +42,7 @@ class SurfaceVertexColorQuantity : public SurfaceColorQuantity {
4042
SurfaceVertexColorQuantity(std::string name, SurfaceMesh& mesh_, std::vector<glm::vec3> values_);
4143

4244
virtual void createProgram() override;
45+
virtual void buildColorOptionsUI() override;
4346

4447
void buildVertexInfoGUI(size_t vInd) override;
4548
};
@@ -53,6 +56,7 @@ class SurfaceFaceColorQuantity : public SurfaceColorQuantity {
5356
SurfaceFaceColorQuantity(std::string name, SurfaceMesh& mesh_, std::vector<glm::vec3> values_);
5457

5558
virtual void createProgram() override;
59+
virtual void buildColorOptionsUI() override;
5660

5761
void buildFaceInfoGUI(size_t fInd) override;
5862
};
@@ -62,17 +66,17 @@ class SurfaceFaceColorQuantity : public SurfaceColorQuantity {
6266
// ========== Texture Color ==========
6367
// ========================================================
6468

65-
class SurfaceTextureColorQuantity : public SurfaceColorQuantity {
69+
class SurfaceTextureColorQuantity : public SurfaceColorQuantity,
70+
public TextureMapQuantity<SurfaceTextureColorQuantity> {
6671
public:
6772
SurfaceTextureColorQuantity(std::string name, SurfaceMesh& mesh_, SurfaceParameterizationQuantity& param_,
6873
size_t dimX, size_t dimY, std::vector<glm::vec3> values_, ImageOrigin origin_);
6974

7075
virtual void createProgram() override;
76+
virtual void buildColorOptionsUI() override;
7177

7278
protected:
7379
SurfaceParameterizationQuantity& param;
74-
size_t dimX, dimY;
75-
ImageOrigin imageOrigin;
7680
};
7781

7882
} // namespace polyscope

include/polyscope/surface_scalar_quantity.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "polyscope/render/engine.h"
1111
#include "polyscope/scalar_quantity.h"
1212
#include "polyscope/surface_mesh.h"
13+
#include "polyscope/texture_map_quantity.h"
1314

1415
namespace polyscope {
1516

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

2627
virtual void draw() override;
2728
virtual void buildCustomUI() override;
29+
virtual void buildSurfaceScalarOptionsUI() {};
2830
virtual std::string niceName() override;
2931
virtual void refresh() override;
3032

@@ -117,20 +119,20 @@ class SurfaceCornerScalarQuantity : public SurfaceScalarQuantity {
117119
// ========== Texture Scalar ==========
118120
// ========================================================
119121

120-
class SurfaceTextureScalarQuantity : public SurfaceScalarQuantity {
122+
class SurfaceTextureScalarQuantity : public SurfaceScalarQuantity,
123+
public TextureMapQuantity<SurfaceTextureScalarQuantity> {
121124
public:
122125
SurfaceTextureScalarQuantity(std::string name, SurfaceMesh& mesh_, SurfaceParameterizationQuantity& param_,
123126
size_t dimX, size_t dimY, const std::vector<float>& values_, ImageOrigin origin_,
124127
DataType dataType_ = DataType::STANDARD);
125128

126129
virtual void createProgram() override;
130+
virtual void buildSurfaceScalarOptionsUI() override;
127131
virtual std::shared_ptr<render::AttributeBuffer> getAttributeBuffer() override;
128132

129133

130134
protected:
131135
SurfaceParameterizationQuantity& param;
132-
size_t dimX, dimY;
133-
ImageOrigin imageOrigin;
134136
};
135137

136138
} // namespace polyscope
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
2+
3+
#pragma once
4+
5+
#include "polyscope/persistent_value.h"
6+
#include "polyscope/polyscope.h"
7+
#include "polyscope/render/engine.h"
8+
#include "polyscope/render/managed_buffer.h"
9+
#include "polyscope/standardize_data_array.h"
10+
11+
namespace polyscope {
12+
13+
// Encapsulates logic which is common to all texture map quantities
14+
15+
template <typename QuantityT>
16+
class TextureMapQuantity {
17+
public:
18+
TextureMapQuantity(QuantityT& parent, size_t dimX, size_t dimY, ImageOrigin origin_);
19+
20+
// Build the ImGUI UIs for texture maps
21+
virtual void buildTextureMapOptionsUI(); // called inside of an options menu
22+
23+
// === Members
24+
QuantityT& quantity;
25+
26+
// NOTE: the main quantity types (scalar quantity, color quantity, etc) provide the buffer members, so this class just
27+
// has secondary options and such
28+
29+
// what kind of texture filtering is used
30+
QuantityT* setFilterMode(FilterMode newFilterMode);
31+
FilterMode getFilterMode();
32+
33+
protected:
34+
size_t dimX, dimY;
35+
ImageOrigin imageOrigin;
36+
37+
// === Visualization parameters
38+
PersistentValue<FilterMode> filterMode; // default is FilterMode::Linear
39+
};
40+
41+
} // namespace polyscope
42+
43+
#include "polyscope/texture_map_quantity.ipp"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
2+
3+
namespace polyscope {
4+
5+
template <typename QuantityT>
6+
TextureMapQuantity<QuantityT>::TextureMapQuantity(QuantityT& quantity_, size_t dimX_, size_t dimY_, ImageOrigin origin_)
7+
: quantity(quantity_), dimX(dimX_), dimY(dimY_), imageOrigin(origin_),
8+
filterMode(quantity.uniquePrefix() + "filterMode", FilterMode::Linear) {}
9+
10+
template <typename QuantityT>
11+
void TextureMapQuantity<QuantityT>::buildTextureMapOptionsUI() {
12+
13+
if (ImGui::BeginMenu("Filter Mode")) {
14+
if (ImGui::MenuItem("linear", NULL, filterMode.get() == FilterMode::Linear)) setFilterMode(FilterMode::Linear);
15+
if (ImGui::MenuItem("nearest", NULL, filterMode.get() == FilterMode::Nearest)) setFilterMode(FilterMode::Nearest);
16+
ImGui::EndMenu();
17+
}
18+
}
19+
20+
template <typename QuantityT>
21+
QuantityT* TextureMapQuantity<QuantityT>::setFilterMode(FilterMode newFilterMode) {
22+
filterMode = newFilterMode;
23+
quantity.refresh();
24+
return &quantity;
25+
}
26+
27+
template <typename QuantityT>
28+
FilterMode TextureMapQuantity<QuantityT>::getFilterMode() {
29+
return filterMode.get();
30+
}
31+
32+
} // namespace polyscope

include/polyscope/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum class VolumeCellType { TET = 0, HEX };
2424

2525
enum class ImplicitRenderMode { SphereMarch, FixedStep };
2626
enum class ImageOrigin { LowerLeft, UpperLeft };
27+
enum class FilterMode { Nearest = 0, Linear };
2728

2829
enum class ParamCoordsType { UNIT = 0, WORLD }; // UNIT -> [0,1], WORLD -> length-valued
2930
enum class ParamVizStyle {

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ SET(HEADERS
336336
${INCLUDE_ROOT}/surface_parameterization_quantity.h
337337
${INCLUDE_ROOT}/surface_scalar_quantity.h
338338
${INCLUDE_ROOT}/surface_vector_quantity.h
339+
${INCLUDE_ROOT}/texture_map_quantity.h
340+
${INCLUDE_ROOT}/texture_map_quantity.ipp
339341
${INCLUDE_ROOT}/types.h
340342
${INCLUDE_ROOT}/utilities.h
341343
${INCLUDE_ROOT}/view.h

0 commit comments

Comments
 (0)