Jump to content

Wrangle Node Evaluation

Recommended Posts

Hi all,

I'm currently working on a project where I need to look at the points in a mesh, and then make a certain percentage of them pair off with one another, pairing with the closest if possible.

Now...I sort of did it, but I'm debugging my it at the moment as some pairings are not working properly (they are being paired with already paired points). Here's a stripped down version of my code (as a side note, the points are dynamic, so I have to use stored point id in an attribute called 'id');

if(i@paired_pt!=-1) return; // Does this work correctly?

int close_pt=-1;

int handle = pcopen(0, "P", @P, range, pt_count), pt;
    if(pcimport(handle, "point.number", pt)){
        if(pt==@ptnum) continue;  // The first one is always the current point
        if(point(0, "paired_pt", pt)==-1){  // Is this point already paired?

if(closept==-1) return; // No match so just exit
i@paired_pt=point(0,"id",closept); // Find the actual id of this paired point

// Is this actually updated, so the comparison at line 0 will work properly when it is evaluated?
setattrib(0, "point", "paired_pt", closept, 0, @id, "set");

So...does the setattrib function actually set the "paired_pt" attribute so that the comparison at line 0 will work properly?


tldr; In a wrangle SOP can attributes that are set be read in the same loop?

Edited by Anti-Distinctlyminty
Link to comment
Share on other sites

Alas I don't think I can. The points need to be paired with one and only one partner. Currently I don't know of any way to ensure that points are not already paired. 

In the attached image you can see that some points are paired off incorrectly. 

Doing this in two passes wont work either I don't think, because you'd end up with the same issue in the second pass - if the target point is already paired, then another must be chosen, but which one? How do I tell that it is not already paired in this second round?



Link to comment
Share on other sites

I got a reply for a developer over at the sidefx forum https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=192857#192857


It basically states that the setting of attributes is done as a post process, so the above code wont work. The solution is to rewrite using a Detail Wrangle SOP and explicitly iterate over the points, storing things in arrays rather than attributes. 

Or alternatively allow the duplicates and then clear them out and re-pair in successive iterations of a for loop.

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...