38 double ieee_check = 1;
45 return (ieee_check == ieee_check);
55 <<
"+------------------------------------+" << endl
57 <<
"+------------------------------------+" << endl
58 <<
"| a - Displays/Hides the axes |" << endl
59 <<
"| A - Turns antialiasing on/off |" << endl
60 <<
"| b/B Toggle 2D boundary |" << endl
61 <<
"| c - Toggle colorbar and caption |" << endl
62 <<
"| C - Change the main plot caption |" << endl
63 <<
"| e - Displays/Hides the elements |" << endl
64 <<
"| f - Smooth/Nonconf/Flat shading |" << endl
65 <<
"| g - Toggle background |" << endl
66 <<
"| h - Displays help menu |" << endl
67 <<
"| i - Toggle the cutting plane |" << endl
68 <<
"| j - Turn on/off perspective |" << endl
69 <<
"| k/K Adjust the transparency level |" << endl
70 <<
"| ,/< Adjust color transparency |" << endl
71 <<
"| l - Turns on/off the light |" << endl
72 <<
"| L - Toggle logarithmic scale |" << endl
73 <<
"| m - Displays/Hides the mesh |" << endl
74 <<
"| n/N Cycle through numberings |" << endl
75 <<
"| o - (De)refine elem. (NC shading) |" << endl
76 <<
"| O - Switch 'o' func. (NC shading) |" << endl
77 <<
"| p/P Cycle through color palettes |" << endl
78 <<
"| q - Quits |" << endl
79 <<
"| r - Reset the plot to 3D view |" << endl
80 <<
"| R - Reset the plot to 2D view |" << endl
81 <<
"| s - Turn on/off unit cube scaling |" << endl
82 <<
"| S - Take snapshot/Record a movie |" << endl
83 <<
"| t - Cycle materials and lights |" << endl
84 <<
"| y/Y Rotate the cutting plane |" << endl
85 <<
"| z/Z Move the cutting plane |" << endl
86 <<
"| \\ - Set light source position |" << endl
87 <<
"| Ctrl+o - Element ordering curve |" << endl
88 <<
"| Ctrl+p - Print to a PDF file |" << endl
89 <<
"+------------------------------------+" << endl
90 <<
"| Function keys |" << endl
91 <<
"+------------------------------------+" << endl
92 <<
"| F1 - X window info and keystrokes |" << endl
93 <<
"| F2 - Update colors, etc. |" << endl
94 <<
"| F3/F4 - Shrink/Zoom elements |" << endl
95 <<
"| F5 - Set level lines |" << endl
96 <<
"| F6 - Palette options |" << endl
97 <<
"| F7 - Manually set min/max value |" << endl
98 <<
"| F8 - List of subdomains to show |" << endl
99 <<
"| F9/F10 - Walk through subdomains |" << endl
100 <<
"| F11/F12 - Shrink/Zoom subdomains |" << endl
101 <<
"+------------------------------------+" << endl
102 <<
"| Keypad |" << endl
103 <<
"+------------------------------------+" << endl
104 <<
"| 1-9 Small rotation, reset with 5 |" << endl
105 <<
"| *,/ Scale up/down |" << endl
106 <<
"| +/- Change z-scaling |" << endl
107 <<
"| . - Start/stop spinning |" << endl
108 <<
"| 0/Enter - Spinning speed and dir. |" << endl
109 <<
"+------------------------------------+" << endl
110 <<
"| Mouse |" << endl
111 <<
"+------------------------------------+" << endl
112 <<
"| left btn - Rotation |" << endl
113 <<
"| middle btn - Translation |" << endl
114 <<
"| right btn - Scaling |" << endl
115 <<
"| left + Alt - Tilt |" << endl
116 <<
"| left + Shift - Spinning |" << endl
117 <<
"| right + Shift - Change light pos. |" << endl
118 <<
"| left + Ctrl - Spherical rotation |" << endl
119 <<
"| middle+ Ctrl - Object translation |" << endl
120 <<
"| right + Ctrl - Object scaling |" << endl
121 <<
"| left + Ctrl + Shift - z-Spinning |" << endl
122 <<
"+------------------------------------+" << endl;
126 static void KeyF8Pressed()
129 Array<int> attr_list(&attr, 1);
130 const Array<int> &all_attr =
vssol->
GetMesh()->attributes;
132 cout <<
"El attributes ON: ";
133 for (
int i = 0; i < all_attr.Size(); i++)
136 cout <<
" " << all_attr[i];
140 cout <<
"El attribute to toggle : " << flush;
146 static void SwitchAttribute(
int increment,
int &attribute,
147 Array<int> &attribute_marker,
150 const char *attr_type = bdr ?
"bdr" :
"element";
151 if (attribute_marker.Size() == 0)
153 cout <<
"There are no " << attr_type <<
" attributes" << endl;
158 attribute_marker = 0;
159 attribute = (increment >= 0) ? 0 : attribute_marker.Size()-1;
163 if (attribute != attribute_marker.Size())
165 attribute_marker[attribute] = 0;
169 attribute_marker = 0;
171 attribute += increment;
173 attribute += attribute_marker.Size()+1;
174 attribute %= attribute_marker.Size()+1;
175 if (attribute != attribute_marker.Size())
177 attribute_marker[attribute] = 1;
178 cout <<
"Showing " << attr_type <<
" attribute " << attribute+1 << endl;
182 attribute_marker = 1;
183 cout <<
"Showing all " << attr_type <<
" attributes" << endl;
197 static void KeyF9Pressed(GLenum state)
199 if (!(state & KMOD_SHIFT))
210 static void KeyF10Pressed(GLenum state)
212 if (!(state & KMOD_SHIFT))
225 drawbdr = (drawbdr+1)%3;
231 if (drawelems == 1 || drawelems == 0)
235 have_sol_range =
true;
239 maxv = mesh->bdr_attributes.Size() ? mesh->bdr_attributes.Max() : 1;
241 UpdateValueRange(
true);
244 else if (drawbdr == 1)
248 else if (drawbdr == 0)
257 SetNewScalingFromBox();
258 UpdateValueRange(
true);
262 FindNewValueRange(
true);
269 vssol -> ToggleDrawBdr();
273 static void KeyMPressed()
275 vssol -> ToggleDrawMesh();
281 vssol -> ToggleDrawNumberings();
285 static void KeyoPressed(GLenum state)
287 if (state & KMOD_CTRL)
289 vssol -> ToggleDrawOrdering();
290 vssol -> PrepareOrderingCurve();
299 static void KeyOPressed(GLenum state)
305 static void KeyEPressed()
307 vssol -> ToggleDrawElems();
311 static void KeyFPressed()
313 vssol -> ToggleShading();
328 static void KeyyPressed()
335 static void KeyYPressed()
342 static void KeyzPressed()
349 static void KeyZPressed()
356 static void KeyF3Pressed()
370 static void KeyF4Pressed()
383 static void KeyF11Pressed()
401 static void KeyF12Pressed()
425 Mesh &m, Vector &s, Vector *normals)
439 drawelems = shading = 1;
445 have_sol_range =
false;
452 TimesToRefine = EdgeRefineFactor = 1;
454 attr_to_show = bdr_attr_to_show = -1;
455 el_attr_to_show.SetSize(mesh->attributes.Max());
457 bdr_el_attr_to_show.SetSize(mesh->bdr_attributes.Size() > 0 ?
458 mesh->bdr_attributes.Max() : 0);
459 bdr_el_attr_to_show = 1;
468 CuttingPlane =
new Plane(-1.0,0.0,0.0,(0.5-eps)*bb.x[0]+(0.5+eps)*bb.x[1]);
513 PrepareLevelCurves();
516 PrepareOrderingCurve();
525 const char *modes[] =
527 "none",
"solution",
"kappa + 1/kappa",
"kappa",
"1/det(J)",
"det(J)",
531 if (drawbdr == 2) {
return; }
533 drawelems = (drawelems + 6) % 7;
535 cout <<
"Surface elements mode : " << modes[drawelems] << endl;
549 have_sol_range =
true;
551 else if (shading == 2)
553 if (drawelems == 1 && have_sol_range)
559 SetNewScalingFromBox();
560 UpdateValueRange(
false);
564 DoAutoscaleValue(
false);
569 PrepareLevelCurves();
576 Mesh *new_m, Vector *new_sol, GridFunction *new_u)
579 if (mesh->GetNE() != new_m->GetNE())
582 int ref = GetAutoRefineFactor();
583 if (TimesToRefine != ref || EdgeRefineFactor != 1)
586 EdgeRefineFactor = 1;
587 cout <<
"Subdivision factors = " << TimesToRefine <<
", 1" << endl;
594 have_sol_range =
false;
599 PrepareLevelCurves();
603 PrepareOrderingCurve();
608 int i,
const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
610 int geom = mesh->GetElementBaseGeometry(i);
611 ElementTransformation *T = mesh->GetElementTransformation(i);
613 DenseMatrix J(Jd, 2, 2);
615 T->Transform(ir, tr);
617 vals.SetSize(ir.GetNPoints());
618 for (
int j = 0; j < ir.GetNPoints(); j++)
620 T->SetIntPoint(&ir.IntPoint(j));
621 Geometries.JacToPerfJac(geom, T->Jacobian(), J);
624 vals(j) = mesh->GetAttribute(i);
626 else if (drawelems >= 4)
636 vals(j) = J.CalcSingularvalue(0)/J.CalcSingularvalue(1);
639 vals(j) = vals(j) + 1.0/vals(j);
646 for (
int j = 0; j < vals.Size(); j++)
653 vals(j) = 1.0 / vals(j);
657 J.ClearExternalData();
661 int i,
const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
665 rsol->GetValues(i, ir, vals, tr);
669 GetRefinedDetJ(i, ir, vals, tr);
673 for (
int j = 0; j < vals.Size(); j++)
675 vals(j) = _LogVal(vals(j));
678 if (shrink != 1.0 || shrinkmat != 1.0)
680 ShrinkPoints(tr, i, 0, 0);
685 int i,
const IntegrationRule &ir, Vector &vals, DenseMatrix &tr,
686 DenseMatrix &normals)
688 int have_normals = 0;
692 rsol->GetGradients(i, ir, tr);
693 normals.SetSize(3, tr.Width());
694 for (
int j = 0; j < tr.Width(); j++)
696 normals(0, j) = -tr(0, j);
697 normals(1, j) = -tr(1, j);
701 rsol->GetValues(i, ir, vals, tr);
705 GetRefinedDetJ(i, ir, vals, tr);
712 for (
int j = 0; j < normals.Width(); j++)
714 if (vals(j) >= minv && vals(j) <= maxv)
716 normals(0, j) *= log_a/vals(j);
717 normals(1, j) *= log_a/vals(j);
721 for (
int j = 0; j < vals.Size(); j++)
723 vals(j) = _LogVal(vals(j));
727 if (shrink != 1.0 || shrinkmat != 1.0)
729 ShrinkPoints(tr, i, 0, 0);
732 for (
int j = 0; j < tr.Width(); j++)
734 normals(0, j) /= shrink;
735 normals(1, j) /= shrink;
745 if (shading == s || s < 0)
757 if (s == 2 || shading == 2)
760 have_sol_range =
false;
764 PrepareLevelCurves();
767 PrepareOrderingCurve();
784 static const char *shading_type[3] =
785 {
"flat",
"smooth",
"non-conforming (with subdivision)"};
788 cout <<
"Shading type : " << shading_type[shading] << endl;
796 SetShading((shading + 1) % 3,
true);
800 SetShading(1 - shading,
true);
810 TimesToRefine += EdgeRefineFactor;
813 if (TimesToRefine > EdgeRefineFactor)
815 TimesToRefine -= EdgeRefineFactor;
823 TimesToRefine /= EdgeRefineFactor;
825 TimesToRefine *= EdgeRefineFactor;
828 if (EdgeRefineFactor > 1)
830 TimesToRefine /= EdgeRefineFactor;
832 TimesToRefine *= EdgeRefineFactor;
840 if (update && shading == 2)
842 have_sol_range =
false;
847 PrepareLevelCurves();
851 cout <<
"Subdivision factors = " << TimesToRefine <<
", " << EdgeRefineFactor
857 refine_func = (refine_func+1)%4;
858 cout <<
"Key 'o' will: ";
862 cout <<
"Increase subdivision factor" << endl;
865 cout <<
"Decrease subdivision factor" << endl;
868 cout <<
"Increase bdr subdivision factor" << endl;
871 cout <<
"Decrease bdr subdivision factor" << endl;
878 if ((tot == TimesToRefine && bdr == EdgeRefineFactor) || tot < 1 || bdr < 1)
885 tot += bdr - tot % bdr;
889 EdgeRefineFactor = bdr;
893 have_sol_range =
false;
898 PrepareLevelCurves();
905 int ne = mesh->GetNE(), ref = 1;
907 while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_max_surf_elem)
917 int ref = GetAutoRefineFactor();
919 cout <<
"Subdivision factors = " << ref <<
", 1" << endl;
921 SetRefineFactors(ref, 1);
926 Array<int> &attr_marker = el_attr_to_show;
928 for (
int i = 0; i < attr_list.Size(); i++)
930 int attr = attr_list[i];
933 cout <<
"Hiding all attributes." << endl;
936 else if (attr > attr_marker.Size())
938 cout <<
"Showing all attributes." << endl;
943 attr_marker[attr-1] = !attr_marker[attr-1];
958 xscale = bb.x[1]-bb.x[0];
959 yscale = bb.y[1]-bb.y[0];
960 zscale = bb.z[1]-bb.z[0];
961 xscale = (xscale < yscale) ? yscale : xscale;
962 xscale = (xscale > 0.0) ? ( 1.0 / xscale ) : 1.0;
964 zscale = (zscale > 0.0) ? ( 1.0 / zscale ) : 1.0;
966 zscale /= ((1. + sqrt(5.)) / 2.);
976 int nv = mesh -> GetNV();
978 double *coord = mesh->GetVertex(0);
980 rval[0] = rval[1] = (*sol)(0);
981 for (i = 1; i < sol->Size(); i++)
983 if ((*sol)(i) < rval[0]) { rval[0] = (*sol)(i); }
984 if ((*sol)(i) > rval[1]) { rval[1] = (*sol)(i); }
986 rx[0] = rx[1] = coord[0];
987 ry[0] = ry[1] = coord[1];
989 for (i = 1; i < nv; i++)
991 coord = mesh->GetVertex(i);
992 if (coord[0] < rx[0]) { rx[0] = coord[0]; }
993 if (coord[1] < ry[0]) { ry[0] = coord[1]; }
994 if (coord[0] > rx[1]) { rx[1] = coord[0]; }
995 if (coord[1] > ry[1]) { ry[1] = coord[1]; }
1000 int ne = mesh -> GetNE();
1001 DenseMatrix pointmat;
1003 RefinedGeometry *RefG;
1004 bool log_scale = logscale;
1007 rx[0] = ry[0] = rval[0] = numeric_limits<double>::infinity();
1008 rx[1] = ry[1] = rval[1] = -rx[0];
1009 for (i = 0; i < ne; i++)
1012 TimesToRefine, EdgeRefineFactor);
1013 GetRefinedValues(i, RefG->RefPts, values, pointmat);
1014 for (j = 0; j < values.Size(); j++)
1018 if (pointmat(0,j) < rx[0]) { rx[0] = pointmat(0,j); }
1019 if (pointmat(0,j) > rx[1]) { rx[1] = pointmat(0,j); }
1023 if (pointmat(1,j) < ry[0]) { ry[0] = pointmat(1,j); }
1024 if (pointmat(1,j) > ry[1]) { ry[1] = pointmat(1,j); }
1028 if (values(j) < rval[0]) { rval[0] = values(j); }
1029 if (values(j) > rval[1]) { rval[1] = values(j); }
1033 logscale = log_scale;
1039 FindNewBox(bb.x, bb.y, bb.z);
1049 SetNewScalingFromBox();
1050 UpdateValueRange(prepare);
1055 double rx[2], ry[2], rv[2];
1057 FindNewBox(rx, ry, rv);
1063 UpdateValueRange(prepare);
1070 FindNewBox(bb.x, bb.y, rv);
1072 UpdateBoundingBox();
1077 if (logscale || LogscaleRange())
1082 logscale = !logscale;
1084 SetLevelLines(minv, maxv, nl);
1085 EventUpdateColors();
1087 PrepareLevelCurves();
1092 PrintLogscale(
false);
1097 PrintLogscale(
true);
1104 PrepareOrderingCurve();
1124 buff.
addText(x[0], x[1], x[2], std::to_string(n));
1128 const int n,
const Array<int> &ind, Array<int> &f_ind)
1132 f_ind.SetSize(ind.Size());
1133 for (
int i = 0; i < ind.Size(); i += n)
1136 for (
int j = 0; j < n; j++)
1138 f_ind[o+j] = ind[i+j];
1160 Array<int> vertices;
1161 double *vtx, *nor, val, s;
1163 for (
int i = 0; i < mesh->GetNE(); i++)
1165 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1167 mesh->GetElementVertices(i, vertices);
1169 if (vertices.Size() == 3)
1171 shape = GL_TRIANGLES;
1178 for (
int j = 0; j < vertices.Size(); j++)
1180 vtx = mesh->GetVertex(vertices[j]);
1181 nor = &(*v_normals)(3*vertices[j]);
1182 val = (*sol)(vertices[j]);
1183 if (logscale && val >= minv && val <= maxv)
1186 val = _LogVal_(val);
1193 MySetColor(poly, val, minv, maxv);
1198 updated_bufs.emplace_back(&disp_buf);
1205 int ne = mesh -> GetNE();
1206 DenseMatrix pointmat;
1207 Array<int> vertices;
1208 double pts[4][3], col[4];
1210 for (i = 0; i < ne; i++)
1212 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1214 mesh->GetPointMatrix (i, pointmat);
1215 mesh->GetElementVertices (i, vertices);
1217 for (j = 0; j < pointmat.Width(); j++)
1219 pts[j][0] = pointmat(0, j);
1220 pts[j][1] = pointmat(1, j);
1221 pts[j][2] = col[j] = LogVal((*sol)(vertices[j]));
1225 DrawTriangle(disp_buf, pts, col, minv, maxv);
1229 DrawQuad(disp_buf, pts, col, minv, maxv);
1232 updated_bufs.emplace_back(&disp_buf);
1246 int ne = mesh -> GetNE();
1247 DenseMatrix pointmat, pts3d, normals;
1249 RefinedGeometry *RefG;
1252 for (i = 0; i < ne; i++)
1254 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1257 TimesToRefine, EdgeRefineFactor);
1258 j = GetRefinedValuesAndNormals(i, RefG->RefPts, values, pointmat,
1260 Array<int> &RG = RefG->RefGeoms;
1261 int sides = mesh->GetElement(i)->GetNVertices();
1264 pts3d.SetSize(3, pointmat.Width());
1265 for (k = 0; k < pointmat.Width(); k++)
1267 pts3d(0, k) = pointmat(0, k);
1268 pts3d(1, k) = pointmat(1, k);
1269 pts3d(2, k) = values(k);
1271 j = (j != 0) ? 2 : 0;
1273 DrawPatch(disp_buf, pts3d, values, normals, sides, fRG, minv, maxv, j);
1275 for (k = 0; k < RG.Size()/sides; k++)
1277 int *ind = &RG[sides*k];
1280 for (j = 0; j < sides; j++)
1282 pts[j][0] = pointmat(0, ind[j]);
1283 pts[j][1] = pointmat(1, ind[j]);
1284 pts[j][2] = col[j] = values(ind[j]);
1288 DrawTriangle(pts, col, minv, maxv);
1292 DrawQuad(pts, col, minv, maxv);
1299 const int vt[2][3] = {{ 0, 1, 2 }, { 2, 3, 0 }};
1300 for (
int it = 0; it < 2; it++)
1302 for (j = 0; j < 3; j++)
1304 pts[j][0] = pointmat(0, ind[vt[it][j]]);
1305 pts[j][1] = pointmat(1, ind[vt[it][j]]);
1306 pts[j][2] = col[j] = values(ind[vt[it][j]]);
1308 DrawTriangle(pts, col, minv, maxv);
1315 pts[2][0] = pts[2][1] = pts[2][2] = 0.0;
1316 for (j = 0; j < 4; j++)
1318 pts[2][0] += pointmat(0, ind[j]);
1319 pts[2][1] += pointmat(1, ind[j]);
1320 pts[2][2] += values(ind[j]);
1326 for (j = 0; j < 4; j++)
1328 pts[0][0] = pointmat(0, ind[j]);
1329 pts[0][1] = pointmat(1, ind[j]);
1330 pts[0][2] = col[0] = values(ind[j]);
1332 pts[1][0] = pointmat(0, ind[l]);
1333 pts[1][1] = pointmat(1, ind[l]);
1334 pts[1][2] = col[1] = values(ind[l]);
1335 DrawTriangle(pts, col, minv, maxv);
1341 updated_bufs.emplace_back(&disp_buf);
1346 palette.SetUseLogscale(0);
1359 PrepareWithNormals();
1369 int ne = mesh -> GetNE();
1370 int nv = mesh -> GetNV();
1371 DenseMatrix pointmat;
1372 Array<int> vertices;
1373 double p[4][3], nor[3];
1379 for (
int d = 0; d < mesh -> attributes.Size(); d++)
1382 if (!el_attr_to_show[mesh -> attributes[d]-1]) {
continue; }
1388 for (i = 0; i < ne; i++)
1389 if (mesh -> GetAttribute(i) == mesh -> attributes[d])
1391 mesh->GetPointMatrix (i, pointmat);
1392 mesh->GetElementVertices (i, vertices);
1394 for (j = 0; j < pointmat.Size(); j++)
1396 p[j][0] = pointmat(0, j);
1397 p[j][1] = pointmat(1, j);
1398 p[j][2] = LogVal((*sol)(vertices[j]));
1401 if (pointmat.Width() == 3)
1411 for (j = 0; j < pointmat.Size(); j++)
1413 nx(vertices[j]) += nor[0];
1414 ny(vertices[j]) += nor[1];
1415 nz(vertices[j]) += nor[2];
1419 for (i = 0; i < ne; i++)
1421 if (mesh -> GetAttribute(i) == mesh -> attributes[d])
1423 GLenum shape = GL_NONE;
1424 switch (mesh->GetElementType(i))
1426 case Element::TRIANGLE:
1427 shape = GL_TRIANGLES;
1429 case Element::QUADRILATERAL:
1433 MFEM_ABORT(
"Invalid 2D element type");
1437 mesh->GetPointMatrix (i, pointmat);
1438 mesh->GetElementVertices (i, vertices);
1440 for (j = 0; j < pointmat.Size(); j++)
1442 double z = LogVal((*sol)(vertices[j]));
1443 MySetColor(poly, z, minv, maxv);
1444 poly.
glNormal3d(nx(vertices[j]), ny(vertices[j]), nz(vertices[j]));
1445 poly.
glVertex3d(pointmat(0, j), pointmat(1, j), z);
1451 updated_bufs.emplace_back(&disp_buf);
1458 PrepareLevelCurves2();
1462 static int vt[4] = { 0, 1, 2, 3 };
1463 Array<int> RG(vt, 4), vertices;
1465 DenseMatrix pointmat;
1469 for (
int i = 0; i < mesh->GetNE(); i++)
1471 mesh->GetElementVertices(i, vertices);
1472 mesh->GetPointMatrix(i, pointmat);
1473 sol->GetSubVector(vertices, values);
1475 for (
int j = 0; j < vertices.Size(); j++)
1477 values(j) = _LogVal(values(j));
1479 RG.SetSize(vertices.Size());
1480 DrawLevelCurves(build, RG, pointmat, values, vertices.Size(), level);
1482 updated_bufs.emplace_back(&lcurve_buf);
1486 gl3::GlBuilder& builder, Array<int> &RG, DenseMatrix &pointmat, Vector &values,
1487 int sides, Array<double> &lvl,
int flat)
1491 double zc = bb.z[1];
1493 for (
int k = 0; k < RG.Size()/sides; k++)
1497 for (
int j = 0; j < sides; j++)
1499 int vv = RG[sides*k+j];
1500 point[j][0] = pointmat(0, vv);
1501 point[j][1] = pointmat(1, vv);
1502 point[j][3] = values(vv);
1503 point[j][2] = (flat) ? zc : point[j][3];
1505 DrawPolygonLevelLines(builder, point[0], sides, lvl, logscale);
1511 int *ind = &RG[sides*k];
1512 const int vt[2][3] = {{ 0, 1, 2 }, { 2, 3, 0 }};
1513 for (
int it = 0; it < 2; it++)
1515 for (
int j = 0; j < 3; j++)
1517 point[j][0] = pointmat(0, ind[vt[it][j]]);
1518 point[j][1] = pointmat(1, ind[vt[it][j]]);
1519 point[j][3] = values(ind[vt[it][j]]);
1520 point[j][2] = (flat) ? zc : point[j][3];
1522 DrawPolygonLevelLines(builder, point[0], 3, lvl, logscale);
1529 int *ind = &RG[sides*k];
1530 point[2][0] = point[2][1] = point[2][2] = 0.0;
1531 for (
int j = 0; j < 4; j++)
1533 point[2][0] += pointmat(0, ind[j]);
1534 point[2][1] += pointmat(1, ind[j]);
1535 point[2][2] += values(ind[j]);
1537 point[2][0] *= 0.25;
1538 point[2][1] *= 0.25;
1539 point[2][2] *= 0.25;
1540 point[2][3] = point[2][2];
1546 for (
int j = 0; j < 4; j++)
1548 point[0][0] = pointmat(0, ind[j]);
1549 point[0][1] = pointmat(1, ind[j]);
1550 point[0][3] = values(ind[j]);
1551 point[0][2] = (flat) ? zc : point[0][3];
1553 point[1][0] = pointmat(0, ind[l]);
1554 point[1][1] = pointmat(1, ind[l]);
1555 point[1][3] = values(ind[l]);
1556 point[1][2] = (flat) ? zc : point[1][3];
1558 DrawPolygonLevelLines(builder, point[0], 3, lvl, logscale);
1566 int i, ne = mesh -> GetNE();
1568 DenseMatrix pointmat;
1569 RefinedGeometry *RefG;
1573 for (i = 0; i < ne; i++)
1576 TimesToRefine, EdgeRefineFactor);
1577 GetRefinedValues (i, RefG->RefPts, values, pointmat);
1578 Array<int> &RG = RefG->RefGeoms;
1579 int sides = mesh->GetElement(i)->GetNVertices();
1581 DrawLevelCurves(build, RG, pointmat, values, sides, level);
1583 updated_bufs.emplace_back(&lcurve_buf);
1595 int i, j, ne = mesh -> GetNE();
1596 DenseMatrix pointmat;
1597 Array<int> vertices;
1602 for (i = 0; i < ne; i++)
1604 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1607 mesh->GetPointMatrix (i, pointmat);
1608 mesh->GetElementVertices (i, vertices);
1610 for (j = 0; j < pointmat.Size(); j++)
1611 lb.
glVertex3d(pointmat(0, j), pointmat(1, j),
1612 LogVal((*sol)(vertices[j])));
1616 updated_bufs.emplace_back(&line_buf);
1621 DenseMatrix pointmat;
1622 Array<int> vertices;
1624 mesh->GetPointMatrix(k, pointmat);
1625 mesh->GetElementVertices(k, vertices);
1628 double xmax = -numeric_limits<double>::infinity();
1629 double ymax = -numeric_limits<double>::infinity();
1630 double xmin = numeric_limits<double>::infinity();
1631 double ymin = numeric_limits<double>::infinity();
1633 int nv = vertices.Size();
1634 for (
int j = 0; j < nv; j++)
1636 double x = pointmat(0,j);
1637 double y = pointmat(1,j);
1638 if (x > xmax) { xmax = x; }
1639 if (x < xmin) { xmin = x; }
1640 if (y > ymax) { ymax = y; }
1641 if (y < ymin) { ymin = y; }
1643 double dx = xmax-xmin;
1644 double dy = ymax-ymin;
1645 double ds = std::min<double>(dx,dy);
1654 PrepareElementNumbering2();
1658 PrepareElementNumbering1();
1666 DenseMatrix pointmat;
1667 Array<int> vertices;
1669 int ne = mesh->GetNE();
1670 for (
int k = 0; k < ne; k++)
1672 mesh->GetPointMatrix (k, pointmat);
1673 mesh->GetElementVertices (k, vertices);
1674 int nv = vertices.Size();
1676 ShrinkPoints(pointmat, k, 0, 0);
1681 for (
int j = 0; j < nv; j++)
1683 xs += pointmat(0,j);
1684 ys += pointmat(1,j);
1685 us += LogVal((*sol)(vertices[j]));
1691 double ds = GetElementLengthScale(k);
1692 double dx = 0.05*ds;
1694 double xx[3] = {xs,ys,us};
1698 updated_bufs.emplace_back(&e_nums_buf);
1703 IntegrationRule center_ir(1);
1704 DenseMatrix pointmat;
1709 int ne = mesh->GetNE();
1710 for (
int i = 0; i < ne; i++)
1712 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1714 center_ir.IntPoint(0) =
1715 Geometries.GetCenter(mesh->GetElementBaseGeometry(i));
1716 GetRefinedValues (i, center_ir, values, pointmat);
1718 double xc = pointmat(0,0);
1719 double yc = pointmat(1,0);
1720 double uc = values(0);
1722 double ds = GetElementLengthScale(i);
1723 double dx = 0.05*ds;
1725 double xx[3] = {xc,yc,uc};
1729 updated_bufs.emplace_back(&e_nums_buf);
1736 PrepareVertexNumbering2();
1740 PrepareVertexNumbering1();
1748 DenseMatrix pointmat;
1749 Array<int> vertices;
1754 const int ne = mesh->GetNE();
1755 for (
int k = 0; k < ne; k++)
1757 mesh->GetPointMatrix (k, pointmat);
1758 mesh->GetElementVertices (k, vertices);
1759 int nv = vertices.Size();
1761 ShrinkPoints(pointmat, k, 0, 0);
1763 double ds = GetElementLengthScale(k);
1764 double xs = 0.05*ds;
1766 for (
int j = 0; j < nv; j++)
1768 double x = pointmat(0,j);
1769 double y = pointmat(1,j);
1770 double u = LogVal((*sol)(vertices[j]));
1772 double xx[3] = {x,y,u};
1777 updated_bufs.emplace_back(&v_nums_buf);
1782 DenseMatrix pointmat;
1784 Array<int> vertices;
1788 const int ne = mesh->GetNE();
1789 for (
int i = 0; i < ne; i++)
1791 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1793 mesh->GetElementVertices (i, vertices);
1795 const IntegrationRule &vert_ir =
1796 *Geometries.GetVertices(mesh->GetElementBaseGeometry(i));
1798 GetRefinedValues (i, vert_ir, values, pointmat);
1800 double ds = GetElementLengthScale(i);
1801 double xs = 0.05*ds;
1803 for (
int j = 0; j < values.Size(); j++)
1805 double xv = pointmat(0, j);
1806 double yv = pointmat(1, j);
1808 double u = values[j];
1810 double xx[3] = {xv,yv,u};
1815 updated_bufs.emplace_back(&v_nums_buf);
1823 Array<int> vertices;
1825 Array<int> edges_ori;
1827 const int ne = mesh->GetNE();
1828 for (
int k = 0; k < ne; k++)
1830 mesh->GetElementEdges(k, edges, edges_ori);
1832 double ds = GetElementLengthScale(k);
1833 double xs = 0.05 * ds;
1835 for (
int i = 0; i < edges.Size(); i++)
1837 mesh->GetEdgeVertices(edges[i], vertices);
1839 p.SetSize(mesh->Dimension(), vertices.Size());
1840 p.SetCol(0, mesh->GetVertex(vertices[0]));
1841 p.SetCol(1, mesh->GetVertex(vertices[1]));
1843 ShrinkPoints(p, k, 0, 0);
1845 const double m[2] = {0.5 * (p(0,0) + p(0,1)), 0.5 * (p(1,0) + p(1,1))};
1847 double u = LogVal(0.5 * ((*sol)(vertices[0]) + (*sol)(vertices[1])));
1849 double xx[3] = {m[0], m[1], u};
1854 updated_bufs.emplace_back(&f_nums_buf);
1859 bool color = draworder < 3;
1861 order_noarrow_buf.clear();
1862 PrepareOrderingCurve1(order_buf,
true, color);
1863 PrepareOrderingCurve1(order_noarrow_buf,
false, color);
1864 updated_bufs.emplace_back(&order_buf);
1865 updated_bufs.emplace_back(&order_noarrow_buf);
1873 DenseMatrix pointmat;
1874 Array<int> vertices;
1876 DenseMatrix pointmat1;
1877 Array<int> vertices1;
1879 int ne = mesh->GetNE();
1880 for (
int k = 0; k < ne-1; k++)
1882 mesh->GetPointMatrix (k, pointmat);
1883 mesh->GetElementVertices (k, vertices);
1884 mesh->GetPointMatrix (k+1, pointmat1);
1885 mesh->GetElementVertices (k+1, vertices1);
1886 int nv = vertices.Size();
1887 int nv1 = vertices1.Size();
1889 ShrinkPoints(pointmat, k, 0, 0);
1890 ShrinkPoints(pointmat1, k+1, 0, 0);
1895 for (
int j = 0; j < nv; j++)
1897 xs += pointmat(0,j);
1898 ys += pointmat(1,j);
1899 us += maxv + double(k)/ne*(maxv-minv);
1908 for (
int j = 0; j < nv1; j++)
1910 xs1 += pointmat1(0,j);
1911 ys1 += pointmat1(1,j);
1912 us1 += maxv + double(k+1)/ne*(maxv-minv);
1921 double ds = sqrt(dx*dx+dy*dy+du*du);
1925 double cval = minv+double(k)/ne*(maxv-minv);
1926 MySetColor(builder, cval, minv, maxv);
1948 PrepareElementNumbering();
1949 PrepareEdgeNumbering();
1950 PrepareVertexNumbering();
1955 int i, j, k, ne = mesh -> GetNE();
1957 DenseMatrix pointmat;
1958 RefinedGeometry *RefG;
1963 for (i = 0; i < ne; i++)
1965 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1968 TimesToRefine, EdgeRefineFactor);
1969 GetRefinedValues (i, RefG->RefPts, values, pointmat);
1970 Array<int> &RG = RefG->RefGeoms;
1971 int sides = mesh->GetElement(i)->GetNVertices();
1973 for (k = 0; k < RG.Size()/sides; k++)
1977 for (j = 0; j < sides; j++)
1979 pointmat(1, RG[sides*k+j]),
1980 values(RG[sides*k+j]));
1985 updated_bufs.emplace_back(&line_buf);
1990 int i, k, ne = mesh -> GetNE();
1992 DenseMatrix pointmat;
1993 RefinedGeometry *RefG;
1998 for (i = 0; i < ne; i++)
2000 if (!el_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
2002 TimesToRefine, EdgeRefineFactor);
2003 GetRefinedValues (i, RefG->RefPts, values, pointmat);
2004 Array<int> &RE = RefG->RefEdges;
2007 for (k = 0; k < RE.Size()/2; k++)
2010 pointmat(1, RE[2*k]),
2013 pointmat(1, RE[2*k+1]),
2019 updated_bufs.emplace_back(&line_buf);
2024 bool had_logscale = logscale;
2025 logscale = logscale && LogscaleRange();
2027 SetLevelLines(minv, maxv, nl);
2029 zscale *= (bb.z[1]-bb.z[0])/(maxv-minv);
2036 EventUpdateColors();
2048 int i, j, ne = mesh->GetNBE();
2049 Array<int> vertices;
2050 DenseMatrix pointmat;
2057 for (i = 0; i < ne; i++)
2059 if (!bdr_el_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
2060 mesh->GetBdrElementVertices(i, vertices);
2061 mesh->GetBdrPointMatrix(i, pointmat);
2062 for (j = 0; j < pointmat.Size(); j++)
2063 bl.
glVertex3d(pointmat(0, j), pointmat(1, j),
2064 LogVal((*sol)(vertices[j])));
2071 FaceElementTransformations *T;
2072 RefinedGeometry *RefG =
2075 IntegrationRule &ir = RefG->RefPts;
2076 IntegrationRule eir(ir.GetNPoints());
2078 double shr = shrink;
2081 for (i = 0; i < ne; i++)
2083 if (!bdr_el_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
2084 en = mesh->GetBdrElementEdgeIndex(i);
2085 T = mesh->GetFaceElementTransformations(en, 4);
2086 T->Loc1.Transform(ir, eir);
2087 GetRefinedValues(T->Elem1No, eir, vals, pointmat);
2091 const double val = mesh->GetBdrAttribute(i);
2092 MySetColor(bl, val, minv, maxv);
2093 for (j = 0; j < vals.Size(); j++)
2095 bl.
glVertex3d(pointmat(0, j), pointmat(1, j), val);
2100 for (j = 0; j < vals.Size(); j++)
2102 bl.
glVertex3d(pointmat(0, j), pointmat(1, j), vals(j));
2107 if (T->Elem2No >= 0)
2109 T = mesh->GetFaceElementTransformations(en, 8);
2110 T->Loc2.Transform(ir, eir);
2111 GetRefinedValues(T->Elem2No, eir, vals, pointmat);
2113 for (j = 0; j < vals.Size(); j++)
2115 bl.
glVertex3d(pointmat(0, j), pointmat(1, j), vals(j));
2123 updated_bufs.emplace_back(&bdr_buf);
2129 DenseMatrix pointmat;
2143 Array<int> vertices;
2145 for (
int i = 0; i < mesh->GetNE(); i++)
2147 mesh->GetPointMatrix(i, pointmat);
2149 for (
int j = 0; j < pointmat.Width(); j++)
2152 CuttingPlane->Transform(pointmat(0, j),
2153 pointmat(1, j), 0.0);
2159 if (n == 0 || n == pointmat.Width())
2164 mesh->GetElementVertices(i, vertices);
2165 values.SetSize(vertices.Size());
2166 ind.SetSize(vertices.Size());
2167 for (
int j = 0; j < values.Size(); j++)
2169 values(j) = LogVal((*sol)(vertices[j]));
2173 DrawCPLine(bld, pointmat, values, ind);
2178 RefinedGeometry *RefG;
2180 for (
int i = 0; i < mesh->GetNE(); i++)
2183 TimesToRefine, EdgeRefineFactor);
2184 GetRefinedValues (i, RefG->RefPts, values, pointmat);
2185 Array<int> &RG = RefG->RefGeoms;
2186 int sides = mesh->GetElement(i)->GetNVertices();
2189 for (
int k = 0; k < RG.Size()/sides; k++)
2191 for (
int j = 0; j < sides; j++)
2193 ind[j] = RG[k*sides+j];
2197 for (
int j = 0; j < sides; j++)
2200 CuttingPlane->Transform(pointmat(0, ind[j]),
2201 pointmat(1, ind[j]), 0.0);
2207 if (n == 0 || n == sides)
2212 DrawCPLine(bld, pointmat, values, ind);
2218 updated_bufs.emplace_back(&cp_buf);
2222 gl3::GlBuilder& bld, DenseMatrix &pointmat, Vector &values, Array<int> &ind)
2224 int n, js, nv = ind.Size();
2228 xs = pointmat(0, ind[js]);
2229 ys = pointmat(1, ind[js]);
2230 s = CuttingPlane->Transform(xs, ys, 0.0);
2232 for (
int j = 0; j < nv; j++)
2234 const double xt = pointmat(0, ind[j]);
2235 const double yt = pointmat(1, ind[j]);
2236 const double t = CuttingPlane->Transform(xt, yt, 0.0);
2237 if ((s >= 0.0 && t < 0.0) || (s < 0.0 && t >= 0.0))
2239 double a = fabs(s) / (fabs(s) + fabs(t));
2242 (1.-a) * ys + a * yt,
2243 (1.-a) * values(ind[js]) + a * values(ind[j]));
2251 if (n != 2 && n != 4)
2253 cerr <<
"n = " << n << endl;
2254 mfem_error(
"VisualizationSceneSolution::DrawCPLine");
2263 PrepareColorBar(minv, maxv, (drawmesh == 2) ? &level :
nullptr );
2268 double* cp_eqn = CuttingPlane->Equation();
2269 params.
clip_plane_eqn = {cp_eqn[0], cp_eqn[1], cp_eqn[2], cp_eqn[3]};
2274 scene.
queue.emplace_back(params, &disp_buf);
2280 scene.
queue.emplace_back(params, &order_noarrow_buf);
2282 else if (draworder == 2)
2284 scene.
queue.emplace_back(params, &order_buf);
2294 scene.
queue.emplace_back(params, &cp_buf);
2303 scene.
queue.emplace_back(params, &bdr_buf);
2309 scene.
queue.emplace_back(params, &line_buf);
2311 else if (drawmesh == 2)
2313 scene.
queue.emplace_back(params, &lcurve_buf);
2319 scene.
queue.emplace_back(params, &e_nums_buf);
2321 else if (drawnums == 2)
2323 scene.
queue.emplace_back(params, &f_nums_buf);
2325 else if (drawnums == 3)
2327 scene.
queue.emplace_back(params, &v_nums_buf);
2333 scene.
queue.emplace_back(params, &order_noarrow_buf);
2335 else if (draworder == 4)
2337 scene.
queue.emplace_back(params, &order_buf);
2348 auto bdr_node = AddModelNode(bld,
"Boundary");
2349 auto bdr_mesh = bld.
addMesh(
"Boundary Mesh");
2352 int nlines = AddLines(
2360 cout <<
"glTF export: no boundary found to export!" << endl;
2366 string name =
"GLVis_scene_000";
2370 auto palette_mat = AddPaletteMaterial(bld);
2371 auto black_mat = AddBlackMaterial(bld);
2373 if (drawelems) { glTF_ExportElements(bld, buf, palette_mat, disp_buf); }
2376 glTF_ExportMesh(bld, buf, black_mat,
2377 (drawmesh == 1) ? line_buf : lcurve_buf);
2379 if (drawbdr) { glTF_ExportBoundary(bld, buf, black_mat); }
2380 if (drawaxes) { glTF_ExportBox(bld, buf, black_mat); }
2383 cout <<
"Exported glTF -> " << name <<
".gltf" << endl;
void SendExposeEvent()
Send expose event. In our case MyReshape is executed and Draw after it.
void PrepareElementNumbering1()
thread_local GeometryRefiner GLVisGeometryRefiner
virtual void ToggleDrawElems()
void GetRefinedDetJ(int i, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
Array< int > el_attr_to_show
void glVertex3d(double x, double y, double z)
void PrepareEdgeNumbering()
thread_local SdlWindow * wnd
virtual std::string GetHelpString() const
double GetElementLengthScale(int k)
virtual void SetShading(int, bool)
void glTF_ExportBoundary(glTF_Builder &bld, glTF_Builder::buffer_id buffer, glTF_Builder::material_id black_mat)
Array< int > bdr_el_attr_to_show
virtual void PrepareLines()
virtual gl3::SceneInfo GetSceneObjs()
void RemoveFPErrors(const DenseMatrix &pts, Vector &vals, DenseMatrix &normals, const int n, const Array< int > &ind, Array< int > &f_ind)
void PrepareVertexNumbering()
void PrepareWithNormals()
void DrawNumberedMarker(gl3::GlDrawable &buff, const double x[3], double dx, int n)
VisualizationSceneSolution()
virtual void ToggleLogscale(bool print)
void PrepareOrderingCurve1(gl3::GlDrawable &buf, bool arrows, bool color)
void PrepareElementNumbering()
virtual void EventUpdateBackground()
void glNormal3dv(const double *d)
virtual void SetRefineFactors(int, int)
buffer_id addBuffer(const std::string &bufferName)
void FindNewBox(double rx[], double ry[], double rval[])
int Compute3DUnitNormal(const double p1[], const double p2[], const double p3[], double nor[])
void addText(float x, float y, float z, const std::string &text)
Adds a string at the given position in object coordinates.
virtual void AutoRefine()
virtual ~VisualizationSceneSolution()
virtual void GetRefinedValues(int i, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
void PrepareVertexNumbering2()
int GetAutoRefineFactor()
double shrinkmat
Shrink factor with respect to the element (material) attributes centers.
void glNormal3d(double nx, double ny, double nz)
virtual void EventUpdateColors()
void NewMeshAndSolution(Mesh *new_m, Vector *new_sol, GridFunction *new_u=NULL)
GlBuilder createBuilder()
void DrawCPLine(gl3::GlBuilder &bld, DenseMatrix &pointmat, Vector &values, Array< int > &ind)
thread_local VisualizationSceneSolution * vssol
mesh_id addMesh(const std::string &meshName)
virtual void UpdateValueRange(bool prepare)
virtual void FindMeshBox(bool prepare)
Crude fixed-function OpenGL emulation helper.
void DrawLevelCurves(gl3::GlBuilder &buf, Array< int > &RG, DenseMatrix &pointmat, Vector &values, int sides, Array< double > &lvl, int flat=0)
thread_local string extra_caption
void PrepareElementNumbering2()
void PrepareLevelCurves()
void addNodeMesh(node_id node, mesh_id mesh)
virtual void FindNewValueRange(bool prepare)
void PrepareVertexNumbering1()
void PrepareLevelCurves2()
void ToggleRefinementFunction()
bool contains_translucent
virtual void SetNewScalingFromBox()
std::array< float, 4 > static_color
void PrepareOrderingCurve()
void setOnKeyDown(int key, Delegate func)
virtual void SetNewScalingFromBox()
void ComputeElemAttrCenter()
Compute the center of gravity for each element attribute.
std::array< double, 4 > clip_plane_eqn
thread_local VisualizationScene * locscene
virtual int GetRefinedValuesAndNormals(int i, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, DenseMatrix &normals)
virtual void glTF_Export()
virtual gl3::SceneInfo GetSceneObjs()
virtual void ToggleAttributes(Array< int > &attr_list)