CullDuplicatePoints question

Hi,

I have a big list of point objects, with each point object having a unique ‘name’.

I am using CullDuplicatePoints to remove the points that are too close together. However, it seems to me that resulting list is just a list of Point3d coordinates, rather than any of the original GUIDs from the original list. At the moment I am using this list to recreate a new list of point objects, but of course these don’t have the names.

What I am looking for is a way to either:
a. use the resulting culled list to delete from the original list of named point objects.
or b: a way to reallocate the names from the original points to the new ones.

Any suggestions welcomed!

thanks
Peter

The code used today by RhinoCommon is here:

There is already a class with better behavior RTree, but it is a bit more difficult to understand. You could edit this method or write an algorithm based on the RTree class?

Does this help?

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

hi @dromepeter,

I wrote a small python script for you.

import rhinoscriptsyntax as rs
import scriptcontext
import copy
tol = scriptcontext.doc.ModelAbsoluteTolerance

def removeDuplicates(points):
    # Create a dictionary to keep track of the Id
    pointDict = {}
    ptList = []
    for pt in points:
        pt3d = rs.coerce3dpoint(pt)
        pointDict[pt3d] = pt
        ptList.append(pt3d)
    
    #sortList
    ptList.sort()
    ptLast = ptList[-1]
    
    for i in range(len(ptList)-2,-1,-1):
        if (abs(ptList[i][0]-ptLast[0]) < tol) and (abs(ptList[i][1]-ptLast[1])) < tol and (abs(ptList[i][2]-ptLast[2]) < tol):
            del ptList[i]
        else:
            ptLast = ptList[i]
    
    #find the the ids with the new list
    outputList = []
    for pt in ptList:
        ptId = pointDict[pt]
        outputList.append(ptId)
    
    return outputList

a = removeDuplicates(points)

I hope this is what you are looking for :smile: I have also attached a GH version.

  • Miguel

Remove Duplicate Points.gh (7.3 KB)

1 Like