Hermes2D  3.0
scalar_view.h
Go to the documentation of this file.
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef __H2D_SCALAR_VIEW_H
19 #define __H2D_SCALAR_VIEW_H
20 
21 #include "view.h"
22 #include "linearizer.h"
23 
24 namespace Hermes
25 {
26  namespace Hermes2D
27  {
28  namespace Views
29  {
30  // you can define NOGLUT to turn off all OpenGL stuff in Hermes2D
31 #ifndef NOGLUT
32 
37  class HERMES_API ScalarView : public View
38  {
39  public:
40 
41  void init();
42 #ifndef _MSC_VER
43  ScalarView(const char* title = "ScalarView", WinGeom* wg = nullptr);
44 #else
45  ScalarView(WinGeom* wg = nullptr);
46 #endif
47  ScalarView(char* title, WinGeom* wg = nullptr);
48  ~ScalarView();
49 
50  void show(MeshFunctionSharedPtr<double> sln, int item = H2D_FN_VAL_0,
51  MeshFunctionSharedPtr<double> xdisp = nullptr, MeshFunctionSharedPtr<double> ydisp = nullptr, double dmult = 1.0);
52 
53  void show(MeshFunctionSharedPtr<std::complex<double> > sln, int item = H2D_FN_VAL_0,
54  MeshFunctionSharedPtr<double> xdisp = nullptr, MeshFunctionSharedPtr<double> ydisp = nullptr, double dmult = 1.0)
55  {
56  throw Exceptions::Exception("Visualization of complex 2D solution is not possible, please use a filter that converts the solution into a real function, then display that one.");
57  }
58 
59  void show_linearizer_data(double eps, int item = H2D_FN_VAL_0);
60 
61  inline void show_mesh(bool show = true) { show_edges = show; refresh(); }
62  inline void show_bounding_box(bool show = true) { show_aabb = show; refresh(); }
63  void show_contours(double step, double orig = 0.0);
64  inline void hide_contours() { contours = false; refresh(); }
65  void set_3d_mode(bool enable = true);
67  void set_vertical_scaling(double sc);
69  void set_min_max_range(double min, double max);
70 
72  virtual void reset_view(bool force_reset);
73 
75  Linearizer* get_linearizer();
76 
80  void set_linearizer_criterion(LinearizerCriterion criterion);
81 
82  protected:
85 
86  protected:
87  struct ElementInfo
88  {
90  float x, y;
92  float width, height;
94  int id;
95  ElementInfo() : x(0), y(0), width(0), height(0), id(-1) {};
96  ElementInfo(int id, float x, float y, float width, float height) : x(x), y(y), width(width), height(height), id(id) {};
97  };
99  std::vector<ElementInfo> element_infos;
100 
102  unsigned int element_id_widget;
103 
106 
108  void init_element_info(MeshSharedPtr mesh);
110  void create_element_info_widgets();
112  void draw_element_infos_2d();
113 
114  protected: //values
115 #define H2DV_GL_MAX_EDGE_BUFFER 128
116 #pragma pack(push)
117 #pragma pack(1)
118  struct GLVertex2
119  {
120  float x, y;
121  float coord;
122  GLVertex2() {};
123  GLVertex2(float x, float y, float coord) : x(x), y(y), coord(coord) {};
125  static const size_t H2D_OFFSETOF_COORD = 2 * sizeof(float);
126  };
127 #pragma pack(pop)
128 
131 
138 
141 
143  void prepare_gl_geometry();
145  void draw_values_2d();
147  void draw_edges_2d();
148 
149  protected: //edges
153  bool show_aabb;
155  float edges_color[3];
156 
158  typedef void(*DrawSingleEdgeCallback)(int inx_vert_a, int inx_vert_b, ScalarView* viewer, void* param);
159 
161  void calculate_mesh_aabb(double* x_min, double* x_max, double* y_min, double* y_max);
162 
164  void draw_aabb();
165 
166  protected:
168  bool contours;
170  double cont_orig, cont_step;
172  float cont_color[3];
177 
178  // Perspective projection parameters.
180  static const int fovy;
182  static const double znear;
184  static const double zfar;
185 
186  bool pmode, mode3d, panning;
187  double xrot, yrot, xtrans, ytrans, ztrans;
188  double xzscale, yscale, xctr, yctr, zctr;
189 
191  double value_irange, value_range_avg;
192 
206  double calculate_ztrans_to_fit_view();
208  virtual void update_layout();
209 
211  void init_lighting();
213  void update_mesh_info();
214 
215  virtual void on_display();
216  void on_display_2d();
217  void on_display_3d();
218 
219  virtual void on_key_down(unsigned char key, int x, int y);
220  virtual void on_mouse_move(int x, int y);
222  virtual void on_right_mouse_down(int x, int y);
223  virtual void on_middle_mouse_down(int x, int y);
224  virtual void on_middle_mouse_up(int x, int y);
225  virtual const char* get_help_text() const;
226  virtual void on_close();
227  };
228 #else
229  class HERMES_API ScalarView : public View
230  {
231  public:
232  void init() { throw Hermes::Exceptions::Exception("GLUT disabled."); }
233  ScalarView(const char* title = "ScalarView", WinGeom* wg = nullptr) {}
234  ScalarView(char* title, WinGeom* wg = nullptr) {}
235 
236  void show(MeshFunctionSharedPtr<double> sln, int item = H2D_FN_VAL_0,
237  MeshFunctionSharedPtr<double> xdisp = nullptr, MeshFunctionSharedPtr<double> ydisp = nullptr, double dmult = 1.0) {
238  throw Hermes::Exceptions::Exception("GLUT disabled.");
239  }
240 
241  void show(MeshFunctionSharedPtr<std::complex<double> > sln, int item = H2D_FN_VAL_0,
242  MeshFunctionSharedPtr<double> xdisp = nullptr, MeshFunctionSharedPtr<double> ydisp = nullptr, double dmult = 1.0)
243  {
244  throw Exceptions::Exception("Visualization of complex 2D solution is not possible, please use a filter that converts the solution into a real function, then display that one.");
245  }
246 
247  void show_linearizer_data(double eps, int item = H2D_FN_VAL_0) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
248 
249  inline void show_mesh(bool show = true) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
250  inline void show_bounding_box(bool show = true) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
251  void show_contours(double step, double orig = 0.0) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
252  inline void hide_contours() { throw Hermes::Exceptions::Exception("GLUT disabled."); }
253  inline void set_3d_mode(bool enable = true) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
254  void set_vertical_scaling(double sc) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
255  void set_min_max_range(double min, double max) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
256  Linearizer* get_linearizer() { throw Hermes::Exceptions::Exception("GLUT disabled."); return nullptr; }
257  void set_linearizer_criterion(LinearizerCriterion criterion) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
258  };
259 #endif
260  }
261  }
262 }
263 #endif
static const int fovy
Field of view in the vertical direction (in degrees).
Definition: scalar_view.h:180
Definition: adapt.h:24
bool show_edges
true to show edges of mesh
Definition: scalar_view.h:151
bool is_constant
true if the function to be displayed is constant
Definition: scalar_view.h:176
Represents a simple visualization window.
Definition: view.h:80
< OpenGL vertex. Used to cache vertices prior rendering
Definition: scalar_view.h:118
File containing LinearizerMultidimensional class.
double zctr
Information about the range of vertex values.
Definition: scalar_view.h:188
int max_gl_tris
A maximum allocated number of triangles.
Definition: scalar_view.h:135
File containing View abstract class.
bool show_values
true to show values
Definition: scalar_view.h:140
bool do_zoom_to_fit
true to automatically translate the view so that the whole model si displayed
Definition: scalar_view.h:174
int gl_tri_cnt
A number of OpenGL triangles.
Definition: scalar_view.h:137
static const double znear
Distance of the near clipping plane of the viewing frustum from the camera.
Definition: scalar_view.h:182
bool show_element_info
true, to draw element info (currently ID) in 2D mode
Definition: scalar_view.h:105
float x
location of center[in physical coordinates]
Definition: scalar_view.h:90
Linearizer * lin
LinearizerMultidimensional class responsible for obtaining linearized data.
Definition: scalar_view.h:84
Visualizes a Scalar PDE solution.
Definition: scalar_view.h:37
bool lin_updated
true, if lin now contains new_ values
Definition: scalar_view.h:130
std::vector< ElementInfo > element_infos
Element info.
Definition: scalar_view.h:99
LinearizerMultidimensional< ScalarLinearizerDataDimensions< LINEARIZER_DATA_TYPE > > Linearizer
Linearizer for scalar cases - historically called Linearizer.
Definition: linearizer.h:201
int max_gl_verts
A maximum allocated number of vertices.
Definition: scalar_view.h:133
bool contours
true to enable drawing of contours
Definition: scalar_view.h:168
static const double zfar
Distance of the Far clipping plane of the viewing frustum from the camera.
Definition: scalar_view.h:184
bool show_aabb
true to show the bounding box
Definition: scalar_view.h:153
Typedefs used throughout the Linearizer functionality.
float width
width, height of AABB[in physical coordinates]
Definition: scalar_view.h:92
unsigned int element_id_widget
A GL display-list denoting a element ID widget. The geometry assumes the size of a pixel is 1x1...
Definition: scalar_view.h:102
double cont_orig
contour settings.
Definition: scalar_view.h:170
Abstract class for criterion according to which the linearizer stops dividing elements at some point ...