无法找到的 matlab mesh2d 问题

matlab mesh2d issue which cant be found

我正在尝试根据我阅读的指南使用 mesh2d 函数。 出于某种原因,我一直收到这个问题:

Undefined function 'mesh2d' for input arguments of type 'double'.

Error in Try1 (line 88)
[p,t] = mesh2d(allnodes, alledges);

我按照这里的指南安装了 mesh2d : https://github.com/dengwirda/mesh2d

但出于某种原因我仍然遇到这个问题... 这是我的代码:(我添加了代码,这样如果我遗漏了一些东西会更容易,而不是我标记坏的部分)

clf
file = 'pattern3';
    P = imread('Pattern3.png');
    P = P(400:3400, 400:3400);
    P = 255 - P*6;

P = 1-im2bw(P);
Nmin = min(size(P));
P = P(1:Nmin, 1:Nmin);
[xg, yg] = meshgrid(1:Nmin, 1:Nmin);
P((xg - Nmin/2).^2 + (yg - Nmin/2).^2 > 0.99*0.25*Nmin^2) = 0;
P = padarray(P, [1 1], 0);

CC = bwconncomp(P);

dtheta    = pi/24;
theta     = (-pi:dtheta:(pi-dtheta))';
nodeouter = [1.1*cos(theta) 1.1*sin(theta)];
Nnodes    = length(nodeouter);
nodelist  = (1:Nnodes)';
allnodes  = nodeouter;
alledges  = [nodelist , mod(nodelist, Nnodes)+1];

for n = 1:CC.NumObjects
%for n = 2:2
    newP = zeros(size(P));
    newP(CC.PixelIdxList{1,n}(:)) = 1;
    newP = filter2(fspecial('average',5),newP);
    C = contourc(newP,[0.2 0.2]);
    C = C(:,2:end)';
    C2 = dpsimplify(C,1);
    m = 1;

    while m <= length(C2(:,1))
       if(C2(m,1) == 1 || C2(m,2) == 1)
           C2(m,:) = [];
       else
           m = m + 1;
       end
    end

    C2 = (C2 - Nmin/2)/(Nmin/2);
    C = (C - Nmin/2)/(Nmin/2);
    figure(1)
    hold all
    plot(C2(:,1), C2(:,2))
    axis image xy
    drawnow

    nodeinner  = C2;
    Nnodeshole = length(nodeinner);
    nodelist   = (1:Nnodeshole)';
    edgelist   = [nodelist , mod(nodelist, Nnodeshole)+1];
    edgelist   = edgelist + Nnodes; 

    allnodes   = [allnodes; nodeinner];
    alledges   = [alledges; edgelist];
    Nnodes     = Nnodes + Nnodeshole;
    n
end

%%

hdata.fun = @(x,y) 0.05*(1 + ((x.^2 + y.^2)/a^2)).^2;
[p,t] = mesh2d(allnodes, alledges); %%here is the issue!!!!!!!!!!!!!!!!!!!!!!!1

%%
as = 0.5;

for n = 1:length(as)
a = as(n);
h = 0;

x = p(:,1);
y = p(:,2);
z = zeros(size(x));
r = sqrt(x.^2 + y.^2);
phi = atan2(y,x);
theta = atan(r/(a+h));
alpha = 2*theta;

xnew = a*sin(alpha).*cos(phi);
ynew = a*sin(alpha).*sin(phi);
znew = -a*cos(alpha);

p2 = [xnew, ynew, znew];
stlwrite('Test.stl', t, p2)

fv.faces = t;
fv.vertices = p2;
clf
figure(3)
patch(fv, 'FaceColor', [1 1 1], 'EdgeColor', 'black', 'LineWidth', 0.1)
axis equal
axis off
xlim([-a a])
ylim([-a a])
zlim([-a a])
camlight head
view(58,28)
zoom(1.5)
drawnow
end

我正在尝试使用的照片:

我最近完全重写了 MESH2D -- 使用更新的网格技术和 MATLAB 功能为它带来 up-to-date。看起来您正在尝试使用旧版本库中的子例程。

根据更新,您想要的例程是 refine2smooth2(它们构建然后优化 two-dimensional 约束 Delaunay 三角剖分)。

我建议您查看 tridemo 中包含的示例代码,了解更新后的 MESH2D 工具箱的工作原理。