polyscope icon indicating copy to clipboard operation
polyscope copied to clipboard

Is there a documented account of how to access picking?

Open avaxman opened this issue 1 year ago • 5 comments

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?

avaxman avatar Apr 07 '24 20:04 avaxman

Are you looking for the buildPickGui() in scr/polyscope.cpp?

Lucascuibu avatar Apr 08 '24 00:04 Lucascuibu

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.

nmwsharp avatar Apr 08 '24 04:04 nmwsharp

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.

nmwsharp avatar Apr 08 '24 05:04 nmwsharp

There are some examples here for writing such mouse interactions https://polyscope.run/features/callbacks_and_UIs/#mouse-interactions

nmwsharp avatar Apr 08 '24 05:04 nmwsharp

Thanks. Indeed this is very useful to have explicitly (for mesh/quantity editing etc.)

avaxman avatar Apr 08 '24 06:04 avaxman