How to get color data from illuminated patch

조회 수: 4 (최근 30일)
Kostas
Kostas 2017년 8월 25일
답변: Kostas 2017년 9월 8일
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!

답변 (1개)

Kostas
Kostas 2017년 9월 8일
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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by