Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcu.write_ply() throws "Incompatible function arguments error" #22

Closed
cravisjan97 opened this issue Sep 19, 2020 · 9 comments
Closed

pcu.write_ply() throws "Incompatible function arguments error" #22

cravisjan97 opened this issue Sep 19, 2020 · 9 comments

Comments

@cravisjan97
Copy link

I am trying to load a mesh in .obj format, perform Lloyd Relaxation and then save the point clouds to .ply format. I am writing the following code:

v,f,n = pcu.read_obj('./data/ChairNoArms9.obj')
samples = pcu.sample_mesh_lloyd(v, f, 15000)
pcu.write_ply(filename='sample.ply', v=samples, f=f, ascii=True)

Note: I have no normals in my mesh file

@cravisjan97
Copy link
Author

I was able to solve the issue by passing in empty numpy arrays to n and uv

@cravisjan97
Copy link
Author

But the point clouds do not make any sense to the input mesh (which is a chair). Am I doing something wrong here?

@fwilliams
Copy link
Owner

Hey thanks for reporting the issue. Can you upload the mesh so I can try it out? I tried sample_mesh_lloyd locally and it seems to work okay.

@cravisjan97
Copy link
Author

@fwilliams
Copy link
Owner

fwilliams commented Sep 22, 2020

Hey, so I just downloaded your mesh and ran sample_mesh_lloyd on it. I a screenshot of the results below and code to reproduce it below.

The results seem quite reasonable to me. For reference, I'm running point_cloud_utils version 0.15.1 installed from conda-forge on a Linux machine.

Could you post a screenshot showing what was wrong with your point cloud? Could you also post the version of point_cloud_utils and platform you're running on.

Reproducing steps

import point_cloud_utils as pcu
v, f, n = pcu.read_obj("ChairArms1.obj")
pts = pcu.sample_mesh_lloyd(v, f, 15000)

I plotted the mesh and points using mayavi:

from mayavi import mlab
mlab.figure(bgcolor=(0.1, 0.1, 0.1))
mlab.triangular_mesh(v[:, 0], v[:, 1], v[:, 2], f)
mlab.triangular_mesh(v[:, 0], v[:, 1], v[:, 2], f, representation='wireframe', color=(0.1, 0.1, 0.1))
mlab.points3d(pts[:, 0], pts[:, 1], pts[:, 2], scale_factor=0.015)
mlab.show()

which yield the following (white points are the lloyd samples):

image

@cravisjan97
Copy link
Author

Is it possible to save the point clouds as .ply file? I am confused with that part of the code. I am saving it as a .ply file and the point clouds do not make any sense.

@fwilliams
Copy link
Owner

fwilliams commented Sep 22, 2020

Yes you can save the point clouds as a PLY file as follows:

import point_cloud_utils as pcu
import numpy as np

v, f, n = pcu.read_obj("ChairArms1.obj")
pts = pcu.sample_mesh_lloyd(v, f, 15000)

pcu.write_ply("out.ply", pts, np.zeros([0, 3], dtype=np.int32), np.zeros([0, 3]), np.zeros([0, 2]))

The zero-arrays are just passing empty faces, normals and uv coordinates.

Currently, the interface for MeshIO is not very user unfriendly. I plan on overhauling this completely in the near future so it's no so confusing.

EDIT: Replaced v with pts in pcu.write_ply(...) above

@cravisjan97
Copy link
Author

cravisjan97 commented Sep 22, 2020

I am confused by this. Shouldn't we be passing 'pts' in write_ply function and not 'v'?. I have replaced the variable 'v' with 'pts' and it works. Thanks for responding!

@fwilliams
Copy link
Owner

Ah yeah you're right! Sorry I didn't test the code before submitting the responds. I just edited the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants