Automated way to convert point clouds from .asc to .ply format and compute normals

339 Views Asked by At

I have a lot of point cloud data saved in files with the .asc extension. I need a way to automate conversion to PLY and compute their normals.

The .asc file data looks like this:

1074.9755859,5.6643524,-305.2966309,59.0000000,1.0000000

1076.0521240,6.5306702,-305.5505371,68.0000000,1.0000000

1077.0552979,7.4164429,-305.5427246,65.0000000,1.0000000

I tried using Cloud Compare Command Line mode:

$ cloudcompare.CloudCompare -O "path/to/ascii/file" -OCTREE_NORMALS 10 -C_EXPORT_FMT PLY -SAVE_CLOUDS

but that is for one file only, and the issue with it is that it requires me to press buttons on the Cloud Compare popup windows for the process to finish. I am not sure how to adapt that to multiple conversions one after another without my intervention.

I installed Cloud Compare, using the snap package.

A solution with Cloud Compare or any other method would be highly appreciated!

EDIT: I managed to find a solution after all. Apparently the Cloud Compare version from the snap package was old and buggy, so I used the Flatpak installation instead, which comes with a newer version.

I made a python script, that can be placed in the folder with the ASCII files, and run from the terminal.

$ python3 convert_to_ply.py

The contents of the file are below:

import os

# get the current working directory
dir_path = os.getcwd()

# Iterate directory
for path in os.listdir(dir_path):
    if path != 'convert_to_ply.py':
        # check if current path is a file
        if os.path.isfile(os.path.join(dir_path, path)):
            # Convert files to PLY format and compute normals
            # -OCTREE_NORMALS {radius}
            os.system('flatpak run org.cloudcompare.CloudCompare -SILENT '
                         '-O ' + str(path) + ' -OCTREE_NORMALS 10 -C_EXPORT_FMT PLY -SAVE_CLOUDS')

The Cloud Compare command line mode documentation can be found here: https://www.cloudcompare.org/doc/wiki/index.php?title=Command_line_mode&oldid=47289

0

There are 0 best solutions below