Use NaNs to hide faces in matlab trisurf/patch renderings

Alec Jacobson

February 11, 2015

weblog/

I recently (re)discovered that if you set the 'CData' value of a face to nan the face will be hidden. This can sometimes be useful if you want to use the wireframe of a model to give context but focus on just a few faces. Here's an example:

% selected faces
I = sparse(125,1,1,size(F,1),1);
A = facet_adjacency_matrix(F);
while true
  % Set all but selected to nan
  tsurf(F,V,'CData',sparse(find(~I),1,nan,size(F,1),1));
  view(-48,4); set(gca,'Visible','off');apply_ambient_occlusion();
  drawnow;
  if nnz(I)==size(F,1);
    break;
  end
  I = A*I;
end

cat nan colors