Skip to content

Commit d3e6ca6

Browse files
committed
revert change which broke default structure getter, fix slice plane volume mesh logic
1 parent 864fb24 commit d3e6ca6

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

src/polyscope.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,6 @@ bool registerStructure(Structure* s, bool replaceIfPresent) {
10601060

10611061
Structure* getStructure(std::string type, std::string name) {
10621062

1063-
if (type == "" || name == "") return nullptr;
1064-
10651063
// If there are no structures of that type it is an automatic fail
10661064
if (state::structures.find(type) == state::structures.end()) {
10671065
exception("No structures of type " + type + " registered");
@@ -1097,7 +1095,7 @@ bool hasStructure(std::string type, std::string name) {
10971095
// Special automatic case, return any
10981096
if (name == "") {
10991097
if (sMap.size() != 1) {
1100-
exception("Cannot use automatic structure get with empty name unless there is exactly one structure of that type "
1098+
exception("Cannot use automatic has-structure test with empty name unless there is exactly one structure of that type "
11011099
"registered");
11021100
}
11031101
return true;

src/slice_plane.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ void SlicePlane::setSliceGeomUniforms(render::ShaderProgram& p) {
125125
126126
127127
void SlicePlane::setVolumeMeshToInspect(std::string meshname) {
128-
VolumeMesh* oldMeshToInspect = polyscope::getVolumeMesh(inspectedMeshName);
128+
VolumeMesh* oldMeshToInspect = inspectedMeshName == "" ? nullptr : polyscope::getVolumeMesh(inspectedMeshName);
129129
if (oldMeshToInspect != nullptr) {
130130
oldMeshToInspect->removeSlicePlaneListener(this);
131131
}
132132
inspectedMeshName = meshname;
133-
VolumeMesh* meshToInspect = polyscope::getVolumeMesh(inspectedMeshName);
133+
VolumeMesh* meshToInspect = inspectedMeshName == "" ? nullptr : polyscope::getVolumeMesh(inspectedMeshName);
134134
if (meshToInspect == nullptr) {
135135
inspectedMeshName = "";
136136
shouldInspectMesh = false;
@@ -153,7 +153,7 @@ void SlicePlane::ensureVolumeInspectValid() {
153153
// This method exists to save us in any cases where we might be inspecting a volume mesh when that mesh is deleted. We
154154
// can't just call setVolumeMeshToInspect(""), because that tries to look up the volume mesh.
155155
156-
if (!hasVolumeMesh(inspectedMeshName)) {
156+
if (inspectedMeshName == "" || !hasVolumeMesh(inspectedMeshName)) {
157157
inspectedMeshName = "";
158158
shouldInspectMesh = false;
159159
volumeInspectProgram = nullptr;
@@ -210,7 +210,7 @@ void SlicePlane::drawGeometry() {
210210
ensureVolumeInspectValid();
211211
212212
if (shouldInspectMesh) {
213-
VolumeMesh* vMesh = polyscope::getVolumeMesh(inspectedMeshName);
213+
VolumeMesh* vMesh = inspectedMeshName == "" ? nullptr : polyscope::getVolumeMesh(inspectedMeshName);
214214
215215
// guard against situations where the volume mesh we are slicing has been deleted
216216
if (vMesh == nullptr) {

test/src/volume_mesh_test.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ TEST_F(PolyscopeTest, VolumeMeshCellVector) {
235235
}
236236

237237
TEST_F(PolyscopeTest, VolumeMeshInspect) {
238+
239+
// in another test below we repeat the same logic, but with a second mesh present
240+
// to ensure the volume mesh lookup logic in the slice plane works right
241+
238242
std::vector<glm::vec3> verts;
239243
std::vector<std::array<int, 8>> cells;
240244
std::tie(verts, cells) = getVolumeMeshData();
@@ -256,7 +260,45 @@ TEST_F(PolyscopeTest, VolumeMeshInspect) {
256260
q1Cat->setEnabled(true);
257261
polyscope::show(3);
258262

259-
polyscope::removeAllStructures();
263+
// clear it out
264+
p->setVolumeMeshToInspect("vol");
265+
polyscope::show(3);
260266

267+
polyscope::removeAllStructures();
261268
polyscope::removeLastSceneSlicePlane();
262269
}
270+
271+
TEST_F(PolyscopeTest, VolumeMeshInspectWithExtra) {
272+
273+
// same as above, but with an additional mesh present
274+
// to ensure the volume mesh lookup logic in the slice plane works right
275+
276+
std::vector<glm::vec3> verts;
277+
std::vector<std::array<int, 8>> cells;
278+
std::tie(verts, cells) = getVolumeMeshData();
279+
polyscope::VolumeMesh* psVol = polyscope::registerVolumeMesh("vol", verts, cells);
280+
polyscope::VolumeMesh* psVolExtra = polyscope::registerVolumeMesh("vol extra", verts, cells);
281+
282+
// plain old inspecting
283+
polyscope::SlicePlane* p = polyscope::addSceneSlicePlane();
284+
p->setVolumeMeshToInspect("vol");
285+
polyscope::show(3);
286+
287+
// with a scalar quantity
288+
std::vector<float> vals(verts.size(), 0.44);
289+
auto q1 = psVol->addVertexScalarQuantity("vals", vals);
290+
q1->setEnabled(true);
291+
polyscope::show(3);
292+
293+
// with a categorical quantity
294+
auto q1Cat = psVol->addVertexScalarQuantity("vals", vals, polyscope::DataType::CATEGORICAL);
295+
q1Cat->setEnabled(true);
296+
polyscope::show(3);
297+
298+
// clear it out
299+
p->setVolumeMeshToInspect("vol");
300+
polyscope::show(3);
301+
302+
polyscope::removeAllStructures();
303+
polyscope::removeLastSceneSlicePlane();
304+
}

0 commit comments

Comments
 (0)