Skip to content

Commit 8ac360d

Browse files
committed
add wireframe mode to sparse grid
1 parent 509fa1b commit 8ac360d

File tree

6 files changed

+301
-43
lines changed

6 files changed

+301
-43
lines changed

include/polyscope/persistent_value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ extern PersistentCache<MeshShadeStyle> persistentCache_MeshNormalType;
146146
extern PersistentCache<FilterMode> persistentCache_FilterMode;
147147
extern PersistentCache<IsolineStyle> persistentCache_IsolineStyle;
148148
extern PersistentCache<MeshSelectionMode> persistentCache_MeshSelectionMode;
149+
extern PersistentCache<SparseVolumeGridRenderMode> persistentCache_SparseVolumeGridRenderMode;
149150

150151
template<> inline PersistentCache<double>& getPersistentCacheRef<double>() { return persistentCache_double; }
151152
template<> inline PersistentCache<float>& getPersistentCacheRef<float>() { return persistentCache_float; }
@@ -163,6 +164,7 @@ template<> inline PersistentCache<MeshShadeStyle>& getPersistentCacheR
163164
template<> inline PersistentCache<FilterMode>& getPersistentCacheRef<FilterMode>() { return persistentCache_FilterMode; }
164165
template<> inline PersistentCache<IsolineStyle>& getPersistentCacheRef<IsolineStyle>() { return persistentCache_IsolineStyle; }
165166
template<> inline PersistentCache<MeshSelectionMode>& getPersistentCacheRef<MeshSelectionMode>() { return persistentCache_MeshSelectionMode; }
167+
template<> inline PersistentCache<SparseVolumeGridRenderMode>& getPersistentCacheRef<SparseVolumeGridRenderMode>() { return persistentCache_SparseVolumeGridRenderMode; }
166168
}
167169
// clang-format on
168170

include/polyscope/sparse_volume_grid.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SparseVolumeGrid : public Structure {
7575
// Corner c = dx*4 + dy*2 + dz maps cell[i] -> index in canonical node order
7676
render::ManagedBuffer<uint32_t> cornerNodeInds[8];
7777

78-
uint64_t nNodes();
78+
uint64_t nNodes(); // NOTE: not populated until nodes are enabled (use ensureHaveCornerNodeIndices() to force this)
7979
const std::vector<glm::ivec3>& getCanonicalNodeInds();
8080
void ensureHaveCornerNodeIndices();
8181

@@ -148,6 +148,18 @@ class SparseVolumeGrid : public Structure {
148148
SparseVolumeGrid* setCubeSizeFactor(double newVal);
149149
double getCubeSizeFactor();
150150

151+
// Render mode (gridcube or wireframe)
152+
SparseVolumeGrid* setRenderMode(SparseVolumeGridRenderMode mode);
153+
SparseVolumeGridRenderMode getRenderMode();
154+
155+
// Wireframe radius as a node-relative value. 1.0 is a reasonable default size.
156+
SparseVolumeGrid* setWireframeRadius(double newVal);
157+
double getWireframeRadius();
158+
159+
// Color used for wireframe rendering
160+
SparseVolumeGrid* setWireframeColor(glm::vec3 val);
161+
glm::vec3 getWireframeColor();
162+
151163
private:
152164
// Field data
153165
glm::vec3 origin;
@@ -171,6 +183,9 @@ class SparseVolumeGrid : public Structure {
171183
PersistentValue<glm::vec3> edgeColor;
172184
PersistentValue<std::string> material;
173185
PersistentValue<float> cubeSizeFactor;
186+
PersistentValue<SparseVolumeGridRenderMode> renderMode;
187+
PersistentValue<float> wireframeRadius;
188+
PersistentValue<glm::vec3> wireframeColor;
174189

175190
// Compute cell positions and GPU indices from occupiedCellsData
176191
void computeCellPositions();
@@ -187,6 +202,13 @@ class SparseVolumeGrid : public Structure {
187202
std::shared_ptr<render::ShaderProgram> program;
188203
std::shared_ptr<render::ShaderProgram> pickProgram;
189204

205+
// Wireframe render mode
206+
std::shared_ptr<render::ShaderProgram> wireframeNodeProgram;
207+
std::shared_ptr<render::ShaderProgram> wireframeEdgeProgram;
208+
void ensureWireframeProgramsPrepared();
209+
void buildWireframeGeometry(std::vector<glm::vec3>& nodePositions, std::vector<glm::vec3>& edgeTailPositions,
210+
std::vector<glm::vec3>& edgeTipPositions);
211+
190212
// === Helpers
191213
void checkForDuplicateCells();
192214
size_t findCellFlatIndex(glm::ivec3 cellInd3);

include/polyscope/types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ POLYSCOPE_DEFINE_ENUM_NAMES(SparseVolumeGridElement,
164164
{SparseVolumeGridElement::NODE, "Node"}
165165
);
166166

167+
enum class SparseVolumeGridRenderMode { Gridcube = 0, Wireframe };
168+
POLYSCOPE_DEFINE_ENUM_NAMES(SparseVolumeGridRenderMode,
169+
{SparseVolumeGridRenderMode::Gridcube, "Gridcube"},
170+
{SparseVolumeGridRenderMode::Wireframe, "Wireframe"}
171+
);
172+
167173
enum class IsolineStyle { Stripe = 0, Contour };
168174
POLYSCOPE_DEFINE_ENUM_NAMES(IsolineStyle,
169175
{IsolineStyle::Stripe, "Stripe"},

src/persistent_value.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PersistentCache<MeshShadeStyle> persistentCache_MeshNormalType;
2424
PersistentCache<FilterMode> persistentCache_FilterMode;
2525
PersistentCache<IsolineStyle> persistentCache_IsolineStyle;
2626
PersistentCache<MeshSelectionMode> persistentCache_MeshSelectionMode;
27+
PersistentCache<SparseVolumeGridRenderMode> persistentCache_SparseVolumeGridRenderMode;
2728
// clang-format on
2829
} // namespace detail
2930
} // namespace polyscope

0 commit comments

Comments
 (0)