Fitting a cilinder to 3D vertices

I am having problems fitting a cylinder to a point cloud. Trying to use "pcfitcylinder", an error saying 'the value of 'ptCloud' is invalid. Expected ptCloud to be a pointCloud object' while the pointcloud is a nx3 created from the vertices of an .stl file. The code is:
Bone_model=stlread(fullfile(Bone_path,Bone_file));
maxDistance=.5
cilinder = pcfitcylinder(Bone_model.vertices,maxDistance);
pcshow (Bone_model.vertices);hold on;
plot(cilinder)
Is there anything i'm doing wrong?

1 comentario

KSSV
KSSV el 30 de Mayo de 2018
It is expecting a different input.....read the documentation.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Mayo de 2018
stlread() appears to be one of the functions from the File Exchange, probably https://www.mathworks.com/matlabcentral/fileexchange/22409-stl-file-reader
The vertices returned by that stlread() function are configured for use by patch(). pcfitcylinder() requires that a pointcloud object be passed in.
You might be able to use
pc = pointcloud(Bone_model.vertices);
[cilinder,inlierIndices] = pcfitcylinder(pc, maxDistance);
cylpc = select(cilinder, inlierIndices);
pcshow(cylpc)
Note that pcfitcylinder attempts to find a subset of the pointcloud that is in the form of an cylinder.

7 comentarios

Daniel Devaprakash
Daniel Devaprakash el 22 de Ag. de 2018
Editada: Walter Roberson el 22 de Ag. de 2018
Hi Walter,
I used the syntax specified in your answer to fit a cylinder to a bone, and I get the following error message:
No appropriate method, property, or field 'Normal' for class 'pointCloud'.
Error in pcfitcylinder (line 118)
if isempty(ptCloud.Normal)
I tried to write include the normal values using the following syntax:
TalusPtCloud = pointCloud(Talus.solidVertices{1,1}, 'Normal', Talus.solidNormals{1,1});
I see the following error message:
Error using pointCloud (line 171)
'Normal' is not a recognized parameter. For a list of valid name-value pair arguments, see the documentation for this function.
Could you please provide any advice on how to solve this issue? Thank you for your time.
Cheers,
Danny
Walter Roberson
Walter Roberson el 22 de Ag. de 2018
Which MATLAB version are you using?
Daniel Devaprakash
Daniel Devaprakash el 22 de Ag. de 2018
Editada: Walter Roberson el 22 de Ag. de 2018
Hi Walter,
I am using 2017b.
Cheers,
Danny
I suspect that you are getting some other pointCloud() routine. 'Normal' has been supported for a number of releases
What shows up for
which -all pointCloud
? You should expect something like
toolbox/vision/vision/pointCloud.m
In your release, line 171 of pointCloud (the line number giving the error in your error message) is in the middle of a block of comments.
Daniel Devaprakash
Daniel Devaprakash el 22 de Ag. de 2018
Editada: Walter Roberson el 22 de Ag. de 2018
Hi Walter,
Thank you very much for your help. Yes, I had two files named as pointCloud.m (second one downloaded from MATLAB central).
Thanks again for your help.
Cheers,
Danny
M.S. Khan
M.S. Khan el 31 de Mayo de 2020
Hi Danny,
could you please explain the coding to me. i also want to apply it on my problem.
Warm regards,
M.S. Khan, which coding are you referring to? The only line of code that Daniel posted was
TalusPtCloud = pointCloud(Talus.solidVertices{1,1}, 'Normal', Talus.solidNormals{1,1});

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 29 de Mayo de 2018

Comentada:

el 31 de Mayo de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by