Hermes2D  2.0
stream_view.h
1 // This file is part of Hermes2D.
2 //
3 // Copyright 2005-2008 Jakub Cerveny <jakub.cerveny@gmail.com>
4 // Copyright 2005-2008 Lenka Dubcova <dubcova@gmail.com>
5 // Copyright 2005-2008 Pavel Solin <solin@unr.edu>
6 //
7 // Hermes2D is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // Hermes2D is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
19 
20 // $Id: view.h 1086 2008-10-21 09:05:44Z jakub $
21 
22 #ifndef __H2D_STREAM_VIEW_H
23 #define __H2D_STREAM_VIEW_H
24 #include "view.h"
25 
26 namespace Hermes
27 {
28  namespace Hermes2D
29  {
30  namespace Views
31  {
32  // you can define NOGLUT to turn off all OpenGL stuff in Hermes2D
33 #ifndef NOGLUT
34 
39  class HERMES_API StreamView : public View
40  {
41  public:
42 
43  StreamView(const char* title = "StreamView", WinGeom* wg = NULL);
44  StreamView(char* title, WinGeom* wg = NULL);
45  ~StreamView();
46 
49  void show(MeshFunction<double>* xsln, MeshFunction<double>* ysln, int marker, double step, double eps = HERMES_EPS_NORMAL);
50  void show(MeshFunction<double>* xsln, MeshFunction<double>* ysln, int marker, double step, double eps, int xitem, int yitem);
51 
54  void add_streamline(double x, double y);
55 
56  protected:
57 
58  struct Node
59  {
60  bool leaf;
61  int level;
62  Node* sons[2];
63  int elements[100];
64  int num_elem;
65  };
66 
67  Vectorizer* vec;
68  double max_mag;
69  bool lines, pmode;
70 
71  double initial_tau;
72  double min_tau;
73  double max_tau;
74  int num_stream;
75  double2** streamlines;
76  int* streamlength;
77  Node* root;
78  double root_x_min;
79  double root_x_max;
80  double root_y_min;
81  double root_y_max;
82 
85  int find_triangle_in_tree(double x, double y, Node* father, double x_min, double x_max, double y_min, double y_max, double3& bar);
86 
90  void add_element_to_tree(Node* father, int e_idx, double x_min, double x_max, double y_min, double y_max);
91 
93  void build_tree();
94  void delete_tree(Node* father);
95 
98  bool is_in_triangle(int idx, double x, double y, double3& bar);
99 
101  bool get_solution_values(double x, double y, double& xval, double& yval);
102 
105  int create_streamline(double x_start, double y_start, int idx);
106 
109  void find_initial_points(int marker, double step, double2*& initial_points);
110 
113  int find_initial_edge(int num_edges, int3* edges);
114 
115  virtual void on_display();
116  virtual void on_mouse_move(int x, int y);
117  virtual void on_key_down(unsigned char key, int x, int y);
118  virtual void on_left_mouse_down(int x, int y);
119  virtual const char* get_help_text() const;
120  };
121 #else
122  class HERMES_API StreamView : public View
123  {
124  public:
125  StreamView(const char* title = "StreamView", WinGeom* wg = NULL) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
126  StreamView(char* title, WinGeom* wg = NULL) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
127 
130  void show(MeshFunction<double>* xsln, MeshFunction<double>* ysln, int marker, double step, double eps = HERMES_EPS_NORMAL) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
131  void show(MeshFunction<double>* xsln, MeshFunction<double>* ysln, int marker, double step, double eps, int xitem, int yitem) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
132 
135  void add_streamline(double x, double y) { throw Hermes::Exceptions::Exception("GLUT disabled."); }
136  };
137 #endif
138  }
139  }
140 }
141 #endif