Azzera filtri
Azzera filtri

Dynamically change FaceVertexCData of a patch

8 visualizzazioni (ultimi 30 giorni)
Andrey Gizdov
Andrey Gizdov il 15 Ott 2018
Commentato: Andrey Gizdov il 15 Ott 2018
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 Commenti
KSSV
KSSV il 15 Ott 2018
If it is a 3d plot...did you try rotating the plot and see?
Andrey Gizdov
Andrey Gizdov il 15 Ott 2018
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)

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 15 Ott 2018
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?
  1 Commento
Andrey Gizdov
Andrey Gizdov il 15 Ott 2018
Done, I just rephrased the question in the form of a simple example.

Accedi per commentare.

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by