Home > vbmeg > external > iso2mesh > plotmesh.m

plotmesh

PURPOSE ^

SYNOPSIS ^

function hm=plotmesh(node,varargin)

DESCRIPTION ^

 hm=plotmesh(node,face,elem,opt)

 plot surface and volumetric meshes
 
 author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>

 input: 
      node: a node coordinate list, 3 columns for x/y/z; if node has a 
            4th column, it will be used to set the color at each node.
      face: a 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.
      elem: a tetrahedral element list; if elem has a 5th column,
            it will be used to separate the mesh into 
            sub-domains and display them in different colors.
      opt:  additional options for the plotting

            for simple point plotting, opt can be markers
            or color options, such as 'r.', or opt can be 
            a logic statement to select a subset of the mesh,
            such as 'x>0 & y+z<1', or an equation defining
            a plane at which a mesh cross-section is plotted, for
            example 'y=2*x'; opt can have more than one
            items to combine these options, for example: 
            plotmesh(...,'x>0','r.'); the range selector must
            appear before the color/marker specifier

 in the event where all of the above inputs have extra settings related to 
 the color of the plot, the priorities are given in the following order:

          opt > node(:,4) > elem(:,5) > face(:,4)

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

 example:

   h=plotmesh(node,'r.');
   h=plotmesh(node,'x<20','r.');
   h=plotmesh(node,face);
   h=plotmesh(node,face,'y>10');
   h=plotmesh(node,face,'facecolor','r');
   h=plotmesh(node,elem,'x<20');
   h=plotmesh(node,elem,'x<20 & y>0');
   h=plotmesh(node,face,elem);
   h=plotmesh(node,face,elem,'linestyle','--');
   h=plotmesh(node,elem,'z=20');
 
 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hm=plotmesh(node,varargin)
0002 %
0003 % hm=plotmesh(node,face,elem,opt)
0004 %
0005 % plot surface and volumetric meshes
0006 %
0007 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
0008 %
0009 % input:
0010 %      node: a node coordinate list, 3 columns for x/y/z; if node has a
0011 %            4th column, it will be used to set the color at each node.
0012 %      face: a 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 %      elem: a tetrahedral element list; if elem has a 5th column,
0020 %            it will be used to separate the mesh into
0021 %            sub-domains and display them in different colors.
0022 %      opt:  additional options for the plotting
0023 %
0024 %            for simple point plotting, opt can be markers
0025 %            or color options, such as 'r.', or opt can be
0026 %            a logic statement to select a subset of the mesh,
0027 %            such as 'x>0 & y+z<1', or an equation defining
0028 %            a plane at which a mesh cross-section is plotted, for
0029 %            example 'y=2*x'; opt can have more than one
0030 %            items to combine these options, for example:
0031 %            plotmesh(...,'x>0','r.'); the range selector must
0032 %            appear before the color/marker specifier
0033 %
0034 % in the event where all of the above inputs have extra settings related to
0035 % the color of the plot, the priorities are given in the following order:
0036 %
0037 %          opt > node(:,4) > elem(:,5) > face(:,4)
0038 %
0039 % output:
0040 %   hm: handle or handles (vector) to the plotted surfaces
0041 %
0042 % example:
0043 %
0044 %   h=plotmesh(node,'r.');
0045 %   h=plotmesh(node,'x<20','r.');
0046 %   h=plotmesh(node,face);
0047 %   h=plotmesh(node,face,'y>10');
0048 %   h=plotmesh(node,face,'facecolor','r');
0049 %   h=plotmesh(node,elem,'x<20');
0050 %   h=plotmesh(node,elem,'x<20 & y>0');
0051 %   h=plotmesh(node,face,elem);
0052 %   h=plotmesh(node,face,elem,'linestyle','--');
0053 %   h=plotmesh(node,elem,'z=20');
0054 %
0055 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0056 %
0057 
0058 selector=[];
0059 opt=[];
0060 face=[];
0061 elem=[];
0062 
0063 if(nargin>1)
0064    hasopt=0;
0065    for i=1:length(varargin)
0066        if(ischar(varargin{i}))
0067         if(~isempty(regexp(varargin{i},'[x-zX-Z]')) && ~isempty(regexp(varargin{i},'[><=&|]')))
0068             selector=varargin{i};
0069             if(nargin>=i+1) opt=varargin(i+1:end); end
0070         else
0071             opt=varargin(i:end);
0072         end
0073         if(i==1)
0074             face=[];elem=[];
0075         elseif(i==2)
0076             if(iscell(varargin{1}) | size(varargin{1},2)<4)
0077                 face=varargin{1}; elem=[];
0078             elseif(size(varargin{1},2)==4)
0079                 faceid=unique(varargin{1}(:,4));
0080                 if(length(faceid)==1)
0081                     face=varargin{1}; elem=[];
0082                 elseif(any(hist(varargin{1}(:,4),unique(varargin{1}(:,4)))>50))
0083                     face=varargin{1}; elem=[];
0084                 else
0085                     elem=varargin{1}; face=[];
0086                 end
0087             else
0088                 elem=varargin{1}; face=[];
0089             end
0090         elseif(i==3)
0091             face=varargin{1};
0092             elem=varargin{2};
0093         end
0094         hasopt=1;
0095         break;
0096     end
0097    end
0098    if(hasopt==0)
0099        if(length(varargin)>=2)
0100         face=varargin{1};
0101         elem=varargin{2};
0102         if(length(varargin)>2) opt=varargin(3:end); end
0103     elseif(iscell(varargin{1}) | size(varargin{1},2)<4)
0104         face=varargin{1}; elem=[];
0105     elseif(size(varargin{1},2)==4)
0106         faceid=unique(varargin{1}(:,4));
0107             if(length(faceid)==1)
0108             face=varargin{1}; elem=[];
0109         elseif(any(hist(varargin{1}(:,4),unique(varargin{1}(:,4)))>50))
0110                 face=varargin{1}; elem=[];
0111         else
0112                 elem=varargin{1}; face=[];
0113         end
0114     else
0115         elem=varargin{1}; face=[];
0116     end
0117    end
0118 end
0119 
0120 holdstate=ishold;
0121 if(~holdstate)
0122     cla;
0123 end
0124 if(size(node,2)==4 && size(elem,2)==5)
0125     warning(['You have specified the node colors by both the 4th ' ...
0126             'and 5th columns of node and face inputs, respectively. ' ...
0127             'The node input takes priority']);
0128 end
0129 if(isempty(face) && isempty(elem))
0130    if(isempty(selector))
0131         if(isempty(opt))
0132            h=plot3(node(:,1),node(:,2),node(:,3),'o');
0133     else
0134            h=plot3(node(:,1),node(:,2),node(:,3),opt{:});
0135     end
0136    else
0137     x=node(:,1);
0138     y=node(:,2);
0139     z=node(:,3);
0140     idx=eval(['find(' selector ')']);
0141     if(~isempty(idx))
0142         if(isempty(opt))
0143         h=plot3(node(idx,1),node(idx,2),node(idx,3),'o');
0144         else
0145         h=plot3(node(idx,1),node(idx,2),node(idx,3),opt{:});
0146         end
0147     else
0148         warning('nothing to plot');
0149     end
0150    end
0151 end
0152 
0153 if(~isempty(face))
0154    hold on;
0155    if(isempty(selector))
0156         if(isempty(opt))
0157            h=plotsurf(node,face);
0158     else
0159            h=plotsurf(node,face,opt{:});
0160     end
0161    else
0162     if(iscell(face))
0163        cent=meshcentroid(node,face);
0164     else
0165        cent=meshcentroid(node,face(:,1:3));
0166     end
0167     x=cent(:,1);
0168     y=cent(:,2);
0169     z=cent(:,3);
0170     idx=eval(['find(' selector ')']);
0171     if(~isempty(idx))
0172         if(iscell(face))
0173             h=plotsurf(node,face(idx),opt{:});
0174         else
0175             h=plotsurf(node,face(idx,:),opt{:});
0176         end
0177     else
0178         warning('no surface to plot');
0179     end
0180    end
0181 end
0182 
0183 if(~isempty(elem))
0184    hold on;
0185    if(isempty(selector))
0186         if(isempty(opt))
0187            h=plottetra(node,elem);
0188     else
0189            h=plottetra(node,elem,opt{:});
0190     end
0191    else
0192    cent=meshcentroid(node,elem(:,1:4));
0193    x=cent(:,1);
0194    y=cent(:,2);
0195    z=cent(:,3);
0196    if(regexp(selector,'='))
0197       if(size(node,2)==4)
0198           [cutpos,cutvalue,facedata]=qmeshcut(elem,node(:,1:3),node(:,4),selector);  
0199       elseif(size(node,2)==3)
0200           [cutpos,cutvalue,facedata]=qmeshcut(elem,node,node(:,3),selector);
0201       else
0202           error('plotmesh can only plot 3D tetrahedral meshes');
0203       end
0204       if(~isreal(cutvalue))
0205           cutvalue=abs(cutvalue);
0206       end
0207       h=patch('Vertices',cutpos,'Faces',facedata,'FaceVertexCData',cutvalue,'facecolor','interp',opt{:});
0208    else
0209       idx=eval(['find(' selector ')']);
0210       if(~isempty(idx))
0211         if(isempty(opt))
0212         h=plottetra(node,elem(idx,:));
0213         else
0214         h=plottetra(node,elem(idx,:),opt{:});
0215         end
0216       else
0217         warning('no tetrahedral element to plot');
0218     end
0219      end
0220    end
0221 end
0222 
0223 if(exist('h','var') & ~holdstate)
0224   hold off;
0225 end
0226 if(exist('h','var'))
0227   if(any(get(gca,'dataaspectratio')>1e8))
0228      view(3);
0229   end
0230   axis equal;
0231 end
0232 if(exist('h','var') & nargout>=1)
0233   hm=h;
0234 end

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