COVISE Core
covise_gridmethods.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COVISE_GRIDMETHODS_H
9 #define COVISE_GRIDMETHODS_H
10 
11 #include <util/coExport.h>
12 #include <ostream>
13 #include <vector>
14 
15 #define PI 3.14159265358979323846
16 
17 #ifdef _WIN32
18 
19 #include <time.h>
20 
21 #ifdef _MSC_VER
22 #define rintf(dval) ((_isnan(dval)) ? (dval) : (((((dval)-floor(dval)) >= 0.5f) ? (ceil(dval)) : (floor(dval)))))
27 #endif // _MSC_VER
28 #endif // _WIN32
29 
30 namespace covise
31 {
32 
34 {
35 public:
36  static int isin_triangle(const float *point,
37  const float *point0,
38  const float *point1,
39  const float *point2,
40  float tolerance);
41  static void interpolateInTriangle(float *v_interp, const float *point,
42  int no_arrays, int array_dim,
43  const float *const *velo, int c0, int c1, int c2,
44  const float *p0, const float *p1, const float *p2);
45  static void ExtractNormal(float *normal, int base, int second, int third,
46  const float *x_in, const float *y_in, const float *z_in);
47  static void ProjectPoint(float *proj_point, const float *point,
48  const int *conn, int elem_cell, int num_of_vert,
49  const float *x_in, const float *y_in, const float *z_in);
50  static float tri_surf(float *surf, const float *p0,
51  const float *p1, const float *p2);
52 
53  // Given the fem natural coordinates (fem_c) of a point ,
54  // in a range from -1 to 1 in an
55  // 8-noded cell, and a field at these 8 points,
56  // interpolate the field at the point at issue.
57  // velos has 8*array_len floats.
58  // output: interp points to array_len floats allocated by the caller.
59  static void interpElem(float fem_c[3], float *interp,
60  int array_len, const float *velos);
61 
62  // used for rectangular grids in binary searches for cell searching
63  static int asc_compar_fp(const void *key, const void *fp);
64  static int desc_compar_fp(const void *key, const void *fp);
65 
67  {
68  float x_min_;
69  float y_min_;
70  float z_min_;
71  float x_max_;
72  float y_max_;
73  float z_max_;
74  float length();
75  };
76 
77  static void getBoundBox(BoundBox &bbox, int no_v, const int *v_l,
78  const float *x_in, const float *y_in, const float *z_in);
79 
80  static float getMaxVel(int no_v, const int *v_l,
81  const float *u, const float *v, const float *w);
83  // Tetrahedronisation for elements in unstructured grids
85  // ind>0: positive decomposition
86  // ind<0: negative decomposition
87  // el, cl: element and connectivity lists of the unstr. grid
88  // i: number of the element we want to decompose
89  // tel: element list of the "minigrid" tetrahedronised output grid
90  // tcl: connectivity list of the "minigrid" tetrahedronised output grid
91  // the entries of the tcl list point to the same coordinate
92  // lists (x_c, y_c, z_c) as are pointed to by the cl input list.
93  static void hex2tet(int ind, const int *el, const int *cl, int i, int *tel, int *tcl);
94  static void prism2tet(int ind, const int *el, const int *cl, int i, int *tel, int *tcl);
95  static void pyra2tet(int ind, const int *el, const int *cl, int i, int *tel, int *tcl);
96 
97  //returns the volume of a tetrahedra cell
98  static float tetra_vol(const float p0[3], const float p1[3],
99  const float p2[3], const float p3[3]);
100  // test if px is in the tetraheder formed by the other 4 points
101  static int isin_tetra(const float px[3], const float p0[3], const float p1[3],
102  const float p2[3], const float p3[3], float rel_tol);
103  // interpolate in a tetrahedron at "point"
104  // c? are the indices in the x_in,y_in and z_in arrays
105  // where the grid point coordinates are found
106  static void interpolateInTetra(float *v_interp, const float *point,
107  int no_arrays, int array_dim, const float *const *velo,
108  int c0, int c1, int c2, int c3,
109  const float *p0, const float *p1, const float *p2, const float *p3);
110  // interpolate in a tetrahedron at "point"
111  // c? are the indices in the x_in,y_in and z_in arrays
112  // where the grid point coordinates are found
113  static int interpolateVInHexa(float *v_interp, const float *point,
114  const float *const *velo, const int *connl,
115  const float *x_in, const float *y_in, const float *z_in);
116  // interpolate in an hexaeder
117  static int interpolateInHexa(float *v_interp, const float *point,
118  int no_arrays, int array_dim, const float *const *velo,
119  const int *connl,
120  const float *x_in, const float *y_in, const float *z_in);
121 
122  /******************************/
123  /* Support for polyhedral cells */
124  /******************************/
125 
126  typedef struct
127  {
128  double x;
129  double y;
130  double z;
131  } POINT3D;
132 
133  typedef struct
134  {
135  int vertex1;
136  int vertex2;
137  int vertex3;
138  } TRIANGLE;
139 
140  typedef std::vector<TRIANGLE> TESSELATION;
141  typedef std::vector<int> POLYGON;
142  typedef std::vector<int>::iterator POLYGON_ITERATOR;
143 
144  static double dot_product(POINT3D vector1, POINT3D vector2);
145  static POINT3D cross_product(POINT3D vector1, POINT3D vector2);
146 
147  static void TesselatePolyhedron(TESSELATION &triangulated_polyhedron, int num_elem_in, int *elem_in, int num_conn_in, int *conn_in, float *xcoord_in, float *ycoord_in, float *zcoord_in);
148  static void ComputeBoundingBox(int num_coord_in, float *x_coord_in, float *y_coord_in, float *z_coord_in, POINT3D &box_min, POINT3D &box_max, int &radius /*, vector<POINT3D> &box_vertices*/);
149 
150  /* Group of functions required for performing an in-polyhedron test, based on the algorithms of O'Rourke */
151  /* (Computational Geometry in C) */
152  static bool InBox(POINT3D box_min, POINT3D box_max, POINT3D query_point);
153  static void RandomRay(POINT3D &end_point, int radius);
154  static char RayBoxTest(POINT3D end_point, POINT3D query_point, POINT3D triangle_box_min, POINT3D triangle_box_max);
155  static int PlaneCoeff(float *triangle_x, float *triangle_y, float *triangle_z, POINT3D &normal, double &distance);
156  static char RayPlaneIntersection(float *triangle_x, float *triangle_y, float *triangle_z, POINT3D query_point, POINT3D end_point, POINT3D &int_point, int &component_index);
157  static int AreaSign(POINT3D new_vertex_1, POINT3D new_vertex_2, POINT3D new_vertex_3);
158  static char InTri2D(POINT3D new_vertex_1, POINT3D new_vertex_2, POINT3D new_vertex_3, POINT3D projected_int_point);
159  static char InTri3D(float *triangle_x, float *triangle_y, float *triangle_z, int component_index, POINT3D int_point);
160  static char InPlane(/*float *triangle_x, float *triangle_y, float *triangle_z, int component_index, POINT3D query_point, POINT3D end_point, POINT3D int_point*/);
161  static int VolumeSign(POINT3D a, POINT3D b, POINT3D c, POINT3D d);
162  static char RayTriangleCrossing(float *triangle_x, float *triangle_y, float *triangle_z, POINT3D query_point, POINT3D end_point);
163  static char RayTriangleIntersection(float *triangle_x, float *triangle_y, float *triangle_z, POINT3D query_point, POINT3D end_point, POINT3D &int_point);
164  static char InPolyhedron(float *x_coord_in, float *y_coord_in, float *z_coord_in, POINT3D box_min, POINT3D box_max, POINT3D query_point, POINT3D &end_point, int radius, TESSELATION triangulated_polyhedron);
165 
166  /* Field interpolation using mean value barycentric coordinates, based on the algorithm of Ju, Schaefer and Warren */
167  /* (Mean Value Coordinates for Closed Triangular Meshes) */
168  // static double InterpolateCellData(int num_coord_in, float *x_coord_in, float *y_coord_in, float *z_coord_in, float *data_in, TESSELATION triangulated_polyhedron, POINT3D query_point);
169  static double InterpolateCellData(int num_coord_in, float *x_coord_in, float *y_coord_in, float *z_coord_in, float *data_in, POINT3D query_point);
170 
171  /***********************************************************/
172 
173  // derivative operators
174  static int derivativesAtCenter(float **v_interp[3],
175  int no_points, int no_arrays, const float *const *velo,
176  int no_el, int no_vert,
177  const int *tl, const int *el, const int *connl,
178  const float *x_in, const float *y_in, const float *z_in);
179 
181  // OCT_TREE stuff
183  // probably an int is more efficient than a bitset.
184  // 10 bits are used per coordinate.
185  typedef int oct_tree_key;
186 
187  struct keyBoundBox
188  {
191  };
192 
193  struct constants
194  {
195  static const int NO_OF_BITS;
196  static const int out_of_domain;
197  };
198 
199  // given a grid bounding box, and a point, calculate oct-tree key
200  static void get_oct_tree_key(oct_tree_key &key, const BoundBox &bbox, float point[3], int exc);
201 
202  // return 1 if there is intersection of a macrocell and a keyBoundBox
203  static int key_bbox_intersection(oct_tree_key macroEl, const keyBoundBox *bbox2, int level);
204 
205  class lists; // hide here STL stuff (see cpp file)
206 
207  // The oct-tree class
208  class octTree
209  {
210  enum
211  {
212  CRIT_LEVEL = 6,
213  SMALL_ENOUGH = 20
214  };
215  lists *lists_;
217  const int *keyBBoxes_;
218  int fill_son_share(oct_tree_key MacroCell, int son, int elem, int level,
219  unsigned char *son_share);
220  int maxOfCountSons(int *);
221 
222  public:
223  octTree(int num_grid_cells, const int *keyBBoxes);
224  int *SonList(oct_tree_key son_key, int *list_cells, int num,
225  unsigned char *son_share, int *count_sons);
226  void ModifyLists(int num, int *elements, int offset);
227  void DivideOctTree(oct_tree_key MacroCell, int *list_cells,
228  int num, int level, int offset);
229  void treePrint(std::ostream &, int, oct_tree_key, int);
230  ~octTree();
231  };
233  // OCT_TREE stuff ends
235 
237  // See cpp file for info about the following functions
239  static void cell3(int idim, int jdim, int kdim,
240  float *x_in, float *y_in, float *z_in,
241  int *i, int *j, int *k,
242  float *a, float *b, float *g,
243  float x[3], float amat[3][3], float bmat[3][3],
244  int *status);
245 
246  static void intp3(int idim, int jdim, int kdim,
247  float *u_in, float *v_in, float *w_in,
248  int i, int j, int k,
249  float a, float b, float g,
250  float *fi);
251 
252  static void metr3(int idim, int jdim, int kdim,
253  float *x_in, float *y_in, float *z_in,
254  int i, int j, int k,
255  float a, float b, float g,
256  float amat[3][3], float bmat[3][3],
257  int *idegen, int *status);
258 
259  static void padv3(int *first, float cellfr, int direction,
260  int idim, int jdim, int kdim,
261  float *x_in, float *y_in, float *z_in,
262  float *u_in, float *v_in, float *w_in,
263  int *i, int *j, int *k,
264  float *a, float *b, float *g, float x[4],
265  float min_velo, int *status, float *ovel, float *nvel);
266 
267  static void ssvdc(float *x, int n, int p, float *s, float *e,
268  float *u, float *v, float *work,
269  int job, int *info);
270 
271  static void srot(int n, float *sx, int incx, float *sy,
272  int incy, float c, float s);
273  static void srotg(float sa, float sb, float c, float s);
274  static void sscal(int n, float sa, float *sx, int incx);
275  static void sswap(int n, float *sx, int incx, float *sy, int incy);
276  static void saxpy(int n, float sa, float *sx, int incx, float *sy, int incy);
277  static float sdot(int n, float *sx, int incx, float *sy, int incy);
278  static float snrm2(int n, float *sx, int incx);
279  static void ptran3(float amat[3][3], float v[3], float vv[3]);
280  static void inv3x3(float a[3][3], float ainv[3][3], int *status);
281 };
282 
283 std::ostream &operator<<(std::ostream &, grid_methods::octTree &);
284 }
285 #endif
Definition: covise_gridmethods.h:126
std::vector< int > POLYGON
Definition: covise_gridmethods.h:141
double x
Definition: covise_gridmethods.h:128
Definition: covise_gridmethods.h:187
float x_max_
Definition: covise_gridmethods.h:71
oct_tree_key min_
Definition: covise_gridmethods.h:189
int oct_tree_key
Definition: covise_gridmethods.h:185
const GLubyte * c
Definition: khronos-glext.h:9864
GLboolean GLboolean g
Definition: khronos-glext.h:6895
double dot_product(EDGE_VECTOR &vector1, EDGE_VECTOR &vector2)
Definition: CuttingSurfaceGPMUtil.h:54
int vertex1
Definition: covise_gridmethods.h:135
GLdouble s
Definition: khronos-glext.h:6441
Definition: covise_gridmethods.h:208
static const int NO_OF_BITS
Definition: covise_gridmethods.h:195
GLsizei GLsizei GLfloat distance
Definition: khronos-glext.h:13024
EDGE_VECTOR cross_product(EDGE_VECTOR &vector1, EDGE_VECTOR &vector2)
Definition: CuttingSurfaceGPMUtil.h:59
lists * lists_
Definition: covise_gridmethods.h:215
float z_min_
Definition: covise_gridmethods.h:70
GLuint interp
Definition: khronos-glext.h:10487
const GLint * first
Definition: khronos-glext.h:6529
int vertex3
Definition: covise_gridmethods.h:137
int num_grid_cells_
Definition: covise_gridmethods.h:216
double y
Definition: covise_gridmethods.h:129
GLuint GLuint num
Definition: khronos-glext.h:10593
float z_max_
Definition: covise_gridmethods.h:73
oct_tree_key max_
Definition: covise_gridmethods.h:190
Definition: covise_gridmethods.h:193
double z
Definition: covise_gridmethods.h:130
float y_max_
Definition: covise_gridmethods.h:72
GLubyte GLubyte GLubyte GLubyte w
Definition: khronos-glext.h:6793
double length(EDGE_VECTOR &vector)
Definition: CuttingSurfaceGPMUtil.h:70
Definition: covise_gridmethods.h:66
GLdouble n
Definition: khronos-glext.h:8447
const int * keyBBoxes_
Definition: covise_gridmethods.h:217
std::vector< TRIANGLE > TESSELATION
Definition: covise_gridmethods.h:140
QTextStream & operator<<(QTextStream &out, const coConfigEntryStringList list)
Definition: coConfigEntryString.cpp:159
GLint GLint GLint GLint GLint x
Definition: khronos-glext.h:6346
const GLdouble * v
Definition: khronos-glext.h:6442
float x_min_
Definition: covise_gridmethods.h:68
#define DOEXPORT
Definition: coExport.h:331
std::vector< int >::iterator POLYGON_ITERATOR
Definition: covise_gridmethods.h:142
int vertex2
Definition: covise_gridmethods.h:136
GLint level
Definition: khronos-glext.h:6344
static const int out_of_domain
Definition: covise_gridmethods.h:196
GLfloat GLfloat p
Definition: khronos-glext.h:9861
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
float y_min_
Definition: covise_gridmethods.h:69
list of all chemical elements
Definition: coConfig.h:26
Definition: covise_gridmethods.h:133
Definition: covise_gridmethods.h:33
GLintptr offset
Definition: khronos-glext.h:6611
GLboolean GLboolean GLboolean b
Definition: khronos-glext.h:6895