ig_intersection_(INT8 *isrc, INT8 *itool, int *nedge, INT8 **facedg8, INT8 *imodel) #endif { int i, stat; INT8 *cobjs; egObject *src, *tool, **facEdg, *model; *nedge = 0; *imodel = 0; src = (egObject *) *isrc; tool = (egObject *) *itool; stat = EG_intersection(src, tool, nedge, &facEdg, &model); if (stat == EGADS_SUCCESS) { *facedg8 = cobjs = (INT8 *) EG_alloc(*nedge*2*sizeof(INT8)); if (cobjs == NULL) { EG_free(facEdg); return EGADS_MALLOC; } for (i = 0; i < *nedge*2; i++) cobjs[i] = (INT8) facEdg[i]; EG_free(facEdg); *imodel = (INT8) model; } return stat; }
void EG_free_interval(Row_hdr *row_hdr, int interval_dim) { int i; for (i=0; i<interval_dim; i++) { if (row_hdr[i].size > 0) (void)EG_free(row_hdr[i].intervals); } (void)EG_free(row_hdr); } /* free_interval */
int EG_open(egObject **context) { egObject *object; egCntxt *cntx; cntx = (egCntxt *) EG_alloc(sizeof(egCntxt)); if (cntx == NULL) return EGADS_MALLOC; object = (egObject *) EG_alloc(sizeof(egObject)); if (object == NULL) { EG_free(cntx); return EGADS_MALLOC; } cntx->outLevel = 1; cntx->signature = EGADSprop; cntx->pool = NULL; cntx->last = object; object->magicnumber = MAGIC; object->oclass = CONTXT; object->mtype = 0; object->tref = NULL; object->attrs = NULL; object->blind = cntx; object->topObj = NULL; object->prev = NULL; object->next = NULL; *context = object; return EGADS_SUCCESS; }
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)); }
ig_attributeadd_(INT8 *obj, const char *name, int *atype, int *len, int *ints, double *reals, char *str, int nameLen, int strLen) #endif { int stat; char *fname, *fstr; egObject *object; object = (egObject *) *obj; fname = EG_f2c(name, nameLen); if (fname == NULL) return EGADS_NONAME; fstr = EG_f2c(str, strLen); stat = EG_attributeAdd(object, fname, *atype, *len, ints, reals, fstr); EG_free(fstr); EG_free(fname); return stat; }
ig_attributedel_(INT8 *obj, const char *name, int nameLen) #endif { int stat; char *fname; egObject *object; object = (egObject *) *obj; fname = EG_f2c(name, nameLen); stat = EG_attributeDel(object, fname); EG_free(fname); return stat; }
ig_loft_(int *nsec, INT8 *secs, int *opt, INT8 *irslt) #endif { int i, stat; egObject *result; const egObject **objs = NULL; *irslt = 0; if (*nsec <= 1) return EGADS_RANGERR; objs = (const egObject **) EG_alloc(*nsec*sizeof(egObject *)); if (objs == NULL) return EGADS_MALLOC; for (i = 0; i < *nsec; i++) objs[i] = (egObject *) secs[i]; stat = EG_loft(*nsec, objs, *opt, &result); if (objs != NULL) EG_free((void *) objs); if (stat == EGADS_SUCCESS) *irslt = (INT8) result; return stat; }
ig_imprintbody_(INT8 *isrc, int *nedge, INT8 *facEdg, INT8 *irslt) #endif { int i, stat; egObject *src, *result, **objs = NULL; *irslt = 0; if (*nedge <= 0) return EGADS_RANGERR; src = (egObject *) *isrc; objs = (egObject **) EG_alloc(*nedge*2*sizeof(egObject *)); if (objs == NULL) return EGADS_MALLOC; for (i = 0; i < *nedge*2; i++) objs[i] = (egObject *) facEdg[i]; stat = EG_imprintBody(src, *nedge, objs, &result); if (objs != NULL) EG_free(objs); if (stat == EGADS_SUCCESS) *irslt = (INT8) result; return stat; }
ig_hollowbody_(INT8 *isrc, int *nface, INT8 *faces, double *offset, int *join, INT8 *irslt) #endif { int i, stat; egObject *src, *result; const egObject **objs = NULL; *irslt = 0; if (*nface <= 0) return EGADS_RANGERR; src = (egObject *) *isrc; objs = (const egObject **) EG_alloc(*nface*sizeof(egObject *)); if (objs == NULL) return EGADS_MALLOC; for (i = 0; i < *nface; i++) objs[i] = (egObject *) faces[i]; stat = EG_hollowBody(src, *nface, objs, *offset, *join, &result); if (objs != NULL) EG_free((void *) objs); if (stat == EGADS_SUCCESS) *irslt = (INT8) result; return stat; }
ig_filletbody_(INT8 *isrc, int *nedge, INT8 *edges, double *radius, INT8 *irslt) #endif { int i, stat; egObject *src, *result; const egObject **objs = NULL; *irslt = 0; if (*nedge <= 0) return EGADS_RANGERR; src = (egObject *) *isrc; objs = (const egObject **) EG_alloc(*nedge*sizeof(egObject *)); if (objs == NULL) return EGADS_MALLOC; for (i = 0; i < *nedge; i++) objs[i] = (egObject *) edges[i]; stat = EG_filletBody(src, *nedge, objs, *radius, &result); if (objs != NULL) EG_free((void *) objs); if (stat == EGADS_SUCCESS) *irslt = (INT8) result; return stat; }
ig_attributeret_(INT8 *obj, char *name, int *atype, int *len, const int **ints, const double **reals, char *str, int nameLen, int strLen) #endif { int stat; char *fname; const char *fstr; egObject *object; *ints = NULL; *reals = NULL; object = (egObject *) *obj; fname = EG_f2c(name, nameLen); if (fname == NULL) return EGADS_NONAME; stat = EG_attributeRet(object, fname, atype, len, ints, reals, &fstr); EG_c2f(fstr, str, strLen); EG_free(fname); return stat; }
ig_chamferbody_(INT8 *isrc, int *nedge, INT8 *edges, INT8 *faces, double *dis1, double *dis2, INT8 *irslt) #endif { int i, stat; egObject *src, *result; const egObject **objs = NULL; *irslt = 0; if (*nedge <= 0) return EGADS_RANGERR; src = (egObject *) *isrc; objs = (const egObject **) EG_alloc(*nedge*2*sizeof(egObject *)); if (objs == NULL) return EGADS_MALLOC; for (i = 0; i < *nedge; i++) { objs[ i] = (egObject *) edges[i]; objs[*nedge+i] = (egObject *) faces[i]; } stat = EG_chamferBody(src, *nedge, objs, &objs[*nedge], *dis1, *dis2, &result); if (objs != NULL) EG_free((void *) objs); if (stat == EGADS_SUCCESS) *irslt = (INT8) result; return stat; }
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; }
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; }
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; }
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; }
int EG_makeTransform(egObject *context, const double *xform, egObject **oform) { int i, stat, outLevel; double *reals, dotXY, dotXZ, dotYZ, dotXX, dotYY, dotZZ; egObject *object; if (context == NULL) return EGADS_NULLOBJ; if (context->magicnumber != MAGIC) return EGADS_NOTOBJ; if (context->oclass != CONTXT) return EGADS_NOTCNTX; if (xform == NULL) return EGADS_NODATA; outLevel = EG_outLevel(context); /* check for "scaled" orthonormality */ dotXX = xform[0]*xform[0] + xform[1]*xform[1] + xform[ 2]*xform[ 2]; dotXY = xform[0]*xform[4] + xform[1]*xform[5] + xform[ 2]*xform[ 6]; dotXZ = xform[0]*xform[8] + xform[1]*xform[9] + xform[ 2]*xform[10]; dotYY = xform[4]*xform[4] + xform[5]*xform[5] + xform[ 6]*xform[ 6]; dotYZ = xform[4]*xform[8] + xform[5]*xform[9] + xform[ 6]*xform[10]; dotZZ = xform[8]*xform[8] + xform[9]*xform[9] + xform[10]*xform[10]; if (sqrt(dotXX) < ZERO) { if (outLevel > 0) printf(" EGADS Error: No Length on Transform (EG_makeTransform)!\n"); return EGADS_DEGEN; } if ((fabs((dotXX-dotYY)/dotXX) > ZERO) || (fabs((dotXX-dotZZ)/dotXX) > ZERO)) { if (outLevel > 0) printf(" EGADS Error: Skew Scaling in Transform (EG_makeTransform)!\n"); return EGADS_BADSCALE; } if ((fabs(dotXY/dotXX) > ZERO) || (fabs(dotXZ/dotXX) > ZERO) || (fabs(dotYZ/dotXX) > ZERO)) { if (outLevel > 0) printf(" EGADS Error: Transform not Orthogonal (EG_makeTransform)!\n"); return EGADS_NOTORTHO; } reals = (double *) EG_alloc(12*sizeof(double)); if (reals == NULL) { if (outLevel > 0) printf(" EGADS Error: Malloc on transform (EG_makeTransform)!\n"); return EGADS_MALLOC; } stat = EG_makeObject(context, &object); if (stat != EGADS_SUCCESS) { EG_free(reals); return stat; } object->oclass = TRANSFORM; object->blind = reals; for (i = 0; i < 12; i++) reals[i] = xform[i]; *oform = object; return EGADS_SUCCESS; }
static int EG_derefObj(egObject *object, /*@null@*/ const egObject *refx, int flg) { int i, j, stat, outLevel; long ptr1, ptr2; egObject *pobj, *nobj, *obj, *context; egCntxt *cntx; egTessel *tess; const egObject *ref; if (object == NULL) return EGADS_NULLOBJ; if (object->magicnumber != MAGIC) return EGADS_NOTOBJ; if (object->oclass == CONTXT) return EGADS_NOTCNTX; if (object->oclass == EMPTY) return EGADS_EMPTY; if (object->oclass == REFERENCE) return EGADS_REFERCE; context = EG_context(object); if (context == NULL) return EGADS_NOTCNTX; cntx = (egCntxt *) context->blind; if (cntx == NULL) return EGADS_NODATA; outLevel = cntx->outLevel; ref = refx; /* context is an attempt to delete */ if ((ref == context) && (object->tref != NULL)) { nobj = object->tref; pobj = NULL; i = 0; while (nobj != NULL) { obj = (egObject *) nobj->attrs; if (obj != ref) i++; pobj = nobj; nobj = (egObject *) pobj->blind; /* next reference */ } if (object->topObj == context) if (i > 0) { if (outLevel > 0) printf(" EGADS Info: dereference with %d active objects!\n", i); return i; } } if (ref == NULL) ref = context; /* we should never see a NULL reference! */ if (object->tref != NULL) { nobj = object->tref; pobj = NULL; while (nobj != NULL) { obj = (egObject *) nobj->attrs; if (obj == ref) break; pobj = nobj; nobj = (egObject *) pobj->blind; /* next reference */ } if (nobj == NULL) { if (refx != NULL) { ptr1 = (long) object; ptr2 = (long) ref; printf(" EGADS Internal: Ref Not Found (EG_dereferenceObject)!\n"); printf(" Object %lx = %d/%d, ref %lx = %d/%d\n", ptr1, object->oclass, object->mtype, ptr2, ref->oclass, ref->mtype); } return EGADS_NOTFOUND; } if (pobj == NULL) { object->tref = (egObject *) nobj->blind; } else { pobj->blind = nobj->blind; } obj = nobj; pobj = obj->prev; nobj = obj->next; if (nobj != NULL) { nobj->prev = pobj; } else { cntx->last = pobj; } pobj->next = nobj; obj->mtype = REFERENCE; obj->oclass = EMPTY; obj->blind = NULL; obj->topObj = context; obj->prev = NULL; obj->next = cntx->pool; cntx->pool = obj; } if (object->tref != NULL) return EGADS_SUCCESS; stat = EG_attributeDel(object, NULL); if (stat != EGADS_SUCCESS) if (outLevel > 0) printf(" EGADS Warning: Del Attributes = %d (EG_destroyObject)!\n", stat); stat = EGADS_SUCCESS; if (object->oclass == TRANSFORM) { EG_free(object->blind); } else if (object->oclass == TESSELLATION) { tess = (egTessel *) object->blind; if (tess != NULL) { EG_dereferenceTopObj(tess->src, object); if (tess->xyzs != NULL) EG_free(tess->xyzs); if (tess->tess1d != NULL) { for (i = 0; i < tess->nEdge; i++) { if (tess->tess1d[i].faces[0].faces != NULL) EG_free(tess->tess1d[i].faces[0].faces); if (tess->tess1d[i].faces[1].faces != NULL) EG_free(tess->tess1d[i].faces[1].faces); if (tess->tess1d[i].faces[0].tric != NULL) EG_free(tess->tess1d[i].faces[0].tric); if (tess->tess1d[i].faces[1].tric != NULL) EG_free(tess->tess1d[i].faces[1].tric); if (tess->tess1d[i].xyz != NULL) EG_free(tess->tess1d[i].xyz); if (tess->tess1d[i].t != NULL) EG_free(tess->tess1d[i].t); } EG_free(tess->tess1d); } if (tess->tess2d != NULL) { for (i = 0; i < 2*tess->nFace; i++) { if (tess->tess2d[i].xyz != NULL) EG_free(tess->tess2d[i].xyz); if (tess->tess2d[i].uv != NULL) EG_free(tess->tess2d[i].uv); if (tess->tess2d[i].ptype != NULL) EG_free(tess->tess2d[i].ptype); if (tess->tess2d[i].pindex != NULL) EG_free(tess->tess2d[i].pindex); if (tess->tess2d[i].tris != NULL) EG_free(tess->tess2d[i].tris); if (tess->tess2d[i].tric != NULL) EG_free(tess->tess2d[i].tric); if (tess->tess2d[i].patch != NULL) { for (j = 0; j < tess->tess2d[i].npatch; j++) { if (tess->tess2d[i].patch[j].ipts != NULL) EG_free(tess->tess2d[i].patch[j].ipts); if (tess->tess2d[i].patch[j].bounds != NULL) EG_free(tess->tess2d[i].patch[j].bounds); } EG_free(tess->tess2d[i].patch); } } EG_free(tess->tess2d); } EG_free(tess); } } else if (object->oclass <= SURFACE) { if ((object->oclass != NIL) && (flg == 0)) stat = EG_destroyGeometry(object); } else { if (flg == 0) stat = EG_destroyTopology(object); } object->mtype = object->oclass; object->oclass = EMPTY; object->blind = NULL; /* patch up the lists & put the object in the pool */ pobj = object->prev; /* always have a previous -- context! */ nobj = object->next; if (nobj == NULL) { if (object != cntx->last) printf(" EGADS Info: Context Last NOT Object Next w/ NULL!\n"); cntx->last = pobj; } else { nobj->prev = pobj; } if (pobj == NULL) { printf(" EGADS Info: PrevObj is NULL (EG_destroyObject)!\n"); } else { pobj->next = nobj; } object->prev = NULL; object->next = cntx->pool; cntx->pool = object; return stat; }
static void EG_readAttrs(egObject *obj, int nattr, FILE *fp) { int i, j, n, type, namlen, len, *ivec, ival; char *name, *string, cval; double *rvec, rval; egAttrs *attrs = NULL; egAttr *attr = NULL; attr = (egAttr *) EG_alloc(nattr*sizeof(egAttr)); if (attr != NULL) { attrs = (egAttrs *) EG_alloc(sizeof(egAttrs)); if (attrs == NULL) { EG_free(attr); attr = NULL; } } for (n = i = 0; i < nattr; i++) { j = fscanf(fp, "%d %d %d", &type, &namlen, &len); if (j != 3) break; name = NULL; if ((attrs != NULL) && (namlen != 0)) name = (char *) EG_alloc((namlen+1)*sizeof(char)); if (name != NULL) { fscanf(fp, "%s", name); } else { for (j = 0; j < namlen; j++) fscanf(fp, "%c", &cval); } if (type == ATTRINT) { if (len == 1) { fscanf(fp, "%d", &ival); } else { ivec = NULL; if ((name != NULL) && (len != 0)) ivec = (int *) EG_alloc(len*sizeof(int)); if (ivec == NULL) { for (j = 0; j < len; j++) fscanf(fp, "%d", &ival); if (name != NULL) { EG_free(name); name = NULL; } } else { for (j = 0; j < len; j++) fscanf(fp, "%d", &ivec[j]); } } } else if (type == ATTRREAL) { if (len == 1) { fscanf(fp, "%lf", &rval); } else { rvec = NULL; if ((name != NULL) && (len != 0)) rvec = (double *) EG_alloc(len*sizeof(double)); if (rvec == NULL) { for (j = 0; j < len; j++) fscanf(fp, "%lf", &rval); if (name != NULL) { EG_free(name); name = NULL; } } else { for (j = 0; j < len; j++) fscanf(fp, "%lf", &rvec[j]); } } } else { do { j = fscanf(fp, "%c", &cval); if (j == 0) break; } while (cval != '#'); string = NULL; if ((name != NULL) && (len != 0)) string = (char *) EG_alloc((len+1)*sizeof(char)); if (string != NULL) { for (j = 0; j < len; j++) fscanf(fp, "%c", &string[j]); string[len] = 0; } else { for (j = 0; j < len; j++) fscanf(fp, "%c", &cval); if (name != NULL) { EG_free(name); name = NULL; } } } if (name != NULL) { attr[n].name = name; attr[n].type = type; attr[n].length = len; if (type == ATTRINT) { if (len == 1) { attr[n].vals.integer = ival; } else { attr[n].vals.integers = ivec; } } else if (type == ATTRREAL) { if (len == 1) { attr[n].vals.real = rval; } else { attr[n].vals.reals = rvec; } } else { attr[n].vals.string = string; } n++; } } if (attrs != NULL) { attrs->nattrs = n; attrs->attrs = attr; obj->attrs = attrs; } }
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; }
int EG_bdry_graph(Row_hdr *row_hdr, int rowh_dim, int num_cols, Node *node, int num_nodes, int clump_id) { float bottom; int i; int j; float left; int *list; int list_ct = 0; int list_size; int *next_list; int next_list_ct = 0; int node_ct = 0; int *previous_list; int previous_list_ct = 0; float right; int *temp_list; float top; list_size = 2*num_cols; /* max number of corner pts on a line */ /* allocate memory for list, next_list, previous_list */ list = EG_malloc(list_size*sizeof(int)); next_list = EG_malloc(list_size*sizeof(int)); previous_list = EG_malloc(list_size*sizeof(int)); if (list == NULL || next_list == NULL || previous_list == NULL) return(-1); /* initialize list counts to 0 */ list_ct = 0; next_list_ct = 0; previous_list_ct = 0; /* initialize the node adjacency list to -1 */ for (i=0; i<num_nodes; i++) { node[i].adj_list[NORTH] = NULL_NODE; node[i].adj_list[SOUTH] = NULL_NODE; node[i].adj_list[EAST] = NULL_NODE; node[i].adj_list[WEST] = NULL_NODE; } /* * Iterate over all intervals to build a graph. In each iteration, * calculate boundary points for each interval rectangle and then * determine appropriate boundary edges for each boundary point by * looking at overlapping intervals. Note that we are working from the * bottom of the set of intervals up to the top. */ for (i=0; i<rowh_dim; i++) { for (j=0; j<row_hdr[i].size; j++) { /* * choose the appropriate intervals to use in determining the * boundary */ if (clump_id != 0 && row_hdr[i].intervals[j].id != clump_id) continue; /* find bounds of rectangle about this interval */ left = row_hdr[i].intervals[j].begin - OFFSET_X; right = row_hdr[i].intervals[j].end + OFFSET_X; top = i + OFFSET_Y; bottom = i - OFFSET_Y; #ifdef NOTNOW left = row_hdr[i].intervals[j].begin * STRETCH_X - OFFSET_X; right = row_hdr[i].intervals[j].end * STRETCH_X + OFFSET_X; top = i * STRETCH_Y + OFFSET_Y; bottom = i * STRETCH_Y - OFFSET_Y; #endif /* set the boundary points of the rectangle about this interval */ /* set left top boundary point and next_list */ node[node_ct].x = left; node[node_ct].y = top; node[node_ct].row = i; node[node_ct].col = j; node[node_ct].near_x = row_hdr[i].intervals[j].begin; set_node_list(node, node_ct, SOUTH, SOUTH_BIT, node_ct+2); node[node_ct].corner = NW; next_list[next_list_ct] = node_ct; next_list_ct++; node_ct++; /* set right top boundary point and next_list */ node[node_ct].x = right; node[node_ct].y = top; node[node_ct].row = i; node[node_ct].col = j; node[node_ct].near_x = row_hdr[i].intervals[j].end; set_node_list(node, node_ct, SOUTH, SOUTH_BIT, node_ct+2); node[node_ct].corner = NE; next_list[next_list_ct] = node_ct; next_list_ct++; node_ct++; /* set left bottom boundary point and list */ node[node_ct].x = left; node[node_ct].y = bottom; node[node_ct].row = i; node[node_ct].col = j; node[node_ct].near_x = row_hdr[i].intervals[j].begin; set_node_list(node, node_ct, NORTH, NORTH_BIT, node_ct-2); node[node_ct].corner = SW; list[list_ct] = node_ct; list_ct++; node_ct++; /* set right bottom boundary point and list */ node[node_ct].x = right; node[node_ct].y = bottom; node[node_ct].row = i; node[node_ct].col = j; node[node_ct].near_x = row_hdr[i].intervals[j].end; set_node_list(node, node_ct, NORTH, NORTH_BIT, node_ct-2); node[node_ct].corner = SE; list[list_ct] = node_ct; list_ct++; node_ct++; } /* for (k=0; k<next_list_ct; k++) printf("next_list[%d] = %d\n", k, next_list[k]); for (k=0; k<list_ct; k++) printf("list[%d] = %d\n", k, list[k]); for (k=0; k<previous_list_ct; k++) printf("previous_list[%d] = %d\n", k, previous_list[k]); */ /* * Merge list with previous list assigning horizontal boundary * edges and working with duplicate boundary points appropriately. * This means that duplicates coming from overlapping rectangles do * not generate boundary edges. Duplicates from caddy corner * rectangles generate two boundary edges. This merge is done in * principle only since a merged list is not created. */ merge_lists(list, list_ct, previous_list, previous_list_ct, node); /* exchange previous list with next list */ temp_list = previous_list; previous_list = next_list; next_list = temp_list; /* * set previous_list_ct to next_list_ct and reset list_ct and * next_list_ct to 0 */ previous_list_ct = next_list_ct; next_list_ct = 0; list_ct = 0; /* for (k=0; k<previous_list_ct; k++) printf("previous_list[%d] = %d\n", k, previous_list[k]); */ } /* * Assign horizontal boundary edges for the last list. This list was * not handled in the above loop. */ merge_lists(list, list_ct, previous_list, previous_list_ct, node); /* free memory for list, next_list, previous_list */ (void)EG_free(list); (void)EG_free(next_list); (void)EG_free(previous_list); return(0); } /* bdry_graph */
int udpSet(char *name, char *value) { int ij, len, icount, jcount; char *pEnd, defn[128]; if (name == NULL) { return EGADS_NONAME; } if (value == NULL) { return EGADS_NULLOBJ; } len = strlen(value); if (len == 0) { return EGADS_NODATA; } if (strcmp(name, "Depth") == 0) { Depth[0] = strtod(value, &pEnd); if (Depth[0] <= 0) { printf(" udpSet: Depth = %f -- reset to 1\n", Depth[0]); Depth[0] = 1; } } else if (strcmp(name, "Segments") == 0) { /* count the number of values */ icount = 0; for (ij = 0; ij < strlen(value); ij++) { if (value[ij] == ';') icount++; } if (icount%4 == 0) { Nseg[0] = icount / 4; } else { printf(" udpSet: Segements must have 4*n values\n"); return EGADS_NODATA; } /* allocate necessary array */ if (Segments[0] != NULL) EG_free(Segments[0]); Segments[0] = (double*) EG_alloc(icount*sizeof(double)); if (Segments[0] == NULL) { return EGADS_MALLOC; } /* extract the data from the string */ icount = 0; for (ij = 0; ij < 4*Nseg[0]; ij++) { jcount = 0; while (icount < strlen(value)) { if (value[icount] == ';') { icount++; break; } else { defn[jcount ] = value[icount]; defn[jcount+1] = '\0'; icount++; jcount++; } } Segments[0][ij] = strtod(defn, &pEnd); } } else { printf(" udpSet: Parameter %s not known\n", name); return EGADS_INDEXERR; } return EGADS_SUCCESS; }
int gem_diamondBody(ego object, /*@null@*/ char *bID, gemBRep *brep) { int i, j, k, m, n, len, stat, oclass, mtype, nobjs, *senses; int nshell, nface, nloop, nedge, nnode, atype, alen; const int *ints; double limits[4]; const double *reals; char buffer[1025]; const char *string; ego geom, *objs; ego *shells, *faces, *loops, *edges, *nodes; gemID gid; gemBody *body; stat = EG_getTopology(object, &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) return stat; if (oclass != BODY) return EGADS_NOTBODY; gid.index = 0; gid.ident.ptr = object; body = (gemBody *) gem_allocate(sizeof(gemBody)); if (body == NULL) return GEM_ALLOC; body->handle = gid; body->nnode = 0; body->nodes = NULL; body->nedge = 0; body->edges = NULL; body->nloop = 0; body->loops = NULL; body->nface = 0; body->faces = NULL; body->nshell = 0; body->shells = NULL; body->attr = NULL; body->type = GEM_SOLID; if ((mtype == SHEETBODY) || (mtype == FACEBODY)) body->type = GEM_SHEET; if (mtype == WIREBODY) body->type = GEM_WIRE; brep->body = body; gem_matIdent(brep->xform); gem_matIdent(brep->invXform); stat = EG_getBoundingBox(object, body->box); if (stat != EGADS_SUCCESS) return stat; nodes = NULL; edges = NULL; loops = NULL; faces = NULL; shells = NULL; stat = EG_getBodyTopos(object, NULL, NODE, &nnode, &nodes); if (stat != EGADS_SUCCESS) goto ret; stat = EG_getBodyTopos(object, NULL, EDGE, &nedge, &edges); if (stat != EGADS_SUCCESS) goto ret; stat = EG_getBodyTopos(object, NULL, LOOP, &nloop, &loops); if (stat != EGADS_SUCCESS) goto ret; stat = EG_getBodyTopos(object, NULL, FACE, &nface, &faces); if (stat != EGADS_SUCCESS) goto ret; stat = EG_getBodyTopos(object, NULL, SHELL, &nshell, &shells); if (stat != EGADS_SUCCESS) goto ret; /* make the nodes */ if ((nnode != 0) && (nodes != NULL)) { stat = GEM_ALLOC; body->nodes = (gemNode *) gem_allocate(nnode*sizeof(gemNode)); if (body->nodes == NULL) goto ret; for (i = 0; i < nnode; i++) body->nodes[i].attr = NULL; body->nnode = nnode; for (i = 0; i < nnode; i++) { stat = EG_getTopology(nodes[i], &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) goto ret; gid.ident.ptr = nodes[i]; body->nodes[i].handle = gid; body->nodes[i].xyz[0] = limits[0]; body->nodes[i].xyz[1] = limits[1]; body->nodes[i].xyz[2] = limits[2]; gem_fillAttrs(nodes[i], &body->nodes[i].attr); } } /* make the edges */ if ((nedge != 0) && (edges != NULL)) { stat = GEM_ALLOC; body->edges = (gemEdge *) gem_allocate(nedge*sizeof(gemEdge)); if (body->edges == NULL) goto ret; for (i = 0; i < nedge; i++) { body->edges[i].faces[0] = body->edges[i].faces[1] = 0; body->edges[i].attr = NULL; } body->nedge = nedge; for (n = i = 0; i < nedge; i++) { stat = EG_getTopology(edges[i], &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) goto ret; if (mtype == DEGENERATE) { edges[i] = NULL; continue; } gid.ident.ptr = edges[i]; body->edges[n].handle = gid; body->edges[n].tlimit[0] = limits[0]; body->edges[n].tlimit[1] = limits[1]; body->edges[n].nodes[0] = gem_lookup(objs[0], nnode, nodes); if (nobjs == 1) { body->edges[n].nodes[1] = body->edges[n].nodes[0]; } else { body->edges[n].nodes[1] = gem_lookup(objs[1], nnode, nodes); } gem_fillAttrs(edges[i], &body->edges[n].attr); n++; } body->nedge = n; } /* make the loops */ if ((nloop != 0) && (loops != NULL)) { stat = GEM_ALLOC; body->loops = (gemLoop *) gem_allocate(nloop*sizeof(gemLoop)); if (body->loops == NULL) goto ret; for (i = 0; i < nloop; i++) { body->loops[i].edges = NULL; body->loops[i].attr = NULL; } body->nloop = nloop; for (i = 0; i < nloop; i++) { stat = EG_getTopology(loops[i], &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) goto ret; gid.ident.ptr = loops[i]; body->loops[i].handle = gid; body->loops[i].type = 0; body->loops[i].face = 0; body->loops[i].edges = (int *) gem_allocate(nobjs*sizeof(int)); stat = GEM_ALLOC; if (body->loops[i].edges == NULL) goto ret; for (n = j = 0; j < nobjs; j++) { k = gem_lookup(objs[j], nedge, edges); if (k == 0) continue; body->loops[i].edges[n] = senses[j]*k; n++; } body->loops[i].nedges = n; gem_fillAttrs(loops[i], &body->loops[i].attr); } } /* make the faces */ if ((nface != 0) && (faces != NULL)) { len = 0; if (bID != NULL) len = strlen(bID); stat = GEM_ALLOC; body->faces = (gemFace *) gem_allocate(nface*sizeof(gemFace)); if (body->faces == NULL) goto ret; for (i = 0; i < nface; i++) { body->faces[i].loops = NULL; body->faces[i].ID = NULL; body->faces[i].attr = NULL; } body->nface = nface; for (i = 0; i < nface; i++) { stat = EG_getTopology(faces[i], &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) goto ret; gid.ident.ptr = faces[i]; body->faces[i].handle = gid; body->faces[i].uvbox[0] = limits[0]; body->faces[i].uvbox[1] = limits[1]; body->faces[i].uvbox[2] = limits[2]; body->faces[i].uvbox[3] = limits[3]; body->faces[i].norm = mtype; body->faces[i].loops = (int *) gem_allocate(nobjs*sizeof(int)); stat = GEM_ALLOC; if (body->faces[i].loops == NULL) goto ret; body->faces[i].nloops = nobjs; for (j = 0; j < nobjs; j++) { k = gem_lookup(objs[j], nloop, loops); body->faces[i].loops[j] = k; if (k == 0) continue; if (body->loops == NULL) continue; body->loops[k-1].face = i+1; if (senses[j] == -1) body->loops[k-1].type = 1; /* set face markers in edge struct */ if (body->edges == NULL) continue; for (n = 0; n < body->loops[k-1].nedges; n++) { m = body->loops[k-1].edges[n]; if (m < 0) { if (body->edges[-m-1].faces[0] != 0) printf(" Diamond Internal: -Face for Edge %d = %d %d\n", -m, body->edges[-m-1].faces[0], i+1); body->edges[-m-1].faces[0] = i+1; } else { if (body->edges[m-1].faces[1] != 0) printf(" Diamond Internal: +Face for Edge %d = %d %d\n", m, body->edges[m-1].faces[1], i+1); body->edges[m-1].faces[1] = i+1; } } } if (bID == NULL) { stat = EG_attributeRet(faces[i], "body", &atype, &alen, &ints, &reals, &string); if ((stat != EGADS_SUCCESS) || (atype != ATTRINT)) { printf(" Diamond Internal: OpenCSM FaceID for %d = %d, atype = %d\n", i+1, stat, atype); } else { snprintf(buffer, 1024, "%d:%d", ints[0], ints[1]); for (j = 2; j < alen; j+=2) { m = strlen(buffer); if (m >= 1024) break; snprintf(&buffer[m], 1024-m, "::%d:%d", ints[j], ints[j+1]); } buffer[1024] = 0; body->faces[i].ID = gem_strdup(buffer); } } else { body->faces[i].ID = (char *) gem_allocate((len+10)*sizeof(char)); if (body->faces[i].ID == NULL) goto ret; snprintf(body->faces[i].ID, len+10, "%s:%d", bID, i+1); } gem_fillAttrs(faces[i], &body->faces[i].attr); } } /* make the shells */ if ((nshell != 0) && (shells != NULL)) { stat = GEM_ALLOC; body->shells = (gemShell *) gem_allocate(nshell*sizeof(gemShell)); if (body->shells == NULL) goto ret; for (i = 0; i < nshell; i++) { body->shells[i].faces = NULL; body->shells[i].attr = NULL; } body->nshell = nshell; for (i = 0; i < nshell; i++) { stat = EG_getTopology(shells[i], &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); if (stat != EGADS_SUCCESS) goto ret; gid.ident.ptr = shells[i]; body->shells[i].handle = gid; body->shells[i].type = 0; body->shells[i].faces = (int *) gem_allocate(nobjs*sizeof(int)); stat = GEM_ALLOC; if (body->shells[i].faces == NULL) goto ret; body->shells[i].nfaces = nobjs; for (j = 0; j < nobjs; j++) body->shells[i].faces[j] = gem_lookup(objs[j], nface, faces); gem_fillAttrs(shells[i], &body->shells[i].attr); } /* set the type for solids */ if ((body->type == GEM_SOLID) && (nshell > 1)) { EG_getTopology(object, &geom, &oclass, &mtype, limits, &nobjs, &objs, &senses); for (j = 0; j < nobjs; j++) { if (senses[j] == 1) continue; k = gem_lookup(objs[j], nshell, shells); if (k == 0) continue; body->shells[k-1].type = 1; } } } gem_fillAttrs(object, &body->attr); stat = EGADS_SUCCESS; ret: if (shells != NULL) EG_free(shells); if (faces != NULL) EG_free(faces); if (loops != NULL) EG_free(loops); if (edges != NULL) EG_free(edges); if (nodes != NULL) EG_free(nodes); return stat; }
static int bodyTessellation(ego tess, int nface, int *nvert, double **verts, int *ntriang, int **triang) { int status, i, j, k, base, npts, ntri, *tri, *table; int plen, tlen; const int *tris, *tric, *ptype, *pindex; double *xyzs; const double *points, *uv; *nvert = *ntriang = 0; *verts = NULL; *triang = NULL; npts = ntri = 0; for (i = 1; i <= nface; i++) { status = EG_getTessFace(tess, i, &plen, &points, &uv, &ptype, &pindex, &tlen, &tris, &tric); if (status != EGADS_SUCCESS) { printf(" Face %d: EG_getTessFace status = %d (bodyTessellation)!\n", i, status); } else { npts += plen; ntri += tlen; } } /* get the memory associated with the points */ table = (int *) EG_alloc(2*npts*sizeof(int)); if (table == NULL) { printf(" Error: Can not allocate node table (bodyTessellation)!\n"); return EGADS_MALLOC; } xyzs = (double *) EG_alloc(3*npts*sizeof(double)); if (xyzs == NULL) { printf(" Error: Can not allocate XYZs (bodyTessellation)!\n"); EG_free(table); return EGADS_MALLOC; } /* zipper up the edges -- a Face at a time */ npts = 0; for (j = 1; j <= nface; j++) { status = EG_getTessFace(tess, j, &plen, &points, &uv, &ptype, &pindex, &tlen, &tris, &tric); if (status != EGADS_SUCCESS) continue; for (i = 0; i < plen; i++) { table[2*npts ] = ptype[i]; table[2*npts+1] = pindex[i]; xyzs[3*npts ] = points[3*i ]; xyzs[3*npts+1] = points[3*i+1]; xyzs[3*npts+2] = points[3*i+2]; /* for non-interior pts -- try to match with others */ if (ptype[i] != -1) for (k = 0; k < npts; k++) if ((table[2*k]==table[2*npts]) && (table[2*k+1]==table[2*npts+1])) { table[2*npts ] = k; table[2*npts+1] = 0; break; } npts++; } } /* fill up the whole triangle list -- a Face at a time */ tri = (int *) EG_alloc(3*ntri*sizeof(int)); if (tri == NULL) { printf(" Error: Can not allocate triangles (bodyTessellation)!\n"); EG_free(xyzs); EG_free(table); return EGADS_MALLOC; } ntri = base = 0; for (j = 1; j <= nface; j++) { /* get the face tessellation and store it away */ status = EG_getTessFace(tess, j, &plen, &points, &uv, &ptype, &pindex, &tlen, &tris, &tric); if (status != EGADS_SUCCESS) continue; for (i = 0; i < tlen; i++, ntri++) { k = tris[3*i ] + base; if (table[2*k-1] == 0) { tri[3*ntri ] = table[2*k-2] + 1; } else { tri[3*ntri ] = k; } k = tris[3*i+1] + base; if (table[2*k-1] == 0) { tri[3*ntri+1] = table[2*k-2] + 1; } else { tri[3*ntri+1] = k; } k = tris[3*i+2] + base; if (table[2*k-1] == 0) { tri[3*ntri+2] = table[2*k-2] + 1; } else { tri[3*ntri+2] = k; } } base += plen; } /* remove the unused points -- crunch the point list * NOTE: the returned pointer verts has the full length (not realloc'ed) */ for (i = 0; i < npts; i++) table[i] = 0; for (i = 0; i < 3*ntri; i++) table[tri[i]-1]++; for (plen = i = 0; i < npts; i++) { if (table[i] == 0) continue; xyzs[3*plen ] = xyzs[3*i ]; xyzs[3*plen+1] = xyzs[3*i+1]; xyzs[3*plen+2] = xyzs[3*i+2]; plen++; table[i] = plen; } /* reset the triangle indices */ for (i = 0; i < 3*ntri; i++) { k = tri[i]-1; tri[i] = table[k]; } EG_free(table); *nvert = plen; *verts = xyzs; *ntriang = ntri; *triang = tri; return EGADS_SUCCESS; }
int udpInitialize(int *nArgs, char ***namex, int **typex, int **idefaulx, double **ddefaulx) { int *type, *idefault; char **name; double *ddefault; /* make the arrays */ ebodys = (ego *) EG_alloc(sizeof(ego )); Depth = (double *) EG_alloc(sizeof(double )); Nseg = (int *) EG_alloc(sizeof(int )); Segments = (double**) EG_alloc(sizeof(double*)); if (ebodys == NULL || Depth == NULL || Nseg == NULL || Segments == NULL) { return EGADS_MALLOC; } /* initialize the array elements that will hold the "current" settings */ ebodys[ 0] = NULL; Depth[ 0] = 1; Nseg[ 0] = 0; Segments[0] = NULL; /* set up returns that describe the UDP */ *nArgs = 2; *namex = NULL; *typex = NULL; *idefaulx = NULL; *ddefaulx = NULL; *namex = name = (char **) EG_alloc((*nArgs)*sizeof(char *)); if (*namex == NULL) { return EGADS_MALLOC; } *typex = type = (int *) EG_alloc((*nArgs)*sizeof(int)); if (*typex == NULL) { EG_free(*namex); return EGADS_MALLOC; } *idefaulx = idefault = (int *) EG_alloc((*nArgs)*sizeof(int)); if (*idefaulx == NULL) { EG_free(*typex); EG_free(*namex); return EGADS_MALLOC; } *ddefaulx = ddefault = (double *) EG_alloc((*nArgs)*sizeof(double)); if (*ddefaulx == NULL) { EG_free(*idefaulx); EG_free(*typex); EG_free(*namex); return EGADS_MALLOC; } name[0] = "Depth"; type[0] = ATTRREAL; idefault[0] = 0; ddefault[0] = 1; name[1] = "Segments"; type[1] = ATTRSTRING; idefault[1] = 0; ddefault[1] = 0; return EGADS_SUCCESS; }
int udpExecute(ego context, ego *ebody, int *nMesh, char **string) { int status = EGADS_SUCCESS; int inode, jnode, nnode, iseg, jseg, jedge, jface, senses[4]; int *ibeg=NULL, *iend=NULL; int ia, ib, ic, id, MAXSIZE=1000; double *X=NULL, *Y=NULL; double xyz[20], data[6], xyz_out[20], D, s, t, xx, yy; double EPS06 = 1.0e-6; ego *enodes=NULL, *eedges=NULL, *efaces=NULL, ecurve, echild[4], eloop, eshell; /* default return values */ *ebody = NULL; *nMesh = 0; *string = NULL; /* increment number of UDPs */ numUdp++; /* increase the arrays to make room for the new UDP */ ebodys = (ego *) EG_reall(ebodys, (numUdp+1)*sizeof(ego )); Depth = (double *) EG_reall(Depth, (numUdp+1)*sizeof(double )); Nseg = (int *) EG_reall(Nseg, (numUdp+1)*sizeof(int )); Segments = (double**) EG_reall(Segments, (numUdp+1)*sizeof(double*)); if (ebodys == NULL || Depth == NULL || Nseg == NULL || Segments == NULL) { return EGADS_MALLOC; } ebodys[ numUdp] = NULL; Segments[numUdp] = (double*) EG_alloc(4*Nseg[0]*sizeof(double)); if (Segments[numUdp] == NULL) { status = EGADS_MALLOC; goto cleanup; } /* copy in the data */ Depth[numUdp] = Depth[0]; Nseg[ numUdp] = Nseg[ 0]; for (iseg = 0; iseg < Nseg[0]; iseg++) { Segments[numUdp][4*iseg ] = Segments[0][4*iseg ]; Segments[numUdp][4*iseg+1] = Segments[0][4*iseg+1]; Segments[numUdp][4*iseg+2] = Segments[0][4*iseg+2]; Segments[numUdp][4*iseg+3] = Segments[0][4*iseg+3]; } /* make an indexed table of the segments */ X = (double *) EG_alloc(MAXSIZE*sizeof(double)); // probably too big Y = (double *) EG_alloc(MAXSIZE*sizeof(double)); ibeg = (int *) EG_alloc(MAXSIZE*sizeof(int )); iend = (int *) EG_alloc(MAXSIZE*sizeof(int )); if (X == NULL || Y == NULL || ibeg == NULL || iend == NULL) { status = EGADS_MALLOC; goto cleanup; } nnode = 0; for (iseg = 0; iseg < Nseg[0]; iseg++) { ibeg[iseg] = -1; for (jnode = 0; jnode < nnode; jnode++) { if (fabs(Segments[0][4*iseg ]-X[jnode]) < EPS06 && fabs(Segments[0][4*iseg+1]-Y[jnode]) < EPS06 ) { ibeg[iseg] = jnode; break; } } if (ibeg[iseg] < 0) { ibeg[iseg] = nnode; X[nnode] = Segments[0][4*iseg ]; Y[nnode] = Segments[0][4*iseg+1]; nnode++; } iend[iseg] = -1; for (jnode = 0; jnode < nnode; jnode++) { if (fabs(Segments[0][4*iseg+2]-X[jnode]) < EPS06 && fabs(Segments[0][4*iseg+3]-Y[jnode]) < EPS06 ) { iend[iseg] = jnode; break; } } if (iend[iseg] < 0) { iend[iseg] = nnode; X[nnode] = Segments[0][4*iseg+2]; Y[nnode] = Segments[0][4*iseg+3]; nnode++; } } /* check for intersections */ for (jseg = 0; jseg < Nseg[0]; jseg++) { for (iseg = jseg+1; iseg < Nseg[0]; iseg++) { ia = ibeg[iseg]; ib = iend[iseg]; ic = ibeg[jseg]; id = iend[jseg]; D = (X[ib] - X[ia]) * (Y[ic] - Y[id]) - (X[ic] - X[id]) * (Y[ib] - Y[ia]); if (fabs(D) > EPS06) { s = ((X[ic] - X[ia]) * (Y[ic] - Y[id]) - (X[ic] - X[id]) * (Y[ic] - Y[ia])) / D; t = ((X[ib] - X[ia]) * (Y[ic] - Y[ia]) - (X[ic] - X[ia]) * (Y[ib] - Y[ia])) / D; if (s > -EPS06 && s < 1+EPS06 && t > -EPS06 && t < 1+EPS06 ) { xx = (1 - s) * X[ia] + s * X[ib]; yy = (1 - s) * Y[ia] + s * Y[ib]; inode = -1; for (jnode = 0; jnode < nnode; jnode++) { if (fabs(xx-X[jnode]) < EPS06 && fabs(yy-Y[jnode]) < EPS06 ) { inode = jnode; break; } } if (inode < 0) { inode = nnode; X[nnode] = xx; Y[nnode] = yy; nnode++; } if (ia != inode && ib != inode) { ibeg[Nseg[0]] = inode; iend[Nseg[0]] = ib; Nseg[0]++; iend[iseg] = inode; } if (ic != inode && id != inode) { ibeg[Nseg[0]] = inode; iend[Nseg[0]] = id; Nseg[0]++; iend[jseg] = inode; } } } } } /* check for degenerate segments */ for (jseg = 0; jseg < Nseg[0]; jseg++) { if (ibeg[jseg] == iend[jseg]) { printf(" udpExecute: segment %d is degenerate\n", iseg); status = EGADS_DEGEN; goto cleanup; } } /* allocate space for the egos */ enodes = (ego *) EG_alloc((2*nnode )*sizeof(ego)); eedges = (ego *) EG_alloc(( nnode+2*Nseg[0])*sizeof(ego)); efaces = (ego *) EG_alloc(( Nseg[0])*sizeof(ego)); if (enodes == NULL || eedges == NULL || efaces == NULL) { status = EGADS_MALLOC; goto cleanup; } /* set up enodes at Z=0 and at Z=Depth */ jnode = 0; for (inode = 0; inode < nnode; inode++) { xyz[0] = X[inode]; xyz[1] = Y[inode]; xyz[2] = 0; status = EG_makeTopology(context, NULL, NODE, 0, xyz, 0, NULL, NULL, &(enodes[jnode])); if (status != EGADS_SUCCESS) goto cleanup; jnode++; } for (inode = 0; inode < nnode; inode++) { xyz[0] = X[inode]; xyz[1] = Y[inode]; xyz[2] = Depth[0]; status = EG_makeTopology(context, NULL, NODE, 0, xyz, 0, NULL, NULL, &(enodes[jnode])); if (status != EGADS_SUCCESS) goto cleanup; jnode++; } /* set up the edges on the z=0 plane */ jedge = 0; for (iseg = 0; iseg < Nseg[0]; iseg++) { xyz[0] = X[ibeg[iseg]]; xyz[1] = Y[ibeg[iseg]]; xyz[2] = 0; xyz[3] = X[iend[iseg]] - X[ibeg[iseg]]; xyz[4] = Y[iend[iseg]] - Y[ibeg[iseg]]; xyz[5] = 0; status = EG_makeGeometry(context, CURVE, LINE, NULL, NULL, xyz, &ecurve); if (status != EGADS_SUCCESS) goto cleanup; echild[0] = enodes[ibeg[iseg]]; echild[1] = enodes[iend[iseg]]; status = EG_invEvaluate(ecurve, xyz, &(data[0]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; xyz[0] = X[iend[iseg]]; xyz[1] = Y[iend[iseg]]; xyz[2] = 0; status = EG_invEvaluate(ecurve, xyz, &(data[1]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; status = EG_makeTopology(context, ecurve, EDGE, TWONODE, data, 2, echild, NULL, &(eedges[jedge])); if (status != EGADS_SUCCESS) goto cleanup; jedge++; } /* set up the edges on the z=Depth plane */ for (iseg = 0; iseg < Nseg[0]; iseg++) { xyz[0] = X[ibeg[iseg]]; xyz[1] = Y[ibeg[iseg]]; xyz[2] = Depth[0]; xyz[3] = X[iend[iseg]] - X[ibeg[iseg]]; xyz[4] = Y[iend[iseg]] - Y[ibeg[iseg]]; xyz[5] = 0; status = EG_makeGeometry(context, CURVE, LINE, NULL, NULL, xyz, &ecurve); if (status != EGADS_SUCCESS) goto cleanup; echild[0] = enodes[ibeg[iseg]+nnode]; echild[1] = enodes[iend[iseg]+nnode]; status = EG_invEvaluate(ecurve, xyz, &(data[0]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; xyz[0] = X[iend[iseg]]; xyz[1] = Y[iend[iseg]]; xyz[2] = Depth[0]; status = EG_invEvaluate(ecurve, xyz, &(data[1]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; status = EG_makeTopology(context, ecurve, EDGE, TWONODE, data, 2, echild, NULL, &(eedges[jedge])); if (status != EGADS_SUCCESS) goto cleanup; jedge++; } /* set up the edges between z=0 and Depth */ for (inode = 0; inode < nnode; inode++) { xyz[0] = X[inode]; xyz[1] = Y[inode]; xyz[2] = 0; xyz[3] = 0; xyz[4] = 0; xyz[5] = 1; status = EG_makeGeometry(context, CURVE, LINE, NULL, NULL, xyz, &ecurve); if (status != EGADS_SUCCESS) goto cleanup; echild[0] = enodes[inode ]; echild[1] = enodes[inode+nnode]; status = EG_invEvaluate(ecurve, xyz, &(data[0]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; xyz[0] = X[inode]; xyz[1] = Y[inode]; xyz[2] = Depth[0]; status = EG_invEvaluate(ecurve, xyz, &(data[1]), xyz_out); if (status != EGADS_SUCCESS) goto cleanup; status = EG_makeTopology(context, ecurve, EDGE, TWONODE, data, 2, echild, NULL, &(eedges[jedge])); if (status != EGADS_SUCCESS) goto cleanup; jedge++; } /* set up the faces */ jface = 0; for (iseg = 0; iseg < Nseg[0]; iseg++) { echild[0] = eedges[iseg]; echild[1] = eedges[2*Nseg[0]+iend[iseg]]; echild[2] = eedges[ Nseg[0]+ iseg ]; echild[3] = eedges[2*Nseg[0]+ibeg[iseg]]; senses[0] = SFORWARD; senses[1] = SFORWARD; senses[2] = SREVERSE; senses[3] = SREVERSE; status = EG_makeTopology(context, NULL, LOOP, CLOSED, NULL, 4, echild, senses, &eloop); if (status != EGADS_SUCCESS) goto cleanup; status = EG_makeFace(eloop, SFORWARD, NULL, &(efaces[jface])); if (status != EGADS_SUCCESS) goto cleanup; jseg = iseg + 1; status = EG_attributeAdd(efaces[jface], "segment", ATTRINT, 1, &jseg, NULL, NULL); if (status != EGADS_SUCCESS) goto cleanup; jface++; } /* make the sheet body */ status = EG_makeTopology(context, NULL, SHELL, OPEN, NULL, jface, efaces, NULL, &eshell); if (status != EGADS_SUCCESS) goto cleanup; status = EG_makeTopology(context, NULL, BODY, SHEETBODY, NULL, 1, &eshell, NULL, ebody); if (status != EGADS_SUCCESS) goto cleanup; /* remember this model (body) */ ebodys[numUdp] = *ebody; cleanup: if (efaces != NULL) EG_free(efaces); if (eedges != NULL) EG_free(eedges); if (enodes != NULL) EG_free(enodes); if (X != NULL) EG_free(X ); if (Y != NULL) EG_free(Y ); if (ibeg != NULL) EG_free(ibeg ); if (iend != NULL) EG_free(iend ); if (status != EGADS_SUCCESS) { *string = udpErrorStr(status); } return status; }
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; }
ig_free_(void **ptr) #endif { EG_free(*ptr); *ptr = NULL; }