Nearest unique/exclusive point using VEX?

   5779   4   1
User Avatar
Member
319 posts
Joined:
Offline
Hello,

I have written a vex sop which finds the nearest n points and their distances in a point cloud. The functionality also includes the ability to plug in a second point cloud to input 2 to use as the ‘query point cloud’. It is basically a pcopen/search using code which I wanted to create for myself as I find wiring together the pc vops to do this task a little convoluted.

What I want to do now, is write another vex sop which will compute the nearest exclusive or unique point for each point (so each points recorded nearest point will never be a duplicate). I have already written nearest point and nearest unique point Python sops, but with large point clouds these become very very slow to compute. The vex nearest point sop is almost instant, even plugging in 1 million points, where the Python nearest point sop takes 10 minutes plus for a million points.

I am not a VEX expert by any stretch, and after looking into the nearest unique point setup I am unsure as to if it is actually possible with VEX due to its SIMD architecture. The Python version I have basically works like this:-

- Get the nearest point and its distance for every point

- Sort points by the distance (so now the point with the smallest distance to its nearest point is now point 0, and the point with the largest distance to its closest point is point N)

- Loop through points again, now smallest distance to largest distance, and again find the nearest point out of all the points for each point, but this time, every time we find a nearest point, remove that point from the list of eligible points to be searched before we search again for the next point.

Is this logic possible with VEX? My Python sops don't use pcopen, but simply for every point it loops through all the other points, works out the distance, adds that to a dictionary which stores the point number and its distance from the current point, then orders the dictionary by smallest distance to largest, and then takes the first index (which is the closest point after sorting).

Is this sort of logic possible in VEX? I have noticed a lot of posts from people confused about the order of printf statements when trying to debug vex code, and the answer seems to be due to VEX's SIMD nature it doesn't process data the same as say Python, more like it runs every line of code for each point and moves on, making replicating the way my python sop is working problematic?

Any advice from people more well versed in VEX would be welcome!

Thanks!
User Avatar
Member
229 posts
Joined: May 2006
Offline
Its hard to do in vex, you can doit using a combination of vex and python.

Via vex you search a list of closest points, in python you do the checking which points are already in use.

I have written a sop node (c++)hat does what you want i think.
Have a look here https://gitorious.org/buddy-sop/buddy-sop [gitorious.org]


Cheers Seb
User Avatar
Member
319 posts
Joined:
Offline
Thanks for sharing Infernalspawn.

I considered using HDK to do this, but I know even less about HDK than I do about VEX! I'll take a look at your sop. I was interested on a general level on what the limitations of VEX are from having trouble trying to do something like this in it. I suppose thats why you opted for a HDK solution?

Thanks again!
User Avatar
Member
229 posts
Joined: May 2006
Offline
The general advantage of vex is its SIMD structure.
All points are processed in parallel, and you have no way to access the results of the vex-calculation of a neighbouring particle in the same vex sop.

This makes it hard to solve the problem you want to solve, as another point may already have claimed the closest point to your current point.

Therefore making a list of closest points and storing them in a array on a point is something that can be done in vex as this is can be done in parallel.
The next step could be done in python, as you have access to all the points at once and their lists of closest points.

The problem could be, depending on how long your list of stored points is
You might end up with points that have no ‘buddy’ as all points in their lists were claimed by other points.
Then you could either increase the list size or, rerunn the list generation on the points that have an not yet found their buddy.


Cheers Seb
User Avatar
Member
8539 posts
Joined: July 2007
Offline
in VEX you are not really limited by SIMD architecture as you can use it in AttribWrangle in Detail mode

what is limiting a bit is the array functions as there are currently no functions for sorting them or finding a value in, so that will make this particular task more difficult.
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links