필터 지우기
필터 지우기

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

조회 수: 21 (최근 30일)
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
Cris LaPierre
Cris LaPierre 2021년 4월 2일
편집: Cris LaPierre 2021년 4월 2일
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 2021년 4월 3일
Hello Cris,
This has solved my problem. I had not realized I was duplicating the data, so thank you for pointing that out.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2021년 4월 1일
편집: Bruno Luong 2021년 4월 1일
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
Jaime Castiblanques
Jaime Castiblanques 2021년 4월 1일
Oh I see. How can I do the connectivity then?
Bruno Luong
Bruno Luong 2021년 4월 2일
편집: Bruno Luong 2021년 4월 2일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by