Thanks to visit codestin.com
Credit goes to glvis.github.io

GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
vsdata.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef GLVIS_VSDATA_HPP
13 #define GLVIS_VSDATA_HPP
14 
15 #include <array>
16 
17 #include "mfem.hpp"
18 #include "openglvis.hpp"
19 
20 using namespace mfem;
21 
22 extern thread_local std::string plot_caption; // defined in glvis.cpp
23 extern thread_local std::string extra_caption; // defined in glvis.cpp
24 
25 class Plane
26 {
27 private:
28  double eqn[4];
29  double phi, theta, rho;
30  double x0,y0,z0;
31  void CartesianToSpherical();
32  void SphericalToCartesian();
33 
34  double bbox_diam;
35 
36  double phi_step, theta_step, rho_step;
37 
38 public:
39  Plane(double A,double B,double C,double D);
40  inline double * Equation() { return eqn; }
41  inline double Transform(double x, double y, double z)
42  { return eqn[0]*x+eqn[1]*y+eqn[2]*z+eqn[3]; }
43  inline double Transform(double * x)
44  { return eqn[0]*x[0]+eqn[1]*x[1]+eqn[2]*x[2]+eqn[3]; }
45 
46  void IncreasePhi();
47  void DecreasePhi();
48  void IncreaseTheta();
49  void DecreaseTheta();
50  void IncreaseDistance();
51  void DecreaseDistance();
52 };
53 
54 
56 {
57 protected:
58  Mesh *mesh;
59  Vector *sol;
60 
61  double minv, maxv;
62 
63  std::string a_label_x, a_label_y, a_label_z;
64 
65  int scaling, colorbar, drawaxes;
66  int auto_ref_max, auto_ref_max_surf_elem;
67 
68  vector<gl3::GlDrawable*> updated_bufs;
74  int caption_w, caption_h;
75 
76  void Init();
77 
78  int arrow_type, arrow_scaling_type;
79 
80  int nl;
81  Array<double> level;
82 
83  int ruler_on;
84  double ruler_x, ruler_y, ruler_z;
85 
86  // autoscale controls the behavior when the mesh/solution are updated:
87  // 0 - do not change the bounding box and the value range
88  // 1 - recompute both the bounding box and the value range (default)
89  // 2 - recompute only the value range
90  // 3 - recompute only the bounding box
91  int autoscale;
92 
93  bool logscale;
94 
95  bool LogscaleRange() { return (minv > 0.0 && maxv > minv); }
96  void PrintLogscale(bool warn);
97 
98  double log_a, unit_a;
99  void SetLogA()
100  {
101  if (logscale)
102  {
103  unit_a = 1.0/log(maxv/minv), log_a = (maxv - minv)*unit_a;
104  }
105  else
106  {
107  unit_a = 1.0/(maxv - minv), log_a = 1.0;
108  }
109  }
110  double _ULogVal(const double &u) { return minv*pow(maxv/minv, u); }
111  double ULogVal(const double &u)
112  { return (logscale ? _ULogVal(u) : minv + (maxv - minv)*u); }
113  double LogUVal(const double &z)
114  {
115  return ((logscale && z >= minv && z <= maxv) ?
116  (log(z/minv)*unit_a) : (z - minv)*unit_a);
117  }
118  double _LogVal_(const double &z) { return (log(z/minv)*log_a + minv); }
119  double _LogVal(const double &z)
120  { return ((z >= minv && z <= maxv) ? _LogVal_(z) : (z)); }
121  double LogVal(const double &z, const bool &log_val)
122  { return (log_val ? _LogVal(z) : z); }
123  double LogVal(const double &z) { return LogVal(z, logscale); }
124 
125  void FixValueRange();
126 
127  void Cone(gl3::GlBuilder& builder, glm::mat4 transform);
128 
129 public:
134  double shrink;
136  double shrinkmat;
137 
139  : a_label_x("x"), a_label_y("y"), a_label_z("z") {}
140  VisualizationSceneScalarData (Mesh & m, Vector & s);
141 
142  virtual ~VisualizationSceneScalarData();
143 
144  virtual std::string GetHelpString() const { return ""; }
145 
146  // Determine 'xscale', 'yscale', and 'zscale' using the current bounding
147  // box, depending on the value of 'scaling'.
148  virtual void SetNewScalingFromBox();
149 
150  // Compute the bounding box, call UpdateBoundingBox.
151  // In 2D the z range is the value range, so FixValueRange and
152  // UpdateValueRange are also called.
153  virtual void FindNewBox(bool prepare) = 0;
154 
155  // Compute the value range based on the current solution, adjust it by
156  // calling FixValueRange and then call UpdateValueRange.
157  virtual void FindNewValueRange(bool prepare) = 0;
158 
159  // Redefined in 2D to call just FindNewBox
160  virtual void FindNewBoxAndValueRange(bool prepare)
161  { FindNewBox(prepare); FindNewValueRange(prepare); }
162 
163  // Redefined in 2D to update only the x- and y-ranges.
164  virtual void FindMeshBox(bool prepare) { FindNewBox(prepare); }
165 
166  // Perform autoscaling depending on the value of 'autoscale':
167  // 0 - do nothing
168  // 1 - call FindNewBoxAndValueRange
169  // 2 - call FindNewValueRange
170  // 3 - call FindMeshBox
171  void DoAutoscale(bool prepare);
172  // Similar to the above but force recomputation of the value range
173  void DoAutoscaleValue(bool prepare);
174 
175  virtual void Prepare() = 0;
176  virtual void PrepareLines() = 0;
177 
178  void UpdateBoundingBox() { SetNewScalingFromBox(); PrepareAxes(); }
179  virtual void EventUpdateBackground() { };
180  virtual void EventUpdateColors() { Prepare(); }
181  virtual void UpdateLevelLines() = 0;
182  virtual void UpdateValueRange(bool prepare) = 0;
183  void SetValueRange(double, double);
184 
185  virtual void SetShading(int, bool) = 0;
186  virtual void SetRefineFactors(int, int) = 0;
187  void SetAutoRefineLimits(int max_ref, int max_surf_elem)
188  {
189  auto_ref_max = max_ref;
190  auto_ref_max_surf_elem = max_surf_elem;
191  }
192  virtual void AutoRefine() = 0;
193  virtual void ToggleAttributes(Array<int> &attr_list) = 0;
194 
195  virtual void PrintState();
196 
197  Mesh *GetMesh() { return mesh; }
198 
199  virtual gl3::SceneInfo GetSceneObjs();
200 
201  void glTF_ExportBox(glTF_Builder &bld,
203  glTF_Builder::material_id black_mat);
204  void glTF_ExportElements(glTF_Builder &bld,
206  glTF_Builder::material_id palette_mat,
207  const gl3::GlDrawable &gl_drawable);
208  void glTF_ExportMesh(glTF_Builder &bld,
210  glTF_Builder::material_id black_mat,
211  const gl3::GlDrawable &gl_drawable);
212  virtual void glTF_Export();
213 
214  double &GetMinV() { return minv; }
215  double &GetMaxV() { return maxv; }
216 
217  void SetLevelLines(double min, double max, int n, int adj = 1);
218 
219  void Arrow(gl3::GlBuilder& builder,
220  double px, double py, double pz,
221  double vx, double vy, double vz, double length,
222  double cone_scale = 0.075);
223  void Arrow2(gl3::GlBuilder& builder,
224  double px, double py, double pz,
225  double vx, double vy, double vz,
226  double length,
227  double cone_scale = 0.075);
228  void Arrow3(gl3::GlBuilder& builder,
229  double px, double py, double pz,
230  double vx, double vy, double vz,
231  double length,
232  double cone_scale = 0.075);
233 
234  void DrawPolygonLevelLines(gl3::GlBuilder& builder, double *point, int n,
235  Array<double> &level, bool log_vals);
236 
237  void ToggleLight() { use_light = !use_light; }
238  void SetLight(bool light_set) { use_light = light_set; }
239 
241  {
242  // colorbar states are: 0) no colorbar, no caption; 1) colorbar with
243  // caption; 2) colorbar without caption.
244  static const int next[2][3] = { { 1, 2, 0 }, { 2, 0, 0 } };
245  colorbar = next[plot_caption.empty()][colorbar];
246  }
247 
248  // Turn on or off the caption
249  void PrepareCaption();
250 
251  void PrepareColorBar(double minval, double maxval,
252  Array<double> * level = NULL,
253  Array<double> * levels = NULL);
254 
255  void SetAxisLabels(const char * a_x, const char * a_y, const char * a_z);
256 
257  void PrepareAxes();
259  {
260  drawaxes = (drawaxes+1)%4;
261  if (drawaxes)
262  {
263  PrepareAxes();
264  }
265  }
266 
268  { scaling = !scaling; SetNewScalingFromBox(); }
269 
270  virtual void ToggleLogscale(bool print);
271 
272  void ToggleRuler();
273  void RulerPosition();
274  virtual void PrepareRuler() { PrepareRuler(logscale); }
275  void PrepareRuler(bool log_z);
276 
277  void ToggleTexture();
278 
279  void Toggle2DView();
280 
281  void SetAutoscale(int _autoscale);
282  int GetAutoscale() const { return autoscale; }
283 
285  void ShrinkPoints(DenseMatrix &pointmat, int i, int fn, int di);
286  // Centers of gravity based on the boundary/element attributes
287  DenseMatrix bdrc, matc;
289  void ComputeBdrAttrCenter();
291  void ComputeElemAttrCenter();
292 };
293 
294 #endif
double _LogVal(const double &z)
Definition: vsdata.hpp:119
double LogVal(const double &z)
Definition: vsdata.hpp:123
double Transform(double x, double y, double z)
Definition: vsdata.hpp:41
gl3::GlDrawable caption_buf
Definition: vsdata.hpp:73
gl3::GlDrawable coord_cross_buf
Definition: vsdata.hpp:70
double LogVal(const double &z, const bool &log_val)
Definition: vsdata.hpp:121
virtual std::string GetHelpString() const
Definition: vsdata.hpp:144
double LogUVal(const double &z)
Definition: vsdata.hpp:113
Definition: vsdata.hpp:25
virtual void EventUpdateColors()
Definition: vsdata.hpp:180
thread_local string plot_caption
Definition: glvis.cpp:60
void SetLight(bool light_set)
Definition: vsdata.hpp:238
double shrinkmat
Shrink factor with respect to the element (material) attributes centers.
Definition: vsdata.hpp:136
double _ULogVal(const double &u)
Definition: vsdata.hpp:110
virtual void EventUpdateBackground()
Definition: vsdata.hpp:179
double * Equation()
Definition: vsdata.hpp:40
double _LogVal_(const double &z)
Definition: vsdata.hpp:118
gl3::GlDrawable axes_buf
Definition: vsdata.hpp:69
vector< gl3::GlDrawable * > updated_bufs
Definition: vsdata.hpp:68
double ULogVal(const double &u)
Definition: vsdata.hpp:111
Crude fixed-function OpenGL emulation helper.
Definition: types.hpp:261
virtual void FindNewBoxAndValueRange(bool prepare)
Definition: vsdata.hpp:160
thread_local string extra_caption
Definition: glvis.cpp:61
gl3::GlDrawable color_bar
Definition: vsdata.hpp:71
double Transform(double *x)
Definition: vsdata.hpp:43
void SetAutoRefineLimits(int max_ref, int max_surf_elem)
Definition: vsdata.hpp:187
virtual void PrepareRuler()
Definition: vsdata.hpp:274
gl3::GlDrawable ruler_buf
Definition: vsdata.hpp:72
virtual void FindMeshBox(bool prepare)
Definition: vsdata.hpp:164
Array< double > level
Definition: vsdata.hpp:81