42 <<
"+------------------------------------+" << endl
44 <<
"+------------------------------------+" << endl
45 <<
"| a - Displays/Hides the axes |" << endl
46 <<
"| A - Turns antialiasing on/off |" << endl
47 <<
"| c - Toggle colorbar and caption |" << endl
48 <<
"| C - Change the main plot caption |" << endl
49 <<
"| e - Displays/Hides the elements |" << endl
50 <<
"| E - Toggle the elements in the CP |" << endl
51 <<
"| f - Smooth/Flat/discont. shading |" << endl
52 <<
"| g - Toggle background |" << endl
53 <<
"| G - Export to glTF format |" << endl
54 <<
"| h - Displays help menu |" << endl
55 <<
"| i - Toggle cutting plane |" << endl
56 <<
"| I - Toggle cutting plane algorithm|" << endl
57 <<
"| j - Turn on/off perspective |" << endl
58 <<
"| k/K Adjust the transparency level |" << endl
59 <<
"| ,/< Adjust color transparency |" << endl
60 <<
"| l - Turns on/off the light |" << endl
61 <<
"| L - Toggle logarithmic scale |" << endl
62 <<
"| m - Displays/Hides the mesh |" << endl
63 <<
"| M - Toggle the mesh in the CP |" << endl
64 <<
"| o/O (De)refine elem, disc shading |" << endl
65 <<
"| p/P Cycle through color palettes |" << endl
66 <<
"| q - Quits |" << endl
67 <<
"| r - Reset the plot to 3D view |" << endl
68 <<
"| R - Reset the plot to 2D view |" << endl
69 <<
"| s - Turn on/off unit cube scaling |" << endl
70 <<
"| S - Take snapshot/Record a movie |" << endl
71 <<
"| t - Cycle materials and lights |" << endl
72 <<
"| u/U Move the level surface |" << endl
73 <<
"| v/V Add/Delete a level surface |" << endl
74 <<
"| w/W Move bdr elements up/down |" << endl
75 <<
"| x/X Rotate cutting plane (phi) |" << endl
76 <<
"| y/Y Rotate cutting plane (theta) |" << endl
77 <<
"| z/Z Translate cutting plane |" << endl
78 <<
"| \\ - Set light source position |" << endl
79 <<
"| Ctrl+o - Element ordering curve |" << endl
80 <<
"| Ctrl+p - Print to a PDF file |" << endl
81 <<
"+------------------------------------+" << endl
82 <<
"| Function keys |" << endl
83 <<
"+------------------------------------+" << endl
84 <<
"| F1 - X window info and keystrokes |" << endl
85 <<
"| F2 - Update colors, etc. |" << endl
86 <<
"| F3/F4 - Shrink/Zoom bdr elements |" << endl
87 <<
"| Ctrl+F3/F4 - Cut face bdr elements |" << endl
88 <<
"| F5 - Set level lines |" << endl
89 <<
"| F6 - Palette options |" << endl
90 <<
"| F7 - Manually set min/max value |" << endl
91 <<
"| F8 - List of subdomains to show |" << endl
92 <<
"| F9/F10 - Walk through subdomains |" << endl
93 <<
"| F11/F12 - Shrink/Zoom subdomains |" << endl
94 <<
"+------------------------------------+" << endl
95 <<
"| Keypad |" << endl
96 <<
"+------------------------------------+" << endl
97 <<
"| 1-9 Small rotation, reset with 5 |" << endl
98 <<
"| *,/ Scale up/down |" << endl
99 <<
"| +/- Change z-scaling |" << endl
100 <<
"| . - Start/stop spinning |" << endl
101 <<
"| 0/Enter - Spinning speed and dir. |" << endl
102 <<
"+------------------------------------+" << endl
103 <<
"| Mouse |" << endl
104 <<
"+------------------------------------+" << endl
105 <<
"| left btn - Rotation |" << endl
106 <<
"| middle btn - Translation |" << endl
107 <<
"| right btn - Scaling |" << endl
108 <<
"| left + Alt - Tilt |" << endl
109 <<
"| left + Shift - Spinning |" << endl
110 <<
"| right + Shift - Change light pos. |" << endl
111 <<
"| left + Ctrl - Spherical rotation |" << endl
112 <<
"| middle+ Ctrl - Object translation |" << endl
113 <<
"| right + Ctrl - Object scaling |" << endl
114 <<
"| left + Ctrl + Shift - z-Spinning |" << endl
115 <<
"+------------------------------------+" << endl;
121 vssol3d -> ToggleCuttingPlane();
127 vssol3d -> ToggleCPAlgorithm();
133 bool color = draworder < 3;
135 order_noarrow_buf.clear();
136 PrepareOrderingCurve1(order_buf,
true, color);
137 PrepareOrderingCurve1(order_noarrow_buf,
false, color);
138 updated_bufs.emplace_back(&order_buf);
139 updated_bufs.emplace_back(&order_noarrow_buf);
150 double ThicknessFactor = 2.0;
151 double MS_Thickness = 2.0;
164 DenseMatrix pointmat;
167 DenseMatrix pointmat1;
168 Array<int> vertices1;
170 int ne = mesh->GetNE();
171 for (
int k = 0; k < ne-1; k++)
173 mesh->GetPointMatrix (k, pointmat);
174 mesh->GetElementVertices (k, vertices);
175 mesh->GetPointMatrix (k+1, pointmat1);
176 mesh->GetElementVertices (k+1, vertices1);
177 int nv = vertices.Size();
178 int nv1 = vertices1.Size();
180 ShrinkPoints(pointmat, k, 0, 0);
181 ShrinkPoints(pointmat1, k+1, 0, 0);
186 for (
int j = 0; j < nv; j++)
199 for (
int j = 0; j < nv1; j++)
201 xs1 += pointmat1(0,j);
202 ys1 += pointmat1(1,j);
203 zs1 += pointmat1(2,j);
212 double ds = sqrt(dx*dx+dy*dy+dz*dz);
216 double cval = minv+double(k)/ne*(maxv-minv);
217 MySetColor(builder, cval, minv, maxv);
248 PrepareCuttingPlane();
249 PrepareCuttingPlaneLines();
262 static void KeyxPressed()
264 vssol3d -> CuttingPlane -> IncreasePhi();
270 static void KeyXPressed()
272 vssol3d -> CuttingPlane -> DecreasePhi();
278 static void KeyyPressed()
280 vssol3d -> CuttingPlane -> IncreaseTheta();
286 static void KeyYPressed()
288 vssol3d -> CuttingPlane -> DecreaseTheta();
294 static void KeyzPressed()
296 vssol3d -> CuttingPlane -> IncreaseDistance();
302 static void KeyZPressed()
304 vssol3d -> CuttingPlane -> DecreaseDistance();
310 static void KeymPressed()
316 static void KeyePressed()
322 static void KeyMPressed()
328 static void KeyEPressed()
330 vssol3d -> ToggleCPDrawElems();
334 static void KeyFPressed()
340 static void KeyoPressed(GLenum state)
342 if (state & KMOD_CTRL)
344 vssol3d -> ToggleDrawOrdering();
345 vssol3d -> PrepareOrderingCurve();
350 if (
vssol3d -> TimesToRefine < 32)
353 if (
vssol3d -> GetShading() == 2)
366 static void KeyOPressed()
368 if (
vssol3d -> TimesToRefine > 1)
371 if (
vssol3d -> GetShading() == 2)
383 static void KeywPressed()
385 if (
vssol3d -> GetShading() == 2)
387 if ( fabs(
vssol3d -> FaceShiftScale += 0.01) < 0.001 )
389 vssol3d -> FaceShiftScale = 0.0;
391 cout <<
"New Shift Scale: " <<
vssol3d -> FaceShiftScale
400 static void KeyWPressed()
402 if (
vssol3d -> GetShading() == 2)
404 if ( fabs(
vssol3d -> FaceShiftScale -= 0.01) < 0.001 )
406 vssol3d -> FaceShiftScale = 0.0;
408 cout <<
"New Shift Scale: " <<
vssol3d -> FaceShiftScale
431 vssol3d -> NumberOfLevelSurf(+1);
437 vssol3d -> NumberOfLevelSurf(-1);
441 static int magic_key_pressed = 0;
444 magic_key_pressed = 1-magic_key_pressed;
447 static void KeyF3Pressed(GLenum state)
449 if (state & KMOD_CTRL)
476 if (magic_key_pressed)
478 vssol3d -> Scale(1.11111111111111111111111);
488 static void KeyF4Pressed(GLenum state)
490 if (state & KMOD_CTRL)
517 if (magic_key_pressed)
528 static void KeyF11Pressed()
537 if (magic_key_pressed)
539 vssol3d -> Scale(1.11111111111111111111111);
547 static void KeyF12Pressed()
556 if (magic_key_pressed)
566 static void KeyF8Pressed()
569 int dim = mesh.Dimension();
570 const Array<int> &all_attr = ((dim == 3) ? mesh.bdr_attributes :
574 Array<int> attr_list(&attr, 1);
576 cout << ((dim == 3) ?
"Bdr a" :
"A") <<
"ttributes ON: ";
577 for (
int i = 0; i < all_attr.Size(); i++)
578 if (attr_marker[all_attr[i]-1])
580 cout <<
" " << all_attr[i];
584 cout << ((dim == 3) ?
"Bdr a" :
"A") <<
"ttribute to toggle : " << flush;
590 static void KeyF9Pressed()
593 int dim = mesh.Dimension();
594 const Array<int> &attr_list = ((dim == 3) ? mesh.bdr_attributes :
599 if (attr_list.Size() == 0)
603 for (i = j = n = 0; i < attr_list.Size(); i++)
604 if (attr_marker[attr_list[i]-1])
610 j = (j + 1) % (attr_list.Size() + 1);
616 if (j == attr_list.Size())
619 cout <<
"Showing all " << ((dim == 3) ?
"bdr " :
"") <<
"attributes "
626 attr_marker[attr-1] = 1;
627 cout <<
"Showing " << ((dim == 3) ?
"bdr " :
"") <<
"attribute "
635 static void KeyF10Pressed()
638 int dim = mesh.Dimension();
639 const Array<int> &attr_list = ((dim == 3) ? mesh.bdr_attributes :
644 if (attr_list.Size() == 0)
649 for (i = j = n = 0; i < attr_list.Size(); i++)
650 if (attr_marker[attr_list[i]-1])
656 j = (j + attr_list.Size()) % (attr_list.Size() + 1);
660 j = attr_list.Size() - 1;
662 if (j == attr_list.Size())
665 cout <<
"Showing all " << ((dim == 3) ?
"bdr " :
"") <<
"attributes "
672 attr_marker[attr-1] = 1;
673 cout <<
"Showing " << ((dim == 3) ?
"bdr " :
"") <<
"attribute "
699 cp_drawmesh = 0; cp_drawelems = 1;
703 drawelems = shading = 1;
714 FaceShiftScale = 0.0;
716 if (mesh->Dimension() == 3)
718 if (!mesh->bdr_attributes.Size())
720 MFEM_WARNING(
"Missing boundary attributes!");
722 bdr_attr_to_show.SetSize(mesh->bdr_attributes.Size() > 0 ?
723 mesh->bdr_attributes.Max() : 0);
727 if (!mesh->attributes.Size())
729 MFEM_WARNING(
"Missing element attributes!");
731 bdr_attr_to_show.SetSize(mesh->attributes.Size() > 0 ?
732 mesh->attributes.Max() : 0);
734 bdr_attr_to_show = 1;
738 FindNewValueRange(
false);
740 node_pos =
new double[mesh->GetNV()];
742 palette.SetIndex(12);
745 CuttingPlane =
new Plane(-1.0,0.0,0.0,(0.5-eps)*bb.x[0]+(0.5+eps)*bb.x[1]);
804 PrepareOrderingCurve();
813 Mesh *new_m, Vector *new_sol, GridFunction *new_u)
815 if (mesh->GetNV() != new_m->GetNV())
818 node_pos =
new double[new_m->GetNV()];
821 if (mesh->Dimension() != new_m->Dimension() ||
822 (mesh->Dimension() == 2 && mesh->GetNE() != new_m->GetNE()) ||
823 (mesh->Dimension() == 3 && mesh->GetNBE() != new_m->GetNBE()))
826 int ref = GetAutoRefineFactor();
827 if (TimesToRefine != ref)
830 cout <<
"Subdivision factor = " << TimesToRefine << endl;
844 PrepareOrderingCurve();
849 if (shading == s || s < 0)
854 if (s > 2 || (GridF == NULL && s > 1))
860 if (GridF != NULL && (s == 2 || os == 2))
869 static const char *shading_type[3] =
870 {
"flat",
"smooth",
"non-conforming (with subdivision)"};
873 cout <<
"Shading type : " << shading_type[shading] << endl;
881 SetShading((shading+1)%3,
true);
885 SetShading(1-shading,
true);
891 if (TimesToRefine == f || f < 1)
904 PrepareOrderingCurve();
910 int ne = mesh->GetNBE(), ref = 1;
911 if (mesh->Dimension() == 2)
916 while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_max_surf_elem)
926 int ref = GetAutoRefineFactor();
928 cout <<
"Subdivision factor = " << ref << endl;
930 SetRefineFactors(ref, 1);
935 int dim = mesh->Dimension();
936 Array<int> &attr_marker = bdr_attr_to_show;
938 for (
int i = 0; i < attr_list.Size(); i++)
940 int attr = attr_list[i];
943 cout <<
"Hiding all" << ((dim == 3) ?
" bdr" :
"") <<
" attributes."
947 else if (attr > attr_marker.Size())
949 cout <<
"Showing all" << ((dim == 3) ?
" bdr" :
"") <<
" attributes."
955 attr_marker[attr-1] = !attr_marker[attr-1];
964 int nv = mesh -> GetNV();
966 double *coord = mesh->GetVertex(0);
968 bb.x[0] = bb.x[1] = coord[0];
969 bb.y[0] = bb.y[1] = coord[1];
970 bb.z[0] = bb.z[1] = coord[2];
972 for (
int i = 1; i < nv; i++)
974 coord = mesh->GetVertex(i);
975 if (coord[0] < bb.x[0]) { bb.x[0] = coord[0]; }
976 if (coord[1] < bb.y[0]) { bb.y[0] = coord[1]; }
977 if (coord[2] < bb.z[0]) { bb.z[0] = coord[2]; }
978 if (coord[0] > bb.x[1]) { bb.x[1] = coord[0]; }
979 if (coord[1] > bb.y[1]) { bb.y[1] = coord[1]; }
980 if (coord[2] > bb.z[1]) { bb.z[1] = coord[2]; }
985 int dim = mesh->Dimension();
986 int ne = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
988 DenseMatrix pointmat;
989 RefinedGeometry *RefG;
991 FaceElementTransformations *Tr;
992 ElementTransformation *T;
994 for (
int i = 0; i < ne; i++)
998 mesh->GetBdrElementFace(i, &fn, &fo);
1001 Tr = mesh->GetFaceElementTransformations(fn, 5);
1002 eir.SetSize(RefG->RefPts.GetNPoints());
1003 Tr->Loc1.Transform(RefG->RefPts, eir);
1004 Tr->Elem1->Transform(eir, pointmat);
1008 T = mesh->GetElementTransformation(i);
1011 T->Transform(RefG->RefPts, pointmat);
1013 for (
int j = 0; j < pointmat.Width(); j++)
1015 if (pointmat(0,j) < bb.x[0]) { bb.x[0] = pointmat(0,j); }
1016 if (pointmat(1,j) < bb.y[0]) { bb.y[0] = pointmat(1,j); }
1017 if (pointmat(2,j) < bb.z[0]) { bb.z[0] = pointmat(2,j); }
1018 if (pointmat(0,j) > bb.x[1]) { bb.x[1] = pointmat(0,j); }
1019 if (pointmat(1,j) > bb.y[1]) { bb.y[1] = pointmat(1,j); }
1020 if (pointmat(2,j) > bb.z[1]) { bb.z[1] = pointmat(2,j); }
1025 UpdateBoundingBox();
1037 minv = GridF->Min();
1038 maxv = GridF->Max();
1041 UpdateValueRange(prepare);
1047 PrepareCuttingPlane();
1049 PrepareOrderingCurve();
1050 if (shading == 2 && drawmesh != 0 && FaceShiftScale != 0.0)
1058 logscale = logscale && LogscaleRange();
1059 palette.SetUseLogscale(logscale);
1061 SetLevelLines(minv, maxv, nl);
1065 EventUpdateColors();
1071 int i, nnodes = mesh -> GetNV();
1073 for (i = 0; i < nnodes; i++)
1075 node_pos[i] = CuttingPlane -> Transform (mesh -> GetVertex (i));
1081 drawmesh = (drawmesh+1)%3;
1087 if (cplane == 2 && cp_drawmesh == 3)
1092 cplane = (cplane+1)%3;
1094 cout <<
"cplane = " << cplane << endl;
1097 if (cplane == 0 || cplane == 2)
1101 PrepareOrderingCurve();
1107 cp_drawelems = 1-cp_drawelems;
1108 PrepareCuttingPlane();
1115 cp_drawmesh = (cp_drawmesh+1)%3;
1117 else if (cplane == 2)
1119 cp_drawmesh = (cp_drawmesh+1)%4;
1121 PrepareCuttingPlaneLines();
1126 cp_algo = (cp_algo+1)%2;
1127 if (shading == 2 && cplane == 1)
1158 const int FaceNo,
const int side,
const IntegrationRule &ir,
1159 DenseMatrix &normals)
1162 double aJInv[9], alnor[3];
1163 DenseMatrix JInv(aJInv, 3, 3);
1164 Vector lnor(alnor, 3), nr;
1165 IntegrationRule eir(ir.GetNPoints());
1166 FaceElementTransformations *Tr;
1167 normals.SetSize(3, ir.GetNPoints());
1168 ElementTransformation *ETr;
1169 IntegrationPointTransformation *LTr;
1172 Tr = mesh->GetFaceElementTransformations(FaceNo, 5);
1178 Tr = mesh->GetFaceElementTransformations(FaceNo, 10);
1182 LTr->Transform(ir, eir);
1183 for (
int i = 0; i < normals.Width(); i++)
1185 LTr->Transf.SetIntPoint(&ir.IntPoint(i));
1186 CalcOrtho(LTr->Transf.Jacobian(), lnor);
1187 ETr->SetIntPoint(&eir.IntPoint(i));
1188 const DenseMatrix &Jac = ETr->Jacobian();
1189 CalcInverse(Jac, JInv);
1190 normals.GetColumnReference(i, nr);
1191 JInv.MultTranspose(lnor, nr);
1197 JInv.ClearExternalData();
1201 int n,
double *points,
int elem,
int func,
int part)
1204 RefinedGeometry *RefG;
1205 IntegrationPointTransformation ip_transf;
1211 ip_transf.Transf.SetFE (&TriangleFE);
1215 ip_transf.Transf.SetFE (&QuadrilateralFE);
1218 DrawRefinedSurf (3, points, elem, func, 0);
1219 for (i = 0; i < 3; i++)
1221 points[4+i] = points[i];
1223 DrawRefinedSurf (4, points+4, elem, func, 1);
1226 DrawRefinedSurf (4, points, elem, func, 0);
1227 for (i = 0; i < 3; i++)
1229 points[8+i] = points[i];
1231 DrawRefinedSurf (4, points+8, elem, func, 1);
1236 DenseMatrix &pm = ip_transf.Transf.GetPointMat();
1238 for (i = 0; i < n; i++)
1239 for (j = 0; j < 3; j++)
1241 pm(j,i) = points[4*i+j];
1243 IntegrationRule tir (RefG -> RefPts.GetNPoints());
1244 ip_transf.Transform (RefG -> RefPts, tir);
1245 DenseMatrix pointmat;
1247 GridF -> GetValues (elem, tir, values, pointmat);
1249 LiftRefinedSurf (n, pointmat, values, NULL);
1254 DrawRefinedSurf (n, pointmat, values, RefG->RefGeoms);
1258 DrawRefinedSurfEdges (n, pointmat, values, RefG->RefEdges, part);
1262 DrawRefinedSurfLevelLines (n, pointmat, values, RefG->RefGeoms);
1268 int n, DenseMatrix &pointmat, Vector &values,
int *RG)
1272 if (FaceShiftScale == 0.0)
1281 double *eqn = CuttingPlane -> Equation();
1282 norm[0] = -eqn[0]; norm[1] = -eqn[1]; norm[2] = -eqn[2];
1289 for (i = 0; i < n; i++)
1290 for (j = 0; j < 3; j++)
1292 pts[i][j] = pointmat(j,RG[i]);
1305 cerr <<
"WARNING: VisualizationSceneSolution3d::LiftRefinedSurf"
1311 double bbox_diam = sqrt ( (bb.x[1]-bb.x[0])*(bb.x[1]-bb.x[0]) +
1312 (bb.y[1]-bb.y[0])*(bb.y[1]-bb.y[0]) +
1313 (bb.z[1]-bb.z[0])*(bb.z[1]-bb.z[0]) );
1314 double sc = FaceShiftScale * bbox_diam;
1316 for (i = 0; i < pointmat.Width(); i++)
1318 double val = sc * (values(i) - minv) / (maxv - minv);
1319 for (j = 0; j < 3; j++)
1321 pointmat(j, i) += val * norm[j];
1327 int n, DenseMatrix &pointmat, Vector &values, Array<int> &RefGeoms)
1329 double norm[3], pts[4][3];
1332 for (
int i = 0; i < RefGeoms.Size()/n; i++)
1334 int *RG = &(RefGeoms[i*n]);
1336 for (j = 0; j < n; j++)
1337 for (
int l = 0; l < 3; l++)
1339 pts[j][l] = pointmat(l, RG[j]);
1353 for (j = 0; j < n; j++)
1355 MySetColor (draw, values(RG[j]), minv, maxv);
1369 int n, DenseMatrix &pointmat, Vector &values, Array<int> &RefEdges,
1372 int k, k_start, k_end;
1375 k_end = RefEdges.Size();
1379 k_end = (k_end/n) * (n-1);
1383 k_start = (k_end/n);
1387 for (k = k_start; k < k_end; k++)
1389 int RE = RefEdges[k];
1391 line.
glVertex3d (pointmat(0, RE), pointmat(1, RE),
1398 int n, DenseMatrix &pointmat, Vector &values, Array<int> &RefGeoms)
1406 for (k = 0; k < RefGeoms.Size()/n; k++)
1408 RG = &(RefGeoms[k*n]);
1410 for (j = 0; j < n; j++)
1412 for (
int i = 0; i < 3; i++)
1414 point[j][i] = pointmat(i, RG[j]);
1416 point[j][3] = values(RG[j]);
1418 DrawPolygonLevelLines(line, point[0], n, level,
false);
1426 int dim = mesh->Dimension();
1427 int ne = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
1428 DenseMatrix pointmat;
1429 Array<int> vertices;
1430 double p[4][3], c[4];
1432 for (i = 0; i < ne; i++)
1436 if (!bdr_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
1442 mesh->GetBdrElementFace(i, &f, &o);
1443 mesh->GetFaceElements(f, &e1, &e2);
1444 mesh->GetElementVertices(e1, vertices);
1448 mesh->GetBdrElementVertices(i, vertices);
1453 if (!bdr_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1455 mesh->GetElementVertices(i, vertices);
1458 if (cplane == 2 && CheckPositions(vertices)) {
continue; }
1462 mesh->GetBdrPointMatrix(i, pointmat);
1466 mesh->GetPointMatrix(i, pointmat);
1469 for (j = 0; j < pointmat.Width(); j++)
1471 p[j][0] = pointmat(0, j);
1472 p[j][1] = pointmat(1, j);
1473 p[j][2] = pointmat(2, j);
1474 c[j] = (*sol)(vertices[j]);
1480 DrawCutTriangle(disp_buf, p, c, minv, maxv);
1484 DrawTriangle(disp_buf, p, c, minv, maxv);
1491 DrawCutQuad(disp_buf, p, c, minv, maxv);
1495 DrawQuad(disp_buf, p, c, minv, maxv);
1499 updated_bufs.emplace_back(&disp_buf);
1507 static void CutReferenceSquare(RefinedGeometry *RefG,
double lambda,
1508 IntegrationRule &RefPts, Array<int> &RefGeoms)
1511 double fl = (1.0-lambda)/2.0;
1512 double fr = (1.0+lambda)/2.0;
1514 int np = RefG->RefPts.Size();
1515 RefPts.SetSize(4*np);
1516 for (
int i = 0; i < np; i++)
1518 double X = RefG->RefPts[i].x;
1519 double Y = RefG->RefPts[i].y;
1522 double phi3 = (1.0-X)*Y, phi2 = X*Y;
1523 double phi0 = (1.0-X)*(1.0-Y), phi1 = X*(1.0-Y);
1526 RefPts[i].x = phi1 + fr * phi2 + fl * phi3;
1527 RefPts[i].y = fl * phi2 + fl * phi3;
1530 RefPts[i+np].x = fr * phi0 + phi1 + phi2 + fr * phi3;
1531 RefPts[i+np].y = fl * phi0 + phi2 + fr * phi3;
1534 RefPts[i+2*np].x = fl * phi0 + fr * phi1 + phi2;
1535 RefPts[i+2*np].y = fr * phi0 + fr * phi1 + phi2 + phi3;
1538 RefPts[i+3*np].x = fl * phi1 + fl * phi2;
1539 RefPts[i+3*np].y = fl * phi1 + fr * phi2 + phi3;
1541 RefPts[i].z = RefG->RefPts[i].z;
1542 RefPts[i+np].z = RefG->RefPts[i].z;
1543 RefPts[i+2*np].z = RefG->RefPts[i].z;
1544 RefPts[i+3*np].z = RefG->RefPts[i].z;
1547 int ne = RefG->RefGeoms.Size();
1548 RefGeoms.SetSize(4*ne);
1549 for (
int i = 0; i < ne; i++)
1551 RefGeoms[i] = RefG->RefGeoms[i];
1552 RefGeoms[i+ne] = RefG->RefGeoms[i] + np;
1553 RefGeoms[i+2*ne] = RefG->RefGeoms[i] + 2*np;
1554 RefGeoms[i+3*ne] = RefG->RefGeoms[i] + 3*np;
1562 static void CutReferenceTriangle(RefinedGeometry *RefG,
double lambda,
1563 IntegrationRule &RefPts, Array<int> &RefGeoms)
1566 double fl = (1.0-lambda)/3.0;
1567 double fr = (1.0+2.0*lambda)/3.0;
1569 int np = RefG->RefPts.Size();
1570 RefPts.SetSize(3*np);
1571 for (
int i = 0; i < np; i++)
1573 double X = RefG->RefPts[i].x;
1574 double Y = RefG->RefPts[i].y;
1577 double phi3 = (1.0-X)*Y, phi2 = X*Y;
1578 double phi0 = (1.0-X)*(1.0-Y), phi1 = X*(1.0-Y);
1581 RefPts[i].x = phi1 + fr * phi2 + fl * phi3;
1582 RefPts[i].y = fl * phi2 + fl * phi3;
1585 RefPts[i+np].x = fr * phi0 + phi1 + fl * phi3;
1586 RefPts[i+np].y = fl * phi0 + phi2 + fr * phi3;
1589 RefPts[i+2*np].x = fl * phi1 + fl * phi2;
1590 RefPts[i+2*np].y = fl * phi1 + fr * phi2 + phi3;
1592 RefPts[i].z = RefG->RefPts[i].z;
1593 RefPts[i+np].z = RefG->RefPts[i].z;
1594 RefPts[i+2*np].z = RefG->RefPts[i].z;
1597 int ne = RefG->RefGeoms.Size();
1598 RefGeoms.SetSize(3*ne);
1599 for (
int i = 0; i < ne; i++)
1601 RefGeoms[i] = RefG->RefGeoms[i];
1602 RefGeoms[i+ne] = RefG->RefGeoms[i] + np;
1603 RefGeoms[i+2*ne] = RefG->RefGeoms[i] + 2*np;
1611 RefinedGeometry *RefG =
1619 int fn, fo, di, have_normals;
1620 double bbox_diam, vmin, vmax;
1623 int dim = mesh->Dimension();
1624 int nbe = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
1625 DenseMatrix pointmat, normals;
1626 Vector values, normal;
1627 RefinedGeometry * RefG;
1628 Array<int> vertices;
1630 IsoparametricTransformation T;
1632 bbox_diam = sqrt ( (bb.x[1]-bb.x[0])*(bb.x[1]-bb.x[0]) +
1633 (bb.y[1]-bb.y[0])*(bb.y[1]-bb.y[0]) +
1634 (bb.z[1]-bb.z[0])*(bb.z[1]-bb.z[0]) );
1635 double sc = FaceShiftScale * bbox_diam;
1637 vmin = numeric_limits<double>::infinity();
1639 for (
int i = 0; i < nbe; i++)
1642 switch ((dim == 3) ? mesh->GetBdrElementType(i) : mesh->GetElementType(i))
1644 case Element::TRIANGLE:
1648 case Element::QUADRILATERAL:
1656 if (!bdr_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
1662 mesh->GetBdrElementFace(i, &f, &o);
1663 mesh->GetFaceElements(f, &e1, &e2);
1664 mesh->GetElementVertices(e1, vertices);
1668 mesh->GetBdrElementVertices(i, vertices);
1673 if (!bdr_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
1674 mesh->GetElementVertices(i, vertices);
1677 if (cplane == 2 && CheckPositions(vertices)) {
continue; }
1681 mesh -> GetBdrElementFace (i, &fn, &fo);
1694 if (di == 1 && !mesh->FaceIsInterior(fn))
1699 IntegrationRule &RefPts = (cut_lambda > 0) ?
1702 GridF -> GetFaceValues (fn, di, RefPts, values, pointmat);
1703 GetFaceNormals(fn, di, RefPts,normals);
1705 ShrinkPoints(pointmat, i, fn, di);
1717 const IntegrationRule &ir = (cut_lambda > 0) ?
1720 GridF->GetValues(i, ir, values, pointmat);
1721 normals.SetSize(3, values.Size());
1722 mesh->GetElementTransformation(i, &T);
1723 for (
int j = 0; j < values.Size(); j++)
1725 T.SetIntPoint(&ir.IntPoint(j));
1726 const DenseMatrix &J = T.Jacobian();
1727 normals.GetColumnReference(j, normal);
1728 CalcOrtho(J, normal);
1729 normal /= normal.Norml2();
1733 ShrinkPoints(pointmat, i, 0, 0);
1736 vmin = fmin(vmin, values.Min());
1737 vmax = fmax(vmax, values.Max());
1742 for (
int j = 0; j < 3; j++)
1747 for (
int k = 0; k < normals.Width(); k++)
1748 for (
int j = 0; j < 3; j++)
1750 norm[j] += normals(j, k);
1753 for (
int k = 0; k < pointmat.Width(); k++)
1755 double val = sc * (values(k) - minv) / (maxv - minv);
1756 for (
int j = 0; j < 3; j++)
1758 pointmat(j, k) += val * norm[j];
1764 have_normals = have_normals ? 2 : 0;
1767 have_normals = -1 - have_normals;
1773 Array<int> &RefGeoms = (cut_lambda > 0) ?
1776 int psides = (cut_lambda > 0) ? 4 : sides;
1777 DrawPatch(disp_buf, pointmat, values, normals, psides, RefGeoms,
1778 minv, maxv, have_normals);
1780 updated_bufs.emplace_back(&disp_buf);
1782 cout <<
"VisualizationSceneSolution3d::PrepareFlat2() : [min,max] = ["
1783 << vmin <<
"," << vmax <<
"]" << endl;
1810 int dim = mesh->Dimension();
1811 int ne = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
1812 int nv = mesh -> GetNV();
1813 DenseMatrix pointmat;
1814 Array<int> vertices;
1825 for (
int i = 0; i < ne; i++)
1827 be_to_ba.AddAColumnInRow(i);
1832 for (
int i = 0; i < ne; i++)
1834 be_to_ba.AddConnection(i, mesh->GetBdrAttribute(i)-1);
1839 for (
int i = 0; i < ne; i++)
1841 be_to_ba.AddConnection(i, mesh->GetAttribute(i)-1);
1844 be_to_ba.ShiftUpI();
1846 Transpose(be_to_ba, ba_to_be);
1849 const Array<int> &attributes =
1850 ((dim == 3) ? mesh->bdr_attributes : mesh->attributes);
1851 for (
int d = 0; d < attributes.Size(); d++)
1853 const int attr = attributes[d]-1;
1855 if (!bdr_attr_to_show[attr]) {
continue; }
1857 const int nelem = ba_to_be.RowSize(attr);
1858 const int *elem = ba_to_be.GetRow(attr);
1860 for (
int i = 0; i < nelem; i++)
1864 mesh->GetBdrElementVertices(elem[i], vertices);
1868 mesh->GetElementVertices(elem[i], vertices);
1870 for (j = 0; j < vertices.Size(); j++)
1872 nx(vertices[j]) = ny(vertices[j]) = nz(vertices[j]) = 0.;
1875 for (
int i = 0; i < nelem; i++)
1879 mesh->GetBdrPointMatrix(elem[i], pointmat);
1880 mesh->GetBdrElementVertices(elem[i], vertices);
1884 mesh->GetPointMatrix(elem[i], pointmat);
1885 mesh->GetElementVertices(elem[i], vertices);
1888 if (pointmat.Width() == 3)
1890 &pointmat(0,2), nor);
1893 &pointmat(0,2), &pointmat(0,3), nor);
1895 for (j = 0; j < pointmat.Size(); j++)
1897 nx(vertices[j]) += nor[0];
1898 ny(vertices[j]) += nor[1];
1899 nz(vertices[j]) += nor[2];
1903 for (
int i = 0; i < nelem; i++)
1911 mesh->GetBdrElementFace(i, &f, &o);
1912 mesh->GetFaceElements(f, &e1, &e2);
1913 mesh->GetElementVertices(e1, vertices);
1915 if (CheckPositions(vertices)) {
continue; }
1919 mesh->GetBdrElementVertices(elem[i], vertices);
1924 mesh->GetElementVertices(elem[i], vertices);
1927 GLenum elemType = GL_NONE;
1928 switch ((dim == 3) ? mesh->GetBdrElementType(elem[i]) :
1929 mesh->GetElementType(elem[i]))
1931 case Element::TRIANGLE:
1932 elemType = GL_TRIANGLES;
1934 case Element::QUADRILATERAL:
1935 elemType = GL_QUADS;
1938 MFEM_ABORT(
"Invalid boundary element type");
1944 mesh->GetBdrPointMatrix(elem[i], pointmat);
1948 mesh->GetPointMatrix(elem[i], pointmat);
1951 for (j = 0; j < pointmat.Size(); j++)
1953 MySetColor(poly, (*sol)(vertices[j]), minv, maxv);
1954 poly.
glNormal3d(nx(vertices[j]), ny(vertices[j]), nz(vertices[j]));
1960 updated_bufs.emplace_back(&disp_buf);
1976 int dim = mesh->Dimension();
1977 int ne = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
1979 DenseMatrix pointmat;
1983 Array<int> vertices;
1985 for (i = 0; i < ne; i++)
1989 if (!bdr_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
1995 mesh->GetBdrElementFace(i, &f, &o);
1996 mesh->GetFaceElements(f, &e1, &e2);
1997 mesh->GetElementVertices(e1, vertices);
2001 mesh->GetBdrElementVertices(i, vertices);
2006 if (!bdr_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
2008 mesh->GetElementVertices(i, vertices);
2011 if (cplane == 2 && CheckPositions(vertices)) {
continue; }
2016 mesh->GetBdrPointMatrix(i, pointmat);
2020 mesh->GetPointMatrix(i, pointmat);
2029 for (j = 0; j < pointmat.Size(); j++)
2031 line.
glVertex3d (pointmat(0, j), pointmat(1, j), pointmat(2, j));
2037 for (j = 0; j < pointmat.Size(); j++)
2039 for (k = 0; k < 3; k++)
2041 point[j][k] = pointmat(k,j);
2043 point[j][3] = (*sol)(vertices[j]);
2045 DrawPolygonLevelLines(line, point[0], pointmat.Size(), level,
false);
2049 updated_bufs.emplace_back(&line_buf);
2059 int dim = mesh->Dimension();
2060 int nbe = (dim == 3) ? mesh->GetNBE() : mesh->GetNE();
2061 DenseMatrix pointmat, normals;
2062 Vector values, normal;
2063 RefinedGeometry * RefG;
2064 Array<int> vertices;
2065 IsoparametricTransformation T;
2067 bbox_diam = sqrt ( (bb.x[1]-bb.x[0])*(bb.x[1]-bb.x[0]) +
2068 (bb.y[1]-bb.y[0])*(bb.y[1]-bb.y[0]) +
2069 (bb.z[1]-bb.z[0])*(bb.z[1]-bb.z[0]) );
2070 double sc = FaceShiftScale * bbox_diam;
2072 for (
int i = 0; i < nbe; i++)
2076 if (!bdr_attr_to_show[mesh->GetBdrAttribute(i)-1]) {
continue; }
2082 mesh->GetBdrElementFace(i, &f, &o);
2083 mesh->GetFaceElements(f, &e1, &e2);
2084 mesh->GetElementVertices(e1, vertices);
2088 mesh->GetBdrElementVertices(i, vertices);
2093 if (!bdr_attr_to_show[mesh->GetAttribute(i)-1]) {
continue; }
2095 mesh->GetElementVertices(i, vertices);
2098 if (cplane == 2 && CheckPositions(vertices)) {
continue; }
2102 mesh -> GetBdrElementFace (i, &fn, &fo);
2107 if (di == 1 && !mesh->FaceIsInterior(fn))
2111 GridF -> GetFaceValues (fn, di, RefG->RefPts, values, pointmat);
2112 ShrinkPoints(pointmat, i, fn, di);
2118 GridF->GetValues(i, RefG->RefPts, values, pointmat);
2119 ShrinkPoints(pointmat, i, 0, 0);
2126 GetFaceNormals(fn, di, RefG->RefPts, normals);
2130 normals.SetSize(3, values.Size());
2131 mesh->GetElementTransformation(i, &T);
2132 for (
int j = 0; j < values.Size(); j++)
2134 T.SetIntPoint(&RefG->RefPts.IntPoint(j));
2135 const DenseMatrix &J = T.Jacobian();
2136 normals.GetColumnReference(j, normal);
2137 CalcOrtho(J, normal);
2138 normal /= normal.Norml2();
2142 for (
int j = 0; j < 3; j++)
2146 for (
int k = 0; k < normals.Width(); k++)
2148 for (
int j = 0; j < 3; j++)
2150 norm[j] += normals(j, k);
2153 double len = sqrt(
InnerProd(norm, norm));
2158 for (
int j = 0; j < 3; j++)
2162 for (
int k = 0; k < pointmat.Width(); k++)
2164 double val = sc * (values(k) - minv) / (maxv - minv);
2165 for (
int j = 0; j < 3; j++)
2167 pointmat(j, k) += val * norm[j];
2174 Array<int> &REdges = RefG->RefEdges;
2177 for (
int k = 0; k < REdges.Size(); k++)
2183 else if (drawmesh == 2)
2187 switch ((dim == 3) ? mesh->GetBdrElementType(i) :
2188 mesh->GetElementType(i))
2190 case Element::TRIANGLE:
2194 case Element::QUADRILATERAL:
2199 for (
int k = 0; k < RefG->RefGeoms.Size()/sides; k++)
2201 int *RG = &(RefG->RefGeoms[k*sides]);
2203 for (
int j = 0; j < sides; j++)
2205 for (
int ii = 0; ii < 3; ii++)
2207 point[j][ii] = pointmat(ii, RG[j]);
2209 point[j][3] = values(RG[j]);
2211 DrawPolygonLevelLines(line, point[0], sides, level,
false);
2215 updated_bufs.emplace_back(&line_buf);
2218 static void CutElement(
const Geometry::Type geom,
const int *vert_flags,
2219 const int **edge_vert_ptr,
int *cut_edges,
2220 int *num_cut_edges,
int *n2_cut_edges)
2222 static const int tet_edges[12]= {0,3, 0,2, 0,1, 1,2, 1,3, 2,3};
2223 static const int pyr_edges[16] =
2224 {0,1, 1,2, 3,2, 0,3, 0,4, 1,4, 2,4, 3,4};
2225 static const int pyr_cutting[16][3] =
2227 { 3, 4, 6}, { 9, -1, 10}, { 4, 6, 1}, {11, -1, 12},
2228 {13, -1, 14}, { 6, 1, 3}, {15, -1, 8}, { 1, 3, 4},
2229 {-1, 10, 0}, { 7, 15, -1}, {-1, 12, 2}, { 0, 9, -1},
2230 {-1, 14, 5}, { 2, 11, -1}, {-1, 8, 7}, { 5, 13, -1}
2232 static const int pri_edges[18] =
2233 {0,1, 1,2, 2,0, 3,4, 4,5, 5,3, 0,3, 1,4, 2,5};
2234 static const int pri_cutting[18][3] =
2236 { 3, -1, 5}, {13, 7, 14}, { 5, -1, 1}, {15, 9, 16},
2237 { 1, -1, 3}, {17, 11, 12},
2238 {14, 0, 13}, {10, -1, 8}, {16, 2, 15}, { 6, -1, 10},
2239 {12, 4, 17}, { 8, -1, 6},
2240 { 7, 14, 0}, { 4, 17, 11}, { 9, 16, 2}, { 0, 13, 7},
2241 {11, 12, 4}, { 2, 15, 9}
2243 static const int hex_edges[24] =
2244 { 0,1, 1,2, 3,2, 0,3, 4,5, 5,6, 7,6, 4,7, 0,4, 1,5, 2,6, 3,7 };
2245 static const int hex_cutting[24][3] =
2247 { 3, 4, 6}, {17, 9, 18}, { 4, 6, 1}, {19, 11, 20},
2248 {21, 12, 22}, { 6, 1, 3}, {23, 14, 16}, { 1, 3, 4},
2249 {18, 0, 17}, {15, 13, 10}, {20, 2, 19}, { 8, 15, 13},
2250 {10, 8, 15}, {22, 5, 21}, {13, 10, 8}, {16, 7, 23},
2251 { 9, 18, 0}, { 7, 23, 14}, {11, 20, 2}, { 0, 17, 9},
2252 {12, 22, 5}, { 2, 19, 11}, {14, 16, 7}, { 5, 21, 12}
2260 case Geometry::TETRAHEDRON:
2263 for (
int j = 0; j < 6; j++, ev += 2)
2264 if (vert_flags[ev[0]] != vert_flags[ev[1]])
2272 case Geometry::PYRAMID:
2276 for (
int j = 0; j < 8; j++, ev += 2)
2278 emark[j] = vert_flags[ev[1]] - vert_flags[ev[0]];
2283 for (j = 0; j < 8; j++)
2285 if (emark[j]) {
break; }
2299 for (j = 0; j < 3; j++)
2301 m = pyr_cutting[k][j];
2304 ev = pyr_edges + 2 * (m / 2);
2305 if ((m%2 == 0 && vert_flags[ev[0]] > vert_flags[ev[1]]) ||
2306 (m%2 == 1 && vert_flags[ev[1]] > vert_flags[ev[0]]))
2312 cut_edges[n2++] = k/2;
2316 while (k/2 != cut_edges[n]);
2332 case Geometry::PRISM:
2336 for (
int j = 0; j < 9; j++, ev += 2)
2338 emark[j] = vert_flags[ev[1]] - vert_flags[ev[0]];
2343 for (j = 0; j < 9; j++)
2345 if (emark[j]) {
break; }
2359 for (j = 0; j < 3; j++)
2361 m = pri_cutting[k][j];
2364 ev = pri_edges + 2 * (m / 2);
2365 if ((m%2 == 0 && vert_flags[ev[0]] > vert_flags[ev[1]]) ||
2366 (m%2 == 1 && vert_flags[ev[1]] > vert_flags[ev[0]]))
2372 cut_edges[n2++] = k/2;
2376 while (k/2 != cut_edges[n]);
2392 case Geometry::CUBE:
2396 for (
int j = 0; j < 12; j++, ev += 2)
2398 emark[j] = vert_flags[ev[1]] - vert_flags[ev[0]];
2403 for (j = 0; j < 12; j++)
2405 if (emark[j]) {
break; }
2419 for (j = 0; j < 3; j++)
2421 m = hex_cutting[k][j];
2422 ev = hex_edges + 2 * (m / 2);
2423 if ((m%2 == 0 && vert_flags[ev[0]] > vert_flags[ev[1]]) ||
2424 (m%2 == 1 && vert_flags[ev[1]] > vert_flags[ev[0]]))
2429 cut_edges[n2++] = k/2;
2433 while (k/2 != cut_edges[n]);
2454 *edge_vert_ptr = ev;
2462 int flag[8], cut_edges[6];
2464 double t, point[6][4], norm[3];
2466 DenseMatrix pointmat;
2469 for (
int i = 0; i < mesh -> GetNE(); i++)
2472 mesh -> GetElementVertices(i, nodes);
2473 for (
int j = 0; j < nodes.Size(); j++)
2475 if (node_pos[nodes[j]] >= 0.0)
2485 CutElement(mesh->GetElementBaseGeometry(i), flag,
2486 &ev, cut_edges, &n, &n2);
2492 mesh -> GetPointMatrix (i, pointmat);
2496 const IntegrationRule *ir;
2497 ir = Geometries.GetVertices (mesh -> GetElementBaseGeometry(i));
2498 pointmat.SetSize (3, ir -> GetNPoints());
2499 for (
int j = 0; j < ir -> GetNPoints(); j++)
2501 const IntegrationPoint &ip = ir -> IntPoint (j);
2502 pointmat(0,j) = ip.x;
2503 pointmat(1,j) = ip.y;
2504 pointmat(2,j) = ip.z;
2507 for (
int j = 0; j < n; j++)
2509 const int *en = ev + 2*cut_edges[j];
2510 t = node_pos[ nodes[en[1]] ];
2511 t = t / ( t - node_pos[ nodes[en[0]] ] );
2512 for (
int k = 0; k < 3; k++)
2514 point[j][k] = t*pointmat(k,en[0]) + (1-t)*pointmat(k,en[1]);
2516 point[j][3] = t*(*sol)(nodes[en[0]]) + (1-t)*(*sol)(nodes[en[1]]);
2526 DrawRefinedSurf(n, point[0], i, 1);
2538 if (no_norm && m > 4)
2540 for (
int j = 3; j < m; j++)
2541 for (
int k = 0; k < 4; k++)
2543 point[j-2][k] = point[j][k];
2560 for (
int j = 0; j < m; j++)
2562 MySetColor(draw, point[j][3], minv, maxv);
2576 DrawRefinedSurf(n, point[0], i, 2);
2583 for (
int j = 0; j < n; j++)
2597 DrawRefinedSurf(n, point[0], i, 3);
2602 DrawPolygonLevelLines(line, point[0], n, level,
false);
2608 for (
int j = 0; j < n2; j++)
2610 cut_edges[j] = cut_edges[j+n];
2620 const DenseMatrix &verts,
const Vector &vert_dist,
const Vector &vals,
2621 const Geometry::Type geom,
const int *elems,
int num_elems,
int func)
2624 if (FaceShiftScale != 0.0)
2626 double bbox_diam = sqrt ( (bb.x[1]-bb.x[0])*(bb.x[1]-bb.x[0]) +
2627 (bb.y[1]-bb.y[0])*(bb.y[1]-bb.y[0]) +
2628 (bb.z[1]-bb.z[0])*(bb.z[1]-bb.z[0]) );
2629 sc = FaceShiftScale * bbox_diam;
2631 const int nv = Geometry::NumVerts[geom];
2635 for (
int i = 0; i < num_elems; i++)
2637 Geometry::Type egeom = geom;
2638 int vert_flag[8], cut_edges[8];
2639 const int *elem = elems + i*nv;
2640 const int *edge_vert;
2641 int n = 0, n2, nev = 0;
2642 for (
int j = 0; j < nv; j++)
2647 egeom = Geometry::TETRAHEDRON;
2651 vert_flag[j] = (vert_dist(elem[j]) >= 0.0) ? n++, 1 : 0;
2653 if (n == 0 || n == nev) {
continue; }
2655 CutElement(egeom, vert_flag, &edge_vert, cut_edges, &n, &n2);
2664 for (
int j = 0; j < n; j++)
2666 const int *ev = edge_vert + 2*cut_edges[j];
2667 double t = vert_dist(elem[ev[0]]);
2668 t = t / (t - vert_dist(elem[ev[1]]));
2669 for (
int d = 0; d < 3; d++)
2671 pts[j][d] = (1-t)*verts(d,elem[ev[0]]) + t*verts(d,elem[ev[1]]);
2673 pts[j][3] = (1-t)*vals(elem[ev[0]]) + t*vals(elem[ev[1]]);
2677 const double *dir = CuttingPlane->Equation();
2678 for (
int j = 0; j < n; j++)
2681 const double val = -sc * (pts[j][3] - minv) / (maxv - minv);
2682 for (
int d = 0; d < 3; d++)
2684 pts[j][d] += val*dir[d];
2699 if (no_norm && m > 4)
2701 for (
int j = 3; j < m; j++)
2703 for (
int k = 0; k < 4; k++)
2705 pts[j-2][k] = pts[j][k];
2722 for (
int j = 0; j < m; j++)
2724 MySetColor(bld, pts[j][3], minv, maxv);
2732 DrawPolygonLevelLines(bld, pts[0], n, level,
false);
2735 for (
int j = 0; j < n2; j++)
2737 cut_edges[j] = cut_edges[j+n];
2747 const DenseMatrix &verts,
const Vector &vert_dist,
const Vector &vals,
2748 const Geometry::Type geom,
const int *faces,
int num_faces)
2751 if (FaceShiftScale != 0.0)
2753 double bbox_diam = sqrt ( (bb.x[1]-bb.x[0])*(bb.x[1]-bb.x[0]) +
2754 (bb.y[1]-bb.y[0])*(bb.y[1]-bb.y[0]) +
2755 (bb.z[1]-bb.z[0])*(bb.z[1]-bb.z[0]) );
2756 sc = FaceShiftScale * bbox_diam;
2758 const int nv = Geometry::NumVerts[geom];
2760 for (
int i = 0; i < num_faces; i++)
2762 int vert_flag[4], cut_edges[4];
2763 const int *face = faces + i*nv;
2765 for (
int j = 0; j < nv; j++)
2767 vert_flag[j] = (vert_dist(face[j]) >= 0.0) ? n++, 1 : 0;
2769 if (n == 0 || n == nv) {
continue; }
2771 for (
int j = 0; j < nv; j++)
2773 const int j1 = (j+1)%nv;
2774 if (vert_flag[j] != vert_flag[j1])
2781 for (
int j = 0; j < n; j++)
2783 const int v0 = cut_edges[j];
2784 const int v1 = (v0+1)%nv;
2785 double t = vert_dist(face[v0]);
2786 t = t / (t - vert_dist(face[v1]));
2787 for (
int d = 0; d < 3; d++)
2789 pts[j][d] = (1-t)*verts(d,face[v0]) + t*verts(d,face[v1]);
2793 pts[j][3] = (1-t)*vals(face[v0]) + t*vals(face[v1]);
2798 const double *dir = CuttingPlane->Equation();
2799 for (
int j = 0; j < n; j++)
2802 const double val = -sc * (pts[j][3] - minv) / (maxv - minv);
2803 for (
int d = 0; d < 3; d++)
2805 pts[j][d] += val*dir[d];
2821 if (cp_drawelems && cplane && mesh->Dimension() == 3)
2825 PrepareCuttingPlane2();
2827 else if (cp_algo == 1)
2829 CuttingPlaneFunc(1);
2833 Vector vals, vert_dist;
2834 DenseMatrix pointmat;
2835 for (
int i = 0; i < mesh->GetNE(); i++)
2837 const Geometry::Type geom = mesh->GetElementBaseGeometry(i);
2838 RefinedGeometry *RefG =
2840 GridF->GetValues(i, RefG->RefPts, vals, pointmat);
2841 vert_dist.SetSize(pointmat.Width());
2842 for (
int j = 0; j < pointmat.Width(); j++)
2844 vert_dist(j) = CuttingPlane->Transform(&pointmat(0,j));
2846 Array<int> &RG = RefG->RefGeoms;
2849 CutRefinedElement(cplane_buf, pointmat, vert_dist, vals, geom,
2850 RG, RG.Size()/Geometry::NumVerts[geom], func);
2854 updated_bufs.emplace_back(&cplane_buf);
2860 double p[4][3], c[4], *coord;
2861 DenseMatrix pointmat, normals;
2863 RefinedGeometry *RefG;
2866 Array<int> partition (mesh -> GetNE());
2868 for (i = 0; i < mesh -> GetNE(); i++)
2871 mesh -> GetElementVertices(i, nodes);
2872 for (j = 0; j < nodes.Size(); j++)
2874 if (node_pos[nodes[j]] >= 0.0) { n++; }
2876 partition[i] = (n == nodes.Size()) ? 0 : 1;
2879 for (i = 0; i < mesh -> GetNFaces(); i++)
2882 mesh -> GetFaceElements (i, &e1, &e2);
2883 if (e2 >= 0 && partition[e1] != partition[e2])
2887 mesh -> GetFaceVertices (i, nodes);
2888 for (j = 0; j < nodes.Size(); j++)
2890 coord = mesh -> GetVertex(nodes[j]);
2894 c[j] = (*sol)(nodes[j]);
2897 if (nodes.Size() == 3)
2899 DrawTriangle(cplane_buf, p, c, minv, maxv);
2903 DrawQuad(cplane_buf, p, c, minv, maxv);
2912 int dir = partition[e1];
2913 GridF -> GetFaceValues (i, dir, RefG->RefPts, values, pointmat);
2914 GetFaceNormals(i, dir, RefG->RefPts, normals);
2915 switch (mesh -> GetFaceBaseGeometry (i))
2917 case Geometry::TRIANGLE: n = 3;
break;
2918 case Geometry::SQUARE: n = 4;
break;
2920 MFEM_ABORT(
"Invalid element type");
2924 DrawPatch(cplane_buf, pointmat, values, normals, n, RefG->RefGeoms,
2925 minv, maxv, dir ? -3 : 2);
2933 cplines_buf.clear();
2935 if (cp_drawmesh && cplane && mesh->Dimension() == 3)
2937 if (cplane == 2 && cp_drawmesh != 3)
2939 PrepareCuttingPlaneLines2();
2943 if (cp_drawmesh == 1 && cp_algo == 1)
2945 CuttingPlaneFunc(2);
2947 else if (cp_drawmesh == 1)
2949 Vector vert_dist, vals;
2950 DenseMatrix pointmat;
2951 int num_faces = mesh->GetNFaces();
2957 cout << _MFEM_FUNC_NAME
2958 <<
": NURBS mesh: cut faces will not be drawn!" << endl;
2961 for (
int i = 0; i < num_faces; i++)
2963 const Geometry::Type geom = mesh->GetFaceBaseGeometry(i);
2964 RefinedGeometry *RefG =
2966 if (FaceShiftScale == 0.0)
2968 ElementTransformation *T = mesh->GetFaceTransformation(i);
2969 T->Transform(RefG->RefPts, pointmat);
2974 GridF->GetFaceValues(i, side, RefG->RefPts, vals, pointmat);
2977 vert_dist.SetSize(pointmat.Width());
2978 for (
int j = 0; j < pointmat.Width(); j++)
2980 vert_dist(j) = CuttingPlane->Transform(&pointmat(0,j));
2982 Array<int> &RG = RefG->RefGeoms;
2984 CutRefinedFace(cplines_buf, pointmat, vert_dist, vals, geom,
2985 RG, RG.Size()/Geometry::NumVerts[geom]);
2988 else if (cp_algo == 1)
2990 CuttingPlaneFunc(3);
2994 Vector vals, vert_dist;
2995 DenseMatrix pointmat;
2996 for (
int i = 0; i < mesh->GetNE(); i++)
2998 const Geometry::Type geom = mesh->GetElementBaseGeometry(i);
2999 RefinedGeometry *RefG =
3001 GridF->GetValues(i, RefG->RefPts, vals, pointmat);
3002 vert_dist.SetSize(pointmat.Width());
3003 for (
int j = 0; j < pointmat.Width(); j++)
3005 vert_dist(j) = CuttingPlane->Transform(&pointmat(0,j));
3007 Array<int> &RG = RefG->RefGeoms;
3010 CutRefinedElement(cplines_buf, pointmat, vert_dist, vals, geom,
3011 RG, RG.Size()/Geometry::NumVerts[geom], func);
3017 updated_bufs.emplace_back(&cplines_buf);
3023 double point[4][4], *coord;
3024 DenseMatrix pointmat;
3026 RefinedGeometry *RefG;
3029 Array<int> partition (mesh -> GetNE());
3030 for (i = 0; i < mesh -> GetNE(); i++)
3033 mesh -> GetElementVertices(i,nodes);
3034 for (j=0; j<nodes.Size(); j++)
3036 if (node_pos[nodes[j]] >= 0.0) { n++; }
3038 partition[i] = (n == nodes.Size()) ? 0 : 1;
3041 for (i = 0; i < mesh -> GetNFaces(); i++)
3044 mesh -> GetFaceElements (i, &e1, &e2);
3045 if (e2 >= 0 && partition[e1] != partition[e2])
3049 mesh -> GetFaceVertices (i, nodes);
3050 for (j = 0; j < nodes.Size(); j++)
3052 coord = mesh -> GetVertex(nodes[j]);
3053 point[j][0] = coord[0];
3054 point[j][1] = coord[1];
3055 point[j][2] = coord[2];
3056 point[j][3] = (*sol)(nodes[j]);
3059 switch (cp_drawmesh)
3064 for (j = 0; j < nodes.Size(); j++)
3071 DrawPolygonLevelLines(line, point[0], nodes.Size(), level,
false);
3081 int di = partition[e1];
3082 GridF -> GetFaceValues (i, di, RefG->RefPts, values, pointmat);
3083 switch (mesh -> GetFaceBaseGeometry (i))
3085 case Geometry::TRIANGLE: n = 3;
break;
3086 case Geometry::SQUARE: n = 4;
break;
3088 MFEM_ABORT(
"Invalid element type");
3091 switch (cp_drawmesh)
3094 DrawRefinedSurfEdges (n, pointmat, values, RefG->RefEdges);
3097 DrawRefinedSurfLevelLines (n, pointmat, values,
3111 const DenseMatrix &verts,
const Vector &vals,
const int *ind,
3112 const Array<double> &surf_levels,
const DenseMatrix *grad)
3114 double t, lvl, normal[3], vert[4][3], norm[4][3];
3115 int i, j, l, pos[4];
3120 for (l = 0; l < surf_levels.Size(); l++)
3122 lvl = surf_levels[l];
3124 for (i = 0; i < 4; i++)
3134 while (vals(pos[i]) < lvl)
3151 while (vals(pos[j]) >= lvl);
3153 Swap<int>(pos[i], pos[j]);
3163 Swap<int>(pos[0], pos[1]);
3167 Swap<int>(pos[2], pos[3]);
3173 Swap<int>(pos[0], pos[3]);
3178 for (
int k = 0; k < 3; k++)
3182 t = (lvl - vals(p0)) / (vals(p1) - vals(p0));
3183 for (
int d = 0; d < 3; d++)
3185 vert[k][d] = (1.0 - t) * verts(d, p0) + t * verts(d, p1);
3188 for (
int d = 0; d < 3; d++)
3190 norm[k][d] = (1.0 - t) * (*grad)(d, p0) + t * (*grad)(d, p1);
3198 MySetColor(draw, lvl, minv, maxv);
3201 for (
int k = 0; k < 3; k++)
3211 MySetColor(draw, lvl, minv, maxv);
3213 for (
int k = 0; k < 3; k++)
3225 static const int idx[4][2] = { {0, 2}, {0, 3}, {1, 3}, {1, 2} };
3227 for (
int k = 0; k < 4; k++)
3229 int p0 = pos[idx[k][0]];
3230 int p1 = pos[idx[k][1]];
3231 t = (lvl - vals(p0)) / (vals(p1) - vals(p0));
3232 for (
int d = 0; d < 3; d++)
3234 vert[k][d] = (1.0 - t) * verts(d, p0) + t * verts(d, p1);
3237 for (
int d = 0; d < 3; d++)
3239 norm[k][d] = (1.0 - t) * (*grad)(d, p0) + t * (*grad)(d, p1);
3248 MySetColor(draw, lvl, minv, maxv);
3251 for (
int k = 0; k < 4; k++)
3261 MySetColor(draw, lvl, minv, maxv);
3263 for (
int k = 0; k < 4; k++)
3278 const Array<bool> &quad_diag,
const Array<int> &faces,
3279 const Array<int> &ofaces)
3282 bool diag = quad_diag[faces[0]];
3283 if ((ofaces[0]/2)%2)
3293 const DenseMatrix &verts,
const Vector &vals,
const int *RG,
const int np,
3294 const int face_splits,
const DenseMatrix *grad)
3297 static const int pyr_tets[2][4] =
3299 { 0, 1, 2, 4 }, { 0, 2, 3, 4 }
3301 for (
int k = 0; k < np; k++)
3303 const int *hv = &RG[5*k];
3306 for (
int j = 0; j < 2; j++)
3309 for (
int i = 0; i < 4; i++)
3311 m_ind[i] = hv[pyr_tets[j][i]];
3313 DrawTetLevelSurf(target, verts, vals, m_ind, levels, grad);
3318 DrawTetLevelSurf(target, verts, vals, hv, levels, grad);
3323 static const int pri_tets[8-2][3][4] =
3326 { { 0, 1, 2, 5 }, { 0, 1, 5, 4 }, { 0, 3, 4, 5 } },
3327 { { 0, 1, 2, 4 }, { 0, 2, 3, 4 }, { 2, 3, 4, 5 } },
3328 { { 0, 1, 2, 4 }, { 0, 2, 5, 4 }, { 0, 3, 4, 5 } },
3329 { { 0, 1, 2, 3 }, { 1, 2, 3, 5 }, { 1, 3, 4, 5 } },
3330 { { 0, 1, 2, 5 }, { 0, 1, 5, 3 }, { 1, 3, 4, 5 } },
3331 { { 0, 1, 2, 3 }, { 1, 2, 3, 4 }, { 2, 3, 4, 5 } }
3334 static const int pri_tets_0[6][4] =
3335 { {0,1,2,6}, {0,1,6,4}, {0,2,3,6}, {0,6,3,4}, {2,3,6,5}, {3,4,6,5} };
3336 static const int pri_tets_7[6][4] =
3337 { {0,1,2,6}, {0,2,5,6}, {0,1,6,3}, {0,3,6,5}, {1,3,4,6}, {3,4,6,5} };
3338 const int fs2 = (~face_splits&7)/2 + 4*((~face_splits&7)%2);
3339 const int n = (np == 1) ? 1 : TimesToRefine;
3341 double vs_data[7], pm_data[3*7], gd_data[3*7];
3342 Vector
vs(vs_data, 7);
3343 DenseMatrix pm(pm_data, 3, 7), gd(gd_data, 3, 7);
3345 for (
int k = 0, l0 = -1, l1 = -1; k < np; k++)
3347 const int pk = k % (n*n);
3354 const int s = l1-l0;
3358 const int fsl = ((pk-l0)%2 == 0) ? face_splits : fs2;
3362 const int *pv = &RG[6*k];
3365 for (
int j = 0; j < 6; j++)
3367 const int idx = pv[j];
3368 for (
int d = 0; d < 3; d++)
3370 pm(d,j) = verts(d,idx);
3371 if (grad) { gd(d,j) = (*grad)(d,idx); }
3375 for (
int d = 0; d < 3; d++)
3377 pm(d,6) = 0.5*(pm(d,1) + pm(d,5));
3378 if (grad) { gd(d,6) = 0.5*(gd(d,1) + gd(d,5)); }
3380 vs(6) = 0.5*(
vs(1) +
vs(5));
3381 const DenseMatrix *gd_ = grad ? &gd : NULL;
3382 for (
int k = 0; k < 6; k++)
3384 DrawTetLevelSurf(pm, vs, pri_tets_0[k], levels, gd_);
3389 for (
int j = 0; j < 6; j++)
3391 const int idx = pv[j];
3392 for (
int d = 0; d < 3; d++)
3394 pm(d,j) = verts(d,idx);
3395 if (grad) { gd(d,j) = (*grad)(d,idx); }
3399 for (
int d = 0; d < 3; d++)
3401 pm(d,6) = 0.5*(pm(d,2) + pm(d,4));
3402 if (grad) { gd(d,6) = 0.5*(gd(d,2) + gd(d,4)); }
3404 vs(6) = 0.5*(
vs(2) +
vs(4));
3405 const DenseMatrix *gd_ = grad ? &gd : NULL;
3406 for (
int k = 0; k < 6; k++)
3408 DrawTetLevelSurf(pm, vs, pri_tets_7[k], levels, gd_);
3414 for (
int j = 0; j < 3; j++)
3416 for (
int i = 0; i < 4; i++)
3418 m_ind[i] = pv[pri_tets[fsl-1][j][i]];
3420 DrawTetLevelSurf(verts, vals, m_ind, levels, grad);
3429 const Array<bool> &quad_diag,
const Array<int> &faces,
3430 const Array<int> &ofaces)
3433 for (
int lf = 2; lf < 5; lf++)
3435 bool diag = quad_diag[faces[lf]];
3436 if ((ofaces[lf]/2)%2)
3447 const DenseMatrix &verts,
const Vector &vals,
const int *RG,
const int np,
3448 const int face_splits,
const DenseMatrix *grad)
3451 static const int pri_tets[3][4] =
3453 { 0, 1, 2, 5 }, { 0, 1, 5, 3 }, { 1, 3, 4, 5 }
3455 for (
int k = 0; k < np; k++)
3457 const int *hv = &RG[6*k];
3458 for (
int j = 0; j < 3; j++)
3461 for (
int i = 0; i < 4; i++)
3463 m_ind[i] = hv[pri_tets[j][i]];
3465 DrawTetLevelSurf(verts, vals, m_ind, levels, grad);
3469 static const int pri_tets[8-2][3][4] =
3472 { { 0, 1, 2, 5 }, { 0, 1, 5, 4 }, { 0, 3, 4, 5 } },
3473 { { 0, 1, 2, 4 }, { 0, 2, 3, 4 }, { 2, 3, 4, 5 } },
3474 { { 0, 1, 2, 4 }, { 0, 2, 5, 4 }, { 0, 3, 4, 5 } },
3475 { { 0, 1, 2, 3 }, { 1, 2, 3, 5 }, { 1, 3, 4, 5 } },
3476 { { 0, 1, 2, 5 }, { 0, 1, 5, 3 }, { 1, 3, 4, 5 } },
3477 { { 0, 1, 2, 3 }, { 1, 2, 3, 4 }, { 2, 3, 4, 5 } }
3480 static const int pri_tets_0[6][4] =
3481 { {0,1,2,6}, {0,1,6,4}, {0,2,3,6}, {0,6,3,4}, {2,3,6,5}, {3,4,6,5} };
3482 static const int pri_tets_7[6][4] =
3483 { {0,1,2,6}, {0,2,5,6}, {0,1,6,3}, {0,3,6,5}, {1,3,4,6}, {3,4,6,5} };
3484 const int fs2 = (~face_splits&7)/2 + 4*((~face_splits&7)%2);
3485 const int n = (np == 1) ? 1 : TimesToRefine;
3487 double vs_data[7], pm_data[3*7], gd_data[3*7];
3488 Vector
vs(vs_data, 7);
3489 DenseMatrix pm(pm_data, 3, 7), gd(gd_data, 3, 7);
3491 for (
int k = 0, l0 = -1, l1 = -1; k < np; k++)
3493 const int pk = k % (n*n);
3500 const int s = l1-l0;
3504 const int fsl = ((pk-l0)%2 == 0) ? face_splits : fs2;
3508 const int *pv = &RG[6*k];
3511 for (
int j = 0; j < 6; j++)
3513 const int idx = pv[j];
3514 for (
int d = 0; d < 3; d++)
3516 pm(d,j) = verts(d,idx);
3517 if (grad) { gd(d,j) = (*grad)(d,idx); }
3521 for (
int d = 0; d < 3; d++)
3523 pm(d,6) = 0.5*(pm(d,1) + pm(d,5));
3524 if (grad) { gd(d,6) = 0.5*(gd(d,1) + gd(d,5)); }
3526 vs(6) = 0.5*(
vs(1) +
vs(5));
3527 const DenseMatrix *gd_ = grad ? &gd : NULL;
3528 for (
int j = 0; j < 6; j++)
3530 DrawTetLevelSurf(target, pm, vs, pri_tets_0[j], levels, gd_);
3535 for (
int j = 0; j < 6; j++)
3537 const int idx = pv[j];
3538 for (
int d = 0; d < 3; d++)
3540 pm(d,j) = verts(d,idx);
3541 if (grad) { gd(d,j) = (*grad)(d,idx); }
3545 for (
int d = 0; d < 3; d++)
3547 pm(d,6) = 0.5*(pm(d,2) + pm(d,4));
3548 if (grad) { gd(d,6) = 0.5*(gd(d,2) + gd(d,4)); }
3550 vs(6) = 0.5*(
vs(2) +
vs(4));
3551 const DenseMatrix *gd_ = grad ? &gd : NULL;
3552 for (
int j = 0; j < 6; j++)
3554 DrawTetLevelSurf(target, pm, vs, pri_tets_7[j], levels, gd_);
3560 for (
int j = 0; j < 3; j++)
3562 for (
int i = 0; i < 4; i++)
3564 m_ind[i] = pv[pri_tets[fsl-1][j][i]];
3566 DrawTetLevelSurf(target, verts, vals, m_ind, levels, grad);
3575 const Array<bool> &quad_diag,
const Array<int> &faces,
3576 const Array<int> &ofaces)
3579 for (
int lf = 0; lf < 6; lf++)
3581 bool diag = quad_diag[faces[lf]];
3582 if ((ofaces[lf]/2)%2)
3593 const DenseMatrix &verts,
const Vector &vals,
const int *RG,
const int nh,
3594 const int face_splits,
const DenseMatrix *grad)
3597 static const int hex_tets[6][4] =
3599 { 0, 1, 2, 6 }, { 0, 5, 1, 6 }, { 0, 4, 5, 6 },
3600 { 0, 2, 3, 6 }, { 0, 3, 7, 6 }, { 0, 7, 4, 6 }
3602 for (
int k = 0; k < nh; k++)
3604 const int *hv = &RG[8*k];
3605 for (
int j = 0; j < 6; j++)
3608 for (
int i = 0; i < 4; i++)
3610 m_ind[i] = hv[hex_tets[j][i]];
3612 DrawTetLevelSurf(verts, vals, m_ind, levels, grad);
3616 const int n = (nh == 1) ? 1 : TimesToRefine;
3618 double vs_data[9], pm_data[3*9], gd_data[3*9];
3619 Vector
vs(vs_data, 9);
3620 DenseMatrix pm(pm_data, 3, 9), gd(gd_data, 3, 9);
3622 for (
int k = 0; k < nh; k++)
3624 const int ix = k%n, iy = (k/n)%n, iz = k/(n*n);
3625 int fsl = face_splits;
3630 fsl = (fsl&(63-2)) + (2-(fsl&8)/4);
3636 fsl = (fsl&(63-16)) + (16-(fsl&4)*4);
3642 fsl = (fsl&(63-32)) + (32-(fsl&1)*32);
3645 const int *hv_orig = &RG[8*k], *hv;
3650 if (1-(fsl&1) == (fsl&32)/32)
3655 else if (4-(fsl&4) == (fsl&16)/4)
3659 static const int rot_x[8] = { 4, 5, 1, 0, 7, 6, 2, 3 };
3660 for (
int j = 0; j < 8; j++)
3662 hv1[j] = hv_orig[rot_x[j]];
3666 fsl = (fsl&16)*2 + (fsl&1)*16 + (8-(fsl&8)) + (fsl&32)/8 +
3667 (2-(fsl&2)) + (fsl&4)/4;
3669 else if (2-(fsl&2) == (fsl&8)/4)
3673 static const int rot_y[8] = { 1, 5, 6, 2, 0, 4, 7, 3 };
3674 for (
int j = 0; j < 8; j++)
3676 hv1[j] = hv_orig[rot_y[j]];
3681 fsl = (fsl&8)*4 + (fsl&16) + (fsl&1)*8 + (fsl&4) + (fsl&32)/16 +
3690 for (
int j = 0; j < 8; j++)
3692 const int idx = hv_orig[j];
3693 for (
int d = 0; d < 3; d++)
3695 pm(d,j) = verts(d,idx);
3696 if (grad) { gd(d,j) = (*grad)(d,idx); }
3700 for (
int d = 0; d < 3; d++)
3703 if (grad) { gd(d,8) = 0.0; }
3706 for (
int j = 0; j < 8; j++)
3708 for (
int d = 0; d < 3; d++)
3711 if (grad) { gd(d,8) += gd(d,j); }
3715 for (
int d = 0; d < 3; d++)
3718 if (grad) { gd(d,8) *= 0.125; }
3722 typedef Mesh::hex_t hex_t;
3723 for (
int j = 0; j < hex_t::NumFaces; j++)
3726 const int *fv = hex_t::FaceVert[j];
3727 const bool diag = fsl&(32>>j);
3750 const DenseMatrix *gp = grad ? &gd : NULL;
3751 DrawTetLevelSurf(target, pm, vs, &tv[0], levels, gp);
3752 DrawTetLevelSurf(target, pm, vs, &tv[4], levels, gp);
3763 static const int rot_z[8] = { 3, 0, 1, 2, 7, 4, 5, 6 };
3764 for (
int j = 0; j < 8; j++)
3766 hv2[j] = hv[rot_z[j]];
3770 fsl = (32-(fsl&32)) + (fsl&2)*8 + (fsl&(16+8+4))/2 + (1-(fsl&1));
3774 const int pv[2][6] =
3776 { hv[0], hv[1], hv[2], hv[4], hv[5], hv[6] },
3777 { hv[2], hv[3], hv[0], hv[6], hv[7], hv[4] }
3780 const double l06 = Distance(&verts(0,hv[0]), &verts(0,hv[6]), 3);
3781 const double l24 = Distance(&verts(0,hv[2]), &verts(0,hv[4]), 3);
3782 const bool diag = (l06 > 1.01*l24);
3783 const int fs1 = (fsl&(16+8))/4 + !diag;
3784 const int fs2 = (fsl&(4+2)) + diag;
3785 DrawRefinedWedgeLevelSurf(target, verts, vals, pv[0], 1, fs1, grad);
3786 DrawRefinedWedgeLevelSurf(target, verts, vals, pv[1], 1, fs2, grad);
3793 static const int ident[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
3796 DenseMatrix pointmat, grad;
3797 Array<int> vertices;
3800 if (drawlsurf == 0 || mesh->Dimension() != 3)
3808 levels.SetSize(nlevels);
3809 for (
int l = 0; l < nlevels; l++)
3811 double lvl = ((double)(50*l+drawlsurf) / (nlevels*50));
3812 levels[l] = ULogVal(lvl);
3818 Array<bool> quad_diag;
3819 if (mesh->HasGeometry(Geometry::SQUARE))
3821 quad_diag.SetSize(mesh->GetNFaces());
3822 for (
int fi = 0; fi < mesh->GetNFaces(); fi++)
3824 const Element *face = mesh->GetFace(fi);
3825 if (face->GetType() != Element::QUADRILATERAL) {
continue; }
3826 ElementTransformation *T = mesh->GetFaceTransformation(fi);
3827 T->Transform(*Geometries.GetVertices(Geometry::SQUARE), pointmat);
3828 const double l02 = Distance(&pointmat(0,0), &pointmat(0,2), 3);
3829 const double l13 = Distance(&pointmat(0,1), &pointmat(0,3), 3);
3830 quad_diag[fi] = (l02 > 1.01*l13);
3834 Array<int> faces, ofaces;
3838 for (
int ie = 0; ie < mesh->GetNE(); ie++)
3840 mesh->GetPointMatrix(ie, pointmat);
3841 mesh->GetElementVertices(ie, vertices);
3842 vals.SetSize(vertices.Size());
3843 for (
int j = 0; j < vertices.Size(); j++)
3845 vals(j) = (*sol)(vertices[j]);
3848 switch (mesh->GetElementType(ie))
3850 case Element::TETRAHEDRON:
3851 DrawTetLevelSurf(lsurf_buf, pointmat, vals, ident, levels);
3853 case Element::PYRAMID:
3855 mesh->GetElementFaces(ie, faces, ofaces);
3856 const int fs = GetPyramidFaceSplits(quad_diag, faces, ofaces);
3857 DrawRefinedPyramidLevelSurf(lsurf_buf, pointmat, vals, ident, 1, fs);
3859 case Element::WEDGE:
3861 mesh->GetElementFaces(ie, faces, ofaces);
3862 const int fs = GetWedgeFaceSplits(quad_diag, faces, ofaces);
3863 DrawRefinedWedgeLevelSurf(lsurf_buf, pointmat, vals, ident, 1, fs);
3866 case Element::HEXAHEDRON:
3868 mesh->GetElementFaces(ie, faces, ofaces);
3869 const int fs = GetHexFaceSplits(quad_diag, faces, ofaces);
3870 DrawRefinedHexLevelSurf(lsurf_buf, pointmat, vals, ident, 1, fs);
3874 MFEM_ABORT(
"Unrecognized 3D element type \""
3875 << mesh->GetElementType(ie) <<
"\"");
3881 RefinedGeometry *RefG;
3882 #define GLVIS_SMOOTH_LEVELSURF_NORMALS
3883 #ifdef GLVIS_SMOOTH_LEVELSURF_NORMALS
3884 const DenseMatrix *gp = &grad;
3886 const DenseMatrix *gp = NULL;
3889 for (
int ie = 0; ie < mesh->GetNE(); ie++)
3891 const Geometry::Type geom = mesh->GetElementBaseGeometry(ie);
3894 GridF->GetValues(ie, RefG->RefPts, vals, pointmat);
3895 #ifdef GLVIS_SMOOTH_LEVELSURF_NORMALS
3896 GridF->GetGradients(ie, RefG->RefPts, grad);
3899 Array<int> &RG = RefG->RefGeoms;
3900 const int nv = mesh->GetElement(ie)->GetNVertices();
3901 const int nre = RG.Size()/nv;
3903 if (geom == Geometry::TETRAHEDRON)
3905 for (
int k = 0; k < nre; k++)
3907 DrawTetLevelSurf(lsurf_buf, pointmat, vals, &RG[nv*k], levels, gp);
3910 else if (geom == Geometry::PYRAMID)
3912 mesh->GetElementFaces(ie, faces, ofaces);
3913 const int fs = GetPyramidFaceSplits(quad_diag, faces, ofaces);
3914 DrawRefinedPyramidLevelSurf(lsurf_buf, pointmat, vals, RG, nre, fs, gp);
3916 else if (geom == Geometry::PRISM)
3918 mesh->GetElementFaces(ie, faces, ofaces);
3919 const int fs = GetWedgeFaceSplits(quad_diag, faces, ofaces);
3920 DrawRefinedWedgeLevelSurf(lsurf_buf, pointmat, vals, RG, nre, fs, gp);
3922 else if (geom == Geometry::CUBE)
3924 mesh->GetElementFaces(ie, faces, ofaces);
3925 const int fs = GetHexFaceSplits(quad_diag, faces, ofaces);
3926 DrawRefinedHexLevelSurf(lsurf_buf, pointmat, vals, RG, nre, fs, gp);
3931 updated_bufs.emplace_back(&lsurf_buf);
3934 cout <<
"VisualizationSceneSolution3d::PrepareLevelSurf() : "
3936 <<
" quads used" << endl;
3944 Array<double>* cb_level =
nullptr,
3945 * cb_levels =
nullptr;
3946 if (drawlsurf) { cb_levels = &levels; }
3947 if (drawmesh == 2 || cp_drawmesh >= 2) { cb_level = &level; }
3948 PrepareColorBar(minv, maxv, cb_level, cb_levels);
3953 double* cp_eqn = CuttingPlane->Equation();
3954 params.
clip_plane_eqn = {cp_eqn[0], cp_eqn[1], cp_eqn[2], cp_eqn[3]};
3959 scene.
queue.emplace_back(params, &lsurf_buf);
3963 scene.
queue.emplace_back(params, &disp_buf);
3965 if (cplane && cp_drawelems)
3968 scene.
queue.emplace_back(params, &cplane_buf);
3975 scene.
queue.emplace_back(params, &order_noarrow_buf);
3977 else if (draworder == 2)
3979 scene.
queue.emplace_back(params, &order_buf);
3987 scene.
queue.emplace_back(params, &line_buf);
3992 scene.
queue.emplace_back(params, &cplines_buf);
3997 scene.
queue.emplace_back(params, &order_noarrow_buf);
3999 else if (draworder == 4)
4001 scene.
queue.emplace_back(params, &order_buf);
4008 string name =
"GLVis_scene_000";
4012 auto palette_mat = AddPaletteMaterial(bld);
4013 auto black_mat = AddBlackMaterial(bld);
4015 if (drawelems) { glTF_ExportElements(bld, buf, palette_mat, disp_buf); }
4016 if (drawmesh) { glTF_ExportMesh(bld, buf, black_mat, line_buf); }
4017 if (cplane && cp_drawelems)
4019 auto cp_elems_node = AddModelNode(bld,
"CP Elements");
4020 auto cp_elems_mesh = bld.
addMesh(
"CP Elements Mesh");
4023 int ntria = AddTriangles(
4031 cout <<
"glTF export: no cp elements found to export!" << endl;
4036 auto cp_lines_node = AddModelNode(bld,
"CP Lines");
4037 auto cp_lines_mesh = bld.
addMesh(
"CP Lines Mesh");
4040 int nlines = AddLines(
4048 cout <<
"glTF export: no cp mesh/level lines found to export!" << endl;
4053 auto lsurf_node = AddModelNode(bld,
"Level Surface");
4054 auto lsurf_mesh = bld.
addMesh(
"Level Surface Mesh");
4057 int ntria = AddTriangles(
4065 cout <<
"glTF export: no level surface elements found to export!"
4069 if (drawaxes) { glTF_ExportBox(bld, buf, black_mat); }
4072 cout <<
"Exported glTF -> " << name <<
".gltf" << endl;
double cut_lambda
Amount of face cutting with keys Ctrl-F3/F4 (0: no cut, 1: cut to edges)
void SendExposeEvent()
Send expose event. In our case MyReshape is executed and Draw after it.
bool cut_updated
Have the reference geometries been updated for the cut?
void CuttingPlaneFunc(int type)
thread_local int quad_counter
thread_local GeometryRefiner GLVisGeometryRefiner
static int GetWedgeFaceSplits(const Array< bool > &quad_diag, const Array< int > &faces, const Array< int > &ofaces)
void PrepareCuttingPlaneLines2()
void NumberOfLevelSurf(int)
void glVertex3d(double x, double y, double z)
int Normalize(double v[])
virtual void FindNewBox(bool prepare)
thread_local Array< int > cut_TriGeoms
void DrawRefinedPyramidLevelSurf(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vals, const int *RG, const int np, const int face_splits, const DenseMatrix *grad=NULL)
Array< int > bdr_attr_to_show
virtual void PrepareCuttingPlane()
void LiftRefinedSurf(int n, DenseMatrix &pointmat, Vector &values, int *RG)
thread_local SdlWindow * wnd
void PrepareCuttingPlaneLines()
static int GetPyramidFaceSplits(const Array< bool > &quad_diag, const Array< int > &faces, const Array< int > &ofaces)
void SetLineWidthMS(float width_ms)
thread_local IntegrationRule cut_QuadPts
virtual void ToggleAttributes(Array< int > &attr_list)
void GetFaceNormals(const int FaceNo, const int side, const IntegrationRule &ir, DenseMatrix &normals)
virtual void PrepareFlat()
virtual void PrepareLines()
virtual gl3::SceneInfo GetSceneObjs()
void addLine(const Vert &v1, const Vert &v2)
virtual void UpdateValueRange(bool prepare)
virtual ~VisualizationSceneSolution3d()
static Vertex create(double *d)
void ComputeBdrAttrCenter()
Compute the center of gravity for each boundary attribute.
void glNormal3dv(const double *d)
void PrepareCuttingPlane2()
buffer_id addBuffer(const std::string &bufferName)
void DrawRefinedSurfLevelLines(int n, DenseMatrix &pointmat, Vector &values, Array< int > &RefGeoms)
int Compute3DUnitNormal(const double p1[], const double p2[], const double p3[], double nor[])
virtual void PrepareOrderingCurve1(gl3::GlDrawable &buf, bool arrows, bool color)
void DrawRefinedWedgeLevelSurf(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vals, const int *RG, const int np, const int face_splits, const DenseMatrix *grad=NULL)
void DrawRefinedSurfEdges(int n, DenseMatrix &pointmat, Vector &values, Array< int > &RefEdges, int part=-1)
void CutReferenceElements(int TimesToRefine, double lambda)
int GetAutoRefineFactor()
thread_local VisualizationSceneSolution3d * vssol3d
double shrinkmat
Shrink factor with respect to the element (material) attributes centers.
thread_local VisualizationSceneScalarData * vs
void glNormal3d(double nx, double ny, double nz)
void ToggleCuttingPlane()
GlBuilder createBuilder()
thread_local Array< int > cut_QuadGeoms
static int GetHexFaceSplits(const Array< bool > &quad_diag, const Array< int > &faces, const Array< int > &ofaces)
mesh_id addMesh(const std::string &meshName)
double InnerProd(const double a[], const double b[])
void DrawTetLevelSurf(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vals, const int *ind, const Array< double > &levels, const DenseMatrix *grad=NULL)
virtual void SetShading(int, bool)
void DrawRefinedSurf(int n, double *points, int elem, int func, int part=-1)
void SetLineWidth(float width)
thread_local int triangle_counter
virtual gl3::SceneInfo GetSceneObjs()
virtual void EventUpdateColors()
void CutRefinedFace(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vert_dist, const Vector &vals, const Geometry::Type geom, const int *faces, int num_faces)
Crude fixed-function OpenGL emulation helper.
void addNodeMesh(node_id node, mesh_id mesh)
void CutRefinedElement(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vert_dist, const Vector &vals, const Geometry::Type geom, const int *elems, int num_elems, int func)
void DrawRefinedHexLevelSurf(gl3::GlDrawable &target, const DenseMatrix &verts, const Vector &vals, const int *RG, const int nh, const int face_splits, const DenseMatrix *grad=NULL)
virtual void PrepareOrderingCurve()
thread_local IntegrationRule cut_TriPts
virtual void SetRefineFactors(int, int)
void glVertex3dv(const double *d)
bool contains_translucent
virtual void AutoRefine()
std::array< float, 4 > static_color
virtual std::string GetHelpString() const
void setOnKeyDown(int key, Delegate func)
void ComputeElemAttrCenter()
Compute the center of gravity for each element attribute.
virtual void FindNewValueRange(bool prepare)
virtual void glTF_Export()
std::array< double, 4 > clip_plane_eqn
void DoAutoscale(bool prepare)
VisualizationSceneSolution3d()
void NewMeshAndSolution(Mesh *new_m, Vector *new_sol, GridFunction *new_u=NULL)