Home > FR3DSource > xFindPolyhedra.m

# xFindPolyhedra

## PURPOSE

xFindHexahedra.m returns a list of indices (i,j,k,m) for which

## SYNOPSIS

function [TList,SS] = xFindPolyhedra(Model,num,PS)

## DESCRIPTION

``` xFindHexahedra.m returns a list of indices (i,j,k,m) for which
A(i,j) > 0, B(k,i) > 0, C(k,j) > 0, D(m,i) > 0, E(m,j) > 0, F(m,k) > 0
G(r,i) > 0, H(r,j) > 0, I(r,m) > 0, J(r,k) > 0```

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 % xFindHexahedra.m returns a list of indices (i,j,k,m) for which
0002 % A(i,j) > 0, B(k,i) > 0, C(k,j) > 0, D(m,i) > 0, E(m,j) > 0, F(m,k) > 0
0003 % G(r,i) > 0, H(r,j) > 0, I(r,m) > 0, J(r,k) > 0
0004
0005 function [TList,SS] = xFindPolyhedra(Model,num,PS)
0006
0007 SS = [];
0008 A=PS{2,1};
0009 if num>2
0010     Cutoff=Model.SSCutoff;
0011     B=PS{3,1};
0012     C=PS{3,2};
0013     if num>3
0014         D=PS{4,1};
0015         E=PS{4,2};
0016         F=PS{4,3};
0017         if num>4
0018             G=PS{5,1};
0019             H=PS{5,2};
0020             I=PS{5,3};
0021             J=PS{5,4};
0022             if num>5
0023                 K=PS{6,1};
0024                 L=PS{6,2};
0025                 M=PS{6,3};
0026                 N=PS{6,4};
0027                 O=PS{6,5};
0028                 if num>6
0029                     P=PS{7,1};
0030                     Q=PS{7,2};
0031                     R=PS{7,3};
0032                     S=PS{7,4};
0033                     T=PS{7,5};
0034                     U=PS{7,6};
0035                     if num>7
0036                         V=PS{8,1};
0037                         W=PS{8,2};
0038                         X=PS{8,3};
0039                         Y=PS{8,4};
0040                         Z=PS{8,5};
0041                         AA=PS{8,6};
0042                         BB=PS{8,7};
0043                         if num>8
0044                             CC=PS{9,1};
0045                             DD=PS{9,2};
0046                             EE=PS{9,3};
0047                             FF=PS{9,4};
0048                             GG=PS{9,5};
0049                             HH=PS{9,6};
0050                             II=PS{9,7};
0051                             JJ=PS{9,8};
0052                         end
0053                     end
0054                 end
0055             end
0056         end
0057     end
0058 end
0059
0060 [j,i] = find(A);
0061 LL = 64000;                                % initial size for list storage
0062 TList = uint16(zeros(LL,num));
0063 count = 0;
0064 switch num
0065     case 2
0066         TList   = [i j];
0067         count=length(i);
0068     case 3
0069         [TList,count]=Case3(Cutoff,TList,LL,i,j,count,A,B,C);
0070
0071     case 4
0072         [TList,count]=Case4(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F);
0073
0074     case 5
0075         [TList,count]=Case5(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J);
0076
0077     case 6
0078         [TList,count]=Case6(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O);
0079
0080     case 7
0081         [TList,count]=Case7(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U);
0082
0083     case 8
0084         [TList,count]=Case8(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB);
0085
0086     case 9
0087         SS = zeros(LL,1);
0088         [TList,count,SS]=Case9(Cutoff,TList,SS,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,GG,HH,II,JJ);
0089         SS = SS(1:count,1);
0090 end
0091 TList = TList(1:count,:);
0092
0093 %---------------------------------------------------------------
0094 function [TList,count]=Case3(Cutoff,TList,LL,i,j,count,A,B,C)
0095
0096
0097 TList = uint16(zeros(LL,3));
0098 count = 0;
0099 for n=1:length(i),
0100   in = i(n);
0101   jn = j(n);
0102   k = find(B(:,in) .* C(:,jn));
0103   K = length(k);
0104   if count + K > LL - 10000,                      % memory management
0107     LL    = length(TList(:,1));
0108 if count > 1000000,
0109   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0110 end
0111   end
0112   for p = 1:K,
0113     kp=k(p);
0114     SSks= A(jn,in) + B(kp,in) + C(kp,jn);
0115     count = count + 1;
0116     TList(count,:) = [in jn kp];
0117   end
0118 end
0119
0120
0121 %---------------------------------------------------------------
0122 function [TList,count]=Case4(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F)
0123
0124   for n=1:length(i),
0125       in = i(n);
0126       jn = j(n);
0127       k = find(B(:,in) .* C(:,jn));
0128       m = find(D(:,in) .* E(:,jn));
0129       [mm,kk]  = find(F(m,k));
0130       if count + length(kk) > LL - 10000,                      % memory management
0133         LL    = length(TList(:,1));
0134 if count > 1000000,
0135   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0136 end
0137       end
0138       for p = 1:length(kk),
0139           kkkp=k(kk(p));
0140           mmmp=m(mm(p));
0141         SSks= A(jn,in) + B(kkkp,in) + C(kkkp,jn) ...
0142             + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0143         if SSks<Cutoff(4)
0144             count = count + 1;
0145             TList(count,:) = [in jn kkkp mmmp];
0146         end
0147       end
0148   end
0149
0150
0151
0152   %---------------------------------------------------------------
0153 function [TList,count]=Case5(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J)
0154
0155   for n=1:length(i),
0156       in = i(n);
0157       jn = j(n);
0158       k = find(B(:,in) .* C(:,jn));
0159       m = find(D(:,in) .* E(:,jn));
0160       [mm,kk]  = find(F(m,k));
0161       r = find(G(:,in) .* H(:,jn));
0162       for p = 1:length(kk),
0163             kkkp = k(kk(p));
0164             mmmp = m(mm(p));
0165            SSkm= A(jn,in) + B(kkkp,in) + C(kkkp,jn) ...
0166             + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0167             if SSkm<Cutoff(4)
0168             rr = find(I(r,kkkp) .* J(r,mmmp));
0169                 for q = 1:length(rr),
0170                     rrrq=r(rr(q));
0171                     SSrs = SSkm + G(rrrq,in)+H(rrrq,jn)+I(rrrq,kkkp)+J(rrrq,mmmp);
0172                     if SSrs<Cutoff(5)
0173                         if count + length(kk) > LL - 10000,                      % memory management
0176                           LL    = length(TList(:,1));
0177 if count > 1000000,
0178   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0179 end
0180                         end
0181                         count = count + 1;
0182                         TList(count,:) = [in jn kkkp mmmp rrrq];
0183                     end
0184                 end
0185             end
0186       end
0187   end % end for n
0188 %---------------------------------------------------------------
0189 function [TList,count]=Case6(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O)
0190
0191     for n=1:length(i),
0192         in = i(n);
0193         jn = j(n);
0194         SSij = A(jn,in);
0195         k = find(B(:,in) .* C(:,jn));
0196         m = find(D(:,in) .* E(:,jn));
0197         [mm,kk] = find(F(m,k));
0198         if length(mm) > 0,
0199             r = find(G(:,in) .* H(:,jn));
0200             s = find(K(:,in) .* L(:,jn));
0201
0202             for p = 1:length(kk),
0203             kkkp = k(kk(p));
0204             mmmp = m(mm(p));
0205             SSkm = SSij + B(kkkp,in) + C(kkkp,jn) ...
0206             + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0207                 if SSkm < Cutoff(4)
0208                     rr = find(I(r,kkkp) .* J(r,mmmp));
0209                     ss = find(M(s,kkkp) .* N(s,mmmp));
0210                     [sr,rs] = find(O(s(ss),r(rr)));
0211                     for q = 1:length(rs),
0212                         rrrrsq=r(rr(rs(q)));
0213                         ssssrq=s(ss(sr(q)));
0214                         if count + length(rs) > LL - 10000,                      % memory management
0217                           LL    = length(TList(:,1));
0218 if count > 1000000,
0219   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0220 end
0221                         end
0222                         SSrs = SSkm + G(rrrrsq,in)+H(rrrrsq,jn)+I(rrrrsq,kkkp)+J(rrrrsq,mmmp)+...
0223                             K(ssssrq,in)+L(ssssrq,jn)+M(ssssrq,kkkp)+N(ssssrq,mmmp)+O(ssssrq,rrrrsq);
0224                         if SSrs < Cutoff(6)
0225                             count = count + 1;
0226                             TList(count,:) = [in jn kkkp mmmp rrrrsq ssssrq];
0227                         end
0228                     end
0229                 end
0230             end
0231         end
0232     end
0233   %---------------------------------------------------------------
0234 function [TList,count]=Case7(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U)
0235     for n=1:length(i),
0236       in = i(n);
0237       jn = j(n);
0238       k = find(B(:,in) .* C(:,jn));
0239       m = find(D(:,in) .* E(:,jn));
0240       [mm,kk]  = find(F(m,k));
0241         r = find(G(:,in) .* H(:,jn));
0242         s = find(K(:,in) .* L(:,jn));
0243         t = find(P(:,in) .* Q(:,jn));
0244         for p = 1:length(kk),
0245             kkkp = k(kk(p));
0246             mmmp = m(mm(p));
0247             SSkm= A(jn,in) + B(kkkp,in) + C(kkkp,jn) ...
0248                 + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0249             if SSkm<Cutoff(4)
0250                 rr = find(I(r,kkkp) .* J(r,mmmp));
0251                 ss = find(M(s,kkkp) .* N(s,mmmp));
0252                 tt = find(R(t,kkkp) .* S(t,mmmp));
0253                 [sr,rs] = find(O(s(ss),r(rr)));
0254                  for q=1:length(rs)
0255                     rrrrsq=r(rr(rs(q)));
0256                     ssssrq=s(ss(sr(q)));
0257                     SSrs = SSkm + G(rrrrsq,in)+H(rrrrsq,jn)+I(rrrrsq,kkkp)+J(rrrrsq,mmmp)+...
0258                         K(ssssrq,in)+L(ssssrq,jn)+M(ssssrq,kkkp)+N(ssssrq,mmmp)+O(ssssrq,rrrrsq);
0259                     if SSrs < Cutoff(6)
0260                         trs = find(T(t(tt),rrrrsq) .* U(t(tt),ssssrq));
0261                         for e=1:length(trs)
0262                             ttttrse=t(tt(trs(e)));
0263                             SSts=SSrs+P(ttttrse,in)+Q(ttttrse,jn)+R(ttttrse,kkkp)+S(ttttrse,mmmp)+T(ttttrse,rrrrsq)+U(ttttrse,ssssrq);
0264                             if SSts<Cutoff(7)
0265                                 if count + length(trs) > LL - 10000,                      % memory management
0268                                   LL    = length(TList(:,1));
0269 if count > 1000000,
0270   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0271 end
0272                                 end
0273                                 count = count + 1;
0274                                 TList(count,:) = [in jn kkkp mmmp rrrrsq ssssrq t(tt(trs(e)))];
0275                             end
0276                         end
0277                     end
0278                  end
0279             end
0280         end
0281     end
0282   %---------------------------------------------------------------
0283   function [TList,count]=Case8(Cutoff,TList,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB)
0284     for n=1:length(i),
0285       in = i(n);
0286       jn = j(n);
0287       k = find(B(:,in) .* C(:,jn));
0288       m = find(D(:,in) .* E(:,jn));
0289       [mm,kk]  = find(F(m,k));
0290         r = find(G(:,in) .* H(:,jn));
0291         s = find(K(:,in) .* L(:,jn));
0292         t = find(P(:,in) .* Q(:,jn));
0293         h = find(V(:,in) .* W(:,jn));
0294         if count + length(kk) > length(TList(:,1)),                  % memory management
0295             TList = [TList; uint16(zeros(LL,8))];
0296             LL = min(2*LL,1000000);
0297         end
0298         for p = 1:length(kk),
0299             kkkp = k(kk(p));
0300             mmmp = m(mm(p));
0301             SSkm= A(jn,in) + B(kkkp,in) + C(kkkp,jn) ...
0302                 + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0303             if SSkm<Cutoff(4)
0304
0305                 rr = find(I(r,kkkp) .* J(r,mmmp));
0306                 ss = find(M(s,kkkp) .* N(s,mmmp));
0307                 tt = find(R(t,kkkp) .* S(t,mmmp));
0308                 hh = find(X(h,kkkp) .* Y(h,mmmp));
0309                 [sr,rs] = find(O(s(ss),r(rr)));
0310
0311                  for q=1:length(rs)
0312                     rrrrsq=r(rr(rs(q)));
0313                     ssssrq=s(ss(sr(q)));
0314                     SSrs = SSkm + G(rrrrsq,in)+H(rrrrsq,jn)+I(rrrrsq,kkkp)+J(rrrrsq,mmmp)+...
0315                         K(ssssrq,in)+L(ssssrq,jn)+M(ssssrq,kkkp)+N(ssssrq,mmmp)+O(ssssrq,rrrrsq);
0316                     if SSrs < Cutoff(6)
0317
0318                         trs = find(T(t(tt),rrrrsq) .* U(t(tt),ssssrq));
0319                         hrs = find(Z(h(hh),rrrrsq) .* AA(h(hh),ssssrq));
0320                         [ht,th] = find(BB(h(hh(hrs)),t(tt(trs))));
0321                         for e=1:length(ht)
0322                             ttttrsthe=t(tt(trs(th(e))));
0323                             hhhhrshte=h(hh(hrs(ht(e))));
0324                             SSts=SSrs+P(ttttrsthe,in)+Q(ttttrsthe,jn)+R(ttttrsthe,kkkp)+S(ttttrsthe,mmmp)+T(ttttrsthe,rrrrsq)+U(ttttrsthe,ssssrq)+...
0325                                 V(hhhhrshte,in)+W(hhhhrshte,jn)+X(hhhhrshte,kkkp)+Y(hhhhrshte,mmmp)+Z(hhhhrshte,rrrrsq)+AA(hhhhrshte,ssssrq)+BB(hhhhrshte,ttttrsthe);
0326                             if SSts<Cutoff(8)
0327                                 if count + length(ht) > LL - 10000,                      % memory management
0330                                   LL    = length(TList(:,1));
0331 if count > 1000000,
0332   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0333 end
0334                                 end
0335                                 count = count + 1;
0336                                 TList(count,:) = [in jn kkkp mmmp rrrrsq ssssrq ttttrsthe hhhhrshte];
0337                             end
0338                         end
0339                     end
0340                  end
0341             end
0342         end
0343     end
0344   %---------------------------------------------------------------
0345     function [TList,count,SS]=Case9(Cutoff,TList,SS,LL,i,j,count,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,GG,HH,II,JJ)
0346
0347     for n=1:length(i),                         % loop through pairs
0348       in = i(n);                               % indices of this pair
0349       jn = j(n);
0350       k = find(B(:,in) .* C(:,jn));            % k that agree with pair
0351       m = find(D(:,in) .* E(:,jn));            % m that agree with pair
0352       [mm,kk]  = find(F(m,k));                 % k and m that match too
0353         r = find(G(:,in) .* H(:,jn));
0354         s = find(K(:,in) .* L(:,jn));
0355         t = find(P(:,in) .* Q(:,jn));
0356         h = find(V(:,in) .* W(:,jn));
0357         u = find(CC(:,in) .* DD(:,jn));
0358         for p = 1:length(kk),                  % loop through tetrahedra
0359             kkkp = k(kk(p));                   % tetrahedron in jn kkkp mmmp
0360             mmmp = m(mm(p));
0361             SSkm = A(jn,in) + B(kkkp,in) + C(kkkp,jn) ...
0362                  + D(mmmp,in) + E(mmmp,jn) + F(mmmp,kkkp);
0363             if SSkm<Cutoff(4)
0364                 rr = find(I(r,kkkp) .* J(r,mmmp));
0365                 ss = find(M(s,kkkp) .* N(s,mmmp));
0366                 tt = find(R(t,kkkp) .* S(t,mmmp));
0367                 hh = find(X(h,kkkp) .* Y(h,mmmp));
0368                 uu = find(EE(u,kkkp).* FF(u,mmmp));
0369                 [sr,rs] = find(O(s(ss),r(rr)));
0370                  for q=1:length(rs)
0371                     rrrrsq=r(rr(rs(q)));
0372                     ssssrq=s(ss(sr(q)));
0373                     SSrs = SSkm + G(rrrrsq,in)+H(rrrrsq,jn)+I(rrrrsq,kkkp)+J(rrrrsq,mmmp)+...
0374                         K(ssssrq,in)+L(ssssrq,jn)+M(ssssrq,kkkp)+N(ssssrq,mmmp)+O(ssssrq,rrrrsq);
0375                     if SSrs < Cutoff(6)
0376                         trs = find(T(t(tt),rrrrsq) .* U(t(tt),ssssrq));
0377                         hrs = find(Z(h(hh),rrrrsq) .* AA(h(hh),ssssrq));
0378                         urs = find(GG(u(uu),rrrrsq) .* HH(u(uu),ssssrq));
0379                         [ht,th] = find(BB(h(hh(hrs)),t(tt(trs))));
0380                         for e=1:length(ht)
0381                             ttttrsthe=t(tt(trs(th(e))));
0382                             hhhhrshte=h(hh(hrs(ht(e))));
0383                                ust = find(II(u(uu(urs)),ttttrsthe) .* JJ(u(uu(urs)),hhhhrshte));
0384                                for ee=1:length(ust)
0385                                    uuuursustee=u(uu(urs(ust(ee))));
0386                                     SSts=SSrs+P(ttttrsthe,in)+Q(ttttrsthe,jn)+R(ttttrsthe,kkkp)+S(ttttrsthe,mmmp)+T(ttttrsthe,rrrrsq)+U(ttttrsthe,ssssrq)+...
0387                                         V(hhhhrshte,in)+W(hhhhrshte,jn)+X(hhhhrshte,kkkp)+Y(hhhhrshte,mmmp)+Z(hhhhrshte,rrrrsq)+AA(hhhhrshte,ssssrq)+BB(hhhhrshte,ttttrsthe)+...
0388                                         CC(uuuursustee,in)+DD(uuuursustee,jn)+EE(uuuursustee,kkkp)+FF(uuuursustee,mmmp)+GG(uuuursustee,rrrrsq)+...
0389                                         HH(uuuursustee,ssssrq)+II(uuuursustee,ttttrsthe)+JJ(uuuursustee,hhhhrshte);
0390                                     if SSts < Cutoff(9)
0391                                         if count + length(ust) > LL - 10000,                      % memory management
0395                                           LL    = length(TList(:,1));
0396 if count > 1000000,
0397   fprintf('Found %2d million candidates so far\n',fix(count/1000000));
0398 end
0399                                         end
0400                                         count = count + 1;
0401                                         TList(count,:) = [in jn kkkp mmmp rrrrsq ssssrq ttttrsthe hhhhrshte uuuursustee];
0402                                         SS(count,1)    = SSts;
0403                                     end
0404                                end
0405                         end
0406                     end
0407                  end
0408             end
0409         end
0410     end
0411   %---------------------------------------------------------------
0412```

Generated on Fri 03-Apr-2009 09:52:35 by m2html © 2003