Ejemplo n.º 1
0
Archivo: dcopy.c Proyecto: OpenMDAO/GEM
int
gem_kernelDelete(gemID handle)
{
  ego object;
  
  object = (ego) handle.ident.ptr;
  return EG_deleteObject(object);
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
  assert(argc == 2);
  ego context;
  CALL(EG_open(&context));
  ego model;
  CALL(EG_loadModel(context, 0, argv[1], &model));
  ego model_geom;
  int model_oclass;
  int model_mtype;
  int nbodies;
  ego* bodies;
  int* body_senses;
  CALL(EG_getTopology(model, &model_geom, &model_oclass, &model_mtype, nullptr,
      &nbodies, &bodies, &body_senses));
  printf("model oclass \"%s\" mtype %d has %d bodies\n",
      get_oclass_name(model_oclass), model_mtype, nbodies);
  auto body = bodies[0];
  int nfaces;
  ego* faces;
  CALL(EG_getBodyTopos(body, nullptr, FACE, &nfaces, &faces));
  printf("first body has %d faces\n", nfaces);
  int nedges;
  ego* edges;
  CALL(EG_getBodyTopos(body, nullptr, EDGE, &nedges, &edges));
  printf("first body has %d edges\n", nedges);
  EG_free(edges);
  int nverts;
  ego* verts;
  CALL(EG_getBodyTopos(body, nullptr, NODE, &nverts, &verts));
  printf("first body has %d verts\n", nverts);
  for (int i = 0; i < nverts; ++i) {
    auto pt = get_point(verts[i]);
    printf("point %d at %f %f %f\n", i + 1, pt[0], pt[1], pt[2]);
  }
  EG_free(verts);
  print_closest_point(faces, 1, {{0.0, 0.75, 0.5}});
  print_closest_point(faces, 2, {{0.5, 0.5, 1.0}});
  print_closest_point(faces, 3, {{0.5, 1.0, 0.5}});
  print_closest_point(faces, 4, {{0.5, 0.5, 0.0}});
  print_closest_point(faces, 5, {{0.5 / sqrt(2), 0.5 / sqrt(2), 0.5}});
  print_closest_point(faces, 6, {{1.0, 0.5, 0.5}});
  print_closest_point(faces, 7, {{0.75, 0.0, 0.5}});
  EG_free(faces);
  CALL(EG_deleteObject(model));
  CALL(EG_close(context));
}
Ejemplo n.º 3
0
int
udpReset(int flag)
{
    int   iudp;

    /* reset the "current" settings */
    if (flag == 0) {
        Depth[0] = 1;
        Nseg[ 0] = 0;

        if (Segments[0] != NULL) {
            EG_free(Segments[0]);
            Segments[0] = NULL;
        }

    /* called when closing up */
    } else {
        for (iudp = 0; iudp <= numUdp; iudp++) {
            if (ebodys[iudp] != NULL) {
                EG_deleteObject(ebodys[iudp]);
                ebodys[iudp] = NULL;
            }
            if (Segments[iudp] != NULL) {
                EG_free(Segments[iudp]);
                Segments[iudp] = NULL;
            }
        }

        EG_free(ebodys  );  ebodys    = NULL;
        EG_free(Depth   );  Depth     = NULL;
        EG_free(Nseg    );  Nseg      = NULL;
        EG_free(Segments);  *Segments = NULL;

        numUdp = 0;
    }

    return EGADS_SUCCESS;
}
Ejemplo n.º 4
0
int
gem_kernelSBO(gemID src, gemID tool, /*@null@*/ double *xform, int type,
              gemModel **model)
{
  int      i, stat, nBRep;
  char     name[25];
  ego      context, obj1, obj2, omdl, oform, copy;
  gemID    gid;
  gemModel *mdl, *prev;
  gemBRep  **BReps;
  gemCntxt *cntxt;
  static int   nBool    = 0;
  static char *nType[3] = {"Subtract", "Intersection", "Union"};

  /* find the context */
  mdl    = *model;
  *model = NULL;
  cntxt  = NULL;
  prev   = mdl->prev;
  while (cntxt == NULL) {
    if  (prev  == NULL) return GEM_BADCONTEXT;
    if ((prev->magic != GEM_MMODEL) && 
        (prev->magic != GEM_MCONTEXT)) return GEM_BADOBJECT;
    if  (prev->magic == GEM_MCONTEXT)  cntxt = (gemCntxt *) prev;
    if  (prev->magic == GEM_MMODEL)    prev  = prev->prev;
  }

  /* do the operation */
  obj1 = (ego) src.ident.ptr;
  obj2 = (ego) tool.ident.ptr;
  if (xform != NULL) {
    stat = EG_getContext(obj2, &context);
    if (stat != EGADS_SUCCESS) return stat;
    stat = EG_makeTransform(context, xform, &oform);
    if (stat != EGADS_SUCCESS) return stat;
    stat = EG_copyObject(obj2, oform, &copy);
    EG_deleteObject(oform);
    if (stat != EGADS_SUCCESS) return stat;
    stat = EG_solidBoolean(obj1, copy, type, &omdl);
    EG_deleteObject(copy);
  } else {
    stat = EG_solidBoolean(obj1, obj2, type, &omdl);
  }
  if (stat != EGADS_SUCCESS) return stat;

  /* fill up the BReps */
  nBool++;
  snprintf(name, 25, "%s-%d", nType[type-1], nBool);
  i    = strlen(name);
  stat = gem_fillModelE(omdl, name, i, &nBRep, &BReps);
  if (stat != EGADS_SUCCESS) return stat;

  mdl = (gemModel *) gem_allocate(sizeof(gemModel));
  if (mdl == NULL) return GEM_ALLOC;

  gid.index      = 0;
  gid.ident.ptr  = omdl;

  mdl->magic     = GEM_MMODEL;
  mdl->handle    = gid;
  mdl->nonparam  = 1;
  mdl->server    = NULL;
  mdl->location  = NULL;
  mdl->modeler   = gem_strdup("EGADS");
  mdl->nBRep     = nBRep;
  mdl->BReps     = BReps;
  mdl->nParams   = 0;
  mdl->Params    = NULL;
  mdl->nBranches = 0;
  mdl->Branches  = NULL;
  mdl->attr      = NULL;
  mdl->prev      = (gemModel *) cntxt;
  mdl->next      = NULL;
    
  for (i = 0; i < nBRep; i++) BReps[i]->omodel = mdl;

  /* insert into context */
  prev = cntxt->model;
  cntxt->model = mdl;
  if (prev != NULL) {
    mdl->next  = prev;
    prev->prev = cntxt->model;
  }
  
  *model = mdl;
  return EGADS_SUCCESS;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  int i, mtype, oclass, nbody, nface, nedge, iface, *senses;
  ego context, model1, model2, wModel, newModel, geom, body;
  ego *bodies1, *bodies2, *faces, *facEdge;

  if (argc != 4) {
    printf("\n Usage: intersect model(body) model(face) face#\n\n");
    return 1;
  }
  iface = atoi(argv[3]);

  /* initialize */
  printf(" EG_open           = %d\n", EG_open(&context));
  printf(" EG_loadModel 1    = %d\n", EG_loadModel(context, 0, argv[1], &model1));
  printf(" EG_loadModel 2    = %d\n", EG_loadModel(context, 0, argv[2], &model2));
  /* get all bodies */
  printf(" EG_getTopology 1  = %d\n", EG_getTopology(model1, &geom, &oclass, 
                                                     &mtype, NULL, &nbody,
                                                     &bodies1, &senses));
  printf(" EG_getTopology 2  = %d\n", EG_getTopology(model2, &geom, &oclass, 
                                                     &mtype, NULL, &nbody,
                                                     &bodies2, &senses));
  printf(" EG_getBodyTopos   = %d\n", EG_getBodyTopos(bodies2[0], NULL, FACE,
                                                      &nface, &faces));
  if ((iface < 1) || (iface > nface)) {
    printf(" ERROR: face # = %d [1-%d]!\n\n", iface, nface);
    printf(" EG_deleteObject   = %d\n", EG_deleteObject(model2));
    printf(" EG_deleteObject   = %d\n", EG_deleteObject(model1));
    printf(" EG_close          = %d\n", EG_close(context));
    return 1;
  }
  iface--;
  printf(" \n");
  
  printf(" EG_intersection   = %d\n", EG_intersection(bodies1[0], faces[iface],
                                                      &nedge, &facEdge, 
                                                      &wModel));
  printf("             nedge = %d\n", nedge);
  printf(" EG_saveModel      = %d\n", EG_saveModel(wModel, "wModel.egads"));

  printf(" EG_imprintBody    = %d\n", EG_imprintBody(bodies1[0], nedge, facEdge,
                                                     &body));
  for (i = 0; i < nedge; i++) facEdge[2*i] = faces[2];
  printf(" EG_imprintBody    = %d\n", EG_imprintBody(bodies2[0], nedge, facEdge,
                                                     &body));
  printf(" EG_makeTopology   = %d\n", EG_makeTopology(context, NULL, MODEL, 0,
                                                      NULL, 1, &body, NULL,
                                                      &newModel));
  printf(" EG_saveModel      = %d\n", EG_saveModel(newModel, "newModel.egads"));
                                                
  printf("\n");
  printf(" EG_deleteObject   = %d\n", EG_deleteObject(newModel));
  printf(" EG_deleteObject   = %d\n", EG_deleteObject(  wModel));
  EG_free(facEdge);
  EG_free(faces);
  printf(" EG_deleteObject   = %d\n", EG_deleteObject(model2));
  printf(" EG_deleteObject   = %d\n", EG_deleteObject(model1));
  printf(" EG_close          = %d\n", EG_close(context));
  return 0;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
    int    i, j, status, oclass, mtype, nbody, nvert, ntriang, nface, *triang;
    char   filename[20];
    float  arg;
    double params[3], box[6], size, *verts;
    FILE   *fp;
    ego    context, model, geom, *bodies, tess, *dum, *faces;

    if ((argc != 2) && (argc != 5)) {
        printf(" Usage: egads2cart Model [angle relSide relSag]\n\n");
        return 1;
    }

    /* look at EGADS revision */
    EG_revision(&i, &j);
    printf("\n Using EGADS %2d.%02d\n\n", i, j);

    /* initialize */
    status = EG_open(&context);
    if (status != EGADS_SUCCESS) {
        printf(" EG_open = %d!\n\n", status);
        return 1;
    }
    status = EG_loadModel(context, 0, argv[1], &model);
    if (status != EGADS_SUCCESS) {
        printf(" EG_loadModel = %d\n\n", status);
        return 1;
    }
    status = EG_getBoundingBox(model, box);
    if (status != EGADS_SUCCESS) {
        printf(" EG_getBoundingBox = %d\n\n", status);
        return 1;
    }
    size = sqrt((box[0]-box[3])*(box[0]-box[3]) + (box[1]-box[4])*(box[1]-box[4]) +
                (box[2]-box[5])*(box[2]-box[5]));

    /* get all bodies */
    status = EG_getTopology(model, &geom, &oclass, &mtype, NULL, &nbody,
                            &bodies, &triang);
    if (status != EGADS_SUCCESS) {
        printf(" EG_getTopology = %d\n\n", status);
        return 1;
    }

    params[0] =  0.025*size;
    params[1] =  0.001*size;
    params[2] = 15.0;
    if (argc == 5) {
        sscanf(argv[2], "%f", &arg);
        params[2] = arg;
        sscanf(argv[3], "%f", &arg);
        params[0] = arg;
        sscanf(argv[4], "%f", &arg);
        params[1] = arg;
        printf(" Using angle = %lf,  relSide = %lf,  relSag = %lf\n",
               params[2], params[0], params[1]);
        params[0] *= size;
        params[1] *= size;
    }

    printf(" Number of Bodies = %d\n\n", nbody);

    /* write out each body as a different Cart3D ASCII tri file */

    for (i = 0; i < nbody; i++) {
        sprintf(filename, "egads.%3.3d.a.tri", i+1);

        mtype = 0;
        EG_getTopology(bodies[i], &geom, &oclass,
                       &mtype, NULL, &j, &dum, &triang);
        if (mtype != SOLIDBODY) continue;   /* only Solid Bodies! */

        status = EG_makeTessBody(bodies[i], params, &tess);
        if (status != EGADS_SUCCESS) {
            printf(" EG_makeTessBody %d = %d\n", i, status);
            continue;
        }
        status = EG_getBodyTopos(bodies[i], NULL, FACE, &nface, &faces);
        if (status != EGADS_SUCCESS) {
            printf(" EG_getBodyTopos %d = %d\n", i, status);
            EG_deleteObject(tess);
            continue;
        }
        EG_free(faces);

        /* zip up the tessellation */

        status = bodyTessellation(tess, nface, &nvert, &verts, &ntriang, &triang);
        EG_deleteObject(tess);
        if (status != EGADS_SUCCESS) continue;

        /* write it out */

        fp = fopen(filename, "w");
        if (fp == NULL) {
            printf(" Can not Open file %s! NO FILE WRITTEN\n", filename);
            EG_free(verts);
            EG_free(triang);
            continue;
        }
        printf("\nWriting Cart3D component file %s\n", filename);
        /* header */
        fprintf(fp, "%d  %d\n", nvert, ntriang);
        /* ...vertList     */
        for(j = 0; j < nvert; j++)
            fprintf(fp, " %f  %f  %f\n", verts[3*j  ], verts[3*j+1], verts[3*j+2]);
        /* ...Connectivity */
        for (j = 0; j < ntriang; j++)
            fprintf(fp, "%6d %6d %6d\n",triang[3*j], triang[3*j+1], triang[3*j+2]);
        /* ...Component list*/
        for (j = 0; j < ntriang; j++)
            fprintf(fp, "%6d\n", i);
        fclose(fp);

        printf("      # verts = %d,  # tris = %d\n\n", nvert, ntriang);
        EG_free(verts);
        EG_free(triang);
    }

    status = EG_deleteObject(model);
    if (status != EGADS_SUCCESS) printf(" EG_deleteObject = %d\n", status);
    EG_close(context);

    return 0;
}
Ejemplo n.º 7
0
int
gem_kernelRegen(gemModel *model)
{
  int    i, j, k, n, nrow, ncol;
  int    stat, actv, type, buildTo, builtTo, nBRep, ibody;
  char   defn[22], name[129];
  void   *modl;
  double real;
  ego    obj;
  modl_T *MODL;
  gemID  handle;
  
  modl = model->handle.ident.ptr;
  MODL = (modl_T *) modl;
  MODL->context = dia_context;
  for (i = 0; i < model->nParams; i++) {
    if (model->Params[i].changed == 0) continue;
    if (model->Params[i].type != GEM_REAL) return GEM_BADTYPE;
  }
  for (i = 0; i < model->nParams; i++) {
    if (model->Params[i].changed == 0) continue;
    stat = ocsmGetPmtr(modl, i+1, &type, &nrow, &ncol, name);
    if (stat != SUCCESS) return stat;
    if ((nrow == 1) && (ncol == 1)) {
      snprintf(defn, 21, "%20.13le", model->Params[i].vals.real);
      defn[21] = 0;
      stat = ocsmSetValu(modl,i+1, 1, 1, defn);
      if (stat != SUCCESS)
        printf(" GEM/OpenCSM status = %d on changing %s to %s!\n",
               stat, model->Params[i].name, defn);
    } else {
      for (n = j = 0; j < ncol; j++)
        for (k = 0; k < nrow; k++, n++) {
          snprintf(defn, 21, "%20.13le", model->Params[i].vals.reals[n]);
          defn[21] = 0;
          stat = ocsmSetValu(modl,i+1, k+1, j+1, defn);
          if (stat != SUCCESS)
            printf(" GEM/OpenCSM status = %d on changing %s[%d,%d] to %s!\n",
                   stat, model->Params[i].name, k+1, j+1, defn);
        }
    }
    model->Params[i].changed = 0;
  }

  for (i = 0; i < model->nBranches; i++) {
    if  (model->Branches[i].changed == 0) continue;  
    actv = OCSM_ACTIVE;
    if (model->Branches[i].sflag == GEM_SUPPRESSED) actv = OCSM_SUPPRESSED;
    stat = ocsmSetBrch(modl, i, actv);
    if (stat != SUCCESS)
      printf(" GEM/OpenCSM status = %d on changing %s to %d!\n",
             stat, model->Branches[i].name, actv);
    model->Branches[i].changed = 0;
  }
  
  /* remove old geometry, rebuild */
  
  for (i = 0; i < model->nBRep; i++) {
    obj = (ego) model->BReps[i]->body->handle.ident.ptr;
    EG_deleteObject(obj);
    gem_releaseBRep(model->BReps[i]);
  }
  gem_free(model->BReps);
  model->BReps = NULL;
  model->nBRep = 0;
  gem_clrDReps(model, 0);
  
  buildTo = 0;                          /* all */
  nbody   = MAX_BODYS;
  stat    = ocsmBuild(modl, buildTo, &builtTo, &nbody, bodyList);
  EG_deleteObject(dia_context);         /* clean up after build */
  if (stat != SUCCESS) return stat;
  nBRep = nbody;

  /* put away the new BReps */
  model->BReps = (gemBRep **) gem_allocate(nBRep*sizeof(gemBRep *));
  if (model->BReps == NULL) {
    for (i = 0; i < nbody; i++) {
      ibody = bodyList[i];
      obj   = MODL->body[ibody].ebody;
      EG_deleteObject(obj);
    }
    return GEM_ALLOC;
  }
  handle.index     = 0;
  handle.ident.ptr = modl;
  for (i = 0; i < nBRep; i++) {
    model->BReps[i] = (gemBRep *) gem_allocate(sizeof(gemBRep));
    if (model->BReps[i] == NULL) {
      for (j = 0; j < i; j++) gem_free(model->BReps[j]);
      gem_free(model->BReps);
      model->BReps = NULL;
      for (j = 0; j < nbody; j++) {
        ibody = bodyList[j];
        obj   = MODL->body[ibody].ebody;
        EG_deleteObject(obj);
      }
      return GEM_ALLOC;
    }
    model->BReps[i]->magic   = GEM_MBREP;
    model->BReps[i]->omodel  = NULL;
    model->BReps[i]->phandle = handle;
    model->BReps[i]->ibranch = 0;
    model->BReps[i]->inumber = 0;
    model->BReps[i]->body    = NULL;
  }
  
  /* reload the BReps */
  for (j = i = 0; i < nbody; i++) {
    ibody = bodyList[i];
    obj   = MODL->body[ibody].ebody;
    stat  = gem_diamondBody(obj, NULL, model->BReps[j]);
    if (stat != EGADS_SUCCESS) {
      for (j = 0; j < nBRep; j++) gem_releaseBRep(model->BReps[j]);
      gem_free(model->BReps);
      model->BReps = NULL;
      for (j = 0; j < nbody; j++) {
        ibody = bodyList[j];
        obj   = MODL->body[ibody].ebody;
        EG_deleteObject(obj);
      }
      return stat;
    }
  }
  for (i = 0; i < nBRep; i++) model->BReps[i]->omodel = model;
  model->nBRep = nBRep;
  gem_clrDReps(model, 1);
  
  /* refresh the parameters */
  for (i = 0; i < model->nParams; i++) {
    stat = ocsmGetPmtr(modl, i+1, &type, &nrow, &ncol, name);
    if (stat != SUCCESS) continue;
    if ((nrow == 1) && (ncol == 1)) {
      stat = ocsmGetValu(modl, i+1, 1, 1, &real);
      if (stat != SUCCESS) continue;
      model->Params[i].vals.real = real;
    } else {
      for (n = j = 0; j < ncol; j++)
        for (k = 0; k < nrow; k++, n++) {
          stat = ocsmGetValu(modl, i+1, k+1, j+1, &real);
          if (stat != SUCCESS) continue;
          model->Params[i].vals.reals[n] = real;
        }
    }
  }

  return GEM_SUCCESS;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
  int          i, j, k, m, n, ibody, stat, oclass, mtype, len, ntri, sum;
  int          nloops, nseg, nledges, *segs, *lsenses, *senses, *esenses;
  int          nh, *heads;
  const int    *tris, *tric, *ptype, *pindex;
  float        arg, color[3], *lsegs;
  double       box[6], size;
  const double *xyzs, *uvs, *ts;
  char         gpname[33], *startapp;
  ego          context, model, geom, *bodies, *dum, *ledges, *loops;
  wvData       items[5];
  float        eye[3]    = {0.0, 0.0, 7.0};
  float        center[3] = {0.0, 0.0, 0.0};
  float        up[3]     = {0.0, 1.0, 0.0};

  /* get our starting application line 
   * 
   * for example on a Mac:
   * setenv wvStart "open -a /Applications/Firefox.app ../client/wv.html"
   */
  startapp = getenv("wvStart");
  
  if ((argc != 2) && (argc != 5)) {
    printf("\n Usage: vTess filename [angle maxlen sag]\n\n");
    return 1;
  }

  /* look at EGADS revision */
  EG_revision(&i, &j);
  printf("\n Using EGADS %2d.%02d\n\n", i, j);

  /* initialize */
  printf(" EG_open           = %d\n", EG_open(&context));
  printf(" EG_loadModel      = %d\n", EG_loadModel(context, 0, argv[1], &model));
  printf(" EG_getBoundingBox = %d\n", EG_getBoundingBox(model, box));
  printf("       BoundingBox = %lf %lf %lf\n", box[0], box[1], box[2]);
  printf("                     %lf %lf %lf\n", box[3], box[4], box[5]);  
  printf(" \n");
  
                            size = box[3]-box[0];
  if (size < box[4]-box[1]) size = box[4]-box[1];
  if (size < box[5]-box[2]) size = box[5]-box[2];

  focus[0] = 0.5*(box[0]+box[3]);
  focus[1] = 0.5*(box[1]+box[4]);
  focus[2] = 0.5*(box[2]+box[5]);
  focus[3] = size;
  
  /* get all bodies */
  stat = EG_getTopology(model, &geom, &oclass, &mtype, NULL, &nbody,
                        &bodies, &senses);
  if (stat != EGADS_SUCCESS) {
    printf(" EG_getTopology = %d\n", stat);
    return 1;
  }
  printf(" EG_getTopology:     nBodies = %d\n", nbody);
  bodydata = (bodyData *) malloc(nbody*sizeof(bodyData));
  if (bodydata == NULL) {
    printf(" MALLOC Error on Body storage!\n");
    return 1;
  }

  EG_setOutLevel(context, 2);		/* get some Debug output */
  params[0] =  0.025*size;
  params[1] =  0.001*size;
  params[2] = 15.0;
  if (argc == 5) {
    sscanf(argv[2], "%f", &arg);
    params[2] = arg;
    sscanf(argv[3], "%f", &arg);
    params[0] = arg;
    sscanf(argv[4], "%f", &arg);
    params[1] = arg;
    printf(" Using angle = %lf,  relSide = %lf,  relSag = %lf\n",
           params[2], params[0], params[1]);
    params[0] *= size;
    params[1] *= size;
  }
  
  /* fill our structure a body at at time */
  for (ibody = 0; ibody < nbody; ibody++) {
  
    mtype = 0;
    EG_getTopology(bodies[ibody], &geom, &oclass, 
                   &mtype, NULL, &j, &dum, &senses);
    bodydata[ibody].body  = bodies[ibody];
    bodydata[ibody].mtype = mtype;
    if (mtype == WIREBODY) {
      printf(" Body %d: Type = WireBody\n", ibody+1);
    } else if (mtype == FACEBODY) {
      printf(" Body %d: Type = FaceBody\n", ibody+1);
    } else if (mtype == SHEETBODY) {
      printf(" Body %d: Type = SheetBody\n", ibody+1);
    } else {
      printf(" Body %d: Type = SolidBody\n", ibody+1);
    }

    stat = EG_getBodyTopos(bodies[ibody], NULL, FACE, 
                           &bodydata[ibody].nfaces, &bodydata[ibody].faces);
    i    = EG_getBodyTopos(bodies[ibody], NULL, EDGE, 
                           &bodydata[ibody].nedges, &bodydata[ibody].edges);
    if ((stat != EGADS_SUCCESS) || (i != EGADS_SUCCESS)) {
      printf(" EG_getBodyTopos Face = %d\n", stat);
      printf(" EG_getBodyTopos Edge = %d\n", i);
      return 1;
    }
    
    stat = EG_makeTessBody(bodies[ibody], params, &bodydata[ibody].tess);
    if (stat != EGADS_SUCCESS) {
      printf(" EG_makeTessBody %d = %d\n", ibody, stat);
      continue;
    }
  }
  printf(" \n");

  /* create the WebViewer context */
  cntxt = wv_createContext(1, 30.0, 1.0, 10.0, eye, center, up);
  if (cntxt == NULL) printf(" failed to create wvContext!\n");
        
  /* make the scene */
  for (sum = stat = ibody = 0; ibody < nbody; ibody++) {
  
    /* get faces */
    for (i = 0; i < bodydata[ibody].nfaces; i++) {
      stat = EG_getTessFace(bodydata[ibody].tess, i+1, &len,
                            &xyzs, &uvs, &ptype, &pindex, &ntri,
                            &tris, &tric);
      if (stat != EGADS_SUCCESS) continue;
      sprintf(gpname, "Body %d Face %d", ibody+1, i+1);
      stat = wv_setData(WV_REAL64, len, (void *) xyzs,  WV_VERTICES, &items[0]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 0!\n", i, gpname);
      wv_adjustVerts(&items[0], focus);
      stat = wv_setData(WV_INT32, 3*ntri, (void *) tris, WV_INDICES, &items[1]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 1!\n", i, gpname);
      color[0]  = 1.0;
      color[1]  = ibody;
      color[1] /= nbody;
      color[2]  = 0.0;
      stat = wv_setData(WV_REAL32, 1, (void *) color,  WV_COLORS, &items[2]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 2!\n", i, gpname);
      for (nseg = j = 0; j < ntri; j++)
        for (k = 0; k < 3; k++)
          if (tric[3*j+k] < j+1) nseg++;
      segs = (int *) malloc(2*nseg*sizeof(int));
      if (segs == NULL) {
        printf(" Can not allocate %d Sides!\n", nseg);
        continue;
      }
      for (nseg = j = 0; j < ntri; j++)
        for (k = 0; k < 3; k++)
          if (tric[3*j+k] < j+1) {
            segs[2*nseg  ] = tris[3*j+sides[k][0]];
            segs[2*nseg+1] = tris[3*j+sides[k][1]];
            nseg++;
          }
      stat = wv_setData(WV_INT32, 2*nseg, (void *) segs, WV_LINDICES, &items[3]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 3!\n", i, gpname);
      free(segs);
/*    color[0] = color[1] = color[2] = 0.8;  */
      color[0] = color[1] = color[2] = 0.0;
      stat = wv_setData(WV_REAL32, 1, (void *) color,  WV_LCOLOR, &items[4]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 4!\n", i, gpname);
      stat = wv_addGPrim(cntxt, gpname, WV_TRIANGLE, 
                         WV_ON|WV_ORIENTATION, 5, items);
      if (stat < 0) {
        printf(" wv_addGPrim = %d for %s!\n", stat, gpname);
      } else {
        if (cntxt != NULL)
          if (cntxt->gPrims != NULL) cntxt->gPrims[stat].lWidth = 1.0;
      }
      sum += ntri;
    }
    
    /* get loops */
    color[0] = color[1] = 0.0;
    color[2] = 1.0;
    for (i = 0; i < bodydata[ibody].nfaces; i++) {
      stat = EG_getTopology(bodydata[ibody].faces[i], &geom, &oclass, 
                            &mtype, NULL, &nloops, &loops, &lsenses);
      if (stat != EGADS_SUCCESS) continue;
      for (nh = j = 0; j < nloops; j++) {
        stat = EG_getTopology(loops[j], &geom, &oclass, &mtype, NULL, 
                              &nledges, &ledges, &esenses);
        if (stat != EGADS_SUCCESS) continue;
        
        /* count */
        for (ntri = nseg = k = 0; k < nledges; k++) {
          m = 0;
          while (ledges[k] != bodydata[ibody].edges[m]) {
            m++;
            if (m == bodydata[ibody].nedges) break;
          }
          /* assume that the edge is degenerate and removed */
          if (m == bodydata[ibody].nedges) continue;
          stat = EG_getTessEdge(bodydata[ibody].tess, m+1, &len,
                                &xyzs, &ts);
          if (stat != EGADS_SUCCESS) {
            printf(" EG_getTessEdge %d = %d!\n", m+1, stat);
            nseg = 0;
            break;
          }
          if (len == 2) 
            if ((xyzs[0] == xyzs[3]) && (xyzs[1] == xyzs[4]) &&
                (xyzs[2] == xyzs[5])) continue;
          nh++;
#ifdef NONINDEXED
          nseg += 2*(len-1);
#else
          nseg += len;
          ntri += 2*(len-1);
#endif
        }
        if (nseg == 0) continue;
        lsegs = (float *) malloc(3*nseg*sizeof(float));
        if (lsegs == NULL) {
          printf(" Can not allocate %d Segments!\n", nseg);
          continue;
        }
#ifndef NONINDEXED
        segs = (int *) malloc(ntri*sizeof(int));
        if (segs == NULL) {
          printf(" Can not allocate %d Line Segments!\n", ntri);
          free(lsegs);
          continue;
        }
#endif
        heads = (int *) malloc(nh*sizeof(int));
        if (heads == NULL) {
          printf(" Can not allocate %d Heads!\n", nh);
#ifndef NONINDEXED
          free(segs);
#endif
          free(lsegs);
          continue;
        }        
        
        /* fill */
        for (nh = ntri = nseg = k = 0; k < nledges; k++) {
          m = 0;
          while (ledges[k] != bodydata[ibody].edges[m]) {
            m++;
            if (m == bodydata[ibody].nedges) break;
          }
          /* assume that the edge is degenerate and removed */
          if (m == bodydata[ibody].nedges) continue;
          EG_getTessEdge(bodydata[ibody].tess, m+1, &len, &xyzs, &ts);
          if (len == 2) 
            if ((xyzs[0] == xyzs[3]) && (xyzs[1] == xyzs[4]) &&
                (xyzs[2] == xyzs[5])) continue;
#ifdef NONINDEXED
          if (esenses[k] == -1) heads[nh] = -nseg/2 - 1;
          for (n = 0; n < len-1; n++) {
            lsegs[3*nseg  ] = xyzs[3*n  ];
            lsegs[3*nseg+1] = xyzs[3*n+1];
            lsegs[3*nseg+2] = xyzs[3*n+2];
            nseg++;
            lsegs[3*nseg  ] = xyzs[3*n+3];
            lsegs[3*nseg+1] = xyzs[3*n+4];
            lsegs[3*nseg+2] = xyzs[3*n+5];
            nseg++;
          }
          if (esenses[k] ==  1) heads[nh] = nseg/2;
#else
          if (esenses[k] == -1) heads[nh] = -ntri/2 - 1;
          for (n = 0; n < len-1; n++) {
            segs[ntri] = n+nseg+1;
            ntri++;
            segs[ntri] = n+nseg+2;
            ntri++;
          }
          if (esenses[k] ==  1) heads[nh] = ntri/2;
          for (n = 0; n < len; n++) {
            lsegs[3*nseg  ] = xyzs[3*n  ];
            lsegs[3*nseg+1] = xyzs[3*n+1];
            lsegs[3*nseg+2] = xyzs[3*n+2];
            nseg++;
          }
#endif
          nh++;
        }
        sprintf(gpname, "Body %d Loop %d/%d", ibody+1, i+1, j+1);
        stat = wv_setData(WV_REAL32, nseg, (void *) lsegs,  WV_VERTICES, &items[0]);
        if (stat < 0) printf(" wv_setData = %d for %s/item 0!\n", i, gpname);
        wv_adjustVerts(&items[0], focus);
        free(lsegs);
        stat = wv_setData(WV_REAL32, 1, (void *) color,  WV_COLORS, &items[1]);
        if (stat < 0) printf(" wv_setData = %d for %s/item 1!\n", i, gpname);
#ifdef NONINDEXED
        stat = wv_addGPrim(cntxt, gpname, WV_LINE, WV_ON, 2, items);
#else
        stat = wv_setData(WV_INT32, ntri, (void *) segs, WV_INDICES, &items[2]);
        if (stat < 0) printf(" wv_setData = %d for %s/item 2!\n", i, gpname);
        free(segs);
        stat = wv_addGPrim(cntxt, gpname, WV_LINE, WV_ON, 3, items);
#endif
        if (stat < 0) {
          printf(" wv_addGPrim = %d for %s!\n", stat, gpname);
        } else {
          if (cntxt != NULL)
            if (cntxt->gPrims != NULL) {
              cntxt->gPrims[stat].lWidth = 1.0;
              n = wv_addArrowHeads(cntxt, stat, 0.05, nh, heads);
              if (n != 0) printf(" wv_addArrowHeads = %d\n", n);
            }
        }
        free(heads);
/*      wv_printGPrim(cntxt, stat);  */
      }
    }
  }
  printf(" ** %d gPrims with %d triangles **\n", stat+1, sum);

  /* start the server code */

  stat = 0;
  if (wv_startServer(7681, NULL, NULL, NULL, 0, cntxt) == 0) {

    /* we have a single valid server -- stay alive a long as we have a client */
    while (wv_statusServer(0)) {
      usleep(500000);
      if (stat == 0) {
        if (startapp != NULL) system(startapp);
        stat++;
      }
/*    wv_broadcastText("I'm here!");  */
    }
  }
  wv_cleanupServers();

  /* finish up */
  for (ibody = 0; ibody < nbody; ibody++) {
    EG_deleteObject(bodydata[ibody].tess);
    EG_free(bodydata[ibody].edges);
    EG_free(bodydata[ibody].faces);
  }
  free(bodydata);

  printf(" EG_deleteObject   = %d\n", EG_deleteObject(model));
  printf(" EG_close          = %d\n", EG_close(context));
  return 0;
}
Ejemplo n.º 9
0
void browserMessage(/*@unused@*/ void *wsi, char *text, /*@unused@*/ int lena)
{
  int          i, j, k, m, n, ibody, stat, sum, len, ntri, index, oclass, mtype;
  int          nloops, nseg, nledges, *segs, *lsenses, *esenses;
  int          nh, *heads;
  const int    *tris, *tric, *ptype, *pindex;
  char         gpname[33];
  float        *lsegs;
  const double *xyzs, *uvs, *ts;
  ego          geom, *ledges, *loops;
  wvData       items[3];
  
  printf(" RX: %s\n", text);
  /* ping it back
  wv_sendText(wsi, text); */
  
  if ((strcmp(text,"finer") != 0) && (strcmp(text,"coarser") != 0)) return;
  if  (strcmp(text,"finer") != 0) {
    params[0] *= 2.0;
  } else {
    params[0] *= 0.5;
  }

  printf(" Using angle = %lf,  relSide = %lf,  relSag = %lf\n",
         params[2], params[0], params[1]);
         
  for (ibody = 0; ibody < nbody; ibody++) {
    EG_deleteObject(bodydata[ibody].tess);
    bodydata[ibody].tess = NULL;
    stat = EG_makeTessBody(bodydata[ibody].body, params, &bodydata[ibody].tess);
    if (stat != EGADS_SUCCESS)
      printf(" EG_makeTessBody %d = %d\n", ibody, stat);
  }

  /* make the scene */
  for (sum = stat = ibody = 0; ibody < nbody; ibody++) {
  
    /* get faces */
    for (i = 0; i < bodydata[ibody].nfaces; i++) {
      stat = EG_getTessFace(bodydata[ibody].tess, i+1, &len,
                            &xyzs, &uvs, &ptype, &pindex, &ntri,
                            &tris, &tric);
      if (stat != EGADS_SUCCESS) continue;
      sprintf(gpname, "Body %d Face %d", ibody+1, i+1);
      index = wv_indexGPrim(cntxt, gpname);
      if (index < 0) {
        printf(" wv_indexGPrim = %d for %s (%d)!\n", i, gpname, index);
        continue;
      }
      stat = wv_setData(WV_REAL64, len, (void *) xyzs,  WV_VERTICES, &items[0]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 0!\n", i, gpname);
      wv_adjustVerts(&items[0], focus);
      stat = wv_setData(WV_INT32, 3*ntri, (void *) tris, WV_INDICES, &items[1]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 1!\n", i, gpname);
      for (nseg = j = 0; j < ntri; j++)
        for (k = 0; k < 3; k++)
          if (tric[3*j+k] < j+1) nseg++;
      segs = (int *) malloc(2*nseg*sizeof(int));
      if (segs == NULL) {
        printf(" Can not allocate %d Sides!\n", nseg);
        continue;
      }
      for (nseg = j = 0; j < ntri; j++)
        for (k = 0; k < 3; k++)
          if (tric[3*j+k] < j+1) {
            segs[2*nseg  ] = tris[3*j+sides[k][0]];
            segs[2*nseg+1] = tris[3*j+sides[k][1]];
            nseg++;
          }
      stat = wv_setData(WV_INT32, 2*nseg, (void *) segs, WV_LINDICES, &items[2]);
      if (stat < 0) printf(" wv_setData = %d for %s/item 2!\n", i, gpname);
      free(segs);
      stat = wv_modGPrim(cntxt, index, 3, items);
      if (stat < 0)
        printf(" wv_modGPrim = %d for %s (%d)!\n", stat, gpname, index);
      sum += ntri;
    }
    
    /* get loops */
    for (i = 0; i < bodydata[ibody].nfaces; i++) {
      stat = EG_getTopology(bodydata[ibody].faces[i], &geom, &oclass, 
                            &mtype, NULL, &nloops, &loops, &lsenses);
      if (stat != EGADS_SUCCESS) continue;
      for (nh = j = 0; j < nloops; j++) {
        stat = EG_getTopology(loops[j], &geom, &oclass, &mtype, NULL, 
                              &nledges, &ledges, &esenses);
        if (stat != EGADS_SUCCESS) continue;
        
        /* count */
        for (ntri = nseg = k = 0; k < nledges; k++) {
          m = 0;
          while (ledges[k] != bodydata[ibody].edges[m]) {
            m++;
            if (m == bodydata[ibody].nedges) break;
          }
          /* assume that the edge is degenerate and removed */
          if (m == bodydata[ibody].nedges) continue;
          stat = EG_getTessEdge(bodydata[ibody].tess, m+1, &len,
                                &xyzs, &ts);
          if (stat != EGADS_SUCCESS) {
            printf(" EG_getTessEdge %d = %d!\n", m+1, stat);
            nseg = 0;
            break;
          }
          if (len == 2) 
            if ((xyzs[0] == xyzs[3]) && (xyzs[1] == xyzs[4]) &&
                (xyzs[2] == xyzs[5])) continue;
          nh++;
#ifdef NONINDEXED
          nseg += 2*(len-1);
#else
          nseg += len;
          ntri += 2*(len-1);
#endif
        }
        if (nseg == 0) continue;
        lsegs = (float *) malloc(3*nseg*sizeof(float));
        if (lsegs == NULL) {
          printf(" Can not allocate %d Segments!\n", nseg);
          continue;
        }
#ifndef NONINDEXED
        segs = (int *) malloc(ntri*sizeof(int));
        if (segs == NULL) {
          printf(" Can not allocate %d Line Segments!\n", ntri);
          free(lsegs);
          continue;
        }
#endif
        heads = (int *) malloc(nh*sizeof(int));
        if (heads == NULL) {
          printf(" Can not allocate %d Heads!\n", nh);
#ifndef NONINDEXED
          free(segs);
#endif
          free(lsegs);
          continue;
        }
        
        /* fill */
        for (nh = ntri = nseg = k = 0; k < nledges; k++) {
          m = 0;
          while (ledges[k] != bodydata[ibody].edges[m]) {
            m++;
            if (m == bodydata[ibody].nedges) break;
          }
          /* assume that the edge is degenerate and removed */
          if (m == bodydata[ibody].nedges) continue;
          EG_getTessEdge(bodydata[ibody].tess, m+1, &len, &xyzs, &ts);
          if (len == 2) 
            if ((xyzs[0] == xyzs[3]) && (xyzs[1] == xyzs[4]) &&
                (xyzs[2] == xyzs[5])) continue;
#ifdef NONINDEXED
          if (esenses[k] == -1) heads[nh] = -nseg/2 - 1;
          for (n = 0; n < len-1; n++) {
            lsegs[3*nseg  ] = xyzs[3*n  ];
            lsegs[3*nseg+1] = xyzs[3*n+1];
            lsegs[3*nseg+2] = xyzs[3*n+2];
            nseg++;
            lsegs[3*nseg  ] = xyzs[3*n+3];
            lsegs[3*nseg+1] = xyzs[3*n+4];
            lsegs[3*nseg+2] = xyzs[3*n+5];
            nseg++;
          }
          if (esenses[k] ==  1) heads[nh] = nseg/2;
#else
          if (esenses[k] == -1) heads[nh] = -ntri/2 - 1;
          for (n = 0; n < len-1; n++) {
            segs[ntri] = n+nseg+1;
            ntri++;
            segs[ntri] = n+nseg+2;
            ntri++;
          }
          if (esenses[k] ==  1) heads[nh] = ntri/2;
          for (n = 0; n < len; n++) {
            lsegs[3*nseg  ] = xyzs[3*n  ];
            lsegs[3*nseg+1] = xyzs[3*n+1];
            lsegs[3*nseg+2] = xyzs[3*n+2];
            nseg++;
          }
#endif
          nh++;
        }
        sprintf(gpname, "Body %d Loop %d/%d", ibody+1, i+1, j+1);
        index = wv_indexGPrim(cntxt, gpname);
        if (index < 0) {
          printf(" wv_indexGPrim = %d for %s (%d)!\n", i, gpname, index);
          continue;
        }
        stat = wv_setData(WV_REAL32, nseg, (void *) lsegs,  WV_VERTICES, &items[0]);
        if (stat < 0) printf(" wv_setData = %d for %s/item 0!\n", i, gpname);
        wv_adjustVerts(&items[0], focus);
        free(lsegs);
#ifdef NONINDEXED
        stat = wv_modGPrim(cntxt, index, 1, items);
#else
        stat = wv_setData(WV_INT32, ntri, (void *) segs, WV_INDICES, &items[1]);
        if (stat < 0) printf(" wv_setData = %d for %s/item 1!\n", i, gpname);
        free(segs);
        stat = wv_modGPrim(cntxt, index, 2, items);
#endif
        if (stat < 0) {
          printf(" wv_modGPrim = %d for %s!\n", stat, gpname);
        } else {
          n = wv_addArrowHeads(cntxt, index, 0.05, nh, heads);
          if (n != 0) printf(" wv_addArrowHeads = %d\n", n);          
        }
        free(heads);
      }
    }
  }
  printf(" **  now with %d triangles **\n\n", sum);

}
Ejemplo n.º 10
0
int
EG_close(egObject *context)
{
  int      outLevel, cnt, ref, total, stat;
  egObject *obj, *next, *last;
  egCntxt  *cntx;

  if (context == NULL)               return EGADS_NULLOBJ;
  if (context->magicnumber != MAGIC) return EGADS_NOTOBJ;
  if (context->oclass != CONTXT)     return EGADS_NOTCNTX;
  cntx = (egCntxt *) context->blind;
  if (cntx == NULL)                  return EGADS_NODATA;
  outLevel = cntx->outLevel;

  /* count all active objects */
  
  cnt = ref = 0;
  obj = context->next;
  while (obj != NULL) {
    if (obj->magicnumber != MAGIC) {
      printf(" EGADS Info: Found BAD Object in cleanup (EG_close)!\n");
      printf("             Class = %d\n", obj->oclass);
      return EGADS_NOTFOUND;
    }
    if (obj->oclass == REFERENCE) {
      ref++;
    } else {
      if (outLevel > 2)
        printf(" EGADS Info: Object oclass = %d, mtype = %d Found!\n",
               obj->oclass, obj->mtype);
      cnt++;
    }
    obj = obj->next;
  }
  total = ref+cnt;
  obj   = cntx->pool;
  while (obj != NULL) {
    next = obj->next;
    obj = next;
    total++;
  }
  if (outLevel > 0)
    printf(" EGADS Info: %d Objects, %d Reference in Use (of %d) at Close!\n",
           cnt, ref, total);

  /* delete unattached geometry and topology objects */
  
  EG_deleteObject(context);
  
  /* delete tessellation objects */

  obj  = context->next;
  last = NULL;
  while (obj != NULL) {
    next = obj->next;
    if (obj->oclass == TESSELLATION)
      if (EG_deleteObject(obj) == EGADS_SUCCESS) {
        obj = last;
        if (obj == NULL) {
          next = context->next;
        } else {
          next = obj->next;
        }
      }
    last = obj;
    obj  = next;
  }

  /* delete all models */

  obj  = context->next;
  last = NULL;
  while (obj != NULL) {
    next = obj->next;
    if (obj->oclass == MODEL)
      if (EG_deleteObject(obj) == EGADS_SUCCESS) {
        obj = last;
        if (obj == NULL) {
          next = context->next;
        } else {
          next = obj->next;
        }
      }
    last = obj;
    obj  = next;
  }
  
  /* delete all bodies that are left */
  
  obj  = context->next;
  last = NULL;
  while (obj != NULL) {
    next = obj->next;
    if (obj->oclass == BODY)
      if (EG_deleteObject(obj) == EGADS_SUCCESS) {
        obj = last;
        if (obj == NULL) {
          next = context->next;
        } else {
          next = obj->next;
        }
      }
    last = obj;
    obj  = next;
  }
  
  /* dereference until nothing is left (which should be the case) */

  do {
    cnt = 0;
    obj = context->next;
    while (obj != NULL) {
      next = obj->next;
      if (obj->oclass != REFERENCE) {
        stat = EG_dereferenceTopObj(obj, NULL);
        if (stat == EGADS_SUCCESS) {
          cnt++;
          break;
        }
      }
      obj = next;
    }
    if (cnt != 0) continue;
    obj = context->next;
    while (obj != NULL) {
      next = obj->next;
      if (obj->oclass != REFERENCE) {
        stat = EG_dereferenceObject(obj, NULL);
        if (stat == EGADS_SUCCESS) {
          cnt++;
          break;
        }
      }
      obj = next;
    }    
  } while (cnt != 0);

  ref = cnt = 0;
  obj = context->next;
  while (obj != NULL) {
    if (cnt == 0)
      if (outLevel > 1)
        printf(" EGADS Info: Undeleted Object(s) in cleanup (EG_close):\n");
    if (obj->oclass == REFERENCE) {
      ref++;
    } else {
      if (outLevel > 1)
        printf("             %d: Class = %d, Type = %d\n", 
               cnt, obj->oclass, obj->mtype);
    }
    obj = obj->next;
    cnt++;
  }
  if (outLevel > 1)
    if ((cnt != 0) && (ref != 0))
      printf("             In Addition to %d Refereces\n", ref);  

  /* clean up the pool */
  
  obj = cntx->pool;
  if (obj == NULL) return EGADS_SUCCESS;
  if (obj->magicnumber != MAGIC) {
    printf(" EGADS Info: Found bad Object in Cleanup (EG_close)!\n");
    printf("             Class = %d\n", obj->oclass);
    return EGADS_SUCCESS;
  }
  while (obj != NULL) {
    if (obj->magicnumber != MAGIC) {
      printf(" EGADS Info: Found BAD Object in Cleanup (EG_close)!\n");
      printf("             Class = %d\n", obj->oclass);
      break;
    }
    next = obj->next;
    EG_free(obj);
    obj = next;
  }
  EG_attributeDel(context, NULL);
  EG_free(context);
  EG_free(cntx);
    
  return EGADS_SUCCESS;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    int    i, j, mtype, oclass, nbody, nedge, *senses;
    double size, box[6];
    ego    context, model, newModel, geom, body, *bodies, *edges, *fedge;

    if (argc < 3) {
        printf("\n Usage: fillet filename relSize [edge# ... edge#]\n\n");
        return 1;
    }

    sscanf(argv[2], "%lf", &size);
    printf("\n fillet: Using Relative Size = %lf\n", size);

    /* initialize */
    printf(" EG_open           = %d\n", EG_open(&context));
    printf(" EG_loadModel      = %d\n", EG_loadModel(context, 0, argv[1], &model));
    if (model == NULL) return 1;

    /* get all bodies */
    printf(" EG_getTopology    = %d\n", EG_getTopology(model, &geom, &oclass,
            &mtype, NULL, &nbody,
            &bodies, &senses));
    /* get all edges in body */
    printf(" EG_getBodyTopos   = %d\n", EG_getBodyTopos(bodies[0], NULL, EDGE,
            &nedge, &edges));
    printf(" EG_getBoundingBox = %d\n", EG_getBoundingBox(bodies[0], box));
    printf("       BoundingBox = %lf %lf %lf\n", box[0], box[1], box[2]);
    printf("                     %lf %lf %lf\n", box[3], box[4], box[5]);

    size *= sqrt((box[0]-box[3])*(box[0]-box[3]) + (box[1]-box[4])*(box[1]-box[4]) +
                 (box[2]-box[5])*(box[2]-box[5]));

    if (argc == 3) {
        /* fillet all of them */
        printf(" \n");
        printf(" EG_fillet         = %d\n", EG_filletBody(bodies[0], nedge, edges, size,
                &body));
    } else {
        fedge = (ego *) malloc((argc-3)*sizeof(ego));
        if (fedge == NULL) {
            printf(" MALLOC ERROR!\n");
            EG_free(edges);
            printf(" EG_deleteObject   = %d\n", EG_deleteObject(model));
            printf(" EG_close          = %d\n", EG_close(context));
            return 1;
        }
        printf("\n fillet: Using Edges = ");
        for (i = 0; i < argc-3; i++) {
            sscanf(argv[i+3], "%d", &j);
            if ((j < 0) || (j > nedge)) {
                printf(" ERROR: Argument %d is %d [1-%d]!\n", i+3, j, nedge);
                free(fedge);
                EG_free(edges);
                printf(" EG_deleteObject   = %d\n", EG_deleteObject(model));
                printf(" EG_close          = %d\n", EG_close(context));
                return 1;
            }
            fedge[i] = edges[j-1];
            printf(" %d", j);
        }
        printf("\n\n");
        /* fillet each of them */
        printf(" EG_fillet         = %d\n", EG_filletBody(bodies[0], argc-3, fedge, size,
                &body));
        free(fedge);
    }

    /* make a model and write it out */
    if (body != NULL) {
        printf(" EG_makeTopology   = %d\n", EG_makeTopology(context, NULL, MODEL, 0,
                NULL, 1, &body, NULL, &newModel));
        printf(" EG_saveModel      = %d\n", EG_saveModel(newModel, "fillet.egads"));
        printf("\n");
        printf(" EG_deleteObject   = %d\n", EG_deleteObject(newModel));
    }

    EG_free(edges);
    printf(" EG_deleteObject   = %d\n", EG_deleteObject(model));
    printf(" EG_close          = %d\n", EG_close(context));
    return 0;
}
Ejemplo n.º 12
0
Archivo: dcopy.c Proyecto: OpenMDAO/GEM
int
gem_kernelCopy(gemBRep *brep, /*@null@*/ double *xform, gemBRep **newBRep)
{
  int      stat, ibody, aindex, atype, alen, *aivec;
  char     *bID, *name;
  double   *arvec;
  ego      body, oform, copy;
  gemBody  *gbody;
  gemBRep  *nbrep;
  gemModel *model;

  *newBRep =  NULL;
  if (brep == NULL) return GEM_NULLOBJ;
  if (brep->magic != GEM_MBREP) return GEM_BADBREP;
  gbody = brep->body;
  body  = (ego) gbody->handle.ident.ptr;
  
  if (xform == NULL) {
    stat = EG_copyObject(body, NULL, &copy);
  } else {
    stat = EG_makeTransform(dia_context, xform, &oform);
    if (stat == EGADS_SUCCESS) {
      stat = EG_copyObject(body, oform, &copy);
      EG_deleteObject(oform);
    }
  }
  if (stat != EGADS_SUCCESS) return stat;
  nbrep = (gemBRep *) gem_allocate(sizeof(gemBRep));
  if (nbrep == NULL) {
    EG_deleteObject(copy);
    return GEM_ALLOC;
  }
  nbrep->magic   = GEM_MBREP;
  nbrep->omodel  = NULL;
  nbrep->phandle = brep->phandle;
  nbrep->ibranch = 0;
  nbrep->inumber = 0;
  nbrep->body    = NULL;
  model = brep->omodel;
  for (ibody = 1; ibody <= model->nBRep; ibody++)
    if (model->BReps[ibody-1] == brep) break;
    
  /* get bID for FaceIDs */
  stat = gem_retAttribute(brep, GEM_BREP, 0, "Name", &aindex, &atype, &alen,
                          &aivec, &arvec, &bID);
  if ((stat != GEM_SUCCESS) || (atype != GEM_STRING)) bID = NULL;
  if (bID == NULL) {
    stat = gem_retAttribute(model, 0, 0, "Name", &aindex, &atype, &alen,
                            &aivec, &arvec, &name);
    if ((stat == GEM_SUCCESS) && (atype == GEM_STRING)) {
      alen = strlen(name)+11;
      bID  = (char *) gem_allocate(alen*sizeof(char));
      if (bID == NULL) {
        gem_releaseBRep(nbrep);
        EG_deleteObject(copy);
        return GEM_ALLOC;
      }
      alen--;
      snprintf(bID, alen, "%s:%d", name, ibody);
      bID[alen] = 0;
    }
  }
  if (bID == NULL) {
    name = model->location;
    if (name == NULL) name = "CopiedModel";
    alen = strlen(name)+11;
    bID  = (char *) gem_allocate(alen*sizeof(char));
    if (bID == NULL) {
      gem_releaseBRep(nbrep);
      EG_deleteObject(copy);
      return GEM_ALLOC;
    }
    alen--;
    snprintf(bID, alen, "%s:%d", name, ibody);
    bID[alen] = 0;
  }
  
  stat = gem_diamondBody(copy, bID, nbrep);
  if (stat != EGADS_SUCCESS) {
    gem_releaseBRep(nbrep);
    EG_deleteObject(copy);
    gem_free(bID);
    return GEM_ALLOC;
  }
  gem_free(bID);

  *newBRep = nbrep;
  return GEM_SUCCESS;
}
Ejemplo n.º 13
0
int
EG_loadModel(egObject *context, int bflg, const char *name, 
             egObject **model)
{
  int          i, j, stat, outLevel, len, nattr, egads = 0;
  egObject     *omodel, *aobj;
  TopoDS_Shape source;
  egadsModel   *mshape = NULL;
  FILE         *fp;
  
  *model = NULL;
  if (context == NULL)               return EGADS_NULLOBJ;
  if (context->magicnumber != MAGIC) return EGADS_NOTOBJ;
  if (context->oclass != CONTXT)     return EGADS_NOTCNTX;
  outLevel = EG_outLevel(context);
  
  if (name == NULL) {
    if (outLevel > 0)
      printf(" EGADS Warning: NULL Filename (EG_loadModel)!\n");
    return EGADS_NONAME;
  }
  
  /* does file exist? */

  fp = fopen(name, "r");
  if (fp == NULL) {
    if (outLevel > 0)
      printf(" EGADS Warning: File %s Not Found (EG_loadModel)!\n", name);
    return EGADS_NOTFOUND;
  }
  fclose(fp);
  
  /* find extension */
  
  len = strlen(name);
  for (i = len-1; i > 0; i--)
    if (name[i] == '.') break;
  if (i == 0) {
    if (outLevel > 0)
      printf(" EGADS Warning: No Extension in %s (EG_loadModel)!\n", name);
    return EGADS_NODATA;
  }
  
  if ((strcasecmp(&name[i],".step") == 0) || 
      (strcasecmp(&name[i],".stp") == 0)) {

    /* STEP files */

    STEPControl_Reader aReader;
    IFSelect_ReturnStatus status = aReader.ReadFile(name);
    if (status != IFSelect_RetDone) {
      if (outLevel > 0)
        printf(" EGADS Error: STEP Read of %s = %d (EG_loadModel)!\n", 
               name, status);
      return EGADS_NOLOAD;
    }

    // inspect the root transfers
    if (outLevel > 2)
      aReader.PrintCheckLoad(Standard_False, IFSelect_ItemsByEntity);

    int nroot = aReader.NbRootsForTransfer();
    if (outLevel > 1)
      printf(" EGADS Info: %s Entries = %d\n", name, nroot);

    for (i = 1; i <= nroot; i++) {
      Standard_Boolean ok = aReader.TransferRoot(i);
      if ((!ok) && (outLevel > 0))
        printf(" EGADS Warning: Transfer %d/%d is not OK!\n", i, nroot);
    }

    int nbs = aReader.NbShapes();
    if (nbs <= 0) {
      if (outLevel > 0)
        printf(" EGADS Error: %s has No Shapes (EG_loadModel)!\n", 
               name);
      return EGADS_NOLOAD;
    }
    if (outLevel > 1)    
      printf(" EGADS Info: %s has %d Shape(s)\n", name, nbs);

    TopoDS_Compound compound;
    BRep_Builder    builder3D;
    builder3D.MakeCompound(compound);
    for (i = 1; i <= nbs; i++) {
      TopoDS_Shape aShape = aReader.Shape(i);
      builder3D.Add(compound, aShape);
    }
    source = compound;
    
  } else if ((strcasecmp(&name[i],".iges") == 0) || 
             (strcasecmp(&name[i],".igs") == 0)) {
             
    /* IGES files */
    
    IGESControl_Reader iReader;
    Standard_Integer stats = iReader.ReadFile(name);
    if (stats != IFSelect_RetDone) {
      if (outLevel > 0)
        printf(" EGADS Error: IGES Read of %s = %d (EG_loadModel)!\n", 
               name, stats);
      return EGADS_NOLOAD;
    }
    iReader.TransferRoots();

    int nbs = iReader.NbShapes();
    if (nbs <= 0) {
      if (outLevel > 0)
        printf(" EGADS Error: %s has No Shapes (EG_loadModel)!\n", 
               name);
      return EGADS_NOLOAD;
    }
    if (outLevel > 1)    
      printf(" EGADS Info: %s has %d Shape(s)\n", name, nbs);

    TopoDS_Compound compound;
    BRep_Builder    builder3D;
    builder3D.MakeCompound(compound);
    for (i = 1; i <= nbs; i++) {
      TopoDS_Shape aShape = iReader.Shape(i);
      builder3D.Add(compound, aShape);
    }
    source = compound;

  } else if ((strcasecmp(&name[i],".brep") == 0) ||
             (strcasecmp(&name[i],".egads") == 0)) {
  
    /* Native OCC file */
    if (strcasecmp(&name[i],".egads") == 0) egads = 1;

    BRep_Builder builder;
    if (!BRepTools::Read(source, name, builder)) {
      if (outLevel > 0)
        printf(" EGADS Warning: Read Error on %s (EG_loadModel)!\n", name);
      return EGADS_NOLOAD;
    }

  } else {
    if (outLevel > 0)
      printf(" EGADS Warning: Extension in %s Not Supported (EG_loadModel)!\n",
             name);
    return EGADS_NODATA;
  }
  
  int nWire  = 0;
  int nFace  = 0;
  int nSheet = 0;
  int nSolid = 0;
  
  TopExp_Explorer Exp;
  for (Exp.Init(source, TopAbs_WIRE,  TopAbs_FACE);
       Exp.More(); Exp.Next()) nWire++;
  for (Exp.Init(source, TopAbs_FACE,  TopAbs_SHELL);
       Exp.More(); Exp.Next()) nFace++;
  for (Exp.Init(source, TopAbs_SHELL, TopAbs_SOLID);
       Exp.More(); Exp.Next()) nSheet++;
  for (Exp.Init(source, TopAbs_SOLID); Exp.More(); Exp.Next()) nSolid++;

  if (outLevel > 1)
    printf("\n EGADS Info: %s has %d Solids, %d Sheets, %d Faces and %d Wires\n",
           name, nSolid, nSheet, nFace, nWire);
           
  int nBody = nWire+nFace+nSheet+nSolid;
  if (nBody == 0) {
    source.Nullify();
    if (outLevel > 0)
      printf(" EGADS Warning: Nothing found in %s (EG_loadModel)!\n", name);
    return EGADS_NODATA;
  }
  
  mshape = new egadsModel;
  mshape->shape  = source;
  mshape->nbody  = nBody;
  mshape->bodies = new egObject*[nBody];
  for (i = 0; i < nBody; i++) {
    stat = EG_makeObject(context, &mshape->bodies[i]);
    if (stat != EGADS_SUCCESS) {
      for (int j = 0; j < i; j++) {
        egObject  *obj   = mshape->bodies[j];
        egadsBody *pbody = (egadsBody *) obj->blind;
        delete pbody;
        EG_deleteObject(mshape->bodies[j]);
      }
      delete [] mshape->bodies;
      delete mshape;
      return stat;
    }
    egObject  *pobj    = mshape->bodies[i];
    egadsBody *pbody   = new egadsBody;
    pbody->nodes.objs  = NULL;
    pbody->edges.objs  = NULL;
    pbody->loops.objs  = NULL;
    pbody->faces.objs  = NULL;
    pbody->shells.objs = NULL;
    pbody->senses      = NULL;
    pobj->blind        = pbody;
  }
  
  i = 0;
  for (Exp.Init(mshape->shape, TopAbs_WIRE,  TopAbs_FACE); 
       Exp.More(); Exp.Next()) {
    egObject  *obj   = mshape->bodies[i++];
    egadsBody *pbody = (egadsBody *) obj->blind;
    pbody->shape     = Exp.Current();
  }
  for (Exp.Init(mshape->shape, TopAbs_FACE,  TopAbs_SHELL);
       Exp.More(); Exp.Next()) {
    egObject  *obj   = mshape->bodies[i++];
    egadsBody *pbody = (egadsBody *) obj->blind;
    pbody->shape     = Exp.Current();
  }
  for (Exp.Init(mshape->shape, TopAbs_SHELL, TopAbs_SOLID);
       Exp.More(); Exp.Next()) {
    egObject  *obj   = mshape->bodies[i++];
    egadsBody *pbody = (egadsBody *) obj->blind;
    pbody->shape     = Exp.Current();
  }
  for (Exp.Init(mshape->shape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
    egObject  *obj   = mshape->bodies[i++];
    egadsBody *pbody = (egadsBody *) obj->blind;
    pbody->shape     = Exp.Current();
  }
  
  stat = EG_makeObject(context, &omodel);
  if (stat != EGADS_SUCCESS) {
    source.Nullify();
    for (i = 0; i < nBody; i++) {
      egObject  *obj   = mshape->bodies[i];
      egadsBody *pbody = (egadsBody *) obj->blind;
      delete pbody;
      EG_deleteObject(mshape->bodies[i]);
    }
    delete [] mshape->bodies;
    delete mshape;
    return stat;
  }
  omodel->oclass = MODEL;
  omodel->blind  = mshape;
  EG_referenceObject(omodel, context);
  
  for (i = 0; i < nBody; i++) {
    egObject  *pobj  = mshape->bodies[i];
    egadsBody *pbody = (egadsBody *) pobj->blind;
    pobj->topObj     = omodel;
    if (((bflg&1) == 0) && (egads == 0)) EG_splitPeriodics(pbody);
    stat = EG_traverseBody(context, i, pobj, omodel, pbody);
    if (stat != EGADS_SUCCESS) {
      mshape->nbody = i;
      EG_destroyTopology(omodel);
      delete [] mshape->bodies;
      delete mshape;
      return stat;
    }
  }

  *model = omodel;
  if (egads == 0) return EGADS_SUCCESS;

  /* get the attributes from the EGADS files */
  
  fp = fopen(name, "r");
  if (fp == NULL) {
    printf(" EGADS Info: Cannot reOpen %s (EG_loadModel)!\n", name);
    return EGADS_SUCCESS;
  }
  char line[81];
  for (;;) {
    line[0] = line[1] = ' ';
    if (fgets(line, 81, fp) == NULL) break;
    if ((line[0] == '#') && (line[1] == '#')) break;
  }
  
  // got the header
  if ((line[0] == '#') && (line[1] == '#')) {
    if (outLevel > 1) printf(" Header = %s\n", line);
    // get number of model attributes
    fscanf(fp, "%d", &nattr);
    if (nattr != 0) EG_readAttrs(omodel, nattr, fp);
    for (i = 0; i < nBody; i++) {
      int otype,  oindex;
      int rsolid, rshell, rface, rloop, redge, rnode;
      int nsolid, nshell, nface, nloop, nedge, nnode;

      fscanf(fp, " %d %d %d %d %d %d %d", &rsolid, &rshell, 
             &rface, &rloop, &redge, &rnode, &nattr);
      if (outLevel > 2)
        printf(" read = %d %d %d %d %d %d %d\n", rsolid, rshell, 
               rface, rloop, redge, rnode, nattr);
      egObject  *pobj  = mshape->bodies[i];
      egadsBody *pbody = (egadsBody *) pobj->blind;
      nnode  = pbody->nodes.map.Extent();
      nedge  = pbody->edges.map.Extent();
      nloop  = pbody->loops.map.Extent();
      nface  = pbody->faces.map.Extent();
      nshell = pbody->shells.map.Extent();
      nsolid = 0;
      if (pobj->mtype == SOLIDBODY) nsolid = 1;
      if ((nnode != rnode) || (nedge  != redge)  || (nloop  != rloop) ||
          (nface != rface) || (nshell != rshell) || (nsolid != rsolid)) {
        printf(" EGADS Info: %d %d, %d %d, %d %d, %d %d, %d %d, %d %d",
               nnode, rnode, nedge,  redge,  nloop,  rloop,
               nface, rface, nshell, rshell, nsolid, rsolid);
        printf("  MisMatch on Attributes (EG_loadModel)!\n");
        fclose(fp);
        return EGADS_SUCCESS;
      }
      // got the correct body -- transfer the attributes
      if (nattr != 0) EG_readAttrs(pobj, nattr, fp);
      for (;;)  {
        j = fscanf(fp, "%d %d %d\n", &otype, &oindex, &nattr);
        if (outLevel > 2)
          printf(" %d:  attr header = %d %d %d\n", 
                 j, otype, oindex, nattr);
        if (j     != 3) break;
        if (otype == 0) break;
        if (otype == 1) {
          aobj = pbody->shells.objs[oindex];
        } else if (otype == 2) {
          aobj = pbody->faces.objs[oindex];
        } else if (otype == 3) {
          aobj = pbody->loops.objs[oindex];
        } else if (otype == 4) {
          aobj = pbody->edges.objs[oindex];
        } else {
          aobj = pbody->nodes.objs[oindex];
        }
        EG_readAttrs(aobj, nattr, fp);
      }
    }
  } else {
    printf(" EGADS Info: EGADS Header not found in %s (EG_loadModel)!\n", 
           name);
    return EGADS_SUCCESS;
  }
  
  fclose(fp);
  return EGADS_SUCCESS;
}