I have written MATLAB code (shown below) which makes an edge and then builds mesh extending from that edge. I can see the 3D model in a figure as a mesh, but there is no way to export this model as a 3d object such as an stl or obj.
I read many examples of converting to stl, which used something like this:
% 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)
But in my code I used just mesh:
figure;
M= surface(-finalLSF);
hold on; contour(phi, [0,0], 'r','LineWidth',2);
I tried many time to convert it but am still having errors.
Code:
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;
For using stlwrite you need the source code of it. Matlab doesnt have the feature. https://de.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin- should do it.
You need to download stlwrite
from File Exchange , and put it within your Matlab path. You can check if it is on your path by typing exist('stlwrite')
. If this returns 2
, you're good. If it returns 0
then you need to add it to your path .
It seems like you have the x
, y
and z
coordinates, in which case you can just call
stlwrite('C:\...\filename.stl', x, y, z);
If you wanted to use isosurface
first, then just use
M = isosurface(x,y,z,F,0);
stlwrite('C:\...\filename.stl', M);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.