tsurf

function tsurf(F,V,vertex_indices,face_indices)
  % trisurf wrapper
  % F: list of faces #F x 3
  % V: vertex positiosn #V x 3 or #V x 2
  % vertex_indices: show vertex indices on plot
  %                 0 -> off
  %                 1 -> text and grey background
  %                >1 -> text
  % face_indices: show face indices on plot
  %                 0 -> off
  %                 1 -> text and grey background
  %                >1 -> text
  %
  % See corresponding paper: "Mixed finite elements for variational surface
  % modeling" by Alec Jacobson, Elif Tosun, Olga Sorkine, and Denis Zorin, SGP
  % 2010
  %
  % Copyright 2010, Alec Jacobson, NYU
  %

  if(~exist('vertex_indices'))
    % off by default
    vertex_indices = 0;
  end
  if(~exist('face_indices'))
    % off by default
    face_indices = 0;
  end

  is_2d = false;
  if(size(V,2)==2 || (size(V,2) ==3 && sum(abs(V(:,3))) == 0))
    V = [V(:,1) V(:,2) 0*V(:,1)];
    is_2d = true;
  elseif(size(V,2)>3 || size(V,2)<2 ) 
    error('V must be #V x 3 or #V x 2');
    return;
  end
  
  
  %trisurf(Tri,X,Y,Z,C)  displays triangles defined in the m-by-3 face 
  %matrix Tri as a surface. Each row of Tri defines a single triangular
  %face by indexing into the vectors or matrices that contain the X, Y, and
  %Z vertices. The color is defined by the vector C.
  trisurf(F,V(:,1),V(:,2),V(:,3));

  % if 2d then set to view (x,y) plane
  if( is_2d )
    view(2);
  end

  %标注面索引
  if(face_indices==1)
    FC = (V(F(:,1),:)+V(F(:,2),:)+V(F(:,3),:))./3;
    text(FC(:,1),FC(:,2),FC(:,3),num2str((1:size(F,1))'),'BackgroundColor',[.8 .8 .8]);
  elseif(face_indices)
    FC = (V(F(:,1),:)+V(F(:,2),:)+V(F(:,3),:))./3;
    text(FC(:,1),FC(:,2),FC(:,3),num2str((1:size(F,1))'));
  end
  %标注点索引
  if(vertex_indices==1)
    text(V(:,1),V(:,2),V(:,3),num2str((1:size(V,1))'),'BackgroundColor',[.8 .8 .8]);
  elseif(vertex_indices)
    text(V(:,1),V(:,2),V(:,3),num2str((1:size(V,1))'));
  end
  % uncomment these to switch to a better 3d surface viewing mode
  %axis equal; axis vis3d;

end





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值