| 1 |
#include "mshmet.h" |
| 2 |
|
| 3 |
unsigned char inxt[3] = {1,2,0}; |
| 4 |
unsigned char iprv[3] = {2,0,1}; |
| 5 |
|
| 6 |
|
| 7 |
/* find all vertices connected to P |
| 8 |
in: start : tetrahedron containing p |
| 9 |
ip : index of p in start |
| 10 |
list : dynamic list structure (allocated outside) |
| 11 |
out: list : list of tets */ |
| 12 |
int boulep_3d(pMesh mesh,int start,int ip,int *list) { |
| 13 |
pTetra pt,pt1; |
| 14 |
pPoint ppt; |
| 15 |
int *adja,adj,i,j,kk,indp,iel,iadr,base,ilist,iilist,nump; |
| 16 |
int llist[LONMAX+2],vois[4]; |
| 17 |
|
| 18 |
pt = &mesh->tetra[start]; |
| 19 |
if ( !pt->v[0] ) return(0); |
| 20 |
nump = pt->v[ip]; |
| 21 |
ppt = &mesh->point[nump]; |
| 22 |
|
| 23 |
/* store initial tetra */ |
| 24 |
base = ++mesh->mark; |
| 25 |
pt->mark = base; |
| 26 |
ilist = 0; |
| 27 |
iilist = 1; |
| 28 |
llist[1] = 4*start + ip; |
| 29 |
/* store first 3 vertices */ |
| 30 |
for (j=0; j<4; j++) { |
| 31 |
if ( j != ip ) { |
| 32 |
ilist++; |
| 33 |
list[ilist] = pt->v[j]; |
| 34 |
mesh->point[ pt->v[j] ].mark = base; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/* store 3 neighbors sharing P */ |
| 39 |
iadr = (start-1)*4 + 1; |
| 40 |
adja = &mesh->adja[iadr]; |
| 41 |
vois[0] = adja[0] >> 2; |
| 42 |
vois[1] = adja[1] >> 2; |
| 43 |
vois[2] = adja[2] >> 2; |
| 44 |
vois[3] = adja[3] >> 2; |
| 45 |
for (i=0; i<4; i++) { |
| 46 |
if ( i == ip ) continue; |
| 47 |
adj = vois[i]; |
| 48 |
if ( adj ) { |
| 49 |
pt1 = &mesh->tetra[adj]; |
| 50 |
if ( pt1->mark != base ) { |
| 51 |
/* not stored yet */ |
| 52 |
pt1->mark = base; |
| 53 |
for (j=0; j<4; j++) |
| 54 |
if ( pt1->v[j] == nump ) break; |
| 55 |
iilist++; |
| 56 |
llist[iilist] = 4*adj + j; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
if ( iilist < 2 ) return(ilist); |
| 61 |
|
| 62 |
/* explore list of neighbors */ |
| 63 |
indp = 2; |
| 64 |
do { |
| 65 |
iel = llist[indp] >> 2; |
| 66 |
pt = &mesh->tetra[iel]; |
| 67 |
iadr = (iel-1)*4 + 1; |
| 68 |
adja = &mesh->adja[iadr]; |
| 69 |
vois[0] = adja[0] >> 2; |
| 70 |
vois[1] = adja[1] >> 2; |
| 71 |
vois[2] = adja[2] >> 2; |
| 72 |
vois[3] = adja[3] >> 2; |
| 73 |
|
| 74 |
for (i=0; i<4; i++) { |
| 75 |
if ( pt->v[i] == nump ) continue; |
| 76 |
adj = vois[i]; |
| 77 |
if ( adj ) { |
| 78 |
pt1 = &mesh->tetra[adj]; |
| 79 |
if ( pt1->mark != base ) { |
| 80 |
pt1->mark = base; |
| 81 |
for (j=0; j<4; j++) |
| 82 |
if ( pt1->v[j] == nump ) break; |
| 83 |
iilist++; |
| 84 |
llist[iilist] = 4*adj + j; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
/* overflow */ |
| 89 |
if ( iilist > LONMAX-3 ) return(-ilist); |
| 90 |
} |
| 91 |
while ( ++indp <= iilist ); |
| 92 |
|
| 93 |
/* store vertices from tetra list */ |
| 94 |
for (i=2; i<=iilist; i++) { |
| 95 |
kk = llist[i] / 4; |
| 96 |
pt = &mesh->tetra[kk]; |
| 97 |
for (j=0; j<4; j++) { |
| 98 |
if ( pt->v[j] != nump ) { |
| 99 |
ppt = &mesh->point[ pt->v[j] ]; |
| 100 |
if ( ppt->mark < base ) { |
| 101 |
ilist++; |
| 102 |
list[ilist] = pt->v[j]; |
| 103 |
ppt->mark = base; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
return(ilist); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
/* store neighboring vertices, return < 0 if overflow */ |
| 114 |
int boulep_2d(pMesh mesh,int start,int ip,int *list) { |
| 115 |
pTria pt; |
| 116 |
int *adja,i1,iadr,nump,voy,ilist,iel; |
| 117 |
|
| 118 |
if ( start < 1 ) return(0); |
| 119 |
pt = &mesh->tria[start]; |
| 120 |
if ( !pt->v[0] ) return(0); |
| 121 |
nump = pt->v[ip]; |
| 122 |
|
| 123 |
/* init list */ |
| 124 |
i1 = inxt[ip]; |
| 125 |
ilist = 1; |
| 126 |
list[1] = pt->v[i1]; |
| 127 |
|
| 128 |
iadr = (start-1)*3 + 1; |
| 129 |
adja = &mesh->adja[iadr]; |
| 130 |
iel = adja[i1] / 3; |
| 131 |
while ( iel && (iel != start) ) { |
| 132 |
pt = &mesh->tria[iel]; |
| 133 |
voy = adja[i1] % 3; |
| 134 |
i1 = iprv[voy]; |
| 135 |
++ilist; |
| 136 |
if ( ilist > LONMAX-2 ) return(-ilist); |
| 137 |
list[ilist] = pt->v[i1]; |
| 138 |
iadr = (iel-1)*3 + 1; |
| 139 |
adja = &mesh->adja[iadr]; |
| 140 |
iel = adja[i1] / 3; |
| 141 |
} |
| 142 |
|
| 143 |
/* reverse loop */ |
| 144 |
if ( iel != start ) { |
| 145 |
voy = inxt[i1]; |
| 146 |
++ilist; |
| 147 |
list[ilist] = pt->v[voy]; |
| 148 |
|
| 149 |
pt = & mesh->tria[start]; |
| 150 |
i1 = iprv[ip]; |
| 151 |
iadr = (start-1)*3 + 1; |
| 152 |
adja = &mesh->adja[iadr]; |
| 153 |
iel = adja[i1] / 3; |
| 154 |
while ( iel && (iel != start) ) { |
| 155 |
pt = &mesh->tria[iel]; |
| 156 |
voy = adja[i1] % 3; |
| 157 |
++ilist; |
| 158 |
if ( ilist > LONMAX-2 ) return(-ilist); |
| 159 |
list[ilist] = pt->v[voy]; |
| 160 |
iadr = (iel-1)*3 + 1; |
| 161 |
adja = &mesh->adja[iadr]; |
| 162 |
i1 = inxt[voy]; |
| 163 |
iel = adja[i1] / 3; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
return(ilist); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|