Looking for a way to patch 44k polygons fast
8 次查看(过去 30 天)
显示 更早的评论
The following is a part of a function that patches triangles with the corresponding colours using a for-loop
for i = 1:numel(tri)/3
color(i, :) = img(center(i,1), center(i,2),:); %gets current color from img
patch(points(tri(i,:), 2), points(tri(i,:), 1), color(i,:)/256, 'EdgeColor','none'); %patches color on polygon
end
%size(tri) = 44721x3
%size(color) = 44271x3
%size(points) = 22429x2
%size(points(tri(i,:),1) = 3x1
%size(points(tri(i,:),2) = 3x1
%size(color(i,:)/256) = 1x3
The only problem is that patching this large number of polygons takes a long time (+/- 19s). Tried using `fill` instead of `patch` to see if that was faster, but sadly that was 13s slower.
Is there a way to speed up the patching process? For example by patching all the polygons in 1 sweep without looping?
0 个评论
采纳的回答
Greg Dionne
2018-10-15
Have you tried using just one patch? You can specify X and Y as matrices (this example taken from the doc page on patch )
x = [2 5; 2 5; 8 8];
y = [4 0; 8 2; 4 0];
c = [0; 1];
figure
patch(x,y,c)
colorbar
You can also use the 'Faces' and 'Vertices' syntax.
v = [2 4; 2 8; 8 4; 5 0; 5 2; 8 0];
f = [1 2 3; 4 5 6];
col = [0; 1];
figure
patch('Faces',f,'Vertices',v,'FaceVertexCData',col,'FaceColor','flat');
colorbar
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!