Page 1 of 1

Method for automating fine registration (ICP) of multiple meshes to a single reference mesh?

Posted: Tue Sep 06, 2022 9:16 am
by tbere9
Hi everyone,

I am currently completing a university project where I have taken 3D scans of some objects to test the accuracy of the devices used. I am doing this by comparing the resulting meshes against reference meshes that act as "ground truths". For a single reference mesh, 80 meshes need to be compared against it. I have already completed rough registration for all of these, so all I need to do now is run the fine registration and mesh-to-mesh distance calculations. However, the fine registration is very time-consuming as each comparison takes about 10 minutes to complete.

To get around this, I have tried to automate this process by using CloudCompare's command line mode. Unfortunately, I haven't used cmd much and haven't done much coding. Currently, I have got the fine registration process to work for a single comparison and have got multiple processess to run at the same time by running the commands in cmd with an "&" symbol in between. This looks like this:

CloudCompare -M_EXPORT_FMT STL -O "C:\Users\...\Reference Scan.stl" -O "C:\Users\...\Compared Scan (1).stl" -ICP -REFERENCE_IS_FIRST -MIN_ERROR_DIFF 1e-5 -OVERLAP 100 & CloudCompare -M_EXPORT_FMT STL -O "C:\Users\...\Reference Scan.stl" -O "C:\Users\...\Compared Scan (2).stl" -ICP -REFERENCE_IS_FIRST -MIN_ERROR_DIFF 1e-5 -OVERLAP 100 & CloudCompare -M_EXPORT_FMT STL -O "C:\Users\...\Reference Scan.stl" -O "C:\Users\...\Compared Scan (3).stl" -ICP -REFERENCE_IS_FIRST -MIN_ERROR_DIFF 1e-5 -OVERLAP 100 & CloudCompare -M_EXPORT_FMT STL -O "C:\Users\...\Reference Scan.stl" -O "C:\Users\...\Compared Scan (4).stl" -ICP -REFERENCE_IS_FIRST -MIN_ERROR_DIFF 1e-5 -OVERLAP 100 & CloudCompare -M_EXPORT_FMT STL -O "C:\Users\...\Reference Scan.stl" -O "C:\Users\...\Compared Scan (5).stl" -ICP -REFERENCE_IS_FIRST -MIN_ERROR_DIFF 1e-5 -OVERLAP 100

While this works, it seems very inefficient and almost crashes my PC when I try to do more than five fine registration processes at once.

Is there any way to automate this fine registration process so that only one process runs at a time and the next process begins when the previous is finished?

I'm mainly concerned about fine registration at the moment, but if anyone knows how to automate mesh-to-mesh distance calculations (the next step for me), I would love to hear your thoughts.
Cheers.

Re: Method for automating fine registration (ICP) of multiple meshes to a single reference mesh?

Posted: Tue Sep 06, 2022 7:08 pm
by daniel
Yes, you shouldn't run them in parallel.

Any batch/script will do that natively if you just put one command per line in a file (i.e. my_process.bat on windows, then call this file in a console, or something else on Linux, such as 'my_process.sh').

And you could even automate it based on the files found in a folder:
see https://www.cloudcompare.org/forum/view ... 083#p26083

Re: Method for automating fine registration (ICP) of multiple meshes to a single reference mesh?

Posted: Fri Sep 16, 2022 4:09 am
by tbere9
Thank you so much Daniel! This has been incredibly helpful for someone who is very new to doing this sort of thing!

For anyone looking to automate fine registration (ICP) and cloud-to-cloud/cloud-to-mesh/mesh-to-mesh comparisons who doesn’t have much background in using Command Prompt (cmd), here is the method that worked for me on both Windows 7 and Windows 10:

set local EnableDelayedExpansion
set Compared={folder with meshes to be compared}
set Reference={folder with reference meshes}
for %%f in ( "%Reference%"\* ) do ("C:\Program Files\CloudCompare\CloudCompare.exe" -SILENT -O %Compared%\%%~nxf -O %Reference%\%%~nxf -ICP -MIN_ERROR_DIFF 1.0E-05 -OVERLAP 100 -RANDOM_SAMPLING_LIMIT 50000 -ROT XYZ -C2M_DIST)
cmd /k


Copy this into Notepad (or Notepad++ if you have that), copy the paths to the Compared and Reference folders into the set Compared= and set Reference= lines, and change any of the parameters to better suit you (e.g. for ICP you might want 80% overlap, so change -OVERLAP 100 to -OVERLAP 80). When you’re done, save the file as an “All Files (*.*)” file and name it with .bat at the end. Now you can run this command by clicking on this .bat file. Two .bin file should be exported into the Compared folder with each comparison – one with the registered mesh and the other with the mesh + the cloud-to-mesh scalar field (the colour map compared to the reference mesh).
The most common issue I had was folders in the Compared and Reference paths had spaces, so I just replaced spaces with underscores.

Final note: If you are running a lot of comparisons/distance computations, the cmd window may run out of lines to record your output as the limit is 9999 lines. If you’re comparing hundreds of meshes like me, you might want to break this up into blocks of 100-150 comparisons so you don’t lose the RMS values for fine registration and mean distance/standard deviation values for distance computation.

Re: Method for automating fine registration (ICP) of multiple meshes to a single reference mesh?

Posted: Fri Sep 16, 2022 9:05 pm
by daniel
Thanks for the feedback!