22
33#pragma once
44
5- #include " polyscope/structure.h"
6-
75#include < cstdint>
6+ #include < string>
87#include < utility>
98
9+ #include " polyscope/utilities.h"
10+ #include " polyscope/weak_handle.h"
11+
1012namespace polyscope {
1113
14+ // Forward decls
15+ class Structure ;
16+
1217// == Main query
1318
1419// Pick queries test a screen location in the rendered viewport, and return a variety of info about what is underneath
1520// the pixel at that point, including what structure is under the cursor, and the scene depth and color.
1621//
17- // This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickQueryResult ) to get
22+ // This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickResult ) to get
1823// structure-specific info, like which vertex/face was clicked on.
1924
2025// Return type for pick queries
21- struct PickQueryResult {
22- bool isHit;
23- Structure* structure;
24- std::string structureType;
25- std::string structureName;
26+ struct PickResult {
27+ bool isHit = false ;
28+ Structure* structure = nullptr ;
29+ WeakHandle<Structure> structureHandle; // same as .structure, but with lifetime tracking
30+ std::string structureType = " " ;
31+ std::string structureName = " " ;
32+ glm::vec2 screenCoords;
33+ glm::ivec2 bufferCoords;
2634 glm::vec3 position;
2735 float depth;
36+ uint64_t localIndex = INVALID_IND_64;
2837};
2938
3039// Query functions to evaluate a pick.
3140// Internally, these do a render pass to populate relevant information, then query the resulting buffers.
32- PickQueryResult queryPickAtScreenCoords (glm::vec2 screenCoords); // takes screen coordinates
33- PickQueryResult queryPickAtBufferCoords (int xPos, int yPos); // takes indices into render buffer
41+ PickResult queryPickAtScreenCoords (glm::vec2 screenCoords); // takes screen coordinates
42+ PickResult queryPickAtBufferCoords (int xPos, int yPos); // takes indices into render buffer
3443
3544namespace pick {
3645
3746// Old, deprecated picking API. Use the above functions instead.
3847// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
3948// that 0 is the first index as returned from requestPickBufferRange())
40- std::pair<Structure*, size_t > pickAtScreenCoords (glm::vec2 screenCoords); // takes screen coordinates
41- std::pair<Structure*, size_t > pickAtBufferCoords (int xPos, int yPos); // takes indices into the buffer
42- std::pair<Structure*, size_t > evaluatePickQuery (int xPos, int yPos); // old, badly named. takes buffer coordinates.
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.
4352
4453// == Stateful picking: track and update a current selection
4554
46- // Get/Set the "selected" item, if there is one (output has same meaning as evaluatePickQuery());
47- std::pair<Structure*, size_t > getSelection ();
48- void setSelection (std::pair<Structure*, size_t > newPick);
55+ // Get/Set the "selected" item, if there is one
56+ PickResult getSelection ();
57+ void setSelection (PickResult newPick);
4958void resetSelection ();
5059bool haveSelection ();
5160void resetSelectionIfStructure (Structure* s); // If something from this structure is selected, clear the selection
@@ -57,11 +66,11 @@ void resetSelectionIfStructure(Structure* s); // If something from this structur
5766// Set up picking (internal)
5867// Called by a structure to figure out what data it should render to the pick buffer.
5968// Request 'count' contiguous indices for drawing a pick buffer. The return value is the start of the range.
60- size_t requestPickBufferRange (Structure* requestingStructure, size_t count);
69+ uint64_t requestPickBufferRange (Structure* requestingStructure, uint64_t count);
6170
6271// Convert between global pick indexing for the whole program, and local per-structure pick indexing
63- std::pair<Structure*, size_t > globalIndexToLocal (size_t globalInd);
64- size_t localIndexToGlobal (std::pair<Structure*, size_t > localPick);
72+ std::pair<Structure*, uint64_t > globalIndexToLocal (uint64_t globalInd);
73+ uint64_t localIndexToGlobal (std::pair<Structure*, uint64_t > localPick);
6574
6675// Convert indices to float3 color and back
6776// Structures will want to use these to fill their pick buffers
0 commit comments