【NX二次开发】将实体离散成点的方法
将实体离散成点可以用UF_FACET_这这一类的ufun函数组合使用。
生成的点的规则可以查看UF_FACET_ask_vertices_of_facet函数的介绍。
源码:(注意:生成的点没有去重)
void discretePoint(const vector<tag_t> &tObjs, const double &dPrecision, vector<Point3d> *vecP) { for (int b = 0; b < tObjs.size(); b++) { UF_FACET_parameters_t parameters; UF_FACET_INIT_PARAMETERS(¶meters); UF_FACET_ask_default_parameters(¶meters); tag_t facetedModels; parameters.specify_max_facet_size = true; parameters.max_facet_size = dPrecision; UF_FACET_facet_solid(tObjs[b], ¶meters, &facetedModels); int maxVerticesInFacet; UF_FACET_ask_max_facet_verts(facetedModels, &maxVerticesInFacet); int vertexArraySize = 3 * maxVerticesInFacet * sizeof(double); double(*vertices)[3] = (double(*)[3])malloc(vertexArraySize); int facetId = UF_FACET_NULL_FACET_ID; UF_FACET_cycle_facets(facetedModels, &facetId); while (facetId != UF_FACET_NULL_FACET_ID) { int vertsInFacet; UF_FACET_ask_vertices_of_facet(facetedModels, facetId, &vertsInFacet, (double(*)[3])vertices); if (vertsInFacet > 0) { for (size_t p = 0; p < vertsInFacet; p++) { Point3d temp; temp.X = vertices[p][0]; temp.Y = vertices[p][1]; temp.Z = vertices[p][2]; (*vecP).push_back(temp); } } UF_FACET_cycle_facets(facetedModels, &facetId); } free(vertices); } }