nibbla Posted June 22, 2020 Share Posted June 22, 2020 I asked this question over at the Houdini forum, but to no avail. I'm trying to group nearby points together using VEX in a point wrangle. This is what I've got at the moment: float dist = ch("dist"); int nearPoints[] = int[](array()); string groupName = concat(“group_”, itoa(i@i)); if(point(0, "grouped", @ptnum) == 0) { nearPoints = nearpoints(0, point(0, "P", @ptnum), dist); foreach(int point; nearPoints) { if(point(0, "grouped", point) == 0) { setpointgroup(0, groupName, point, 1, "set"); setpointattrib(0, "grouped", point, 1, "set"); } } i@i++; } But there is only one group being created containing all of the points. File is attached. Group points with Vex.hipnc Quote Link to comment Share on other sites More sharing options...
Gorrod Posted June 22, 2020 Share Posted June 22, 2020 (edited) The biggest issue here I think is that wrangle nodes and for loops in wrangles do not have feedback. So if you change a group or attribute on a point in a point wrangle, another point being processed by that same pointwrangle can not read the result of any other iteration by that wrangle. Generally SOP nodes process their incoming geometry only. To circumvent that, you could either do a foreach loop with feedback and iterate over every point and create your groups like that or use a detail wrangle with a while loop and write everything you want to change and access at the same time into arrays and not attributes. My solution for your file would look like this, using a detailwrangle: int idx = 0; int pts[] = expandpointgroup(0, ""); int isGrouped[] = array(); foreach(int pt; pts) append(isGrouped, 0); int groupIdx = 0; while(idx < (len(pts))) { int pt = pts[idx]; if(!isGrouped[idx]) { foreach(int npt; nearpoints(0, point(0, "P", pt), chf("maxDist"))) { setpointgroup(0, "_"+itoa(groupIdx), npt, 1, "set"); isGrouped[npt] = 1; } groupIdx++; } idx++; } Group_points_with_Vex_ben.hipnc Edited June 22, 2020 by Gorrod Quote Link to comment Share on other sites More sharing options...
tamagochy Posted June 22, 2020 Share Posted June 22, 2020 (edited) I made fast fix. Look at file Group points with Vex_fix.hipnc Edited June 22, 2020 by tamagochy Quote Link to comment Share on other sites More sharing options...
flcc Posted June 23, 2020 Share Posted June 23, 2020 (edited) A simple u based solution. i@nbpt = @numpt / @numprim; i@uidx = (@nbpt-1) * @curveu; int itsprim[] = pointprims(0, @ptnum); i@primid = itsprim[0]; s@grp = 'group_' + itoa(@uidx); setpointgroup(0,@grp,@ptnum,1,'set'); By the way, almost all variable are attributes, but it's just for "debugging" purpose. I get a little lazy sometimes. Group points with Vex_F.hipnc Edited June 23, 2020 by flcc Quote Link to comment Share on other sites More sharing options...
nibbla Posted June 23, 2020 Author Share Posted June 23, 2020 That's great! Thank you for all the replies. Flcc: I guess a prerequisite for this solution is having curves of equal length and points, right? Gorrod: I didn't know you could use expandpointgroup(0, ""); to get all of the points. That's a nice trick! Quote Link to comment Share on other sites More sharing options...
flcc Posted June 23, 2020 Share Posted June 23, 2020 (edited) 7 hours ago, nibbla said: Flcc: I guess a prerequisite for this solution is having curves of equal length and points, right? Efectively with this snippet it's required. But I'm pretty sure it would be not to hard to fix. Just thinking of it, make a resample with same number of points but evenly spaced, then a copy attribute on the original curves could do the trick. I'll try it if i find some time. Edited June 23, 2020 by flcc Quote Link to comment Share on other sites More sharing options...
flcc Posted June 23, 2020 Share Posted June 23, 2020 (edited) It actually works as is, and I can't really explain why. It seems that when the resampling options are unchecked, the resample node gives the u values for the points as if they were equally spaced. Which is strange, but exactly what we want. Another strange thing, it's like the resample node gave the u values before resampling. In the doc it's clearly written that these are the values of the output points. You can see this in the second set-up on the right in the file. am i missing something ? Can Someone give some light ? Group points with Vex_F2.hipnc Edited June 23, 2020 by flcc 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.