예제 #1
0
/**
 * \param mesh pointer toward the mesh structure.
 * \param np number of vertices.
 * \param nt number of triangles.
 * \param na number of edges.
 * \return 0 if failed, 1 otherwise.
 *
 * Set the number of vertices, triangles and edges of the
 * mesh and allocate the associated tables. If call twice, reset the
 * whole mesh to realloc it at the new size
 *
 */
int MMGS_Set_meshSize(MMG5_pMesh mesh, int np, int nt, int na) {
  int k;

  if ( ( (mesh->info.imprim > 5) || mesh->info.ddebug ) &&
       ( mesh->point || mesh->tria || mesh->edge) )
    fprintf(stdout,"  ## Warning: new mesh\n");

  mesh->np  = np;
  mesh->nt  = nt;
  mesh->na  = na;
  mesh->npi = mesh->np;
  mesh->nti = mesh->nt;
  mesh->nai = mesh->na;

  if ( mesh->point )
    _MMG5_DEL_MEM(mesh,mesh->point,(mesh->npmax+1)*sizeof(MMG5_Point));
  if ( mesh->tria )
    _MMG5_DEL_MEM(mesh,mesh->tria,(mesh->nt+1)*sizeof(MMG5_Tria));
  if ( mesh->edge )
    _MMG5_DEL_MEM(mesh,mesh->edge,(mesh->na+1)*sizeof(MMG5_Edge));

  /*tester si -m defini : renvoie 0 si pas ok et met la taille min dans info.mem */
  if( mesh->info.mem > 0) {
    if ( mesh->npmax < mesh->np || mesh->ntmax < mesh->nt) {
      _MMGS_memOption(mesh);
      //     printf("pas de pbs ? %d %d %d %d %d %d -- %d\n",mesh->npmax,mesh->np,
      //     mesh->ntmax,mesh->nt,mesh->nemax,mesh->ne,mesh->info.mem);
      if ( mesh->npmax < mesh->np || mesh->ntmax < mesh->nt) {
        fprintf(stdout,"not enough memory: np : %d %d nt : %d %d \n"
                ,mesh->npmax,mesh->np, mesh->ntmax,mesh->nt);
        return(0);
      }
    } else if(mesh->info.mem < 39) {
      printf("not enough memory  %d\n",mesh->info.mem);
      return(0);
    }
  } else {
    mesh->npmax = MG_MAX(1.5*mesh->np,_MMG5_NPMAX);
    mesh->ntmax = MG_MAX(1.5*mesh->nt,_MMG5_NTMAX);

  }
  _MMG5_ADD_MEM(mesh,(mesh->npmax+1)*sizeof(MMG5_Point),"initial vertices",
                printf("  Exit program.\n");
                exit(EXIT_FAILURE));
  _MMG5_SAFE_CALLOC(mesh->point,mesh->npmax+1,MMG5_Point);

  _MMG5_ADD_MEM(mesh,(mesh->ntmax+1)*sizeof(MMG5_Tria),"initial triangles",return(0));
  _MMG5_SAFE_CALLOC(mesh->tria,mesh->ntmax+1,MMG5_Tria);


  mesh->namax = mesh->na;
  if ( mesh->na ) {
    _MMG5_ADD_MEM(mesh,(mesh->na+1)*sizeof(MMG5_Edge),"initial edges",return(0));
    _MMG5_SAFE_CALLOC(mesh->edge,(mesh->na+1),MMG5_Edge);
  }
예제 #2
0
파일: analys.c 프로젝트: XL64/mmg
/** compute normals at C1 vertices, for C0: tangents */
static int _MMG5_norver(MMG5_pMesh mesh) {
    MMG5_pTria     pt;
    MMG5_pPoint    ppt;
    MMG5_xPoint   *pxp;
    double    n[3],dd;
    int      *adja,k,kk,ng,nn,nt,nf;
    char      i,ii,i1;
    /* recomputation of normals only if mesh->xpoint has been freed */
    if ( mesh->xpoint ) {
        if ( abs(mesh->info.imprim) > 3 || mesh->info.ddebug ) {
            fprintf(stdout,"  ## Warning: no research of boundary points");
            fprintf(stdout," and normals of mesh. ");
            fprintf(stdout,"mesh->xpoint must be freed to enforce analysis.\n");
        }
        return(1);
    }

    /* identify boundary points */
    ++mesh->base;
    mesh->xp = 0;
    for (k=1; k<=mesh->nt; k++) {
        pt = &mesh->tria[k];
        if ( !MG_EOK(pt) )  continue;

        for (i=0; i<3; i++) {
            ppt = &mesh->point[pt->v[i]];
            if ( ppt->flag == mesh->base )  continue;
            else {
                ++mesh->xp;
                ppt->flag = mesh->base;
            }
        }
    }

    /* memory to store normals for boundary points */
    mesh->xpmax  = MG_MAX( (long long)(1.5*mesh->xp),mesh->npmax);

    _MMG5_ADD_MEM(mesh,(mesh->xpmax+1)*sizeof(MMG5_xPoint),"boundary points",return(0));
    _MMG5_SAFE_CALLOC(mesh->xpoint,mesh->xpmax+1,MMG5_xPoint);

    /* compute normals + tangents */
    nn = ng = nt = nf = 0;
    mesh->xp = 0;
    ++mesh->base;
    for (k=1; k<=mesh->nt; k++) {
        pt = &mesh->tria[k];
        if ( !MG_EOK(pt) )  continue;

        adja = &mesh->adjt[3*(k-1)+1];
        for (i=0; i<3; i++) {
            ppt = &mesh->point[pt->v[i]];
            if ( ppt->tag & MG_CRN || ppt->tag & MG_NOM || ppt->flag == mesh->base )  continue;

            /* C1 point */
            if ( !MG_EDG(ppt->tag) ) {
                if ( !_MMG5_boulen(mesh,k,i,n) ) {
                    ++nf;
                    continue;
                }
                else {
                    ++mesh->xp;
                    if(mesh->xp > mesh->xpmax){
                        _MMG5_TAB_RECALLOC(mesh,mesh->xpoint,mesh->xpmax,0.2,MMG5_xPoint,
                                     "larger xpoint table",
                                     mesh->xp--;
                                     return(0));
                    }
                    ppt->xp = mesh->xp;
                    pxp = &mesh->xpoint[ppt->xp];
                    memcpy(pxp->n1,n,3*sizeof(double));
                    ppt->flag = mesh->base;
                    nn++;
                }
            }

            /* along ridge-curve */
            i1  = _MMG5_inxt2[i];
            if ( !MG_EDG(pt->tag[i1]) )  continue;
            else if ( !_MMG5_boulen(mesh,k,i,n) ) {
                ++nf;
                continue;
            }
            ++mesh->xp;
            if(mesh->xp > mesh->xpmax){
                _MMG5_TAB_RECALLOC(mesh,mesh->xpoint,mesh->xpmax,0.2,MMG5_xPoint,
                             "larger xpoint table",
                             mesh->xp--;
                             return(0));
            }
            ppt->xp = mesh->xp;
            pxp = &mesh->xpoint[ppt->xp];
            memcpy(pxp->n1,n,3*sizeof(double));

            if ( pt->tag[i1] & MG_GEO && adja[i1] > 0 ) {
                kk = adja[i1] / 3;
                ii = adja[i1] % 3;
                ii = _MMG5_inxt2[ii];
                if ( !_MMG5_boulen(mesh,kk,ii,n) ) {
                    ++nf;
                    continue;
                }
                memcpy(pxp->n2,n,3*sizeof(double));

                /* compute tangent as intersection of n1 + n2 */
                pxp->t[0] = pxp->n1[1]*pxp->n2[2] - pxp->n1[2]*pxp->n2[1];
                pxp->t[1] = pxp->n1[2]*pxp->n2[0] - pxp->n1[0]*pxp->n2[2];
                pxp->t[2] = pxp->n1[0]*pxp->n2[1] - pxp->n1[1]*pxp->n2[0];
                dd = pxp->t[0]*pxp->t[0] + pxp->t[1]*pxp->t[1] + pxp->t[2]*pxp->t[2];
                if ( dd > _MMG5_EPSD2 ) {
                    dd = 1.0 / sqrt(dd);
                    pxp->t[0] *= dd;
                    pxp->t[1] *= dd;
                    pxp->t[2] *= dd;
                }
                ppt->flag = mesh->base;
                ++nt;
                continue;
            }

            /* compute tgte */
            ppt->flag = mesh->base;
            ++nt;
            if ( !_MMG5_boulec(mesh,k,i,pxp->t) ) {
                ++nf;
                continue;
            }
            dd = pxp->n1[0]*pxp->t[0] + pxp->n1[1]*pxp->t[1] + pxp->n1[2]*pxp->t[2];
            pxp->t[0] -= dd*pxp->n1[0];
            pxp->t[1] -= dd*pxp->n1[1];
            pxp->t[2] -= dd*pxp->n1[2];
            dd = pxp->t[0]*pxp->t[0] + pxp->t[1]*pxp->t[1] + pxp->t[2]*pxp->t[2];
            if ( dd > _MMG5_EPSD2 ) {
                dd = 1.0 / sqrt(dd);
                pxp->t[0] *= dd;
                pxp->t[1] *= dd;
                pxp->t[2] *= dd;
            }
        }