コード例 #1
0
ファイル: mmgs1.c プロジェクト: XL64/mmg
/* Analyze triangles and move points to make mesh more uniform */
static int movtri(pMesh mesh,pSol met,int maxit) {
    pTria    pt;
    pPoint   ppt;
    int      it,k,ier,base,nm,ns,nnm,list[LMAX+2],ilist;
    char     i;

    if ( abs(info.imprim) > 5 || info.ddebug )
        fprintf(stdout,"  ** OPTIMIZING MESH\n");

    base = 1;
    for (k=1; k<=mesh->np; k++)  mesh->point[k].flag = base;

    it = nnm = 0;
    do {
        base++;
        nm = ns = 0;
        for (k=1; k<=mesh->nt; k++) {
            pt = &mesh->tria[k];
            if ( !MS_EOK(pt) || pt->ref < 0 )   continue;

            for (i=0; i<3; i++) {
                ppt = &mesh->point[pt->v[i]];

                if ( ppt->flag == base || MS_SIN(ppt->tag) || ppt->tag & MS_NOM )
                    continue;
                ier = 0;
                ilist = boulet(mesh,k,i,list);

                if ( MS_EDG(ppt->tag) ) {
                    ier = movridpt(mesh,met,list,ilist);
                    if ( ier )  ns++;
                }
                else
                    ier = movintpt(mesh,met,list,ilist);
                if ( ier ) {
                    nm++;
                    ppt->flag = base;
                }
            }
        }
        nnm += nm;
        if ( info.ddebug )  fprintf(stdout,"     %8d moved, %d geometry\n",nm,ns);
    }
    while ( ++it < maxit && nm > 0);

    if ( (abs(info.imprim) > 5 || info.ddebug) && nnm > 0 )
        fprintf(stdout,"     %8d vertices moved, %d iter.\n",nnm,it);

    return(nnm);
}
コード例 #2
0
ファイル: colver.c プロジェクト: arthurlevy/mmg
/* collapse edge i of k, i1->i2 */
int litcol(MMG5_pMesh mesh,int k,char i,double kali) {
  MMG5_pTria     pt,pt0,pt1;
  MMG5_pPoint    p1,p2;
  double         kal,ps,cosnold,cosnnew,n0old[3],n0new[3],n1old[3],n1new[3],n00old[3],n00new[3];
  int            *adja,list[_MMG5_LMAX+2],jel,ip2,l,ilist;
  char           i1,i2,j,jj,j2,open;

  pt0 = &mesh->tria[0];
  pt  = &mesh->tria[k];
  i1  = _MMG5_inxt2[i];
  i2  = _MMG5_iprv2[i];
  ip2 = pt->v[i2];

  /* collect all triangles around vertex i1 */
  ilist = boulet(mesh,k,i1,list);

  /* check for open ball */
  adja = &mesh->adja[3*(k-1)+1];
  open = adja[i] == 0;

  if ( ilist > 3 ) {
    /* check references */
    jel = list[1] / 3;
    pt1 = &mesh->tria[jel];
    if ( abs(pt->ref) != abs(pt1->ref) )  return(0);

    /* analyze ball */
    for (l=1; l<ilist-1+open; l++) {
      jel = list[l] / 3;
      j   = list[l] % 3;
      jj  = _MMG5_inxt2[j];
      j2  = _MMG5_iprv2[j];
      pt1 = &mesh->tria[jel];

      /* check normal flipping */
      if ( !_MMG5_nortri(mesh,pt1,n1old) )  return(0);
      memcpy(pt0,pt1,sizeof(MMG5_Tria));
      pt0->v[j] = ip2;
      if ( !_MMG5_nortri(mesh,pt0,n1new) )  return(0);
      ps = n1new[0]*n1old[0] + n1new[1]*n1old[1]  + n1new[2]*n1old[2];
      if ( ps < 0.0 )  return(0);

      /* keep normals at 1st triangles */
      if ( l == 1 && !open ) {
        memcpy(n00old,n1old,3*sizeof(double));
        memcpy(n00new,n1new,3*sizeof(double));
      }

      /* check normals deviation */
      if ( !(pt1->tag[j2] & MG_GEO) ) {
        if ( l > 1 ) {
          cosnold = n0old[0]*n1old[0] + n0old[1]*n1old[1] + n0old[2]*n1old[2];
          cosnnew = n0new[0]*n1new[0] + n0new[1]*n1new[1] + n0new[2]*n1new[2];
          if ( cosnold < _MMG5_ANGEDG ) {
            if ( cosnnew < MG_MIN(0.0,cosnold) )  return(0);
          }
          else if ( cosnnew < _MMG5_ANGEDG )  return(0);
        }

        memcpy(n0old,n1old,3*sizeof(double));
        memcpy(n0new,n1new,3*sizeof(double));
      }
      /* check quality */
      kal = ALPHAD*_MMG5_caltri_iso(mesh,NULL,pt0);
      if ( kal < NULKAL )  return(0);
    }

    /* check angle between 1st and last triangles */
    if ( !open ) {
      cosnold = n00old[0]*n1old[0] + n00old[1]*n1old[1] + n00old[2]*n1old[2];
      cosnnew = n00new[0]*n1new[0] + n00new[1]*n1new[1] + n00new[2]*n1new[2];
      if ( cosnold < _MMG5_ANGEDG ) {
        if ( cosnnew < MG_MIN(0.0,cosnold) )  return(0);
      }
      else if ( cosnnew < _MMG5_ANGEDG )  return(0);

      /* other reference checks */
      jel = list[ilist-1] / 3;
      pt  = &mesh->tria[jel];
      jel = list[ilist-2] / 3;
      pt1 = &mesh->tria[jel];
      if ( abs(pt->ref) != abs(pt1->ref) )  return(0);
    }

    return(colver(mesh,list,ilist));
  }

  /* specific test: no collapse if any interior edge is EDG */
  else if ( ilist == 3 ) {
    p1 = &mesh->point[pt->v[i1]];
    if ( MS_SIN(p1->tag) )  return(0);
    else if (  MG_EDG(pt->tag[i2]) && !MG_EDG(pt->tag[i]) )  return(0);
    else if ( !MG_EDG(pt->tag[i2]) &&  MG_EDG(pt->tag[i]) )  return(0);
    else if (  MG_EDG(pt->tag[i2]) &&  MG_EDG(pt->tag[i]) && MG_EDG(pt->tag[i1]) )  return(0);

    return(colver3(mesh,list));
  }

  /* for specific configurations along open ridge */
  else if ( ilist == 2 ) {
    if ( !open )  return(0);
    jel = list[1] / 3;
    j   = list[1] % 3;
    jj  = _MMG5_inxt2[j];
    pt1 = &mesh->tria[jel];
    if ( abs(pt->ref) != abs(pt1->ref) )  return(0);
    else if ( !(pt1->tag[jj] & MG_GEO) )  return(0);

    p1 = &mesh->point[pt->v[i1]];
    p2 = &mesh->point[pt1->v[jj]];
    if ( p2->tag > p1->tag || p2->ref != p1->ref )  return(0);

    return(colver2(mesh,list));
  }

  return(0);
}