27 <<
"+------------------------------------+" << endl
29 <<
"+------------------------------------+" << endl
30 <<
"| a - Displays/Hides the axes |" << endl
31 <<
"| A - Turns antialiasing on/off |" << endl
32 <<
"| b - Displacements step back |" << endl
33 <<
"| B - Toggle 2D boundary |" << endl
34 <<
"| c - Toggle colorbar and caption |" << endl
35 <<
"| C - Change the main plot caption |" << endl
36 <<
"| d - Displays/Hides displacements |" << endl
37 <<
"| e - Displays/Hides the elements |" << endl
38 <<
"| f - Smooth/Flat shading |" << endl
39 <<
"| g - Toggle background |" << endl
40 <<
"| h - Displays help menu |" << endl
41 <<
"| i - Toggle the cutting plane |" << endl
42 <<
"| j - Turn on/off perspective |" << endl
43 <<
"| k/K Adjust the transparency level |" << endl
44 <<
"| ,/< Adjust color transparency |" << endl
45 <<
"| l - Turns on/off the light |" << endl
46 <<
"| L - Toggle logarithmic scale |" << endl
47 <<
"| m - Displays/Hides the mesh |" << endl
48 <<
"| n - Displacements step forward |" << endl
49 <<
"| N - Cycle through numberings |" << endl
50 <<
"| o - (De)refine elem. (NC shading) |" << endl
51 <<
"| O - Switch 'o' func. (NC shading) |" << endl
52 <<
"| p/P Cycle through color palettes |" << endl
53 <<
"| q - Quits |" << endl
54 <<
"| r - Reset the plot to 3D view |" << endl
55 <<
"| R - Reset the plot to 2D view |" << endl
56 <<
"| s - Turn on/off unit cube scaling |" << endl
57 <<
"| S - Take snapshot/Record a movie |" << endl
58 <<
"| t - Cycle materials and lights |" << endl
59 <<
"| u - Vector sampling; scalar func. |" << endl
60 <<
"| U - Switch 'u' functionality |" << endl
61 <<
"| v - Cycle through vector fields |" << endl
62 <<
"| V - Change the arrows scaling |" << endl
63 <<
"| \\ - Set light source position |" << endl
64 <<
"| Ctrl+p - Print to a PDF file |" << endl
65 <<
"+------------------------------------+" << endl
66 <<
"| Function keys |" << endl
67 <<
"+------------------------------------+" << endl
68 <<
"| F1 - X window info and keystrokes |" << endl
69 <<
"| F2 - Update colors, etc. |" << endl
70 <<
"| F3/F4 - Shrink/Zoom elements |" << endl
71 <<
"| F5 - Set level lines |" << endl
72 <<
"| F6 - Palette options |" << endl
73 <<
"| F7 - Manually set min/max value |" << endl
74 <<
"| F8 - List of subdomains to show |" << endl
75 <<
"| F9/F10 - Walk through subdomains |" << endl
76 <<
"| F11/F12 - Shrink/Zoom subdomains |" << endl
77 <<
"+------------------------------------+" << endl
78 <<
"| Keypad |" << endl
79 <<
"+------------------------------------+" << endl
80 <<
"| 1-9 Small rotation, reset with 5 |" << endl
81 <<
"| *,/ Scale up/down |" << endl
82 <<
"| +/- Change z-scaling |" << endl
83 <<
"| . - Start/stop spinning |" << endl
84 <<
"| 0/Enter - Spinning speed and dir. |" << endl
85 <<
"+------------------------------------+" << endl
86 <<
"| Mouse |" << endl
87 <<
"+------------------------------------+" << endl
88 <<
"| left btn - Rotation |" << endl
89 <<
"| middle btn - Translation |" << endl
90 <<
"| right btn - Scaling |" << endl
91 <<
"| left + Alt - Tilt |" << endl
92 <<
"| left + Shift - Spinning |" << endl
93 <<
"| right + Shift - Change light pos. |" << endl
94 <<
"| left + Ctrl - Spherical rotation |" << endl
95 <<
"| middle+ Ctrl - Object translation |" << endl
96 <<
"| right + Ctrl - Object scaling |" << endl
97 <<
"| left + Ctrl + Shift - z-Spinning |" << endl
98 <<
"+------------------------------------+" << endl;
136 PrepareDisplacedMesh();
149 cout <<
"New arrow scale: " << flush;
151 cout <<
"New arrow scale = " <<
vsvector -> ArrowScale << endl;
194 cout <<
"Vector subdivision factor = "
206 cout <<
"Key 'u' will: ";
210 cout <<
"Increase vector subdivision factor" << endl;
214 cout <<
"Decrease vector subdivision factor" << endl;
218 cout <<
"Cycle through vector-to-scalar functions" << endl;
225 const char *modes[] =
226 {
"none",
"vector->scalar function",
"det(J0)/det(J)",
"det(J)/det(J0)" };
228 drawelems = (drawelems+3)%4;
230 cout <<
"Surface elements mode : " << modes[drawelems] << endl;
232 if (drawelems != 0 && shading == 2)
234 DoAutoscaleValue(
false);
238 PrepareLevelCurves();
245 drawvector = (drawvector+1)%4;
246 PrepareVectorField();
251 "magnitude",
"direction",
"x-component",
"y-component",
"divergence",
256 Vector & sx, Vector & sy)
262 sol =
new Vector(mesh -> GetNV());
271 FiniteElementSpace *fes = vgf.FESpace();
272 if (fes == NULL || vgf.VectorDim() != 2)
274 cout <<
"VisualizationSceneVector::VisualizationSceneVector" << endl;
280 mesh = fes->GetMesh();
282 solx =
new Vector(mesh -> GetNV());
283 soly =
new Vector(mesh -> GetNV());
285 vgf.GetNodalValues (*solx, 1);
286 vgf.GetNodalValues (*soly, 2);
288 sol =
new Vector(mesh -> GetNV());
297 if (vc0.Size() != vgf.Size())
309 return sqrt(x*x+y*y);
355 if (VecGridF->FESpace()->GetVDim() == 1)
357 if (dynamic_cast<const ND_FECollection*>(VecGridF->FESpace()->FEColl()))
359 if (i == 5) { i = 0; }
360 else if (i == 3) { i = 5; }
361 else { i = (i + 1) % 5; }
381 for (i = 0; i < mesh->GetNV(); i++)
383 (*sol)(i) = Vec2Scalar((*solx)(i), (*soly)(i));
387 DoAutoscaleValue(
false);
390 PrepareLevelCurves();
402 PrepareVectorField();
419 Mesh *new_mesh = vgf.FESpace()->GetMesh();
420 if (mesh->GetNE() != new_mesh->GetNE())
423 int ref = GetAutoRefineFactor();
424 if (TimesToRefine != ref || EdgeRefineFactor != 1)
427 EdgeRefineFactor = 1;
428 cout <<
"Subdivision factors = " << TimesToRefine <<
", 1" << endl;
430 if (RefineFactor != 1)
433 cout <<
"Vector subdivision factor = 1" << endl;
438 solx =
new Vector(mesh->GetNV());
439 soly =
new Vector(mesh->GetNV());
441 vgf.GetNodalValues(*solx, 1);
442 vgf.GetNodalValues(*soly, 2);
445 if (vc0.Size() != vgf.Size())
454 sol =
new Vector(mesh->GetNV());
455 for (
int i = 0; i < mesh->GetNV(); i++)
457 (*sol)(i) = Vec2Scalar((*solx)(i), (*soly)(i));
470 cout <<
"VisualizationSceneVector::NewMeshAndSolution() : "
471 " maxlen not updated!" << endl;
475 PrepareVectorField();
487 for (
int i = 0; i < mesh->GetNV(); i++)
489 (*sol)(i) = Vec2Scalar((*solx)(i), (*soly)(i));
494 PrepareVectorField();
530 int i,
const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
534 DenseMatrix vec_vals;
535 ElementTransformation *T;
537 double ev[2], evec[4];
538 int vdim = VecGridF->FESpace()->GetVDim();
540 Vector curl(curl_v, 1);
542 VecGridF->GetVectorValues(i, ir, vec_vals, tr);
543 vals.SetSize(vec_vals.Width());
544 for (
int j = 0; j < vec_vals.Width(); j++)
549 T = mesh->GetElementTransformation(i);
550 T->SetIntPoint(&ir.IntPoint(j));
553 vals(j) = VecGridF->GetDivergence(*T);
557 VecGridF->GetCurl(*T, curl);
567 VecGridF->GetVectorGradient(*T, gv);
570 vals(j) = gv(1, 0) - gv(0, 1);
575 gv.CalcEigenvalues(ev, evec);
576 vals(j) = ev[1] - ev[0];
585 vals(j) = Vec2Scalar(vec_vals(0, j), vec_vals(1, j));
591 ElementTransformation *T = mesh->GetElementTransformation(i);
593 T->Transform(ir, tr);
595 vals.SetSize(ir.GetNPoints());
598 for (
int j = 0; j < ir.GetNPoints(); j++)
600 T->SetIntPoint(&ir.IntPoint(j));
601 vals(j) = T->Weight();
606 mesh->GetElementTransformation(i, vc0, &T0);
607 for (
int j = 0; j < ir.GetNPoints(); j++)
609 T->SetIntPoint(&ir.IntPoint(j));
610 T0.SetIntPoint(&ir.IntPoint(j));
611 vals(j) = T->Weight() / T0.Weight();
617 for (
int j = 0; j < vals.Size(); j++)
624 vals(j) = 1.0 / vals(j);
630 for (
int j = 0; j < vals.Size(); j++)
632 vals(j) = _LogVal(vals(j));
635 if (shrink != 1.0 || shrinkmat != 1.0)
637 ShrinkPoints(tr, i, 0, 0);
642 int i,
const IntegrationRule &ir, Vector &vals, DenseMatrix &tr,
643 DenseMatrix &normals)
645 int have_normals = 0;
647 GetRefinedValues(i, ir, vals, tr);
654 int ne = mesh -> GetNE();
655 DenseMatrix pointmat;
657 double zc = 0.5*(bb.z[0]+bb.z[1]);
660 displine_buf.clear();
664 for (
int i = 0; i < ne; i++)
667 mesh->GetPointMatrix (i, pointmat);
668 mesh->GetElementVertices (i, vertices);
670 for (
int j = 0; j < pointmat.Size(); j++)
682 else if (drawdisp < 2)
685 DenseMatrix vvals, pm;
687 for (
int i = 0; i < ne; i++)
689 RefinedGeometry *RefG =
691 TimesToRefine, EdgeRefineFactor);
692 VecGridF->GetVectorValues(i, RefG->RefPts, vvals, pm);
694 Array<int> &RE = RefG->RefEdges;
696 for (
int k = 0; k+1 < RE.Size(); k++)
699 pm(0, RE[k]) + sc * vvals(0, RE[k]),
700 pm(1, RE[k]) + sc * vvals(1, RE[k]), zc);
703 pm(0, RE[k]) + sc * vvals(0, RE[k]),
704 pm(1, RE[k]) + sc * vvals(1, RE[k]), zc);
712 DenseMatrix vvals, pm;
714 double x_min, x_max, y_min, y_max;
715 Array<double> levels_x, levels_y;
717 x_min = y_min = numeric_limits<double>::infinity();
718 x_max = y_max = -x_min;
720 for (
int i = 0; i < ne; i++)
722 RefinedGeometry *RefG =
724 TimesToRefine, EdgeRefineFactor);
725 VecGridF->GetVectorValues(i, RefG->RefPts, vvals, pm);
729 for (
int j = 0; j < vvals.Width(); j++)
731 double x = vvals(0, j), y = vvals(1, j);
737 rho = sqrt(x * x + y * y);
743 if (x_min > x) { x_min = x; }
744 if (x_max < x) { x_max = x; }
745 if (y_min > y) { y_min = y; }
746 if (y_max < y) { y_max = y; }
752 int n = level.Size()-1;
756 if ((x_max - x_min) < (y_max - y_min))
759 ny = (int)ceil(n * (y_max - y_min) / (x_max - x_min));
763 nx = (int)ceil(n * (x_max - x_min) / (y_max - y_min));
771 levels_x.SetSize(nx+1);
772 levels_y.SetSize(ny+1);
773 for (
int i = 0; i <= nx; i++)
775 double a = double(i) / nx;
776 levels_x[i] = (1. - a) * x_min + a * x_max;
778 double offs = 1e-3 / nx;
779 levels_x[0] = (1. - offs) * x_min + offs * x_max;
780 levels_x[nx] = offs * x_min + (1. - offs) * x_max;
781 for (
int i = 0; i <= ny; i++)
783 double a = double(i) / ny;
784 levels_y[i] = (1. - a) * y_min + a * y_max;
787 levels_y[0] = (1. - offs) * y_min + offs * y_max;
788 levels_y[ny] = offs * y_min + (1. - offs) * y_max;
791 for (
int i = 0; i < ne; i++)
793 RefinedGeometry *RefG =
795 TimesToRefine, EdgeRefineFactor);
796 VecGridF->GetVectorValues(i, RefG->RefPts, vvals, pm);
803 Add(pm, vvals, 1.-sc, vvals);
808 for (
int j = 0; j < vvals.Width(); j++)
810 double x = vvals(0, j), y = vvals(1, j);
814 rho = sqrt(x * x + y * y);
822 Array<int> &RG = RefG->RefGeoms;
823 int sides = mesh->GetElement(i)->GetNVertices();
825 vals.SetSize(vvals.Width());
826 for (
int j = 0; j < vvals.Width(); j++)
828 vals(j) = vvals(0, j);
830 DrawLevelCurves(build, RG, pm, vals, sides, levels_x, 1);
831 for (
int j = 0; j < vvals.Width(); j++)
833 vals(j) = vvals(1, j);
835 DrawLevelCurves(build, RG, pm, vals, sides, levels_y, 1);
839 updated_bufs.emplace_back(&displine_buf);
845 double vy,
double cval)
847 double zc = 0.5*(bb.z[0]+bb.z[1]);
854 arrow_scaling_type = 0;
855 Arrow(builder, px, py, zc, vx, vy, 0.0, 1.0, 1./4./3.);
857 else if (drawvector > 0)
859 double area = (bb.x[1]-bb.x[0])*(bb.y[1]-bb.y[0]);
860 double h = sqrt(area/mesh->GetNV()) * ArrowScale;
863 arrow_scaling_type = 1;
865 MySetColor(builder, cval, minv, maxv);
869 Arrow(builder, px, py, zc, vx, vy, 0.0, h, 0.125);
874 Arrow(builder, px, py, zc, vx, vy, 0.0,
875 h*max(0.01, len/maxlen), 0.125);
898 palette.SetUseLogscale(logscale);
903 for (i = 0; i < mesh->GetNV(); i++)
905 double *v = mesh->GetVertex(i);
906 DrawVector(v[0], v[1], (*solx)(i), (*soly)(i), (*sol)(i));
909 if (shading == 2 && RefineFactor > 1)
911 DenseMatrix vvals, pm;
912 for (i = 0; i < mesh->GetNE(); i++)
914 const IntegrationRule *ir =
916 mesh->GetElementBaseGeometry(i), RefineFactor);
921 VecGridF->GetVectorValues(i, *ir, vvals, pm);
922 for (
int j = 0; j < vvals.Width(); j++)
924 DrawVector(pm(0, j), pm(1,j), vvals(0, j), vvals(1, j),
925 Vec2Scalar(vvals(0, j), vvals(1, j)));
928 for (i = 0; i < mesh->GetNEdges(); i++)
930 const IntegrationRule *ir =
932 mesh->GetFaceBaseGeometry(i), RefineFactor);
937 VecGridF->GetFaceVectorValues(i, 0, *ir, vvals, pm);
938 for (
int j = 0; j < vvals.Width(); j++)
940 DrawVector(pm(0, j), pm(1,j), vvals(0, j), vvals(1, j),
941 Vec2Scalar(vvals(0, j), vvals(1, j)));
957 updated_bufs.emplace_back(&vector_buf);
965 PrepareColorBar(minv, maxv, (drawmesh == 2) ? &level :
nullptr );
970 double* cp_eqn = CuttingPlane->Equation();
971 params.
clip_plane_eqn = {cp_eqn[0], cp_eqn[1], cp_eqn[2], cp_eqn[3]};
975 scene.
queue.emplace_back(params, &vector_buf);
980 scene.
queue.emplace_back(params, &disp_buf);
988 scene.
queue.emplace_back(params, &cp_buf);
997 scene.
queue.emplace_back(params, &bdr_buf);
1003 scene.
queue.emplace_back(params, &line_buf);
1005 else if (drawmesh == 2)
1007 scene.
queue.emplace_back(params, &lcurve_buf);
1013 scene.
queue.emplace_back(params, &e_nums_buf);
1015 else if (drawnums == 2)
1017 scene.
queue.emplace_back(params, &v_nums_buf);
1020 if (drawvector == 1)
1022 scene.
queue.emplace_back(params, &vector_buf);
1031 scene.
queue.emplace_back(params, &displine_buf);
1039 string name =
"GLVis_scene_000";
1043 auto palette_mat = AddPaletteMaterial(bld);
1044 auto pal_lines_mat = AddPaletteLinesMaterial(bld, palette_mat);
1045 auto black_mat = AddBlackMaterial(bld);
1049 auto vec_node = AddModelNode(bld,
"Vectors");
1050 auto vec_mesh = bld.
addMesh(
"Vectors Mesh");
1053 int ntria = AddTriangles(
1057 (drawvector == 1) ? black_mat : palette_mat,
1059 int nlines = AddLines(
1063 (drawvector == 1) ? black_mat : pal_lines_mat,
1065 if (ntria == 0 || nlines == 0)
1067 cout <<
"glTF export: no vectors found to export!" << endl;
1070 if (drawelems) { glTF_ExportElements(bld, buf, palette_mat, disp_buf); }
1073 glTF_ExportMesh(bld, buf, black_mat,
1074 (drawmesh == 1) ? line_buf : lcurve_buf);
1076 if (drawbdr) { glTF_ExportBoundary(bld, buf, black_mat); }
1077 if (drawaxes) { glTF_ExportBox(bld, buf, black_mat); }
1080 cout <<
"Exported glTF -> " << name <<
".gltf" << endl;
void SendExposeEvent()
Send expose event. In our case MyReshape is executed and Draw after it.
thread_local GeometryRefiner GLVisGeometryRefiner
double VecLength(double x, double y)
thread_local VisualizationSceneVector * vsvector
void glVertex3d(double x, double y, double z)
double VecDivSubst(double x, double y)
thread_local SdlWindow * wnd
double(* Vec2ScalarFunctions[7])(double, double)
double VecDirection(double x, double y)
void SetGridFunction(StreamState &state)
virtual gl3::SceneInfo GetSceneObjs()
virtual ~VisualizationSceneVector()
const char * Vec2ScalarNames[7]
thread_local double new_maxlen
thread_local int ianimmax
buffer_id addBuffer(const std::string &bufferName)
virtual std::string GetHelpString() const
double VecCurlSubst(double x, double y)
virtual int GetRefinedValuesAndNormals(int i, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, DenseMatrix &normals)
void NewMeshAndSolution(Mesh *new_m, Vector *new_sol, GridFunction *new_u=NULL)
VisualizationSceneVector(Mesh &m, Vector &sx, Vector &sy)
thread_local VisualizationSceneSolution * vssol
mesh_id addMesh(const std::string &meshName)
double VecDotNx(double x, double y)
void NewMeshAndSolution(GridFunction &vgf)
void CycleVec2Scalar(int print=0)
virtual void PrepareVectorField()
virtual void GetRefinedValues(int i, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr)
Crude fixed-function OpenGL emulation helper.
virtual gl3::SceneInfo GetSceneObjs()
double VecDotNy(double x, double y)
thread_local string extra_caption
void addNodeMesh(node_id node, mesh_id mesh)
void DrawVector(double, double, double, double, double)
virtual void ToggleDrawElems()
bool contains_translucent
virtual void glTF_Export()
std::array< float, 4 > static_color
void setOnKeyDown(int key, Delegate func)
void PrepareDisplacedMesh()
std::array< double, 4 > clip_plane_eqn
thread_local VisualizationScene * locscene
double VecAnisotrSubst(double x, double y)