Vex equivalent of Group Expand node?

   2466   2   0
User Avatar
Member
45 posts
Joined: April 2016
Offline
Hey all,
Does anyone have the vex equivalent of the group expand node?

why:
I want to contract a group by n levels and then expand it again by n levels to get clear out of singleton points that are not connected to the main body of points.

this is to clean up the results of an Attribute Transfer node that has pieces that are overlapping and the values need to be part of a single island so I can use it in a point deform node as the piece attribute.
User Avatar
Member
4711 posts
Joined: Feb. 2012
Offline
Hi,

You can use neighbours and polyneighbours functions:
https://www.sidefx.com/docs/houdini/vex/functions/neighbours.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/vex/functions/polyneighbours.html [www.sidefx.com]

This one does it for points:

function int [ ] getPointNeighbours ( int geo; int ptindex; int depth; int accumulate )
{
    int pts [ ] = array ( ptindex );
    int lastpts [ ] = pts;
    
    for ( int i = 0; i < depth; ++i )
    {
        int newpts [ ] = { };
        foreach ( int pt; lastpts )
        {
            int connected [ ] = neighbours ( geo, pt );
            foreach ( int c; connected )
            {
                if ( find ( pts, c ) < 0 )
                {
                    append ( pts, c );
                    append ( newpts, c );
                }
            }
        }
        lastpts = newpts;
    }
    
    if ( accumulate )
        return pts;
    else
        return lastpts;
}

int pts [ ] = getPointNeighbours ( 0, 42, chi("depth"), chi("accumulate") );
foreach ( int pt; pts )
    setpointgroup ( 0, "pts", pt, 1 );
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
45 posts
Joined: April 2016
Offline
Animatrix, this is great! thank you. I was able to adapt that.

Here are the two functions I came up with with help from Animatrix_ to contract a group:


function int [ ] groupexpand ( int geo; int pts []; int depth ){
    //int pts [ ] = expandpointgroup(0,groupname);
    int lastpts [ ] = pts ;
    for ( int i = 0; i < depth; ++i ){
        int newpts [ ] = { };
        foreach ( int pt; lastpts ){
            int connected [ ] = neighbours ( geo, pt );
            foreach ( int c; connected ){
                if ( find ( pts, c ) < 0 ){
                    append ( pts, c );
                    append ( newpts, c );
                }
            }
        }
        lastpts = newpts;
    }
    return pts;
}


function int [ ] groupcontract (int geo; int pts []; int depth  ){
    //int pts [ ] = expandpointgroup(0,groupname);
    int lastpts [ ] = pts ;
    for ( int i = 0; i < depth; ++i ){
        //printf("lastpts loop %d len: %d \n",i,len(lastpts));
        int rempts [ ] = { };
        int keeppts [ ] = { };
        foreach ( int pt; lastpts ){
            int connected [ ] = neighbours ( geo, pt );
            foreach ( int c; connected ){
                if ( find ( lastpts, c ) < 0 ){
                    if (find ( rempts, pt ) < 0 ){
                        append ( rempts, pt );
                    }
                }
            }
        }
        foreach (int kpt; lastpts){
            if (find(rempts,kpt)<0){
               append ( keeppts, kpt );
            }
        }
        lastpts = keeppts; 
    }
    return lastpts;
}
Edited by geordiemartinez - Feb. 12, 2021 18:12:53
  • Quick Links