Skip to content

CloudComPy M3C2 plugin computes values with a 'shift' #220

Open

Description

@Ezguer1

Hello everybody,

I am calculating volumes of rockfall events using CloudCompare and its M3C2 plugin. As I am dealing with a vast number of events, I want to write a code using the CloudComPy environment to loop over all of the events and calculate the M3C2 distance for them automatically.
However, when I run the M3C2 algorithm on my pointclouds via python something weird happens: It calculates the distances with a shift (see graphic below to see what I mean).
Does somebody have an idea what might be causing this issue?

Image Left: manual computation of M3C2 in CloudCompare, Right: M3C2 output when using CloudComPy

My code looks like this:
`import subprocess
import os
import cloudComPy as cc
import cloudComPy.M3C2

#initialize CloudCompare
cc.initCC()
cloudcompare_exe = r'c:\Program Files\CloudCompare\CloudCompare.exe'

#USER INPUT
#Parameters
directory = r'motherdirectory'
filepath = r'pathTo .bin file'
output_folder_M3C2 = r'Here I want to store the results'
M3C2_params = r'.txt file containing the M3C2 parameters' #First, you have to perform ONE M3C2 and save the parameters to a file
first_last_year = ['2020', '2024']
name_cirque = 'Aneto'
amount_of_events = 94

#DATA READING
#loading bin file and extract structure
datafile = cc.importFile(filepath)
list_cloud_names = datafile[4]
list_clouds = datafile[1]
firstyear_events = list_clouds[0:(amount_of_events - 1)]
lastyear_events = list_clouds[(amount_of_events + 1):(amount_of_events * 2)]

#PERFORM M3C2
#indexes to loop through clouds
i = 0
M3C2_list = []

#perform M3C2
while i < amount_of_events:
ref = lastyear_events[i]
comp = firstyear_events[i]
M3C2_i = cc.M3C2.computeM3C2([ref,comp], M3C2_params) #compute M3C2 for cloud i +1
M3C2_list.append(M3C2_i) #add entities (clouds) to newly created list
cc.SaveEntities([M3C2_i],os.path.join(output_folder_M3C2,name_cirque +
'M3C2_' + str(i+1)))
i += 1`

And I my parameter .txt file like this: (I exported it directly from the M3C2 popup window in CloudCompare with the parameters desired)
[General]
M3C2VER=1
NormalScale=100
NormalMode=0
NormalMinScale=2
NormalStep=0.5
NormalMaxScale=5
NormalUseCorePoints=false
NormalPreferedOri=4
SearchScale=0.5
SearchDepth=20
SubsampleRadius=14.06076
SubsampleEnabled=false
RegistrationError=0.162448
RegistrationErrorEnabled=true
UseSinglePass4Depth=false
PositiveSearchOnly=false
UseMedian=false
UseMinPoints4Stat=false
MinPoints4Stat=5
ProjDestIndex=1
UseOriginalCloud=false
ExportStdDevInfo=false
ExportDensityAtProjScale=false
MaxThreadCount=10
UsePrecisionMaps=false
PM1Scale=1
PM2Scale=1

Thanks for you help in advance.

Activity

  1. prascle commented on Dec 8, 2025

    @prascle
    Collaborator

    Hello,
    I'm afraid my answer got lost somewhere, sorry about that, this question is quite old now!
    I spent some time checking the code without finding an explanation for these discrepancies. My series of tests shows consistent results between clouComPy and the GUI.

    • Have you tried using the M3C2guessParamsToFile method (see the documentation on using M3C2)?
    • What versions of cloudComPy and CloudCompare are you using?
    • Could you provide a dataset to reproduce the problem?

    Regards,
    Paul

  2. Ezguer1 commented on Dec 18, 2025

    @Ezguer1
    Author

    Hello Paul,
    Thank you for your response and for addressing my problem.

    I'm gladly providing you with my dataset. Please find the .bin file attached together with my code and parameter file. The .bin contains 2 pointclouds that I initially compared with M3C2 in the GUI to find areas of significant change. These, I cut out of both clouds and now I want to calculate the distance between these subsets for every area of significant change. For the dataset provided, I already did that manually using the parameters I saved in the parameter file and you can find the results in the folder VolCalc in the project to compare those with the results of the code. As I need to use specific parameters, using the M3C2guessParamsToFile operation does not make sense unfortunately.

    I am using CloudCompare 2.13.12 and CloudComPy311.

    I thank you for checking and wish you a nice day,
    Kind regards

    testdata.zip

  3. Ezguer1 commented on Dec 19, 2025

    @Ezguer1
    Author

    Hey Paul,

    I found out, that as soon as I save the new clouds as .las files using: cc.SavePointCloud(), it works. So I can work around the problem which seems to occur when saving the entities as .bin files which happens defaultly when saving them using cc.SaveEntities().
    Maybe this is of help/interest to you.

    Have a good one

  4. prascle commented on Dec 19, 2025

    @prascle
    Collaborator

    Hi,
    Thanks for this information! That's a rather strange side effect. I downloaded your dataset and my idea was to check the differences between CloudComPy (based on CloudCompare 2.14alpha, June 2025) and CloudCompare 2.13.2 (there are some changes in the normals, which may not be correctly taken into account in CloudComPy). I will try to reproduce the behavior you are observing.

    Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions