void tag_copy_sets(iMesh_Instance imeshImpl, iBase_TagHandle copyTag, const std::set<iBase_EntitySetHandle> ©Sets, iBase_TagHandle tag, const char *tag_val) { int err; int tag_size; iMesh_getTagSizeBytes(imeshImpl, tag, &tag_size, &err); check_error(imeshImpl, err); // allocate temp space for tag value std::vector<char> value; value.resize(tag_size); void *value_ptr = &value[0]; int value_alloc = tag_size, value_size; // for each orig copy set with this tag, copy it to its copy std::set<iBase_EntitySetHandle>::iterator set; for (set = copySets.begin(); set != copySets.end(); ++set) { // get the tag value iMesh_getEntSetData(imeshImpl, *set, tag, &value_ptr, &value_alloc, &value_size, &err); if (err == iBase_TAG_NOT_FOUND) continue; check_error(imeshImpl, err); // compare to tag value if necessary if (tag_val && memcmp(tag_val, value_ptr, tag_size)) continue; // if we got here, we should set the tag on the copy; get the copy iBase_EntitySetHandle copy_set; iMesh_getEntSetEHData(imeshImpl, *set, copyTag, reinterpret_cast<iBase_EntityHandle*>(©_set), &err); if (err == iBase_TAG_NOT_FOUND) continue; check_error(imeshImpl, err); if (copy_set != *set) { iMesh_setEntSetData(imeshImpl, copy_set, tag, value_ptr, tag_size, &err); check_error(imeshImpl, err); } } }
static dErr doMaterial(iMesh_Instance mesh,iBase_EntitySetHandle root) { static const char matSetName[] = "MAT_SET",matNumName[] = "MAT_NUM"; dMeshTag matSetTag,matNumTag; dMeshESH mat[2]; dMeshEH *ents; MeshListEH r=MLZ,v=MLZ; MeshListInt rvo=MLZ; MeshListReal x=MLZ; dReal fx,center[3],*matnum; dInt nents; dErr err; dFunctionBegin; iMesh_createTag(mesh,matSetName,1,iBase_INTEGER,&matSetTag,&err,sizeof(matSetName));dICHK(mesh,err); iMesh_createTag(mesh,matNumName,1,iBase_DOUBLE,&matNumTag,&err,sizeof(matNumName));dICHK(mesh,err); iMesh_getEntities(mesh,root,iBase_REGION,iMesh_ALL_TOPOLOGIES,MLREF(r),&err);dICHK(mesh,err); iMesh_getEntArrAdj(mesh,r.v,r.s,iBase_VERTEX,MLREF(v),MLREF(rvo),&err);dICHK(mesh,err); iMesh_getVtxArrCoords(mesh,v.v,v.s,iBase_INTERLEAVED,MLREF(x),&err);dICHK(mesh,err); err = dMalloc(r.s*sizeof(ents[0]),&ents);dCHK(err); err = dMalloc(r.s*sizeof(matnum[0]),&matnum);dCHK(err); for (dInt i=0; i<2; i++) { iMesh_createEntSet(mesh,0,&mat[i],&err);dICHK(mesh,err); iMesh_setEntSetData(mesh,mat[i],matSetTag,(char*)&i,sizeof(i),&err);dICHK(mesh,err); nents = 0; for (dInt j=0; j<r.s; j++) { dGeomVecMeanI(8,x.v+3*rvo.v[j],center); fx = sqrt(dGeomDotProd(center,center)); /* material 0 if inside the unit ball, else material 1 */ if (i == (fx < 1.0) ? 0 : 1) { ents[nents] = r.v[j]; matnum[nents] = 1.0 * i; nents++; } } iMesh_addEntArrToSet(mesh,ents,nents,mat[i],&err);dICHK(mesh,err); iMesh_setArrData(mesh,ents,nents,matNumTag,(char*)matnum,nents*(int)sizeof(matnum[0]),&err);dICHK(mesh,err); } err = dFree(ents);dCHK(err); err = dFree(matnum);dCHK(err); MeshListFree(r); MeshListFree(v); MeshListFree(rvo); MeshListFree(x); dFunctionReturn(0); }