Jump to content

Nearest single point ID to attribute


Recommended Posts


What I need to do is store the number of the nearest point in a point attribute, so that I can then connect each point to its nearest neighbor.

What "anim" does here is exactly what I need (don't want to revive a thread):


My issue is that I don't know what he's doing in the VOP; I was hoping somebody had a simpler method to do this?

PS. I know I can just use a POP and create a proximity node, but in the interest of learning VOP I want to see if this is possible...

Link to comment
Share on other sites

His scene is everything you need. So let's analyse his vopsop for you.

Jump into the vopsop.

The first node after globals is the important one, it's the point cloud open. It takes a series of points and pulls them into the vop. So in this case he's just pulled in the input (look at the default parameter on the node).

He then does two pciterates, which will iterate through each point. I don't normally do it like he does it, but I believe all he's doing is making sure there's two points near the query position. First will be the point right at query position (itself) and the next will be the nearest point to it).

So the "and1" will return 1 if two points are found, if not it'll return 0.

So if it found two points it'll jump into the if statement, so jump into that and see whats there.

Ignore everything at the top, that's getting a vector between them, what you want are the two purple ones at the bottom.

So the pcimport will return the point number of the incoming point (from the second pciterate, ie the nearest point to current point).

He then creates an attribute called "neighbour_pt" which will store the point number of the nearest point to an attribute on the current point.

Exit the if statement and you'll see pcclose, this closes off the point cloud, which I believe you have to do if you use the pciterate in the way he has done instead of in a loop.

That's it, you should see in the details view that it's stored the point number of the nearest point to each one.

Hope that helps you out a bit, everything is there for you to check through and work out what's going on.


Link to comment
Share on other sites

  • 2 weeks later...

I'd be interested in better understanding this as well.

For instance:

What, exactly, are the two pciterates doing? Why would each pciterate represent a different member of the point cloud if each is simply iterating over all of the (2) points in the cloud? Inside the for loop, how do I know which point the pcimport node is getting its data from? What about this structure tells me that it wouldn't grab $PT for the current point itself? The basic logic seems to be "if there are two points, get the point number." You can see the missing puzzle piece in the previous statement.

It's very difficult to find in depth explanation for the function of many of the looping features in VEX. This network works great, and beats the hell out of doing a per point forEach loop, but it would be great to understand exactly how it works.

Link to comment
Share on other sites

Well no, the pciterate would iterate over every point only in a for/while loop.

What it is doing there is the first one is finding the first point, which will be the point nearest to P, so itself. The next iterate then finds the next one. So what point you are looking at for the rest of the vop is the nearest point to the current point.

Make sense?


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...