88#include < utility>
99
1010namespace polyscope {
11- namespace pick {
1211
12+ // == Main query
1313
14- // == Set up picking
15- // Called by a structure to figure out what data it should render to the pick buffer.
16- // Request 'count' contiguous indices for drawing a pick buffer. The return value is the start of the range.
17- size_t requestPickBufferRange (Structure* requestingStructure, size_t count);
14+ // Pick queries test a screen location in the rendered viewport, and return a variety of info about what is underneath
15+ // the pixel at that point, including what structure is under the cursor, and the scene depth and color.
16+ //
17+ // This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickQueryResult) to get
18+ // structure-specific info, like which vertex/face was clicked on.
19+
20+ // Return type for pick queries
21+ struct PickQueryResult {
22+ bool isHit;
23+ Structure* structure;
24+ std::string structureType;
25+ std::string structureName;
26+ glm::vec3 position;
27+ float depth;
28+ };
29+
30+ // Query functions to evaluate a pick.
31+ // 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
1834
35+ namespace pick {
1936
20- // == Main query
37+ // Old, deprecated picking API. Use the above functions instead.
2138// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
2239// that 0 is the first index as returned from requestPickBufferRange())
2340std::pair<Structure*, size_t > pickAtScreenCoords (glm::vec2 screenCoords); // takes screen coordinates
2441std::pair<Structure*, size_t > pickAtBufferCoords (int xPos, int yPos); // takes indices into the buffer
2542std::pair<Structure*, size_t > evaluatePickQuery (int xPos, int yPos); // old, badly named. takes buffer coordinates.
2643
27-
2844// == Stateful picking: track and update a current selection
2945
3046// Get/Set the "selected" item, if there is one (output has same meaning as evaluatePickQuery());
@@ -38,6 +54,11 @@ void resetSelectionIfStructure(Structure* s); // If something from this structur
3854
3955// == Helpers
4056
57+ // Set up picking (internal)
58+ // Called by a structure to figure out what data it should render to the pick buffer.
59+ // 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);
61+
4162// Convert between global pick indexing for the whole program, and local per-structure pick indexing
4263std::pair<Structure*, size_t > globalIndexToLocal (size_t globalInd);
4364size_t localIndexToGlobal (std::pair<Structure*, size_t > localPick);
0 commit comments