CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
294 stars 42 forks source link

How to compute split distances in C2C distance computation? #56

Open kk5460 opened 2 years ago

kk5460 commented 2 years ago

Hello, thanks for your great work.

I want to get split distances per dimension X, Y and Z in C2C distances computation and use dimension Z distance for filtering cloud by value. There are setSplitDistances() and getSplitDistance() in params. But I found no way to use these params to get split distances. Could you please tell me how to get split distances dimension X, Y and Z in C2C distances computation, if it is possible?

With best regards

prascle commented 2 years ago

Hello, The split distance part has not been tested correctly, the interface is not user friendly and with bad documentation. Thanks for your help to fix CloudComPy!

Here is an example of use, adapted from test009.py

I will improve and simplify the interface, add and name automatically the scalar fields to the cloud, and rewrite the documentation! Regards, Paul

# --- compute split distances cloud - cylinder vertices

nbCpu = psutil.cpu_count()
bestOctreeLevel = cc.DistanceComputationTools.determineBestOctreeLevel(cloud, None, cylinder.getAssociatedCloud())
params = cc.Cloud2CloudDistancesComputationParams()
params.maxThreadCount = nbCpu
params.octreeLevel = bestOctreeLevel
params.setSplitDistances(cloud.size()) # creates 3 scalar fields of cloud.size(), not yet associated to the cloud

cc.DistanceComputationTools.computeCloud2CloudDistances(cloud, cylinder.getAssociatedCloud(), params)

sfx = params.getSplitDistance(0)       # access to scalar fields
sfx.computeMinAndMax()
sfy = params.getSplitDistance(1)
sfy.computeMinAndMax()
sfz = params.getSplitDistance(2)
sfz.computeMinAndMax()

asfx = sfx.toNpArray()                 # add the scalar fields to the cloud
asfy = sfy.toNpArray()
asfz = sfz.toNpArray()
cloud.addScalarField("dx")
cloud.addScalarField("dy")
cloud.addScalarField("dz")
dic = cloud.getScalarFieldDic()
csfx = cloud.getScalarField(dic["dx"])
csfy = cloud.getScalarField(dic["dy"])
csfz = cloud.getScalarField(dic["dz"])
csfx.fromNpArrayCopy(asfx)
csfy.fromNpArrayCopy(asfy)
csfz.fromNpArrayCopy(asfz)
kk5460 commented 2 years ago

Dear Paul,

Thank you for your help. This satisfies my needs perfectly.

Many thanks