Jump to content
Sign in to follow this  
nibbla

Grouping nearby points with VEX

Recommended Posts

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

Share this post


Link to post
Share on other sites
Posted (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 by Gorrod

Share this post


Link to post
Share on other sites
Posted (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. :lol:

  

Group points with Vex_F.hipnc

Edited by flcc

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
Posted (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 by flcc

Share this post


Link to post
Share on other sites
Posted (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 ?

u_values.JPG

Group points with Vex_F2.hipnc

Edited by flcc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×