19 {
GMSH_FULLRC,
"OutputFile",
nullptr,
"bubbles.geo"}};
27 return "Plugin(Bubbles) constructs a geometry consisting of "
28 "`bubbles' inscribed in the Voronoi of an input triangulation. "
29 "`ShrinkFactor' allows to change the size of the bubbles. "
30 "The plugin expects a triangulation in the `z = 0' plane to exist "
31 "in the current model.\n\n"
32 "Plugin(Bubbles) creates one `.geo' file.";
55 static double myangle(
double c[3],
double p[3])
57 double v[3] = {1, 0, 0};
58 double n[3] = {0, 0, 1};
59 if(fabs(
c[0] - p[0]) < 1e-12 && fabs(
c[1] - p[1]) < 1e-12 &&
60 fabs(
c[2] - p[2]) < 1e-12)
73 double p1[3] = {
b1.x(),
b1.y(),
b1.z()};
74 double p2[3] = {b2.
x(), b2.
y(), b2.
z()};
75 double c[3] = {
v.
x(),
v.
y(),
v.
z()};
86 FILE *fp =
Fopen(fileName.c_str(),
"w");
88 Msg::Error(
"Could not open output file '%s'", fileName.c_str());
101 fprintf(fp,
"lc = %g;\n", lc);
104 (*vit)->writeGEO(fp,
"lc");
107 (*eit)->writeGEO(fp);
110 (*fit)->writeGEO(fp);
111 fprintf(fp,
"Delete { Surface {%d}; }\n", (*fit)->tag());
117 std::map<MVertex *, std::vector<SPoint3> > v2t;
118 for(std::size_t i = 0; i < (*fit)->triangles.size(); i++)
119 for(
int j = 0; j < 3; j++)
120 v2t[(*fit)->triangles[i]->getVertex(j)].push_back(
121 (*fit)->triangles[i]->barycenter());
124 for(
auto it = v2t.begin(); it != v2t.end(); it++) {
127 it->second.push_back(
128 SPoint3(it->first->x(), it->first->y(), it->first->z()));
131 for(
auto it = v2t.begin(); it != v2t.end(); it++) {
132 if(it->second.size() > 2) {
135 for(std::size_t i = 0; i < it->second.size(); i++) bc += it->second[i];
136 bc *= 1. / (
double)it->second.size();
138 std::sort(it->second.begin(), it->second.end(), comp);
141 for(std::size_t i = 0; i < it->second.size(); i++) {
142 double dir[3] = {it->second[i].x() - bc.
x(),
143 it->second[i].y() - bc.
y(),
144 it->second[i].z() - bc.
z()};
145 it->second[i][0] -= shrink * dir[0];
146 it->second[i][1] -= shrink * dir[1];
147 it->second[i][2] -= shrink * dir[2];
151 int nump = it->second.size();
152 for(
int i = 0; i < nump; i++) {
154 fprintf(fp,
"Point(%d) = {%.16g, %.16g, %.16g, lc};\n", p++, b.
x(),
157 fprintf(fp,
"BSpline(%d) = {", l++);
158 for(
int i = nump - 1; i >= 0; i--) fprintf(fp,
"%d,", p - i - 1);
159 fprintf(fp,
"%d};\n", p - nump);
160 fprintf(fp,
"Curve Loop(%d) = {%d};\n", ll++, l - 1);
161 fprintf(fp,
"Plane Surface(%d) = {%d};\n", s++, ll - 1);
164 fprintf(fp,
"Physical Surface(%d) = {%d:%d};\n", ps++, sbeg, s - 1);
166 fprintf(fp,
"Plane Surface(%d) = {%d, %d:%d};\n", s++, (*fit)->tag(), llbeg,
168 fprintf(fp,
"Physical Surface(%d) = {%d};\n", ps++, s - 1);