0

我已经编写了 MATLAB 代码(如下所示),它制作了一条边,然后构建了从该边延伸的网格。我可以将图中的 3D 模型视为网格,但无法将此模型导出为 stl 或 obj 等 3d 对象。

我阅读了许多转换为 stl 的示例,其中使用了以下内容:

% Extract the surface mesh
M=isosurface(x,y,z,F,0);
tr=TriRep(M.faces,M.vertices);
figure('color','w'), h=trimesh(tr); axis equal
% Write to .stl
stlwrite('PillBoxExample.stl',tr.Triangulation,tr.X)

但在我的代码中,我只使用了网格:

figure;
M= surface(-finalLSF); 
hold on;  contour(phi, [0,0], 'r','LineWidth',2);

我尝试了很多次来转换它,但仍然有错误。

代码:

Img = imread('MK2.jpg'); 
Img=double(Img(:,:,1));
%
% ... other code ...
%
figure;
M= mesh(-finalLSF); 
hold on;  contour(phi, [0,0], 'r','LineWidth',2);
str=['Final level set function, ', num2str(iter_outer*iter_inner+iter_refine), ' iterations'];
title(str);
axis on;
4

2 回答 2

0

要使用 stlwrite,您需要它的源代码。Matlab 没有这个功能。 https://de.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin-应该这样做。

于 2017-06-13T19:36:18.640 回答
0

您需要从 File Exchange下载stlwrite,并将其放在您的 Matlab 路径中。您可以通过键入来检查它是否在您的路径上exist('stlwrite')。如果这返回2,你很好。如果它返回0,那么您需要将它添加到您的路径中。

看起来你有x,yz坐标,在这种情况下你可以打电话

stlwrite('C:\...\filename.stl', x, y, z);

如果您想先使用isosurface,则只需使用

M = isosurface(x,y,z,F,0);
stlwrite('C:\...\filename.stl', M);
于 2017-06-14T10:59:55.993 回答