CloudCompare / CloudComPy

Python wrapper for CloudCompare
Other
292 stars 41 forks source link

Open laz point clouds #18

Closed timkuro closed 2 years ago

timkuro commented 2 years ago

Hi,

I'm getting started with cloudcompy. After having successfully installed the program, i am trying to install my first point clouds. For this I use the loadPointCloud() function. So far, this works only with xyz files. However, my point clouds are in laz format. Is there any way to import the point clouds? Or is there an overview of the supported formats?

Thanks for help! Tim

prascle commented 2 years ago

Hello,

It should work. You can have a look on test020.py in doc/PythonAPI_test. The test does not test .laz files but only the uncompressed form .las. However, I have checked CloudComPy can read and write .laz files (tested on the latest Windows release, but I suppose it should work on older releases, Windows and Linux. If it still doesn't work, can you tell me what to test again (which release, which os, possibly a small example file that would be readable with CloudCompare and not with CloudComPy).

Thanks Paul

timkuro commented 2 years ago

Hi,

thanks for reply. Unfortunately I still have the same problem. My operating system is Windows 10 Enterprise and I installed the latest release using these installation instructions.

My code looks as follows:

import cloudComPy as cc
cc.initCC

cloud = cc.loadPointCloud("data/test.xyz") 
print(cloud.getName())
# this works fine

bdoms = cc.loadPointCloud("data/bdomsThinned.laz") 
print(bdoms.getName())
# returns following error message:
# AttributeError: 'NoneType' object has no attribute 'getName'

My LAZ file is the following: bdomsThinned.zip

Hope you can help me with this information. Tim

prascle commented 2 years ago

Hello, I just downloaded your file and I can upload it to cloudComPy.

Maybe it's just the typo in your script: cc.initCC should be replaced by cc.initCC()

I hope it's enough. Let me know if there is a similar typo somewhere in the documentation or samples. Regards, Paul

timkuro commented 2 years ago

Yes, that was the solution. Thanks for the support!

15251818948 commented 3 months ago

import os import sys from contextlib import contextmanager

@contextmanager def stderr_redirected(to=os.devnull): '''

from https://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python/17954769#17954769

import os

with stderr_redirected(to=filename):
    print("from Python")
    os.system("echo non-Python applications are also supported")
'''
fd = sys.stderr.fileno()

##### assert that Python and C stdio write using the same file descriptor
####assert libc.fileno(ctypes.c_void_p.in_dll(libc, "stderr")) == fd == 1

def _redirect_stderr(to):
    sys.stderr.close() # + implicit flush()
    os.dup2(to.fileno(), fd) # fd writes to 'to' file
    sys.stderr = os.fdopen(fd, 'w') # Python writes to fd

with os.fdopen(os.dup(fd), 'w') as old_stderr:
    with open(to, 'w') as file:
        _redirect_stderr(to=file)
    try:
        yield # allow code to be run with the redirected stderr
    finally:
        _redirect_stderr(to=old_stderr) # restore stderr.
                                        # buffering and flags such as
                                        # CLOEXEC may be different

with stderr_redirected(): import cloudComPy as cc cc.initCC() cloud = cc.loadPointCloud("data/bdomsThinned.laz") name = cloud.getName() print("cloud name: %s"%cloud.getName())

15251818948 commented 3 months ago

Traceback (most recent call last): File "C:\Users\zhoux\Desktop\PycharmProjects\CoudComPy\day one.py", line 39, in name = cloud.getName() AttributeError: 'NoneType' object has no attribute 'getName'