# Coloring faces of isosurface corresponding to intensities in a 3D plot.

22 views (last 30 days)
Kevin Semmelink on 8 Apr 2016
Commented: Kevin Semmelink on 9 Apr 2016
Hello,
I’m trying to determine a way to visualize the intensity of light in a cavity. For this 3D volume cavity I created an isosurface and for all triangles in this isosurface the intensity of light was calculated. I calculated the intensity for the isonormals instead of the individual pixels to simplify the calculations.
I was wondering if it is possible to give every face in the isosurface a color corresponding with its intensity.
There are different ways to color an isosurface, but these are all based on the values corresponding with the volume and not with the values corresponding with the isosurface.
Is there a way to color the isosurface corresponding with the calculated intensities so I can visualize the intensity course?
The code I’ve used to show my segment cavity is as follows:
S = isosurface(Im, 0.5); h = patch(S, 'Facecolor', 'none', 'EdgeColor', 'k');
And the size of the matrix with is as shown below:
Intensity_matrix = [‘number of faces’ ; 1]; %with all intensities corresponding to the faces of the isosurface.

Mike Garrity on 8 Apr 2016
Yes, you want to set the FaceVertexCData property of the patch object to your data, and the FaceColor property to 'flat'.
Here's a simple example:
%%Create an isosurface
[x y z v] = flow;
p = patch(isosurface(x, y, z, v, -3));
daspect([1 1 1])
view(3)
%%Compute the area of each face
u = p.Vertices(p.Faces(:,2),:) - p.Vertices(p.Faces(:,1),:);
v = p.Vertices(p.Faces(:,3),:) - p.Vertices(p.Faces(:,1),:);
n = cross(u,v);
a = sqrt(n(:,1).^2 + n(:,2).^2 + n(:,3).^2) / 2;
%%Color the faces with the area
p.FaceVertexCData = a;
p.FaceColor = 'flat';
p.EdgeColor = 'none'; Instead of the area, you would use your calculated data. The FaceVertexCData property should be a vector whose length is the same as the number of faces in your patch.
Kevin Semmelink on 9 Apr 2016
Thank you!