CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
292 stars 41 forks source link

Saving a point cloud as las-file #20

Closed tmoelter closed 2 years ago

tmoelter commented 2 years ago

Hi, I'm very happy that there exist now an option to use CloudCompare via python. So far I started to install everything on my windows machine and tried some operations such as computing volume density. After that I wanted to save the point cloud using res = cloudComPy.SavePointCloud(cloud, "path/to/save/file.las"). Unfortunately no file is written and when I print "res" in spyder the output is CC_FERR_THIRD_PARTY_LIB_EXCEPTION. I tried to save the point cloud as asc-file and luckily it works. However las-files are actually the things I need. Any suggestions what I did wrong or where the error might occur?

Thanks in advance! Tina

dgirardeau commented 2 years ago

have you tried to remove any non latin character or space character from the file path? (it's kind of a lucky guess ;) )

tmoelter commented 2 years ago

Thanks for the quick response. I have no space characters or non latin characters in my file path, so this is sadly not the solution. I tried it also with the point cloud which is used in the testing scripts, but no difference.

prascle commented 2 years ago

I Just tried to reproduce the problem, I obtain a similar behaviour when cc initialisation cc.initCC() is missing

import cloudComPy as cc
cc.initCC()

initCC must be called just after import to get a correct access to the I/O plugins. Did you call initCC ?

tmoelter commented 2 years ago

Yes, I did. My code looks like this:

import sys
import os
import glob

import numpy as np

os.environ["_CCTRACE_"]="ON"
import cloudComPy as cc

# Needed once before dealing with plugins
cc.initCC()

# Cloud path
cpath = "path/to/file.las"

# Read point cloud from file
cloud = cc.loadPointCloud(cpath)

dens_res = cc.computeLocalDensity(cc.Density.DENSITY_3D, 2, [cloud])

# Save point cloud to file
res = cc.SavePointCloud(cloud, "path/to/outfile.las")

But I also tried to rasterize a point cloud (cc.RasterizeGeoTiffOnly(cloud, gridStep=2.0, pathToImages="path/to/raster.tif")) and it also failed. So I'm not sure whether there went something wrong with my installation.

prascle commented 2 years ago

Have you tried to do the same with the CloudCompare GUI provided with CloudComPy ? Could you check the Console in CloudCompare to see if there are problems with the plugins ?

tmoelter commented 2 years ago

That was a good hint: When I start Cloud Compare using Anaconda Prompt (after activating CloudComPy39 and run the envCloudComPy.bat), do the density calculation and than try to export the resulting point cloud, I first get an PDAL exception ("Can't create dimension with invalid name 'Volume density (r_2)'.") followed by another error message while saving: "*** the third-party library in charge of saving/loading the file has thrown an exception".

When I do the exact same operation with my Cloud Compare installation it works fine...

And rasterization also works, also when using the Cloud Compare GUI which comes with the installation of CloudComPy.

tmoelter commented 2 years ago

I guess it is issue with the density calculation, since I tried the same operation in Cloud Compare provided with CloudComPy and in spyder without calculation the density and it worked without exceptions. I simply loaded the point cloud and saved it under a new name.

prascle commented 2 years ago

From what I understand, we have two problems: the density calculation, and the rasterize function. If by chance you are able to provide a small dataset and instructions to reproduce the density calculation problem, that's great. For the RasterizeGeoTiffOnly instruction, can you try again with all the parameters explicit, there might be a problem with the optional parameters, I'll have to check the code...

tmoelter commented 2 years ago

Instructions to density calculation

A) In Anaconda Prompt:

  1. activate CloudComPy39
  2. cd path\to\CloudCompy\installation
  3. envCloudComPy.bat
  4. spyder

B) Run the following code in spyder

# -*- coding: utf-8 -*-
import sys
import os

import numpy as np

os.environ["_CCTRACE_"]="ON"
import cloudComPy as cc

cc.initCC()

cpath = "C:/path/to/pcloud.las"
cloud = cc.loadPointCloud(cpath)

dens_res = cc.computeLocalDensity(cc.Density.DENSITY_3D, 2, [cloud])

res = cc.SavePointCloud(cloud, "C:/path/to/pcloud_3Ddens_r2.las")

Rasterization

When I run the rasterization function as you showed it in test025.py (cc.RasterizeGeoTiffOnly(cloud, 0.01, cc.CC_DIRECTION.Z, True, True, False, dataDir, False, cc.ProjectionType.PROJ_AVERAGE_VALUE, cc.ProjectionType.PROJ_AVERAGE_VALUE, cc.EmptyCellFillOption.FILL_MAXIMUM_HEIGHT)) it works perfectly fine. The error just occurs if I not call all parameters explicitly (e.g. cc.RasterizeGeoTiffOnly(cloud, gridStep=2.0, pathToImages=dataDir)) test_data.zip

tmoelter commented 2 years ago

Update to rasterization problem: I tested multiple different options and I noticed that it doesn't work when I call the arguments and assign values (e.g. cc.RasterizeGeoTiffOnly(cloud=cloud, gridStep=2, *ALL OTHER PARAMETERS*, gridBBox=cc.ccBox)). It just works if the arguments are not called namely and are just set by position (as in your example in test025.py). Than it also works when I just define the cloud and the gridStep (cc.RasterizeGeoTiffOnly(cloud, 2.0))

prascle commented 2 years ago

Thank you for your help in identifying these bugs! You are right, that's what I assumed, many functions with optional parameters are not wrapped correctly, in the sense that the naming of the arguments does not work, only their position works. This should not be complicated to fix, but requires a systematic correction of the wrapping of the overloaded functions. This will take a few days... I will also look at the density calculation bug. Regards, Paul

tmoelter commented 2 years ago

Thanks, Paul! I really appreciate your help and quick response.

prascle commented 2 years ago

I have published a new release, I hope your issues are solved, see https://www.simulation.openfields.fr/ Regards, Paul