Effacer les filtres
Effacer les filtres

Is there a reason why my stl file isn't being read correctly?

22 vues (au cours des 30 derniers jours)
Jaime Castiblanques
Jaime Castiblanques le 17 Mar 2021
I have a code that reads stl files created in Inventor and plots them. Although it works well for some parts, there are some with which stlread has trouble. Instead of plotting the correct surface, it deforms it. My code is:
% Reads the file
data=stlread('Countercurves.stl');
x = data.Points(:,1);
y = data.Points(:,2);
z = data.Points(:,3);
%Meshing of the file
DT = delaunayTriangulation(x,y,z);
[Tfb,Xfb] = freeBoundary(DT);
TR = triangulation(Tfb,Xfb);
V = vertexNormal(TR);
%Plots the surface with the surface normals
figure
trisurf(TR,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(Xfb(:,1),Xfb(:,2),Xfb(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
In the good cases, I get something like the following hemiellipsoid, whereas in the bad ones, I get the figure below:
The latter should be a sinusoidal surface. However, for some reason the spaces are filled in, and the code plots the surface normals of the edges. Any help?
  6 commentaires
Cris LaPierre
Cris LaPierre le 2 Avr 2021
Modifié(e) : Cris LaPierre le 2 Avr 2021
Yes, now I do. stlread is loading the stl files just fine. It is your code to extract the surface normals that seems to be the issue.
unzip('stls.zip');
data=stlread('Countercurves.stl');
trisurf(data)
figure
data2=stlread('SingleCurvature_r100.stl');
trisurf(data2)
It looks like you are duplicating the information already contained in an stl file. Try simplifying your code to the following (after loading the file).
%Meshing of the file
V = vertexNormal(data);
%Plots the surface with the surface normals
figure
trisurf(data,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(data.Points(:,1),data.Points(:,2),data.Points(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
hold off
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
I've gone this far, so we might as well see what it looks like for the other stl file you shared.
%Meshing of the file
V = vertexNormal(data2);
%Plots the surface with the surface normals
figure
trisurf(data2,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(data2.Points(:,1),data2.Points(:,2),data2.Points(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
hold off
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
Jaime Castiblanques
Jaime Castiblanques le 3 Avr 2021
Hello Cris,
This has solved my problem. I had not realized I was duplicating the data, so thank you for pointing that out.

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 1 Avr 2021
Modifié(e) : Bruno Luong le 1 Avr 2021
You should not use delaunayTriangulation to make connectiviy of the points. It creates a convex hull of all the points.
Usualy the connectivity is from structure read from the file.
  2 commentaires
Jaime Castiblanques
Jaime Castiblanques le 1 Avr 2021
Oh I see. How can I do the connectivity then?
Bruno Luong
Bruno Luong le 2 Avr 2021
Modifié(e) : Bruno Luong le 2 Avr 2021
See Cris answer, he plots TRISURF directly from the data structure read from file.
The STL data has a list of point AND the connectivity.
Please inspect the structure returns by stlread and read documentation of TRISURF.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by