Home > atmlab > gridcreation > uniformsphere > TriQuad.m

TriQuad

PURPOSE ^

Subdivide triangular mesh using triangular quadrisection. During this

SYNOPSIS ^

function TR=TriQuad(TR)

DESCRIPTION ^

 Subdivide triangular mesh using triangular quadrisection. During this
 operation new vertices are inserted at the edge midpoints thereby 
 producing four new faces for every face of the original mesh. 
 Illustration of this operation is provided below:
 
                     x3                        x3
                    /  \      subdivision     /  \
                   /    \         -->        v3__v2
                  /      \                  / \  / \
                x1________x2              x1___v1___x2

                   Original vertices:    x1, x2, x3
                   New vertices:         v1, v2, v3

 INPUT ARGUMENTS:
   - TR   : input mesh. TR can be specified as a TriRep object or a cell,
            such that TR={X Tri}, where X is the list of vertex 
            coordiantes and Tri is the list of faces.

 OUTPUT:
   - TR  : subdivided mesh. Same format as input.

 AUTHOR: Anton Semechko (a.semechko@gmail.com)
 DATE: May.2012

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

TriQuad.m

SOURCE CODE ^

0001 function TR=TriQuad(TR)
0002 % Subdivide triangular mesh using triangular quadrisection. During this
0003 % operation new vertices are inserted at the edge midpoints thereby
0004 % producing four new faces for every face of the original mesh.
0005 % Illustration of this operation is provided below:
0006 %
0007 %                     x3                        x3
0008 %                    /  \      subdivision     /  \
0009 %                   /    \         -->        v3__v2
0010 %                  /      \                  / \  / \
0011 %                x1________x2              x1___v1___x2
0012 %
0013 %                   Original vertices:    x1, x2, x3
0014 %                   New vertices:         v1, v2, v3
0015 %
0016 % INPUT ARGUMENTS:
0017 %   - TR   : input mesh. TR can be specified as a TriRep object or a cell,
0018 %            such that TR={X Tri}, where X is the list of vertex
0019 %            coordiantes and Tri is the list of faces.
0020 %
0021 % OUTPUT:
0022 %   - TR  : subdivided mesh. Same format as input.
0023 %
0024 % AUTHOR: Anton Semechko (a.semechko@gmail.com)
0025 % DATE: May.2012
0026 %
0027 
0028 % Get the list of vertex cooridnates and list of faces
0029 if strcmp(class(TR),'TriRep')
0030     X=TR.X;
0031     Tri=TR.Triangulation;
0032 elseif iscell(TR) && numel(TR)==2
0033     X=TR{1};
0034     Tri=TR{2};
0035     
0036     % Check the format
0037     if isempty(X) || ~ismatrix(X) || ~isnumeric(X) || ~strcmp(class(X),'double') || isequal(X,round(X))
0038         error('Invalid entry for the list of vertices')
0039     end
0040     
0041     if isempty(Tri) || ~ismatrix(X) || ~isnumeric(Tri) || ~isequal(Tri,round(Tri))
0042         error('Invalid entry for the list of faces')
0043     end
0044     
0045     Tri=double(Tri);
0046     
0047 else
0048     error('Unrecognized input format')
0049 end
0050     
0051 Nx=size(X,1);   % # of vertices
0052 Nt=size(Tri,1); % # of faces
0053 
0054 % Compute edge mid-points
0055 V1=(X(Tri(:,1),:)+X(Tri(:,2),:))/2;
0056 V2=(X(Tri(:,2),:)+X(Tri(:,3),:))/2;
0057 V3=(X(Tri(:,3),:)+X(Tri(:,1),:))/2;
0058 V =[V1;V2;V3];
0059 
0060 % Remove repeating vertices
0061 [V,~,idx]=unique(V,'rows');
0062 
0063 % Assign indices to the new triangle vertices
0064 V1= Nx + idx(1:Nt);
0065 V2= Nx + idx((Nt+1):2*Nt);
0066 V3= Nx + idx((2*Nt+1):3*Nt);
0067 clear idx
0068 
0069 % Define new faces
0070 T1= [Tri(:,1) V1 V3];
0071 T2= [Tri(:,2) V2 V1];
0072 T3= [Tri(:,3) V3 V2];
0073 T4= [V1       V2 V3];
0074 clear V1 V2 V3
0075 
0076 % New mesh
0077 X=[X;V]; 
0078 Tri=[T1;T2;T3;T4];
0079 
0080 if strcmp(class(TR),'TriRep')
0081     TR=TriRep(Tri,X);
0082 else
0083     TR={X,Tri};
0084 end
0085

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005