30 return N.
x() * n[0] + N.
y() * n[1] + N.
z() * n[2];
36 if(!
f->getNodes(pts))
return 0.;
37 if((pts[0]->degenerated ? 1 : 0) + (pts[1]->degenerated ? 1 : 0) +
38 (pts[2]->degenerated ? 1 : 0) <
41 return qa1 *
_cos_N(pts[0], pts[1], pts[2], gf);
49 Msg::Info(
"Writing debug file '%s'", iii);
51 FILE *view_c =
Fopen(
"param_mesh_as_it_is_in_3D.pos",
"w");
53 Msg::Error(
"Could not open file 'param_mesh_as_it_is_in_3D.pos'");
56 fprintf(view_c,
"View \"paramC\"{\n");
61 if(!(*tit)->deleted && (*tit)->getNodes(pts)) {
62 for(
int j = 0; j < 3; j++) {
64 pts[j]->
degenerated == 1 ? pts[(j + 1) % 3]->u : pts[j]->u;
65 double U2 = pts[(j + 1) % 3]->degenerated == 1 ? pts[j]->u :
68 pts[j]->
degenerated == 2 ? pts[(j + 1) % 3]->v : pts[j]->v;
69 double V2 = pts[(j + 1) % 3]->degenerated == 2 ? pts[j]->v :
74 for(
int k = 1; k < 30; k++) {
75 double t = (double)k / 29;
76 SPoint2 p = p1 * (1. - t) + p2 * t;
79 fprintf(view_c,
"SL(%g,%g,%g,%g,%g,%g){1,1,1};\n", pa.x(), pa.y(),
80 pa.z(), pb.
x(), pb.
y(), pb.
z());
87 fprintf(view_c,
"};\n");
96 fprintf(
f,
"View \"scalar\" {\n");
101 if(!(*tit)->deleted && (*tit)->getNodes(pts)) {
104 "ST(%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%"
105 "22.15E,%22.15E){%g,%g,%g};\n",
106 pts[0]->X, pts[0]->Y, pts[0]->Z, pts[1]->X, pts[1]->Y,
107 pts[1]->Z, pts[2]->X, pts[2]->Y, pts[2]->Z, (
double)pts[0]->iD,
108 (
double)pts[1]->iD, (
double)pts[2]->iD);
112 if((pts[0]->degenerated ? 1 : 0) + (pts[1]->degenerated ? 1 : 0) +
113 (pts[2]->degenerated ? 1 : 0) >
115 else if(pts[0]->degenerated == 1)
116 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
117 pts[1]->u, pts[1]->v, 0.0, pts[2]->u, pts[2]->v, 0.0,
118 pts[2]->u, pts[0]->v, 0.0, pts[1]->u, pts[0]->v, 0.0,
119 (
double)pts[1]->iD, (
double)pts[2]->iD, (
double)pts[0]->iD,
121 else if(pts[1]->degenerated == 1)
122 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
123 pts[2]->u, pts[2]->v, 0.0, pts[0]->u, pts[0]->v, 0.0,
124 pts[0]->u, pts[1]->v, 0.0, pts[2]->u, pts[1]->v, 0.0,
125 (
double)pts[2]->iD, (
double)pts[0]->iD, (
double)pts[1]->iD,
127 else if(pts[2]->degenerated == 1)
128 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
129 pts[0]->u, pts[0]->v, 0.0, pts[1]->u, pts[1]->v, 0.0,
130 pts[1]->u, pts[2]->v, 0.0, pts[0]->u, pts[2]->v, 0.0,
131 (
double)pts[0]->iD, (
double)pts[1]->iD, (
double)pts[2]->iD,
133 else if(pts[0]->degenerated == 2)
134 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
135 pts[1]->u, pts[1]->v, 0.0, pts[2]->u, pts[2]->v, 0.0,
136 pts[0]->u, pts[2]->v, 0.0, pts[0]->u, pts[1]->v, 0.0,
137 (
double)pts[1]->iD, (
double)pts[2]->iD, (
double)pts[0]->iD,
139 else if(pts[1]->degenerated == 2)
140 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
141 pts[2]->u, pts[2]->v, 0.0, pts[0]->u, pts[0]->v, 0.0,
142 pts[1]->u, pts[0]->v, 0.0, pts[1]->u, pts[2]->v, 0.0,
143 (
double)pts[2]->iD, (
double)pts[0]->iD, (
double)pts[1]->iD,
145 else if(pts[2]->degenerated == 2)
146 fprintf(
f,
"SQ(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g){%g,%g,%g,%g};\n",
147 pts[0]->u, pts[0]->v, 0.0, pts[1]->u, pts[1]->v, 0.0,
148 pts[2]->u, pts[1]->v, 0.0, pts[2]->u, pts[0]->v, 0.0,
149 (
double)pts[0]->iD, (
double)pts[1]->iD, (
double)pts[2]->iD,
153 "ST(%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%22.15E,%"
154 "22.15E,%22.15E){%g,%g,%g};\n",
155 pts[0]->u, pts[0]->v, 0.0, pts[1]->u, pts[1]->v, 0.0,
156 pts[2]->u, pts[2]->v, 0.0, (
double)pts[0]->iD,
157 (
double)pts[1]->iD, (
double)pts[2]->iD);
170 double a[3] = {p1->
X - p2->
X, p1->
Y - p2->
Y, p1->
Z - p2->
Z};
171 double b[3] = {p1->
X - p3->
X, p1->
Y - p3->
Y, p1->
Z - p3->
Z};
172 c[2] = a[0] * b[1] - a[1] * b[0];
173 c[1] = -a[0] * b[2] + a[2] * b[0];
174 c[0] = a[1] * b[2] - a[2] * b[1];
180 double const a[2] = {p1->
u - p2->
u, p1->
v - p2->
v};
181 double const b[2] = {p1->
u - p3->
u, p1->
v - p3->
v};
182 return a[0] * b[1] - a[1] * b[0];
198 if(!p1 || !p2 || !p3) {
199 Msg::Error(
"Invalid point in parametric triangle surface computation");
209 double du = fabs(p3->
u - p2->
u);
210 c = 2 * fabs(0.5 * (p3->
v + p2->
v) - p1->
v) * du;
213 double du = fabs(p3->
u - p1->
u);
214 c = 2 * fabs(0.5 * (p3->
v + p1->
v) - p2->
v) * du;
217 double du = fabs(p2->
u - p1->
u);
218 c = 2 * fabs(0.5 * (p2->
v + p1->
v) - p3->
v) * du;
221 double dv = fabs(p3->
v - p2->
v);
222 c = 2 * fabs(0.5 * (p3->
u + p2->
u) - p1->
u) * dv;
225 double dv = fabs(p3->
v - p1->
v);
226 c = 2 * fabs(0.5 * (p3->
u + p1->
u) - p2->
u) * dv;
229 double dv = fabs(p2->
v - p1->
v);
230 c = 2 * fabs(0.5 * (p2->
u + p1->
u) - p3->
u) * dv;
239 std::vector<BDS_Face *> t;
240 t.reserve(
edges.size());
242 auto it =
edges.begin();
243 while(it !=
edges.end()) {
244 std::size_t
const number_of_faces = (*it)->numfaces();
246 for(std::size_t i = 0; i < number_of_faces; ++i) {
247 BDS_Face *
const tt = (*it)->faces(i);
248 if(tt && std::find(t.begin(), t.end(), tt) == t.end()) {
280 auto it =
points.find(&P);
287 auto eit = p->
edges.begin();
288 while(eit != p->
edges.end()) {
289 if((*eit)->p1 == p && (*eit)->p2->
iD == num2)
return (*eit);
290 if((*eit)->p2 == p && (*eit)->p1->
iD == num2)
return (*eit);
308 double y3,
double x4,
double y4,
double x[2])
312 mat[0][0] = (x2 - x1);
313 mat[0][1] = -(x4 - x3);
314 mat[1][0] = (y2 - y1);
315 mat[1][1] = -(y4 - y3);
318 if(!
sys2x2(mat, rhs, x))
return 0;
319 if(x[0] >= 0.0 && x[0] <= 1.0 && x[1] >= 0.0 && x[1] <= 1.0)
return 1;
327 auto it = ts.begin();
328 while(it != ts.end()) {
335 if(p2b && p2 == p2b) {
348 std::set<EdgeToRecover> *e2r,
349 std::set<EdgeToRecover> *not_recovered)
360 Msg::Error(
"Could not find points %d or %d in BDS mesh", num1, num2);
364 Msg::Debug(
"Edge %d %d has to be recovered", num1, num2);
369 std::vector<BDS_Edge *> intersected;
371 bool selfIntersection =
false;
373 auto it =
edges.begin();
374 while(it !=
edges.end()) {
376 if(!e->
deleted && e->
p1 != p1 && e->
p1 != p2 && e->
p2 != p1 &&
379 p1->
v, p2->
u, p2->
v, x)) {
385 Msg::Debug(
"edge %d %d on model edge %d cannot be recovered because"
386 " it intersects %d %d on model edge %d",
387 num1, num2, itr2->ge->tag(), e->
p1->
iD, e->
p2->
iD,
391 not_recovered->insert(
393 selfIntersection =
true;
396 intersected.push_back(e);
401 if(selfIntersection)
return nullptr;
403 if(!intersected.size() || ix > 300) {
410 "edge %d %d cannot be recovered at all, look at debugp.pos "
415 Msg::Debug(
"edge %d %d cannot be recovered at all", num1, num2);
423 std::vector<int>::size_type ichoice = 0;
424 bool success =
false;
425 while(!success && ichoice < intersected.size()) {
430 Msg::Debug(
"edge %d %d cannot be recovered at all\n", num1, num2);
454 return (o1 == e1 && o2 == e2 && o3 == e3) ||
455 (o1 == e1 && o2 == e3 && o3 == e2) ||
456 (o1 == e2 && o2 == e1 && o3 == e3) ||
457 (o1 == e2 && o2 == e3 && o3 == e1) ||
458 (o1 == e3 && o2 == e1 && o3 == e2) ||
459 (o1 == e3 && o2 == e2 && o3 == e1);
464 for(
int i = 0; i < e1->
numfaces(); i++) {
468 for(
int i = 0; i < e2->
numfaces(); i++) {
472 for(
int i = 0; i < e3->
numfaces(); i++) {
482 if(efound)
return efound;
488 Msg::Error(
"Could not find points %d or %d", p1, p2);
536 if(
points.erase(p))
delete p;
542 auto res =
geom.insert(e);
543 if(!res.second)
delete e;
549 oface[0] = oface[1] =
nullptr;
550 pts1[0] = pts1[1] = pts1[2] = pts1[3] =
nullptr;
551 pts2[0] = pts2[1] = pts2[2] = pts2[3] =
nullptr;
553 if(!
faces(0)->getNodes(pts1))
return;
554 if(pts1[0] !=
p1 && pts1[0] !=
p2)
556 else if(pts1[1] !=
p1 && pts1[1] !=
p2)
562 if(!
faces(1)->getNodes(pts2))
return;
563 if(pts2[0] !=
p1 && pts2[0] !=
p2)
565 else if(pts2[1] !=
p1 && pts2[1] !=
p2)
574 oface[0] = oface[1] =
nullptr;
577 if(!
faces(0)->getNodes(pts))
return;
578 if(pts[0] !=
p1 && pts[0] !=
p2)
580 else if(pts[1] !=
p1 && pts[1] !=
p2)
587 if(!
faces(1)->getNodes(pts))
return;
588 if(pts[0] !=
p1 && pts[0] !=
p2)
590 else if(pts[1] !=
p1 && pts[1] !=
p2)
600 auto it =
geom.find(&ge);
601 if(it ==
geom.end())
return nullptr;
607 std::stack<BDS_Face *> _stack;
610 while(!_stack.empty()) {
639 template <
class T>
bool operator()(T *
const face) {
return !face->deleted; }
657 while(it !=
edges.end()) {
696 if(!op[0] || !op[1])
return false;
698 const int CHECK1 = -1, CHECK2 = -1;
700 if(p1->
iD == CHECK1 && p2->
iD == CHECK2)
701 printf(
"splitting edge %d %d opp %d %d new %d\n", p1->
iD, p2->
iD, op[0]->
iD,
703 if(check_area_param) {
711 if(area1 > 1.1 * area0 || area1 < 0.9 * area0) {
return false; }
714 if(p1->
iD == CHECK1 && p2->
iD == CHECK2)
715 printf(
"%d %d %d %d\n", p1->
iD, p2->
iD, op[0]->
iD, op[1]->
iD);
721 for(
int i = 0; i < 3; i++) {
723 orientation = pts1[(i + 1) % 3] == p2 ? 1 : -1;
748 edges.push_back(p1_mid);
750 edges.push_back(mid_p2);
752 edges.push_back(op1_mid);
754 edges.push_back(mid_op2);
757 if(orientation == 1) {
758 t1 =
new BDS_Face(op1_mid, p1_op1, p1_mid);
759 t2 =
new BDS_Face(mid_op2, op2_p2, mid_p2);
760 t3 =
new BDS_Face(op1_p2, op1_mid, mid_p2);
761 t4 =
new BDS_Face(p1_op2, mid_op2, p1_mid);
764 t1 =
new BDS_Face(p1_op1, op1_mid, p1_mid);
765 t2 =
new BDS_Face(op2_p2, mid_op2, mid_p2);
766 t3 =
new BDS_Face(op1_mid, op1_p2, mid_p2);
767 t4 =
new BDS_Face(mid_op2, p1_op2, p1_mid);
798 double p1[2] = {_p1->
u, _p1->
v};
799 double p2[2] = {_p2->
u, _p2->
v};
800 double op1[2] = {_q1->
u, _q1->
v};
801 double op2[2] = {_q2->
u, _q2->
v};
806 return (ori_t1 * ori_t2 > 0);
844 if(fabs(s1 + s2 - s3 - s4) > 1.e-12 * (s3 + s4)) {
return false; }
858 if(_op1 != _oq1 && _op1 != _oq2 && _op1 != _oq3) {
862 else if(_op2 != _oq1 && _op2 != _oq2 && _op2 != _oq3) {
866 else if(_op3 != _oq1 && _op3 != _oq2 && _op3 != _oq3) {
871 Msg::Warning(
"Unable to detect the new edge in BDS_SwapEdgeTestQuality\n");
875 if(p1->
degenerated && p2->degenerated)
return false;
887 double const mina = std::min(qa1, qa2);
888 double const minb = std::min(qb1, qb2);
900 if(fabs(s1 + s2 - s3 - s4) > 1.e-12 * (s3 + s4)) {
return false; }
916 double OLD = std::min(
_ori * qa1 *
_cos_N(_p1, _p2, _p3,
gf),
919 double NEW = std::min(
_ori * qb1 *
_cos_N(_op1, _op2, _op3,
gf),
922 if(OLD < 0.5 && OLD < NEW)
return true;
951 if(nbFaces != 2)
return false;
955 const int CHECK1 = -1, CHECK2 = -1;
961 if(!op[0] || !op[1])
return false;
963 if(p1->
iD == CHECK1 && p2->
iD == CHECK2) {
964 printf(
"- e %d %d --> %d %d\n", p1->
iD, p2->
iD, op[0]->
iD, op[1]->
iD);
965 printf(
"- %d %d %d\n", pts1[0]->iD, pts1[1]->iD, pts1[2]->iD);
966 printf(
"- %d %d %d\n", pts2[0]->iD, pts2[1]->iD, pts2[2]->iD);
973 if(p1->
iD == CHECK1 && p2->
iD == CHECK2) printf(
"topology OK \n");
980 for(
int i = 0; i < 3; i++) {
982 orientation = pts1[(i + 1) % 3] == p2 ? 1 : -1;
987 if(orientation == 1) {
988 if(!theTest(p1, p2, op[0], p2, p1, op[1], p1, op[1], op[0], op[1], p2,
993 if(!theTest(p2, p1, op[0], p1, p2, op[1], p1, op[0], op[1], op[1], op[0],
998 if(p1->
iD == CHECK1 && p2->
iD == CHECK2) printf(
"TEST1 OK\n");
1000 if(!theTest(p1, p2, op[0], op[1]))
return false;
1002 if(p1->
iD == CHECK1 && p2->
iD == CHECK2) printf(
"TEST2 OK\n");
1010 if(p1_op1 == p1_op2 || op2_p2 == op1_p2)
return false;
1026 if(orientation == 1) {
1038 edges.back()->g = ge;
1053 return std::count_if(
1076 if(!force && e->
numfaces() != 2)
return false;
1081 if(!force && e->
g && p->
g) {
1085 const int CHECK1 = -1, CHECK2 = -1;
1087 if(e->
p1->
iD == CHECK1 && e->
p2->
iD == CHECK2) {
1088 printf(
"collapsing edge %p %p onto %p\n", e->
p1, e->
p2, p);
1089 printf(
"collapsing edge %d %d onto %d\n", e->
p1->
iD, e->
p2->
iD, p->
iD);
1093 for(
size_t i = 0; i < e->
p1->
edges.size(); i++) {
1094 for(
size_t j = 0; j < e->
p2->
edges.size(); j++) {
1107 if(!oface[0] || !oface[1]) {
1108 Msg::Error(
"No opposite face in edge collapse");
1111 for(
size_t i = 0; i < oface[0]->
edges.size(); i++) {
1112 if(oface[0]->
edges[i]->p1 == oface[0] &&
1113 oface[0]->
edges[i]->p2 == oface[1])
1115 if(oface[0]->
edges[i]->p1 == oface[1] &&
1116 oface[0]->
edges[i]->p2 == oface[0])
1119 if(!force && oface[0]->g && oface[0]->g->classif_degree == 2 &&
1120 oface[0]->
edges.size() <= 4)
1122 if(!force && oface[1]->g && oface[1]->g->classif_degree == 2 &&
1123 oface[1]->
edges.size() <= 4)
1125 if(!force && oface[0]->g && oface[0]->g->classif_degree < 2 &&
1126 oface[0]->
edges.size() <= 3)
1128 if(!force && oface[1]->g && oface[1]->g->classif_degree < 2 &&
1129 oface[1]->
edges.size() <= 3)
1140 double area_old = 0.0;
1141 double area_new = 0.0;
1143 auto it = t.begin();
1144 while(it != t.end()) {
1150 if(t->
e1 != e && t->
e2 != e && t->
e3 != e) {
1152 pt[0][nt] = (pts[0] == p) ? o : pts[0];
1153 pt[1][nt] = (pts[1] == p) ? o : pts[1];
1154 pt[2][nt] = (pts[2] == p) ? o : pts[2];
1155 if(!pt[0][nt] || !pt[1][nt] || !pt[2][nt]) {
1156 Msg::Error(
"Invalid point in edge collapse");
1161 if(!force && snew < .02 * sold) {
return false; }
1172 if(!force && fabs(area_old - area_new) > 1.e-12 * (area_old + area_new)) {
1178 auto it = t.begin();
1179 while(it != t.end()) {
1188 auto eit =
edges.begin();
1189 while(eit !=
edges.end()) {
1190 (*eit)->p1->config_modified = (*eit)->p2->config_modified =
true;
1191 ept[0][kk] = ((*eit)->p1 == p) ? (o ? o->
iD : -1) : (*eit)->p1->iD;
1192 ept[1][kk] = ((*eit)->p2 == p) ? (o ? o->
iD : -1) : (*eit)->p2->iD;
1193 if(ept[0][kk] < 0 || ept[1][kk] < 0) {
1194 Msg::Error(
"Something wrong in edge collapse");
1197 egs[kk++] = (*eit)->g;
1207 for(
int k = 0; k < nt; k++) {
1213 for(
int i = 0; i < kk; ++i) {
1215 if(e && !e->
g) e->
g = egs[i];
1225 const std::vector<BDS_Point *> &nbg)
1227 double p_[2] = {p->
u, p->
v};
1228 double q_[2] = {nbg[0]->degenerated == 1 ? nbg[1]->u : nbg[0]->u,
1229 nbg[0]->degenerated == 2 ? nbg[1]->v : nbg[0]->v};
1230 double r_[2] = {nbg[1]->degenerated == 1 ? nbg[0]->u : nbg[1]->u,
1231 nbg[1]->degenerated == 2 ? nbg[0]->v : nbg[1]->v};
1233 for(
size_t i = 1; i < nbg.size(); ++i) {
1235 BDS_Point *p1 = nbg[(i + 1) % nbg.size()];
1241 if(sign * sign_ <= 0)
return false;
1247 std::vector<BDS_Point *> &nbg,
1248 std::vector<BDS_Face *> &ts,
1251 if(p->
iD == CHECK) {
1252 printf(
"LISTING THE TRIANGLES\n");
1253 for(
size_t i = 0; i < ts.size(); i++) {
1255 if(ts[i]->getNodes(pts)) {
1256 printf(
"TR %lu : %p %p %p\n", i, pts[0], pts[1], pts[2]);
1257 printf(
"TR %lu : %d %d - %d %d - %d %d\n", i, ts[i]->e1->p1->iD,
1258 ts[i]->e1->p2->iD, ts[i]->e2->p1->iD, ts[i]->e2->p2->iD,
1259 ts[i]->e3->p1->iD, ts[i]->e3->p2->iD);
1264 if(ts.empty())
return false;
1267 for(
size_t i = 0; i < ts.size(); i++) {
1269 if(!ts[i]->getNodes(pts))
continue;
1275 else if(pts[1] == p) {
1284 nbg.push_back(pp[0]);
1285 nbg.push_back(pp[1]);
1292 if(p1 == pp[0] && p0 != pp[1]) {
1293 nbg.push_back(pp[1]);
1297 else if(p1 == pp[1] && p0 != pp[0]) {
1298 nbg.push_back(pp[0]);
1305 if(nbg.size() == ts.size())
break;
1306 if(!found)
return false;
1309 if(p->
iD == CHECK) {
1310 printf(
"FINALLY : ");
1311 for(
size_t i = 0; i < nbg.size(); i++) { printf(
"%d ", nbg[i]->iD); }
1318 const std::vector<BDS_Point *> &nbg,
1321 if(nbg.empty())
return 1.e22;
1323 double MAX = 0.,
MIN = 0.;
1324 for(
size_t i = 0; i < nbg.size(); ++i) {
1325 const double dx = p->
X - nbg[i]->X;
1326 const double dy = p->
Y - nbg[i]->Y;
1327 const double dz = p->
Z - nbg[i]->Z;
1328 const double l2 = dx * dx + dy * dy + dz * dz;
1329 MAX = i ? std::max(
MAX, l2) : l2;
1330 MIN = i ? std::min(
MIN, l2) : l2;
1333 if(!
MAX)
return 1.e22;
1339 const std::vector<SPoint2> &kernel,
1340 const std::vector<double> &lc,
double &U,
1341 double &V,
double &LC)
1345 for(
size_t i = 0; i < kernel.size(); ++i) {
1347 double du = p->
u - gp.
u();
1348 double dv = p->
v - gp.
v();
1349 double denom = (du * du + dv * dv);
1351 double dx = p->
X - gp.
x();
1352 double dy = p->
Y - gp.
y();
1353 double dz = p->
Z - gp.
z();
1354 double fact = sqrt((dx * dx + dy * dy + dz * dz) / denom);
1356 U += kernel[i].x() * fact;
1357 V += kernel[i].y() * fact;
1369 const std::vector<double> &lc,
double &U,
1370 double &V,
double &LC)
1373 for(
size_t i = 0; i < kernel.size(); ++i) {
1380 LC /= kernel.size();
1388 A[0][0] = p2.
x() - p1.
x();
1389 A[0][1] = q1.
x() - q2.
x();
1390 A[1][0] = p2.
y() - p1.
y();
1391 A[1][1] = q1.
y() - q2.
y();
1392 double b[2] = {q1.
x() - p1.
x(), q1.
y() - p1.
y()};
1397 const std::vector<BDS_Point *> &nbg,
1398 std::vector<SPoint2> &kernel,
1399 std::vector<double> &lc,
int check)
1402 if(p->
iD == check)
f = fopen(
"kernel.pos",
"w");
1405 if(p->
iD == check) {
1406 fprintf(
f,
"View \"kernel\"{\n");
1407 fprintf(
f,
"SP(%g,%g,0){2};\n", p->
u, p->
v);
1410 double ll = p->
lc();
1413 for(
size_t i = 0; i < nbg.size(); i++) {
1414 if(nbg[i]->degenerated == 1) {
1415 kernel.push_back(
SPoint2(p->
u, nbg[i]->v));
1416 kernel.push_back(
SPoint2(nbg[(i + 1) % nbg.size()]->u, nbg[i]->v));
1418 lc.push_back(nbg[i]->lc());
1419 lc.push_back(nbg[i]->lc());
1421 else if(nbg[i]->degenerated == 2) {
1422 kernel.push_back(
SPoint2(nbg[i]->u, p->
v));
1423 kernel.push_back(
SPoint2(nbg[i]->u, nbg[(i + 1) % nbg.size()]->v));
1425 lc.push_back(nbg[i]->lc());
1426 lc.push_back(nbg[i]->lc());
1428 else if(nbg[(i + 1) % nbg.size()]->degenerated == 1) {
1429 kernel.push_back(
SPoint2(nbg[i]->u, nbg[i]->v));
1430 kernel.push_back(
SPoint2(nbg[i]->u, nbg[(i + 1) % nbg.size()]->v));
1431 lc.push_back(nbg[i]->lc());
1432 lc.push_back(nbg[i]->lc());
1434 else if(nbg[(i + 1) % nbg.size()]->degenerated == 2) {
1435 kernel.push_back(
SPoint2(nbg[i]->u, nbg[i]->v));
1436 kernel.push_back(
SPoint2(nbg[(i + 1) % nbg.size()]->u, nbg[i]->v));
1437 lc.push_back(nbg[i]->lc());
1438 lc.push_back(nbg[i]->lc());
1441 kernel.push_back(
SPoint2(nbg[i]->u, nbg[i]->v));
1442 lc.push_back(nbg[i]->lc());
1446 if(p->
iD == check) {
1447 for(
size_t i = 0; i < kernel.size(); i++) {
1448 fprintf(
f,
"SL(%g,%g,0,%g,%g,0){4,4};\n", kernel[i].x(), kernel[i].y(),
1449 kernel[(i + 1) % kernel.size()].x(),
1450 kernel[(i + 1) % kernel.size()].y());
1456 for(
size_t i = 0; i < kernel.size(); i++) {
1458 double lc_now = lc[i];
1459 for(
size_t j = 0; j < kernel.size(); j++) {
1460 if(i != j && i != (j + 1) % kernel.size()) {
1461 const SPoint2 &p0 = kernel[j];
1462 const SPoint2 &p1 = kernel[(j + 1) % kernel.size()];
1465 if(x[0] > 0 && x[0] < 1.0) {
1466 p_now = (pp * (1. - x[0])) + (p_now * x[0]);
1467 lc_now = ll * (1. - x[0]) + lc_now * x[0];
1476 if(p->
iD == check) {
1484 const std::vector<SPoint2> &kernel,
SPoint3 &target,
1487 double minDist = 1.e22;
1490 for(
size_t i = 0; i < kernel.size(); ++i) {
1491 SPoint2 p1(kernel[i].x(), kernel[i].y());
1492 SPoint2 p2(kernel[(i + 1) % kernel.size()].x(),
1493 kernel[(i + 1) % kernel.size()].y());
1494 for(
int j = 1; j < N; j++) {
1495 for(
int k = 1; k < N - j; k++) {
1496 double xi = (double)j / (2 * N);
1497 double eta = (double)k / (2 * N);
1498 SPoint2 p = p0 * (1 - xi - eta) + p1 * xi + p2 * eta;
1500 double d = ((target.
x() - gp.x()) * (target.
x() - gp.x()) +
1501 (target.
y() - gp.y()) * (target.
y() - gp.y()) +
1502 (target.
z() - gp.z()) * (target.
z() - gp.z()));
1511 return gf->
point(pMin);
1516 const std::vector<BDS_Point *> &nbg,
1517 const std::vector<SPoint2> &kernel,
1518 const std::vector<double> &lc,
1519 GFace *gf,
int check)
1522 double oldX = p->
X, oldY = p->
Y, oldZ = p->
Z, oldU = p->
u, oldV = p->
v;
1525 for(
size_t i = 0; i < nbg.size(); ++i) {
1526 SPoint3 pi(nbg[i]->X, nbg[i]->Y, nbg[i]->Z);
1527 SPoint3 pip(nbg[(i + 1) % nbg.size()]->X, nbg[(i + 1) % nbg.size()]->Y,
1528 nbg[(i + 1) % nbg.size()]->Z);
1532 double nrm = pv.
norm();
1533 x += (pi + p0 + pip) * (nrm / 3.0);
1537 if(p->
iD == check) printf(
"%12.5E %12.5E %12.5E\n", x.
x(), x.
y(), x.
z());
1547 double uv[2] = {U, V};
1552 if(p->
iD == check) {
1561 if(E_moved < E_unmoved) {
return true; }
1569 if(p->
iD == check) printf(
"NO WAY\n");
1575 const std::vector<BDS_Point *> &nbg,
1576 const std::vector<SPoint2> &kernel,
1577 const std::vector<double> &lc,
1578 GFace *gf,
int check)
1580 double U, V, LC, oldX = p->
X, oldY = p->
Y, oldZ = p->
Z, oldU = p->
u,
1591 if(p->
iD == check) printf(
"%g vs %g\n", E_unmoved, E_moved);
1593 if(E_moved < E_unmoved) {
1605 return RATIO2 > .25;
1625 printf(
"VERTEX %d TRYING TO MOVE from its initial position %g %g\n", CHECK,
1628 std::vector<BDS_Point *> nbg;
1629 std::vector<double> lc;
1630 std::vector<SPoint2> kernel;
1633 if(p->
iD == CHECK) printf(
"%d adjacent triangles\n", (
int)ts.size());
1637 if(p->
iD == CHECK) printf(
"%d adjacent vertices\n", (
int)nbg.size());
1641 if(RATIO > threshold)
return false;