85 (*q)->nc =
MG_MAX(2048/nv,16);
115 int nbBitsInt,depthMax,dim,i,sizBr,nvTemp;
119 nbBitsInt =
sizeof(int64_t)*8;
120 depthMax = nbBitsInt/dim - 1;
124 for ( i = 0; i<sizBr; i++)
137 nvTemp |= nvTemp >> 1;
138 nvTemp |= nvTemp >> 2;
139 nvTemp |= nvTemp >> 4;
140 nvTemp |= nvTemp >> 8;
141 nvTemp |= nvTemp >> 16;
186 double prec = 1./(1<<30);
188 int ix = (int)floor((ver[0]-prec)*s);
189 int iy = (int)floor((ver[1]-prec)*s);
190 int iz = (int)floor((ver[2]-prec)*s);
191 ix = (ix > 0) ? ix:0;
192 iy = (iy > 0) ? iy:0;
193 iz = (iz > 0) ? iz:0;
199 i += ((ix & s) >> j)<<place;
201 i += ((iy & s) >> j)<<place;
203 i += ((iz & s) >> j)<<place;
227 int64_t oldCoor, newCoor;
233 memcpy(&pt, oldVer ,dim*
sizeof(
double));
235 memcpy(&pt, newVer ,dim*
sizeof(
double));
238 if (newCoor == oldCoor) {
244 memcpy(&pt, oldVer ,dim*
sizeof(
double));
249 memcpy(&pt, newVer ,dim*
sizeof(
double));
269 x = cellCenter[0]-zoneCenter[0];
270 y = cellCenter[1]-zoneCenter[1];
271 z = cellCenter[2]-zoneCenter[2];
273 r1 = sqrt(x*x+y*y+z*z);
282 return (r1+1.732051*l<l0);
300 memmove(&(distList[index+2]),&(distList[index+1]),(size-(index+1))*
sizeof(
double));
301 distList[index+1] = dist;
318 memmove(&(qlist[index+2]),&(qlist[index+1]),(size-(index+1))*
sizeof(
MMG3D_PROctree_s*));
320 if (index+2+(size-(index+1))>61 || index+1<0)
321 fprintf(stderr,
"\n ## Error: %s: index"
322 " too large %i > 61\n",__func__, index+2+(size-(index+1));
341 if (indexMin > indexMax)
343 else if (indexMax - indexMin <2)
346 if (indexMin >= 60 || indexMax>=60)
347 fprintf(stderr,
"\n ## Error: %s: index should not be that large %i %i.\n",
348 __func__,indexMin, indexMax);
350 if (dist > distList[indexMax])
357 indexMed = (indexMin + indexMax)/2;
360 if (indexMed >= 60 || indexMed < 0)
361 fprintf(stderr,
"\n ## Error: %s: index should not be that large %i.\n",
365 if (dist > distList[indexMed])
387 double rect1Temp[6], rect2Temp[6];
389 rect1Temp[0] = rectin[0];
390 rect1Temp[1] = rectin[1];
391 rect1Temp[2] = rectin[2];
392 rect1Temp[3] = rectin[3]+rectin[0];
393 rect1Temp[4] = rectin[4]+rectin[1];
394 rect1Temp[5] = rectin[5]+rectin[2];
396 rect2Temp[0] = rectinout[0];
397 rect2Temp[1] = rectinout[1];
398 rect2Temp[2] = rectinout[2];
399 rect2Temp[3] = rectinout[3]+rectinout[0];
400 rect2Temp[4] = rectinout[4]+rectinout[1];
401 rect2Temp[5] = rectinout[5]+rectinout[2];
403 rectinout[0] = rect1Temp[0]>rect2Temp[0] ? rect1Temp[0]:rect2Temp[0];
404 rectinout[1] = rect1Temp[1]>rect2Temp[1] ? rect1Temp[1]:rect2Temp[1];
405 rectinout[2] = rect1Temp[2]>rect2Temp[2] ? rect1Temp[2]:rect2Temp[2];
406 rectinout[3] = rect1Temp[3]<rect2Temp[3] ? rect1Temp[3]:rect2Temp[3];
407 rectinout[4] = rect1Temp[4]<rect2Temp[4] ? rect1Temp[4]:rect2Temp[4];
408 rectinout[5] = rect1Temp[5]<rect2Temp[5] ? rect1Temp[5]:rect2Temp[5];
410 rectinout[3] = rectinout[3] - rectinout[0];
411 rectinout[4] = rectinout[4] - rectinout[1];
412 rectinout[5] = rectinout[5] - rectinout[2];
414 if ( rectinout[3]<=0 || rectinout[4]<=0 || rectinout[5]<=0 )
return 0;
445 double l0,
int nc,
int dim,
int* index)
448 double centertemp[3];
450 double l = 1./(1<<(q->
depth+1));
453 int indexTemp,i,j,k,nBranch;
475 x = dist[nc-3] - center[0];
476 y = dist[nc-2] - center[1];
477 z = dist[nc-1] - center[2];
480 distTemp = x*x+y*y+z*z;
489 if (indexTemp+1<*index)
495 dist[*index]=distTemp;
501 dist[*index]=distTemp;
513 recCenter[i] = (rect[i]>center[i]);
514 recCenter[i+3] = ((rect[i]+rect[i+3])>center[i]);
525 if (((i && recCenter[3]) || (!i && !recCenter[0])) &&
526 ((j && recCenter[4]) || (!j && !recCenter[1]))&&
527 ((k && recCenter[5]) || (!k && !recCenter[2])))
533 recttemp[0] = center[0]-l*(1-i);
534 recttemp[1] = center[1]-l*(1-j);
535 recttemp[2] = center[2]-l*(1-k);
536 recttemp[3] = recttemp[4] = recttemp[5] = l;
541 centertemp[0] = center[0]-l/2+i*l;
542 centertemp[1] = center[1]-l/2+j*l;
543 centertemp[2] = center[2]-l/2+k*l;
547 centertemp, recttemp, qlist, dist,
548 ani, l0, nc, dim, index) )
577 double rect2[6], center[3], *dist;
584 memcpy(&rect2, rect,
sizeof(
double)*dim*2);
599 dist[q->
nc-3] = rect[0]+rect[3]/2;
600 dist[q->
nc-2] = rect[1]+rect[4]/2;
601 dist[q->
nc-1] = rect[2]+rect[5]/2;
607 for (i = 0; i<index; i++)
613 for (i = 0; i < dim; ++i)
617 memcpy(&rect2, rect,
sizeof(
double)*dim*2);
620 q->
nc, dim, &index) ) {
651 const MMG5_int no,
int nv)
653 double pt[3],quadrant;
654 int dim, nbBitsInt,depthMax,i,j,k;
658 nbBitsInt =
sizeof(int64_t)*8;
660 depthMax = nbBitsInt/dim - 1;
663 if ( q->
depth < depthMax )
675 sizeRealloc = q->
nbVer;
677 MMG5_ADD_MEM(
mesh,(sizeRealloc-sizeRealloc/2)*
sizeof(MMG5_int),
"PROctree realloc",
693 for ( i = 0; i<sizBr; i++)
699 for (i = 0; i<nv; i++)
702 memcpy(&pt,
mesh->
point[q->
v[i]].
c ,dim*
sizeof(
double));
703 for ( j =0; j < q->
depth; j++)
705 for (k = 0; k<dim; k++)
707 pt[k] -= ((double) (pt[k]>0.5))*0.5;
723 for ( i = 0; i<dim; i++)
725 quadrant += ((double) (ver[i]>0.5))*(1<<i);
726 ver[i] -= ((double) (ver[i]>0.5))*0.5;
746 sizeRealloc = q->
nbVer;
748 MMG5_ADD_MEM(
mesh,(sizeRealloc-sizeRealloc/2)*
sizeof(MMG5_int),
"PROctree realloc",
753 else if (q->
nbVer%nv == 0)
781 assert(no<=mesh->np);
782 memcpy(&pt,
mesh->
point[no].
c ,dim*
sizeof(
double));
806 assert(q->
nbVer>indNo);
807 for(i=0; i<q->
nbVer; ++i)
809 memmove(&q->
v[indNo],&q->
v[indNo+1], (q->
nbVer-indNo-1)*
sizeof(MMG5_int));
816 memcpy(vTemp, q->
v,q->
nbVer*
sizeof(MMG5_int));
842 assert(*index+q->
nbVer<=nv);
844 memcpy(&(q0->
v[*index]), q->
v, q->
nbVer*
sizeof(MMG5_int));
846 for(i = 0; i<(*index); ++i)
850 for (i = 0; i<(1<<dim); ++i)
872 assert(q->
nbVer==nv);
874 for (i = 0; i<(1<<dim); ++i)
905 for ( i = 0; i<q->
nbVer; ++i)
919 }
else if ( q->
nbVer == nv+1)
922 for ( i = 0; i<dim; ++i)
924 quadrant += ((double) (ver[i]>0.5))*(1<<i);
925 ver[i] -= ((double) (ver[i]>0.5))*0.5;
929 nbVerTemp = q->
branches[(int)quadrant].nbVer;
949 for ( i = 0; i<dim; ++i)
951 quadrant += ((double) (ver[i]>0.5))*(1<<i);
952 ver[i] -= ((double) (ver[i]>0.5))*0.5;
957 nbVerTemp = q->
branches[(int)quadrant].nbVer;
960 if (nbVerTemp <= q->branches[(
int)quadrant].nbVer)
986 memcpy(&pt,
mesh->
point[no].
c ,dim*
sizeof(
double));
1011 for (i = 0; i < (1<<dim); i++)
1015 }
else if (q->
depth == depth)
1017 fprintf(stdout,
"%i ",q->
nbVer);
1035 for (i = 0; i<(int)
sizeof(
int)*8/dim; i++)
1037 fprintf(stdout,
"\n depth %i \n", i);
1041 fprintf(stdout,
"\n end \n");
1057 for (i = 0; i<(int)
sizeof(
int)*8/dim; i++)
1059 fprintf(stdout,
"\n depth %i \n", i);
1063 fprintf(stdout,
"\n end \n");
1083 for (i= 0; i <(1<<dim); i++)
1088 }
else if(q->
v != NULL)
1099 nVer = (nVer < nv) ? nVer : (
int)(((q->
nbVer-0.1)/nv+1)*nv);
1100 (*s2) += nVer*
sizeof(MMG5_int);
1146 double d2,ux,uy,uz,hpi,hp1,hpi2,methalo[6];
1153 ani[0] =
sol->m[ip];
1154 ani[3] =
sol->m[ip];
1155 ani[5] =
sol->m[ip];
1164 hpi = lmax*
sol->m[ip];
1170 methalo[0] = ppt->
c[0] - hpi;
1171 methalo[1] = ppt->
c[1] - hpi;
1172 methalo[2] = ppt->
c[2] - hpi;
1173 methalo[3] = methalo[4] = methalo[5] = 2.*hpi;
1183 for ( i=0; i<ncells; ++i )
1185 for (j=0; j<lococ[i]->
nbVer; ++j)
1188 ip1 = lococ[i]->
v[j];
1191 hpi2 = lmax *
sol->m[ip1];
1194 ux = pp1->
c[0] - ppt->
c[0];
1195 uy = pp1->
c[1] - ppt->
c[1];
1196 uz = pp1->
c[2] - ppt->
c[2];
1198 d2 = ux*ux + uy*uy + uz*uz;
1200 if ( d2 < hp1 || d2 < hpi2*hpi2 )
1228 double d2,ux,uy,uz,methalo[6];
1229 double det,dmi, *ma, *mb,m1,m2,m3,dx,dy,dz;
1238 iadr = ip*
sol->size;
1246 det = ma[0] * (ma[3]*ma[5] - ma[4]*ma[4])
1247 - ma[1] * (ma[1]*ma[5] - ma[2]*ma[4])
1248 + ma[2] * (ma[1]*ma[4] - ma[3]*ma[2]);
1250 if ( det <= 0. )
return 1;
1253 m1 = ma[3]*ma[5] - ma[4]*ma[4];
1254 m2 = ma[0]*ma[5] - ma[2]*ma[2];
1255 m3 = ma[0]*ma[3] - ma[1]*ma[1];
1257 if ( m1<=0. || m2<=0. || m3<=0.)
return 1;
1259 dx = lmax * sqrt(m1 * det) ;
1260 dy = lmax * sqrt(m2 * det) ;
1261 dz = lmax * sqrt(m3 * det) ;
1269 methalo[0] = ppt->
c[0] - dx;
1270 methalo[1] = ppt->
c[1] - dy;
1271 methalo[2] = ppt->
c[2] - dz;
1284 for ( i=0; i<ncells; ++i )
1286 for (j=0; j<lococ[i]->
nbVer; ++j)
1288 ip1 = lococ[i]->
v[j];
1291 ux = pp1->
c[0] - ppt->
c[0];
1292 uy = pp1->
c[1] - ppt->
c[1];
1293 uz = pp1->
c[2] - ppt->
c[2];
1295 d2 = ma[0]*ux*ux + ma[3]*uy*uy + ma[5]*uz*uz
1296 + 2.0*(ma[1]*ux*uy + ma[2]*ux*uz + ma[4]*uy*uz);
1304 iadr = ip1*
sol->size;
1306 d2 = mb[0]*ux*ux + mb[3]*uy*uy + mb[5]*uz*uz
1307 + 2.0*(mb[1]*ux*uy + mb[2]*ux*uz + mb[4]*uy*uz);
MMG5_pMesh MMG5_pSol * sol
int MMG3D_getListSquareRec(MMG3D_PROctree_s *q, double *center, double *rect, MMG3D_PROctree_s ***qlist, double *dist, double *ani, double l0, int nc, int dim, int *index)
int MMG3D_movePROctree(MMG5_pMesh mesh, MMG3D_pPROctree q, MMG5_int no, double *newVer, double *oldVer)
void MMG3D_mergeBranchesRec(MMG3D_PROctree_s *q0, MMG3D_PROctree_s *q, int dim, int nv, int *index)
int * MMG3D_sizeArbre(MMG3D_pPROctree q, int dim)
void MMG3D_mergeBranches(MMG5_pMesh mesh, MMG3D_PROctree_s *q, int dim, int nv)
int MMG3D_seekIndex(double *distList, double dist, int indexMin, int indexMax)
void MMG3D_printArbre(MMG3D_pPROctree q)
void MMG3D_freePROctree_s(MMG5_pMesh mesh, MMG3D_PROctree_s *q, int nv)
int MMG3D_delPROctreeVertex(MMG5_pMesh mesh, MMG3D_PROctree_s *q, MMG5_int indNo)
int MMG3D_intersectRect(double *rectin, double *rectinout)
void MMG3D_freePROctree(MMG5_pMesh mesh, MMG3D_pPROctree *q)
void MMG3D_initPROctree_s(MMG3D_PROctree_s *q)
void MMG3D_printArbreDepth(MMG3D_PROctree_s *q, int depth, int nv, int dim)
int MMG3D_delPROctreeRec(MMG5_pMesh mesh, MMG3D_PROctree_s *q, double *ver, const MMG5_int no, const int nv)
void MMG3D_placeInListPROctree(MMG3D_PROctree_s **qlist, MMG3D_PROctree_s *q, int index, int size)
int MMG3D_PROctreein_iso(MMG5_pMesh mesh, MMG5_pSol sol, MMG3D_pPROctree PROctree, MMG5_int ip, double lmax)
int MMG3D_getListSquare(MMG5_pMesh mesh, double *ani, MMG3D_pPROctree q, double *rect, MMG3D_PROctree_s ***qlist)
void MMG3D_sizeArbreRec(MMG3D_PROctree_s *q, int nv, int dim, int *s1, int *s2)
int MMG3D_isCellIncluded(double *cellCenter, double l, double *zoneCenter, double l0)
int MMG3D_addPROctree(MMG5_pMesh mesh, MMG3D_pPROctree q, const MMG5_int no)
void MMG3D_printSubArbre(MMG3D_PROctree_s *q, int nv, int dim)
int MMG3D_addPROctreeRec(MMG5_pMesh mesh, MMG3D_PROctree_s *q, double *ver, const MMG5_int no, int nv)
int64_t MMG3D_getPROctreeCoordinate(MMG3D_pPROctree q, double *ver, int dim)
int MMG3D_delPROctree(MMG5_pMesh mesh, MMG3D_pPROctree q, const int no)
int MMG3D_initPROctree(MMG5_pMesh mesh, MMG3D_pPROctree *q, int nv)
void MMG3D_placeInListDouble(double *distList, double dist, int index, int size)
int MMG3D_PROctreein_ani(MMG5_pMesh mesh, MMG5_pSol sol, MMG3D_pPROctree PROctree, MMG5_int ip, double lmax)
Types used throughout the Mmg libraries.
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG5_SAFE_REALLOC(ptr, prevSize, newSize, type, message, law)
#define MMG5_SAFE_MALLOC(ptr, size, type, law)
#define MMG5_DEL_MEM(mesh, ptr)
struct MMG3D_PROctree_s * branches
Structure to store vertices of an MMG mesh.