CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
283 stars 40 forks source link

FlagDuplicatePoints #171

Open Group5AAU opened 4 months ago

Group5AAU commented 4 months ago

Hello!

We are trying to use the functions '.GeometricalAnalysisTools.FlagDuplicatePoints' and 'filterPointsByScalarValue' to remove duplicate points from our point cloud. Does anyone know which arrays or values to use?

image

It sort of works, but it no where near removes as many points as it does when manually using the tool 'Remove duplicate points' within CloudCompare itself.

Hope anyone can help :)

Best Regards!

prascle commented 4 months ago

Hello,

I can't reproduce the problem: in the following test, I create a cloud with random duplicate points and remove the duplicates (here, I've chosen 1.e-3 as the distance criterion), then save the original cloud and the cloud without duplicates. Using CloudCompare, I remove the duplicate points from the original cloud with the same criterion: I get the same cloud as the one calculated by CloudCompy.

The only parameter you need to choose is the distance criterion, which depends on your problem. For the filter, I use 0. for min and max.

Can you provide a dataset and a script to reproduce the problem ? Best regards, Paul

import sys
import math
import numpy as np

os.environ["_CCTRACE_"]="ON" # only if you want C++ debug traces

import cloudComPy as cc

# --- generate a set of coords and a scalar field

npts = 1000000
phi = 2*np.pi*np.random.random((npts))
theta = 2*np.pi*np.random.random((npts))
r = 5 + 0.3*np.sin(2*2*np.pi*phi + 3*2*np.pi*theta)
x = np.float32(r*np.sin(phi)*np.cos(theta))
y = np.float32(r*np.sin(phi)*np.sin(theta))
z = np.float32(r*np.cos(phi))
coords = np.column_stack((x,y,z))
dr = np.float32(np.sqrt(x*x + y*y + z*z) -5)

# --- create the pointCloud, add the scalar field

cloud = cc.ccPointCloud("boule")
cloud.coordsFromNPArray_copy(coords)
cloud.addScalarField("delta")
sf = cloud.getScalarField(0)
sf.fromNpArrayCopy(dr)

# --- remove the duplicates (distances < 1.e-3)

dupSFindex = cloud.addScalarField("DuplicateFlags")
cloud.setCurrentScalarField(dupSFindex)
ret = cc.GeometricalAnalysisTools.FlagDuplicatePoints(cloud, 1.e-3) # identify duplicated points
noDuplCloud = cloud.filterPointsByScalarValue(0., 0., outside=False) # remove duplicated pts

cc.SaveEntities([cloud, noDuplCloud], "boules.bin")