Home > vbmeg > external > iso2mesh > latticegrid.m

latticegrid

PURPOSE ^

SYNOPSIS ^

function [node,face,centroids]=latticegrid(varargin)

DESCRIPTION ^

 [node,face,centroids]=latticegrid(xrange,yrange,zrange,...)

 generate a 3D lattice

 author: Qianqian Fang, <q.fang at neu.edu>

 input: 
   xrange, yrange, zrange ...: 1D vectors specifying the range of each
         dimension of the lattice

 output:
   node: the vertices of the 3D lattice
   face: the list of cell faces of the lattice, including both internal
         and external facets. By default, face is in the form of a cell
         array, with each row representing a face. One can use
         cell2mat(face) to convert it to an array
   centroids: the centroids of each lattice cell

 example:
    % generate a 3D lattice
    [node,face,c0]=latticegrid([1 2 4],1:3,1:4);
    plotmesh(node,face)
    
    % mesh the 3D lattice based on the face info
    [no,el]=surf2mesh(node,face,[],[],1,0.01,c0);
    figure; plotmesh(no,el)

    % mesh a 2-layer structure using a simple lattice
    [node,face,c0]=latticegrid([0 10],[0 5],[0 3.5 4]);
    c0(:,4)=[0.01;0.001];
    [no,el]=surf2mesh(node,face,[],[],1,[],c0);
    figure; plotmesh(no,el)

 -- 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 [node,face,centroids]=latticegrid(varargin)
0002 %
0003 % [node,face,centroids]=latticegrid(xrange,yrange,zrange,...)
0004 %
0005 % generate a 3D lattice
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 %
0009 % input:
0010 %   xrange, yrange, zrange ...: 1D vectors specifying the range of each
0011 %         dimension of the lattice
0012 %
0013 % output:
0014 %   node: the vertices of the 3D lattice
0015 %   face: the list of cell faces of the lattice, including both internal
0016 %         and external facets. By default, face is in the form of a cell
0017 %         array, with each row representing a face. One can use
0018 %         cell2mat(face) to convert it to an array
0019 %   centroids: the centroids of each lattice cell
0020 %
0021 % example:
0022 %    % generate a 3D lattice
0023 %    [node,face,c0]=latticegrid([1 2 4],1:3,1:4);
0024 %    plotmesh(node,face)
0025 %
0026 %    % mesh the 3D lattice based on the face info
0027 %    [no,el]=surf2mesh(node,face,[],[],1,0.01,c0);
0028 %    figure; plotmesh(no,el)
0029 %
0030 %    % mesh a 2-layer structure using a simple lattice
0031 %    [node,face,c0]=latticegrid([0 10],[0 5],[0 3.5 4]);
0032 %    c0(:,4)=[0.01;0.001];
0033 %    [no,el]=surf2mesh(node,face,[],[],1,[],c0);
0034 %    figure; plotmesh(no,el)
0035 %
0036 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0037 %
0038 
0039 n=length(varargin);
0040 p=cell(n,1);
0041 [p{:}]=ndgrid(varargin{:});
0042 node=zeros(length(p{1}(:)),n);
0043 for i=1:n
0044    node(:,i)=p{i}(:);
0045 end
0046 if(nargout==1)
0047     return;
0048 end
0049 
0050 dim=size(p{1});
0051 
0052 dd=[dim(1) dim(1)*dim(2)];
0053 onecube=[0 dd(1) dd(1)+1 1; ...
0054          0 1 dd(2)+1 dd(2); ...
0055          0 dd(2) dd(2)+dd(1) dd(1)];
0056 onecube=[onecube;onecube+repmat([dd(2);dd(1);1],1,4)];
0057 
0058 len=prod(dim(1:3)-1);
0059 face=repmat(onecube,len,1);
0060 [xx,yy,zz]=ndgrid(1:dim(1)-1,1:dim(2)-1,1:dim(3)-1);
0061 idx=sub2ind(dim,xx(:),yy(:),zz(:))';
0062 orig=repmat(idx,size(onecube,1),1);
0063 
0064 for i=1:size(onecube,2)
0065     face(:,i)=face(:,i)+orig(:);
0066 end
0067 face=unique(face,'rows');
0068 face=mat2cell(face,ones(size(face,1),1));
0069 
0070 if(nargout>=3)
0071     diffvec=cellfun(@diff,varargin,'UniformOutput',false);
0072     [xx,yy,zz]=ndgrid(diffvec{:});
0073     centroids=node(idx,:)+[xx(:) yy(:) zz(:)]*0.5;
0074 end

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