nearest point to the current point id

   1890   2   0
User Avatar
Member
52 posts
Joined: Feb. 2016
Online
Ello,
I'd like to try and write the nearpoint vex function in a way that lets me grab the ID of the nearest point to the current point on the same geometry, if I write
int npt = nearpoint( 0 , @P, chf("maxDist"));

this fetches the current point index, since it is the ID at @P location. but I'd like to ommit the current point index, I want the nearest point to it instead.
One workaround I've used so far is to use the nearpoints function instead and set the max search points to 2, get the second index, since I know the first index is the one at @P. like this:
int npts[] = nearpoints( 0 , @P, chf("maxDist") , 2);
int nearpointID = npts[1];

I saw in the documentation that you can also specify a group of points to consider for the search, and that it accepts a "SOP-style group pattern such as 0-10 or @Cd.x>0.5."
so I tried this code to try and ignore the current ptnum:
int npt = nearpoint( 0 , "!@ptnum", @P, chf("maxDist"));
but this still returns the current point ID, which leads me to believe my syntax must be wrong, I'm not sure what to try next..
Edited by NNNenov - June 17, 2023 14:28:47
User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
NNNenov
Ello,
I'd like to try and write the nearpoint vex function in a way that lets me grab the ID of the nearest point to the current point on the same geometry, if I write
int npt = nearpoint( 0 , @P, chf("maxDist"));

this fetches the current point index, since it is the ID at @P location. but I'd like to ommit the current point index, I want the nearest point to it instead.
One workaround I've used so far is to use the nearpoints function instead and set the max search points to 2, get the second index, since I know the first index is the one at @P. like this:
int npts[] = nearpoints( 0 , @P, chf("maxDist") , 2);
int nearpointID = npts[1];

The first point is not guaranteed to be the current point, for example if there are overlapping points. The safer method is to use the removevalue method:

removevalue ( pts, @ptnum );

NNNenov
I saw in the documentation that you can also specify a group of points to consider for the search, and that it accepts a "SOP-style group pattern such as 0-10 or @Cd.x>0.5."
so I tried this code to try and ignore the current ptnum:
int npt = nearpoint( 0 , "!@ptnum", @P, chf("maxDist"));
but this still returns the current point ID, which leads me to believe my syntax must be wrong, I'm not sure what to try next..

Your adhoc group syntax is wrong. It should include the literal point number i.e. "!5". But I wouldn't recommend this approach. If you do this, every call that has a different adhoc group will create a new acceleration data structure, slowing down the point cloud look up significantly.

Your workaround above is actually the right approach.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
52 posts
Joined: Feb. 2016
Online
animatrix_
Your adhoc group syntax is wrong. It should include the literal point number i.e. "!5". But I wouldn't recommend this approach. If you do this, every call that has a different adhoc group will create a new acceleration data structure, slowing down the point cloud look up significantly.

Ahh I see, I was confused because in the help they used "@Cd.x>0.5" as an example, I usually get a bit lost knowing whats allowed when it comes to group pattern syntax.


animatrix_
The first point is not guaranteed to be the current point, for example if there are overlapping points. The safer method is to use the removevalue method:

removevalue ( pts, @ptnum );

This is so cool, I didnt know you could do that, thank you!
  • Quick Links