How to get color data from illuminated patch

4 visualizzazioni (ultimi 30 giorni)
Kostas
Kostas il 25 Ago 2017
Risposto: Kostas il 8 Set 2017
Hello! I'm trying to illuminate a patch representing a terrain, and then extract the grayscale values of the colors of each face for processing. However, I haven't yet found a way to do this. When I was working with surfaces I could use surfl and get the surface handle. However I haven't found and equivalent function for patches.
I use the following code to create and light the patch:
figure;
trisurf(Terrain.patch.faces, Terrain.patch.vertices(:,1), Terrain.patch.vertices(:,2), Terrain.patch.vertices(:,3),...
'EdgeColor', 'none', 'FaceLighting', 'gouraud', 'BackFaceLighting', 'unlit', 'FaceColor','white');
axis equal vis3d; % Set aspect ratio.
% convert illum. az. and el. to lighting direction vector
vs = [1;0;0];
vr = sph2cartvec(vs,Terrain.sunAzEl(1),Terrain.sunAzEl(2));
light('Position',vr);
and I get the following figure:
However when I try to get the patch handle to plot it in another figure:
handleGround = findobj(gca,'Type','patch');
figure;
trisurf(handleGround.Faces, handleGround.Vertices(:,1), handleGround.Vertices(:,2), handleGround.Vertices(:,3),handleGround.FaceVertexCData,...
'EdgeColor', 'none');
axis equal vis3d;
I cannot seem to get the new illuminted face color values. With plotting the new patch I get the following figure:
So, how do I get the patch face colors for the illuminated patch? Thanks in advance!

Risposte (1)

Kostas
Kostas il 8 Set 2017
Well, in the end I decided to do it the simple way: find the normal vectors to each patch with patchnormals.m from the File Exchange, and calculate illumination per patch with e.g. diffuse or specular.
N = patchnormals(TerrainPatch); Terrain.illumination = diffuse(N(:,1), N(:,2), N(:,3), vr);
See here for more details

Community Treasure Hunt

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

Start Hunting!

Translated by