Open avaxman opened 5 months ago
Are you looking for the buildPickGui() in scr/polyscope.cpp?
I'm guessing in C++?
There are the pick
functions
std::pair<Structure*, size_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
std::pair<Structure*, size_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
This gives you a pointer to which structure is at that screen location, and an index indicating which element within the structure you clicked on. E.g. for a point cloud this is just the index of a point.
But the API here is real ugly for meshes etc. In this case, the local index is into a combined index space with elements ordered sequentially as [vertices faces edges halfedges corners]
. So you need a little arithmetic logic to figure out whether the user clicked on a vertex/face/edge/etc. You can see Polyscope internally figuring out which kind of index it is here.
This isn't very easy to use :) I will mark this bug as a TODO to remind me to add a better API for testing if a vertex was clicked etc.
Actually you should use
std::pair<Structure*, size_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
std::pair<Structure*, size_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
rather than the old evaluatePickQuery()
(just edited the comment above to no longer suggest this). They do the same thing under the hood, but they properly distinguish screen coords vs. pixel indices, which is annoying but necessary to get right for your code to work cross-platform on high-DPI screens.
There are some examples here for writing such mouse interactions https://polyscope.run/features/callbacks_and_UIs/#mouse-interactions
Thanks. Indeed this is very useful to have explicitly (for mesh/quantity editing etc.)
I am trying to access the picking of faces or vertices within a callback function to manipulate their content. However I didn't find any explicit way to do this in the documentation. Is this written somewhere?