Home > vbmeg > external > iso2mesh > plotsurf.m

plotsurf

PURPOSE ^

SYNOPSIS ^

function hm=plotsurf(node,face,varargin)

DESCRIPTION ^

 hm=plotsurf(node,face,opt)

 plot 3D surface meshes (2d manifold) or polylines (1d manifold)
 
 author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>

 input: 
      node: node coordinates, dimension (nn,3); if node has a 
            4th column, it will be used to set the color at each node.
      face: triangular surface face list; if face has a 4th column,
            it will be used to separate the surface into 
            sub-surfaces and display them in different colors;
            face can be a cell array, each element of the array represents
            a polyhedral facet of the mesh, if an element is an array with
            two array subelements, the first one is the node index, the
            second one is a scalar as the group id of the facet.
      opt:  additional options for the plotting, see plotmesh

 output:
   hm: handle or handles (vector) to the plotted surfaces

 example:

   h=plotsurf(node,face);
   h=plotsurf(node,face,'facecolor','r');
   h=plotsurf(node,edges,'linestyle','-','linewidth',2,'color','r');

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function hm=plotsurf(node,face,varargin)
0002 %
0003 % hm=plotsurf(node,face,opt)
0004 %
0005 % plot 3D surface meshes (2d manifold) or polylines (1d manifold)
0006 %
0007 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
0008 %
0009 % input:
0010 %      node: node coordinates, dimension (nn,3); if node has a
0011 %            4th column, it will be used to set the color at each node.
0012 %      face: triangular surface face list; if face has a 4th column,
0013 %            it will be used to separate the surface into
0014 %            sub-surfaces and display them in different colors;
0015 %            face can be a cell array, each element of the array represents
0016 %            a polyhedral facet of the mesh, if an element is an array with
0017 %            two array subelements, the first one is the node index, the
0018 %            second one is a scalar as the group id of the facet.
0019 %      opt:  additional options for the plotting, see plotmesh
0020 %
0021 % output:
0022 %   hm: handle or handles (vector) to the plotted surfaces
0023 %
0024 % example:
0025 %
0026 %   h=plotsurf(node,face);
0027 %   h=plotsurf(node,face,'facecolor','r');
0028 %   h=plotsurf(node,edges,'linestyle','-','linewidth',2,'color','r');
0029 %
0030 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0031 %
0032 
0033 rngstate = rand ('state');
0034 
0035 if(nargin>=2)
0036   randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E"
0037   if(isoctavemesh) randseed=randseed+3; end
0038   if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED')))
0039         randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED');
0040   end
0041   rand('state',randseed);
0042 
0043   if(iscell(face))
0044     sc=sparse(10,3); % face colormap
0045     sc(1:10,:)=rand(3,10)';
0046     len=length(face);
0047     newsurf=cell(1);
0048     % reorganizing each labeled surface into a new cell
0049     for i=1:len
0050         fc=face{i};
0051         if(iscell(fc) && length(fc)>=2)
0052             if(fc{2}+1>10)
0053                 sc(fc{2}+1,:)=rand(1,3);
0054             end
0055             if(fc{2}+1>length(newsurf))
0056                 newsurf{fc{2}+1}={};
0057             end
0058             newsurf{fc{2}+1}{end+1}=fc{1};
0059         else % unlabeled facet is tagged by 0
0060             if(iscell(fc))
0061                 newsurf{1}{end+1}=cell2mat(fc);
0062             else
0063                 newsurf{1}{end+1}=fc;
0064             end
0065         end
0066     end
0067     hold on;
0068     h=[];
0069     newlen=length(newsurf);
0070 
0071     for i=1:newlen
0072         if(isempty(newsurf{i})); continue; end
0073         try 
0074             subface=cell2mat(newsurf{i}')';
0075             if(size(subface,1)>1 && ismatrix(subface))
0076                subface=subface';
0077             end
0078             h=[h patch('Vertices',node,'Faces',subface,'facecolor',sc(i,:),varargin{:})];
0079         catch
0080             for j=1:length(newsurf{i})
0081                 h=[h patch('Vertices',node,'Faces',newsurf{i}{j},'facecolor',sc(i,:),varargin{:})];
0082             end
0083         end
0084     end
0085   else
0086     if(size(face,2)==4)
0087         tag=face(:,4);
0088         types=unique(tag);
0089         hold on;
0090         h=[];
0091         for i=1:length(types)
0092             if(size(node,2)==3)
0093                 h=[h plotasurf(node,face(tag==types(i),1:3),'facecolor',rand(3,1),varargin{:})];
0094             else
0095                 h=[h plotasurf(node,face(tag==types(i),1:3),varargin{:})];
0096             end
0097         end
0098     else
0099         h=plotasurf(node,face,varargin{:});
0100     end
0101   end
0102 end    
0103 if(~isempty(h)) 
0104   axis equal;
0105   if(all(get(gca,'view')==[0 90]))
0106       view(3);
0107   end
0108 end
0109 if(~isempty(h) && nargout>=1)
0110   hm=h;
0111 end
0112 
0113 rand ('state',rngstate);
0114 
0115 %-------------------------------------------------------------------------
0116 function hh=plotasurf(node,face,varargin)
0117 isoct=isoctavemesh;
0118 if(size(face,2)<=2)
0119     h=plotedges(node,face,varargin{:});
0120 else
0121   if(size(node,2)==4)
0122     if(isoct && ~exist('trisurf','file'))
0123         h=trimesh(face(:,1:3),node(:,1),node(:,2),node(:,3),node(:,4),'edgecolor','k',varargin{:});
0124     else
0125         h=trisurf(face(:,1:3),node(:,1),node(:,2),node(:,3),node(:,4),varargin{:});
0126     end
0127   else
0128     if(isoct && ~exist('trisurf','file'))
0129         h=trimesh(face(:,1:3),node(:,1),node(:,2),node(:,3),'edgecolor','k',varargin{:});
0130     else
0131         h=trisurf(face(:,1:3),node(:,1),node(:,2),node(:,3),varargin{:});
0132     end
0133   end
0134 end
0135 if(exist('h','var')) hh=h; end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005