Anti-Distinctlyminty Posted January 7, 2016 Share Posted January 7, 2016 (edited) 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; while(pciterate(handle)){ 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? closept=pt; break; } } } pcclose(handle); 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 January 7, 2016 by Anti-Distinctlyminty Quote Link to comment Share on other sites More sharing options...
Atom Posted January 7, 2016 Share Posted January 7, 2016 (edited) If you're not sure, use two wrangles. Make your sets in one wrangle and your checks in the following one. Edited January 7, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
Anti-Distinctlyminty Posted January 7, 2016 Author Share Posted January 7, 2016 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? Quote Link to comment Share on other sites More sharing options...
iamyog Posted January 7, 2016 Share Posted January 7, 2016 Did not really have the time to read your code but this can be informative: http://forums.odforce.net/topic/15140-is-it-possible-to-use-vex-for-accumulated-calculations/#entry93502 Quote Link to comment Share on other sites More sharing options...
Anti-Distinctlyminty Posted January 7, 2016 Author Share Posted January 7, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.