7 #include "GmshConfig.h"
17 #if !defined(HAVE_ANN)
20 std::vector<int> &surfaces)
22 Msg::Error(
"Gmsh must be compiled with ANN support to carve holes in meshes");
34 ANNidxArray index =
new ANNidx[1];
35 ANNdistArray dist =
new ANNdist[1];
36 std::vector<T *> temp;
37 for(std::size_t i = 0; i < elements.size(); i++) {
38 for(std::size_t j = 0; j < elements[i]->getNumVertices(); j++) {
39 MVertex *v = elements[i]->getVertex(j);
40 double xyz[3] = {v->
x(), v->
y(), v->
z()};
41 kdtree->annkSearch(xyz, 1, index, dist);
42 double d = std::sqrt(dist[0]);
48 temp.push_back(elements[i]);
58 void addFaces(std::vector<T *> &elements, std::set<MFace, MFaceLessThan> &
faces)
60 for(std::size_t i = 0; i < elements.size(); i++) {
61 for(
int j = 0; j < elements[i]->getNumFaces(); j++) {
62 MFace f = elements[i]->getFace(j);
73 std::vector<int> &surfaces)
75 Msg::Info(
"Carving hole %d from surface %d at distance %g", num, surfaces[0],
81 for(std::size_t i = 0; i < surfaces.size(); i++) {
84 Msg::Error(
"Unknown carving surface %d", surfaces[i]);
90 ANNpointArray kdnodes = annAllocPts(numnodes, 3);
92 for(std::size_t i = 0; i < surfaces.size(); i++) {
101 ANNkd_tree *kdtree =
new ANNkd_tree(kdnodes, numnodes, 3);
111 annDeallocPts(kdnodes);
120 std::set<MFace, MFaceLessThan>
faces;
121 std::vector<GFace *>
f = gr->
faces();
122 for(
auto it =
f.begin(); it !=
f.end(); it++) {
123 addFaces((*it)->triangles,
faces);
124 addFaces((*it)->quadrangles,
faces);
131 std::set<MVertex *> verts;
132 for(
auto it =
faces.begin(); it !=
faces.end(); it++) {
133 for(std::size_t i = 0; i < it->getNumVertices(); i++) {
134 it->getVertex(i)->setEntity(gf);
135 verts.insert(it->getVertex(i));
137 if(it->getNumVertices() == 3)
139 new MTriangle(it->getVertex(0), it->getVertex(1), it->getVertex(2)));
140 else if(it->getNumVertices() == 4)
142 new MQuadrangle(it->getVertex(0), it->getVertex(1), it->getVertex(2),