Tags

, , ,

EDIT: 06, December 2016

I rarely find the time to update this blog, my bad. The point cloud plucker is especially useful for removing points that are too close to one another. An implementation in VEX is a lot more faster than a Python implementation. Below is the VEX code for this:

VEX CODE:

int handle = pcopen(@OpInput1, "P", @P, chf("rad"), chi("num"));
while(pciterate(handle)){
   i@many = pcnumfound(handle);
   for(int i = 0; i<i@many;i++){
      if(i==0)continue;//ignore myself
      else{
         pcimport(handle,"point.number",i@nearptnum);//import ptnum of nearpoints
         /* If point is already in group exit the loop, else add point to group */
         if(inpointgroup(0,"rmve_grp",i@nearptnum)==0){
            setpointgroup(geoself(),"rmve_grp",i@nearptnum,1,"set");
 
         };
      };
    };
};

pcclose(handle); 

This python code allows one to remove points that are too close to one another in a point cloud. The result ideally should be a well spaced point cloud. A radius is specified and each point in the point cloud is tested to see if they are in proximity of the specified radius. The ‘plucked’ points are then added to a group: ‘rmve_grp’. You typically want to run this code from a python defined SOP and append a delete SOP (deleting non-selected ‘rmve_grp’) to view the points that have been plucked, or vice – versa as the case may be.

PYTHON CODE:

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

#Define a group that holds all points that have been removed
rmv_grp = geo.createPointGroup("rmve_grp")
rad = 1
#Iterate through all points
for pt in geo.points():
   #Continue if pt is already in removed group
   if pt in rmv_grp.points():
      continue
   else:
      #otherwise, find the points close to pt and less than specified radius
      for apt in geo.points():
         # Don't perform test on myself
         if pt == apt:
            continue
         else:
            # find close points to pt but less than distance threshold
            ptdisp = pt.position() - apt.position() # displacement vector
            ptdist = ptdisp.length()
            if ptdist < rad:
               rmv_grp.add(apt)
               break

NB: This implementation is a bit buggy. A better implementation would be to wrap this code in a recursive function. This will be addressed in a future post.

Advertisements