Dynamically change FaceVertexCData of a patch

7 次查看(过去 30 天)
Hi,
I have a patchTest() function as follows:
function [mainPatch] = patchTest()
mainColor = [1 0 0];
vert = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
face = [1 2 6;5 2 3;7 6 3;4 8 7;4 1 5;8 1 2;3 4 5;6 7 8];
%Use one color for each face (An RGB triplet)
%True color, one color per face - data format
colorData = zeros(size(face,1), 3);
for i=1:size(colorData,1)
colorData(i,:) = mainColor;
end
figure;
axis ij
axis tight
grid on;
daspect([1,1,1])
rotate3d on;
mainPatch = patch('Faces',face,'Vertices',vert);
mainPatch.FaceAlpha = 1;
mainPatch.EdgeColor = 'b';
mainPatch.FaceColor = 'flat';
mainPatch.FaceVertexCData = colorData;
end
[mainPatch] = patchTest();
As you can see, I assign the patch object to a work space variable called mainPatch. What I want to do next is input this variable in another function and be able to modify the FaceVertexCData property of the patch. This is an example of what I want to achieve:
function [] = recolorTest(mainPatch)
%Recolor patch
newColor = [0 .75 0];
%Rows of the triangular faces which I want to recolor
newCTriangles = reshape([3, 6, 2],3,1)
colorData = mainPatch.FaceVertexCData;
for i=1:size(newCTriangles,1)
colorData(newCTriangles(i,1),:) = newColor;
end
end
I then call the function to recolor the patch
recolorTest(mainPatch);
The problem is that no changes in color appear on the patch figure. I also checked the current FaceVertexCData:
newColorData = mainPatch.FaceVertexCData;
In this variable, no changes in the color of the faces has appeared either. What am I doing wrong?
  2 个评论
KSSV
KSSV 2018-10-15
If it is a 3d plot...did you try rotating the plot and see?
Andrey Gizdov
Andrey Gizdov 2018-10-15
Yes, I have. There is no change on the plot. I also checked the FaceVertexCData of the patch, and no changes have been made to it either. I'm very unfamiliar with how handles of objects work, so I'm guessing that the issue would have something to do with that I'm maybe not accessing the color data in a correct way... (I can be wrong)

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2018-10-15
What is the value of your patch's CDataMapping property?
What type of values are you using to set the FaceVertexCData property? One color per face, one color per vertex, indexed colors, true colors? Double or single precision, integer data, or logical? If double or single precision, are the values between 0 and 1 or are some of them larger than that?
Can you post a small simple example with which you see no change when you modify the FaceVertexCData property? Say no more than 10-15 data points?

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by