Home > vbmeg > external > iso2mesh > bbxflatsegment.m

bbxflatsegment

PURPOSE ^

SYNOPSIS ^

function seg=bbxflatsegment(node,loop)

DESCRIPTION ^

 seg=bbxflatsegment(node,loop)

 decompose edge loops into flat segments along the x/y/z 
 planes of the bounding box

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2008/04/08

 input:   
    node:  x,y,z coordinates of each node of the mesh
    loop:  input, a single vector separated by NaN, each segment
             is a close-polygon consisted by node IDs 
 output:
    seg:   output, a single vector separated by NaN, each segment
             is a close-polygon on x/y/z plane 

 -- 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 seg=bbxflatsegment(node,loop)
0002 %
0003 % seg=bbxflatsegment(node,loop)
0004 %
0005 % decompose edge loops into flat segments along the x/y/z
0006 % planes of the bounding box
0007 %
0008 % author: Qianqian Fang, <q.fang at neu.edu>
0009 % date: 2008/04/08
0010 %
0011 % input:
0012 %    node:  x,y,z coordinates of each node of the mesh
0013 %    loop:  input, a single vector separated by NaN, each segment
0014 %             is a close-polygon consisted by node IDs
0015 % output:
0016 %    seg:   output, a single vector separated by NaN, each segment
0017 %             is a close-polygon on x/y/z plane
0018 %
0019 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0020 %
0021 
0022 pos=node(loop,:);
0023 
0024 % get the bounding box
0025 mi=min(pos);
0026 ma=max(pos);
0027 
0028 % extract nodes on the bounding box
0029 idx0=find(abs(pos(:,1)-mi(1))<1e-6)';
0030 idx1=find(abs(pos(:,1)-ma(1))<1e-6)';
0031 
0032 idy0=find(abs(pos(:,2)-mi(2))<1e-6)';
0033 idy1=find(abs(pos(:,2)-ma(2))<1e-6)';
0034 
0035 idz0=find(abs(pos(:,3)-mi(3))<1e-6)';
0036 idz1=find(abs(pos(:,3)-ma(3))<1e-6)';
0037 
0038 % need to be more than 3 points to make a flat polygon
0039 
0040 if(length(idx0)<=3) idx0=[]; end
0041 if(length(idx1)<=3) idx1=[]; end
0042 if(length(idy0)<=3) idy0=[]; end
0043 if(length(idy1)<=3) idy1=[]; end
0044 if(length(idz0)<=3) idz0=[]; end
0045 if(length(idz1)<=3) idz1=[]; end
0046 
0047 nn=length(loop);
0048 
0049 % if the original is a flat polygon, return
0050 
0051 if(unique(length(idx0))==nn | unique(length(idx1))==nn ...
0052   |unique(length(idy0))==nn | unique(length(idy1))==nn ...
0053   |unique(length(idz0))==nn | unique(length(idz1))==nn) 
0054     seg=loop(:)';
0055     return;
0056 end
0057 
0058 % otherwise, find the combination that split the loop
0059 
0060 if(length(unique([idx0 idy0 idz0]))==nn)
0061    seg= [loop(idx0),nan,loop(idy0),nan,loop(idz0)];
0062 elseif(length(unique([idx0 idy1 idz0]))==nn)
0063    seg= [loop(idx0),nan,loop(idy1),nan,loop(idz0)];
0064 elseif(length(unique([idx0 idy0 idz1]))==nn)
0065    seg= [loop(idx0),nan,loop(idy0),nan,loop(idz1)];
0066 elseif(length(unique([idx0 idy1 idz1]))==nn)
0067    seg= [loop(idx0),nan,loop(idy1),nan,loop(idz1)];
0068 elseif(length(unique([idx1 idy0 idz0]))==nn)
0069    seg= [loop(idx1),nan,loop(idy0),nan,loop(idz0)];
0070 elseif(length(unique([idx1 idy1 idz0]))==nn)
0071    seg= [loop(idx1),nan,loop(idy1),nan,loop(idz0)];
0072 elseif(length(unique([idx1 idy0 idz1]))==nn)
0073    seg= [loop(idx1),nan,loop(idy0),nan,loop(idz1)];
0074 elseif(length(unique([idx1 idy1 idz1]))==nn)
0075    seg= [loop(idx1),nan,loop(idy1),nan,loop(idz1)];
0076 else
0077     seg=[];
0078 end
0079 
0080 % remove pattern [ ... nan nan ...] in the result
0081 
0082 if(length(seg) & any(isnan(seg)))
0083     id=regexp(sprintf('%d',isnan(seg)),'11');
0084     if(length(id))
0085         seg(id+1)=[];
0086     end
0087 end

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