`Pointcloud.from_ply()` returns Nonetype


I was hoping to load compas.geometry.Pointcloud in order to view it by view2 and found this problem, even using the official airplane.ply file in https://people.sc.fsu.edu/~jburkardt/data/ply/airplane.ply:

from compas.geometry import Pointcloud

pcd = Pointcloud.from_ply("") # Neither relative nor absolute path works in my case

print (type(pcd))

>>><class 'NoneType'>

Thanks in advance for any reply!

It seems it is not implemented.
If you look at the source code you can see only function definition:

    def from_ply(cls, filepath):
        """Construct a pointcloud from a PLY file.

        filepath : str | bytes | os.PathLike
            Path of the PLY file.



You can try ply reader alone. Just a quick check, it reads the ASCII file:

ply_object = reader.PLYReader("C:/test0.ply")

unfortunately, it is still not working in my ASCII file:(

UnicodeDecodeError: 'gbk' codec can't decode byte 0xfd in position 275: illegal multibyte sequence

The UnicodeDecodeError you encountered indicates that there was an issue decoding a byte sequence using the ‘gbk’ codec, which is used for decoding text in the GBK character encoding. The error message specifically points out that byte 0xfd in position 275 of the input cannot be decoded as a valid character in the GBK encoding.

You can try to check the line 275 by opening the files in the text editor or vs code, if there are any weird characters. I have a feeling that you are using binary not ascii.

Can you share the file?
Normally ply files are just txt files with just an ending of .ply, so as long as you are not using binary you should be even be able to parse it yourself:

thanks again for the reply! I just found this example file works,

I will check my file for sure.

While, since the official document is very missing, I can only run the code you sent me without any operation. Even the ._read_data() function is not listed in the doc. I wonder is there a way to transfer the ply_object into compas.geometry.Pointcloud? Thanks!

At the current implementation no.
But you can read the ply and then assign point list to the pointcloud property. It is a very light implementation of a point list from what I see here, what do you want to use it for ? :
compas/src/compas/geometry/pointclouds/pointcloud.py at main · compas-dev/compas (github.com)

awesome! I got what you mean! Actually, I am trying to read the PointCloud and visualize it in compas_viwe2 as Rhino&GH are not meant for point clouds, view2 is perfect in this role:

as you said, I convert the reader object to compas.geometry.Pointcloud:

from compas.files import PLYReader
from compas.geometry import Pointcloud
ply_object =PLYReader("src\standard_pcd.ply")

pcd = Pointcloud([[v["x"], v["y"],v["z"]] for v in ply_object.vertices])

print (len(pcd.points))

Then I visualize the point cloud:

from compas_view2.app import App
viewer = App()

The visual effect is not the best but it works somehow! thanks for the answer!

1 Like