Delete duplicate lines

   1945   2   1
User Avatar
Member
17 posts
Joined: 7月 2018
Offline
Hello,

I wrote the following code for a python SOP that removes duplicate lines. The basic idea is that it finds the mid-point of each line, and stores it in an array. If the mid-point already exists in the array, it adds the line to an array of lines to be deleted and then deletes them.

It was more a proof of concept, as I was hoping to write something equivalent but faster in VEX. To my horror, my VEX really chugged. I was using groups and inpointgroup to store and search for the results, but it was incredibly slow.

node = hou.pwd()
geo = node.geometry()

r = 3

centres = []
deletes = []
for i in geo.prims():
    pts = i.points()
    x0,y0,z0 = pts[0].position()
    x1,y1,z1 = pts[1].position()
    centre = (round((((x1-x0)*0.5)+x0),r), round((((y1-y0)*0.5)+y0),r), round((((z1-z0)*0.5)+z0),r))
    if centre in centres:
        deletes.append(i)
    else:
        centres.append(centre)
    
geo.deletePrims(deletes, keep_points = False)

So I was just wondering if there was anyone out there who can give me some pointers on writing it in VEX.

That's unless of course, I have stumbled upon an instance of Python that runs faster than VEX…



Ash
User Avatar
Member
4548 posts
Joined: 2月 2012
Offline
Hi,

A more robust and generic method would be to fuse the geometry and then use 2 Primitive Wrangle nodes like this:

string serializepointindices ( int primindex )
{
    int indices [ ] = primvertices ( 0, primindex );
    int count = len ( indices );
    for ( int i = 0; i < count; ++i )
        indices [ i ] = vertexpoint ( 0, indices [ i ] );
        
    indices = sort ( indices );
    return sprintf ( "%s", indices );
}

s@pointlist = serializepointindices ( @primnum );

string pointList = prim ( 1, "pointlist", @primnum );
int index = findattribval ( 1, "primitive", "pointlist", pointList );
if ( @primnum != index )
    removeprim ( geoself ( ), @primnum, 1 );

This method can delete any polygons, not just lines.

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
17 posts
Joined: 7月 2018
Offline
Hi Animatrix_,

That was a quick response, and some equally speedy VEX! I really appreciate your help.

It's a very interesting approach, and I think I need a mental reset between moving from python to vex.

BTW, cool Vimeo channel.

Thanks,



Ash
  • Quick Links