CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
292 stars 41 forks source link

Long running time of M3C2 plugin #28

Closed chrise96 closed 2 years ago

chrise96 commented 2 years ago

The M3C2 algorithm in CloudComPy is slow compared to the implementation of CloudCompare.

I put all the files to recreate the experiment here. The timing of the plugins: Cloudcompare M3C2: ~20 seconds CoudComPy M3C2: 15 minutes (sometimes it takes longer ~20 min)

This is the code I use:

import os
import sys
import math
os.environ["_CCTRACE_"]="ON"

import cloudComPy as cc
import numpy as np
import time

cc.initCC()  # to do once before using plugins or dealing with numpy

paramFilename = "m3c2_params.txt"

start = time.time()

if cc.isPluginM3C2():
    import cloudComPy.M3C2
    cloud = cc.loadPointCloud('sidewalk_filter.txt')
    cloud1 = cc.loadPointCloud('sidewalk_filter2.txt')

    cloud2 = cc.M3C2.computeM3C2([cloud,cloud1], paramFilename)

    cc.SaveEntities([cloud, cloud1, cloud2], "M3C2.bin")

    end = time.time()
    print(end - start)
chrise96 commented 2 years ago

It seems this is an issue / bug in cc.loadPointCloud and the point clouds that I use. The point clouds have next to x,y,z the scalar field label. The scalar field label can have a value between 0 and 10 for each point. If I remove this scalar field, the loading is fast and the process takes ~30 seconds overall! 👍

Question: If I want to save to a file extension other than .bin, it saves three files. How can I only save the point cloud with the M3C2 in .laz format?

prascle commented 2 years ago

Hello, sorry for the time taken to answer... I tested your dataset on Linux, with CloudComPy and CloudCompare, and I get very similar times (~8s for the M3C2 calculation, about 10s on the whole script). In my script I directly loaded the files in laz format, not in txt format, it's much faster !

cloud = cc.loadPointCloud('sidewalk_filter.laz')
cloud1 = cc.loadPointCloud('sidewalk_filter2.laz')

The M3C2 algorithm is indeed very sensitive to parameterization, I was careful to use the same set of parameters to compare. I haven't tested it on Windows, but I hope it's about the same. To save only the result, you can use cc.SavePointCloud(cloud2, "M3C2.laz") Let me know if you still see performance issues. Regards, Paul

chrise96 commented 2 years ago

Oh, no worries! Yes the title of this issue is a little misleading now, M3C2 is fast indeed!

I run on Linux with the package CloudComPy39_20220320.7z and I'm not able to load point clouds in laz/las format. It says: [CloudCompare] [Load] Can't guess file format: unhandled file extension 'laz'

Thank you for the command for saving in laz format 👍

prascle commented 2 years ago

Oh, could you check the result of the command ldd CloudComPy39/lib/cloudcompare/plugins/libQPDAL_IO_PLUGIN.so after setting the CloudComPy environment ? Is there a library missing ? maybe libomp.so.5 ? in that case: sudo apt-get install libomp5 Otherwise, let me know.

chrise96 commented 2 years ago

libomp5 is already installed.

But, the output when running import cloudComPy as cc:

[CloudCompare]  libQPDAL_IO_PLUGIN.so does not seem to be a valid plugin    (Cannot load library /home/ceijg/Downloads/CloudComPy39/lib/cloudcompare/plugins/libQPDAL_IO_PLUGIN.so: (libpdal_base.so.13: cannot open shared object file: No such file or directory))

Maybe this is an issue?

prascle commented 2 years ago

Yes, it is a problem. libpdal_base.so.13 is provided by the conda environment. You should have something like that, when the CloudComPy environment is correctly set :

(CloudComPy39) paul@paul-TRX40-AORUS-XTREME:~/projets/CloudComPy/installConda$ ldd CloudComPy39/lib/cloudcompare/plugins/libQPDAL_IO_PLUGIN.so
/bin/bash: /home/paul/miniconda3/envs/CloudComPy39/lib/libtinfo.so.6: no version information available (required by /bin/bash)
    linux-vdso.so.1 (0x00007ffe5448f000)
    libCCPluginAPI.so => /home/paul/projets/CloudComPy/installConda/CloudComPy39/lib/cloudcompare/libCCPluginAPI.so (0x00007f1ec5358000)
    libpdal_base.so.13 => /home/paul/miniconda3/envs/CloudComPy39/lib/libpdal_base.so.13 (0x00007f1ec4bbf000)
    libpdal_util.so.13 => /home/paul/miniconda3/envs/CloudComPy39/lib/libpdal_util.so.13 (0x00007f1ec4b8b000)
    libQCC_GL_LIB.so => /home/paul/projets/CloudComPy/installConda/CloudComPy39/lib/cloudcompare/libQCC_GL_LIB.so (0x00007f1ec4ace000)
    libQCC_IO_LIB.so => /home/paul/projets/CloudComPy/installConda/CloudComPy39/lib/cloudcompare/libQCC_IO_LIB.so (0x00007f1ec4a06000)
    libgdal.so.29 => /home/paul/miniconda3/envs/CloudComPy39/lib/libgdal.so.29 (0x00007f1ec3238000)
... (a long list)

I suppose something is missing or outdated (pdal ?) in your conda packaging.

chrise96 commented 2 years ago

Oke, installed pdal now using conda instead of pip. Got a lot of conflicts that conda needed to resolve (luckily it was able to do by downgrading some libraries)... Now the code can load laz files 👍

antoinebio commented 2 years ago

hello @chrise96 I see you call a txt file for using m3c2 "m3c2_params.txt" are there any special text format & rules when you write down that kind of parameter file ? same question with C2C ? should I save that txt in ANSI ? thank you. antoine