Skip to content

Commit efa47e1

Browse files
committed
move stateful selection functions out of pick namespace
1 parent 31d9db8 commit efa47e1

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

include/polyscope/pick.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ struct PickResult {
3939
// Query functions to evaluate a pick.
4040
// Internally, these do a render pass to populate relevant information, then query the resulting buffers.
4141
PickResult queryPickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
42-
PickResult queryPickAtBufferInds(glm::ivec2 bufferInds); // takes indices into render buffer
42+
PickResult queryPickAtBufferInds(glm::ivec2 bufferInds); // takes indices into render buffer
4343

44-
namespace pick {
45-
46-
// Old, deprecated picking API. Use the above functions instead.
47-
// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
48-
// that 0 is the first index as returned from requestPickBufferRange())
49-
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
50-
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
51-
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
5244

5345
// == Stateful picking: track and update a current selection
5446

@@ -60,6 +52,15 @@ bool haveSelection();
6052
void resetSelectionIfStructure(Structure* s); // If something from this structure is selected, clear the selection
6153
// (useful if a structure is being deleted)
6254

55+
namespace pick {
56+
57+
// Old, deprecated picking API. Use the above functions instead.
58+
// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
59+
// that 0 is the first index as returned from requestPickBufferRange())
60+
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
61+
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
62+
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
63+
6364

6465
// == Helpers
6566

src/pick.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ PickResult queryPickAtBufferInds(glm::ivec2 bufferInds) {
4646
return result;
4747
}
4848

49+
// == Manage stateful picking
50+
51+
void resetSelection() {
52+
state::globalContext.haveSelectionVal = false;
53+
state::globalContext.currSelectionPickResult = PickResult();
54+
}
55+
56+
bool haveSelection() { return state::globalContext.haveSelectionVal; }
57+
58+
void resetSelectionIfStructure(Structure* s) {
59+
if (state::globalContext.haveSelectionVal && state::globalContext.currSelectionPickResult.structure == s) {
60+
resetSelection();
61+
}
62+
}
63+
64+
PickResult getSelection() { return state::globalContext.currSelectionPickResult; }
65+
66+
void setSelection(PickResult newPick) {
67+
if (!newPick.isHit) {
68+
resetSelection();
69+
} else {
70+
state::globalContext.haveSelectionVal = true;
71+
state::globalContext.currSelectionPickResult = newPick;
72+
}
73+
}
74+
4975

5076
namespace pick {
5177

@@ -86,32 +112,6 @@ uint64_t requestPickBufferRange(Structure* requestingStructure, uint64_t count)
86112
return ret;
87113
}
88114

89-
// == Manage stateful picking
90-
91-
void resetSelection() {
92-
haveSelectionVal = false;
93-
currSelectionPickResult = PickResult();
94-
}
95-
96-
bool haveSelection() { return haveSelectionVal; }
97-
98-
void resetSelectionIfStructure(Structure* s) {
99-
if (haveSelectionVal && currSelectionPickResult.structure == s) {
100-
resetSelection();
101-
}
102-
}
103-
104-
PickResult getSelection() { return currSelectionPickResult; }
105-
106-
void setSelection(PickResult newPick) {
107-
if (!newPick.isHit) {
108-
resetSelection();
109-
} else {
110-
haveSelectionVal = true;
111-
currSelectionPickResult = newPick;
112-
}
113-
}
114-
115115
// == Helpers
116116

117117
std::pair<Structure*, uint64_t> globalIndexToLocal(uint64_t globalInd) {

src/polyscope.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void processInputEvents() {
406406
if (dragDistSinceLastRelease < dragIgnoreThreshold) {
407407
ImVec2 p = ImGui::GetMousePos();
408408
PickResult pickResult = queryPickAtScreenCoords(glm::vec2{p.x, p.y});
409-
pick::setSelection(pickResult);
409+
setSelection(pickResult);
410410
}
411411

412412
// Reset the drag distance after any release
@@ -415,7 +415,7 @@ void processInputEvents() {
415415
// Clear pick
416416
if (ImGui::IsMouseReleased(1)) {
417417
if (dragDistSinceLastRelease < dragIgnoreThreshold) {
418-
pick::resetSelection();
418+
resetSelection();
419419
}
420420
dragDistSinceLastRelease = 0.0;
421421
}
@@ -755,20 +755,19 @@ void buildStructureGui() {
755755
}
756756

757757
void buildPickGui() {
758-
if (pick::haveSelection()) {
758+
if (haveSelection()) {
759759

760760
ImGui::SetNextWindowPos(ImVec2(view::windowWidth - (rightWindowsWidth + imguiStackMargin),
761761
2 * imguiStackMargin + lastWindowHeightUser));
762762
ImGui::SetNextWindowSize(ImVec2(rightWindowsWidth, 0.));
763763

764764
ImGui::Begin("Selection", nullptr);
765-
PickResult selection = pick::getSelection();
765+
PickResult selection = getSelection();
766766

767767

768768
ImGui::Text("screen coordinates: (%.2f,%.2f) depth: %g", selection.screenCoords.x, selection.screenCoords.y,
769769
selection.depth);
770-
ImGui::Text("world position: <%g, %g, %g>", selection.position.x, selection.position.y,
771-
selection.position.z);
770+
ImGui::Text("world position: <%g, %g, %g>", selection.position.x, selection.position.y, selection.position.z);
772771
ImGui::NewLine();
773772

774773
ImGui::TextUnformatted((selection.structureType + ": " + selection.structureName).c_str());
@@ -1122,7 +1121,7 @@ void removeStructure(std::string type, std::string name, bool errorIfAbsent) {
11221121
for (auto& g : state::groups) {
11231122
g.second->removeChildStructure(*s);
11241123
}
1125-
pick::resetSelectionIfStructure(s);
1124+
resetSelectionIfStructure(s);
11261125
sMap.erase(s->name);
11271126
updateStructureExtents();
11281127
return;
@@ -1183,7 +1182,7 @@ void removeAllStructures() {
11831182
}
11841183

11851184
requestRedraw();
1186-
pick::resetSelection();
1185+
resetSelection();
11871186
}
11881187

11891188

0 commit comments

Comments
 (0)