Matlab:从轮廓线创建 3D 图形时的伪影
Matlab: artifacts when creating 3D figure from contour lines
我需要绘制 3 级振幅并将其映射到另一个距离以获得锥形 3D 图形。这是一张原始图片,级别为最大值的 90%、80% 和 70%:
这里是轮廓线的数据:https://pastebin.com/NUaJJbpt .
我选择使用 shapeAlpha() 绘制 3D 多边形:
clear;
c11 = load('cntr1.txt', '-ascii');
c21 = load('cntr2.txt', '-ascii');
c31 = load('cntr3.txt', '-ascii');
c11(:, 1:2) = c11(:, 1:2)-100.;
c21(:, 1:2) = c21(:, 1:2)-100.;
c31(:, 1:2) = c31(:, 1:2)-100.;
c12(:, 1:2) = c11(:, 1:2).*804./540.;
c22(:, 1:2) = c21(:, 1:2).*804./540.;
c32(:, 1:2) = c31(:, 1:2).*804./540.;
c11(:, 3) = 540.;
c21(:, 3) = 540.;
c31(:, 3) = 540.;
c11 = [c11; c21];
c21 = [c21; c31];
c12(:, 3) = 804.;
c22(:, 3) = 804.;
c32(:, 3) = 804.;
c12 = [c12; c22];
c22 = [c22; c32];
P1 = [c11(:,1), c11(:,2), c11(:,3); c12(:,1), c12(:,2), c12(:,3)];
P2 = [c21(:,1), c21(:,2), c21(:,3); c22(:,1), c22(:,2), c22(:,3)];
P3 = [c31(:,1), c31(:,2), c31(:,3); c32(:,1), c32(:,2), c32(:,3)];
P1 = unique(P1, 'rows');
P2 = unique(P2, 'rows');
P3 = unique(P3, 'rows');
figure;
hold on;
axis equal;
shp1 = alphaShape(P1(:,1), P1(:,2), P1(:,3), Inf);
shp2 = alphaShape(P2(:,1), P2(:,2), P2(:,3), Inf);
shp3 = alphaShape(P3(:,1), P3(:,2), P3(:,3), Inf);
h3 = shp3.plot;
h2 = shp2.plot;
h1 = shp1.plot;
set(h1,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'green');
set(h2,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'blue');
set(h3,'edgecolor', 'none', 'facealpha', 0.4, 'facecolor', 'red');
view(3);
hold off;
这是我得到的:
据我了解,颜色干扰的发生是因为每个图形都是实心的,没有孔,我需要内圆是实心的,外两个层次是"rings"。我已经尝试了 HoleThreshold
和 RegionThreshold
的各种值,但后来我得到了错误或不完整的渲染。
我的问题:如何创建具有不同颜色和透明度的三个幅度级别的图,以便它们不会相互干扰?
避免顶部和底部难看颜色渲染的一个简单解决方法是使 P1
、P2
和 P3
的 z 值彼此略微偏移:
offset = 0.1;
P2(:,3) = P2(:,3) + offset;
P3(:,3) = P3(:,3) + offset*2;
然而,体积仍然是固体,因此透明体积仍然重叠。
我需要绘制 3 级振幅并将其映射到另一个距离以获得锥形 3D 图形。这是一张原始图片,级别为最大值的 90%、80% 和 70%:
这里是轮廓线的数据:https://pastebin.com/NUaJJbpt .
我选择使用 shapeAlpha() 绘制 3D 多边形:
clear;
c11 = load('cntr1.txt', '-ascii');
c21 = load('cntr2.txt', '-ascii');
c31 = load('cntr3.txt', '-ascii');
c11(:, 1:2) = c11(:, 1:2)-100.;
c21(:, 1:2) = c21(:, 1:2)-100.;
c31(:, 1:2) = c31(:, 1:2)-100.;
c12(:, 1:2) = c11(:, 1:2).*804./540.;
c22(:, 1:2) = c21(:, 1:2).*804./540.;
c32(:, 1:2) = c31(:, 1:2).*804./540.;
c11(:, 3) = 540.;
c21(:, 3) = 540.;
c31(:, 3) = 540.;
c11 = [c11; c21];
c21 = [c21; c31];
c12(:, 3) = 804.;
c22(:, 3) = 804.;
c32(:, 3) = 804.;
c12 = [c12; c22];
c22 = [c22; c32];
P1 = [c11(:,1), c11(:,2), c11(:,3); c12(:,1), c12(:,2), c12(:,3)];
P2 = [c21(:,1), c21(:,2), c21(:,3); c22(:,1), c22(:,2), c22(:,3)];
P3 = [c31(:,1), c31(:,2), c31(:,3); c32(:,1), c32(:,2), c32(:,3)];
P1 = unique(P1, 'rows');
P2 = unique(P2, 'rows');
P3 = unique(P3, 'rows');
figure;
hold on;
axis equal;
shp1 = alphaShape(P1(:,1), P1(:,2), P1(:,3), Inf);
shp2 = alphaShape(P2(:,1), P2(:,2), P2(:,3), Inf);
shp3 = alphaShape(P3(:,1), P3(:,2), P3(:,3), Inf);
h3 = shp3.plot;
h2 = shp2.plot;
h1 = shp1.plot;
set(h1,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'green');
set(h2,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'blue');
set(h3,'edgecolor', 'none', 'facealpha', 0.4, 'facecolor', 'red');
view(3);
hold off;
这是我得到的:
据我了解,颜色干扰的发生是因为每个图形都是实心的,没有孔,我需要内圆是实心的,外两个层次是"rings"。我已经尝试了 HoleThreshold
和 RegionThreshold
的各种值,但后来我得到了错误或不完整的渲染。
我的问题:如何创建具有不同颜色和透明度的三个幅度级别的图,以便它们不会相互干扰?
避免顶部和底部难看颜色渲染的一个简单解决方法是使 P1
、P2
和 P3
的 z 值彼此略微偏移:
offset = 0.1;
P2(:,3) = P2(:,3) + offset;
P3(:,3) = P3(:,3) + offset*2;
然而,体积仍然是固体,因此透明体积仍然重叠。