Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a documented account of how to access picking? #269

Open
avaxman opened this issue Apr 7, 2024 · 5 comments
Open

Is there a documented account of how to access picking? #269

avaxman opened this issue Apr 7, 2024 · 5 comments

Comments

@avaxman
Copy link

avaxman commented Apr 7, 2024

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?

@Lucascuibu
Copy link

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

@nmwsharp
Copy link
Owner

nmwsharp commented Apr 8, 2024

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
Copy link
Owner

nmwsharp commented Apr 8, 2024

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
Copy link
Owner

nmwsharp commented Apr 8, 2024

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

@avaxman
Copy link
Author

avaxman commented Apr 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants