FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_vis_define_parameters.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
7 
8 #include <math.h>
9 #include "hecmw_vis_mem_util.h"
10 
11 #define EPSILON 0.00000001
12 #define PI 3.1415926
13 
14 void transform_range_vertex(double range[6], double vertex[24]) {
15  vertex[0 * 3] = vertex[4 * 3] = vertex[7 * 3] = vertex[3 * 3] = range[0];
16  vertex[1 * 3] = vertex[5 * 3] = vertex[6 * 3] = vertex[2 * 3] = range[1];
17  vertex[0 * 3 + 1] = vertex[1 * 3 + 1] = vertex[5 * 3 + 1] =
18  vertex[4 * 3 + 1] = range[2];
19  vertex[3 * 3 + 1] = vertex[2 * 3 + 1] = vertex[6 * 3 + 1] =
20  vertex[7 * 3 + 1] = range[3];
21  vertex[0 * 3 + 2] = vertex[1 * 3 + 2] = vertex[2 * 3 + 2] =
22  vertex[3 * 3 + 2] = range[4];
23  vertex[4 * 3 + 2] = vertex[5 * 3 + 2] = vertex[6 * 3 + 2] =
24  vertex[7 * 3 + 2] = range[5];
25  return;
26 }
27 
28 static void normalize_f(double vector[3]) {
29  int i;
30  double norm_v;
31  norm_v = sqrt(vector[0] * vector[0] + vector[1] * vector[1] +
32  vector[2] * vector[2]);
33  if (fabs(norm_v) > EPSILON) {
34  for (i = 0; i < 3; i++) vector[i] /= norm_v;
35  }
36  return;
37 }
38 
39 void get_frame_transform_matrix(double view_point_d[3], double screen_point[3],
40  double up[3], double coff_matrix[3][3]) {
41  double U[3], V[3], N[3];
42  int i;
43 
44  for (i = 0; i < 3; i++) {
45  N[i] = -(view_point_d[i] - screen_point[i]);
46  }
47  normalize_f(N);
48  /* find the direction of axis U */
49  U[0] = up[1] * N[2] - N[1] * up[2];
50  U[1] = -up[0] * N[2] + N[0] * up[2];
51  U[2] = up[0] * N[1] - N[0] * up[1];
52  normalize_f(U);
53  /*find the direction of axis V */
54  V[0] = N[1] * U[2] - U[1] * N[2];
55  V[1] = -N[0] * U[2] + U[0] * N[2];
56  V[2] = N[0] * U[1] - U[0] * N[1];
57  normalize_f(V);
58  for (i = 0; i < 3; i++) {
59  coff_matrix[i][0] = U[i];
60  coff_matrix[i][1] = V[i];
61  coff_matrix[i][2] = N[i];
62  }
63  return;
64 }
65 
66 void find_inverse_matrix(double coff_matrix[3][3], double inv_matrix[3][3]) {
67  int i, j;
68  double a[3][3], norm_a, aa[3][3];
69 
70  for (i = 0; i < 3; i++)
71  for (j = 0; j < 3; j++) a[i][j] = coff_matrix[i][j];
72  norm_a = a[0][0] * a[1][1] * a[2][2] + a[0][1] * a[1][2] * a[2][0] +
73  a[0][2] * a[1][0] * a[2][1] - a[0][2] * a[1][1] * a[2][0] -
74  a[0][1] * a[1][0] * a[2][2] - a[0][0] * a[1][2] * a[2][1];
75  if (fabs(norm_a) < 1.0E-7)
77  "ERROR: HEC-MW-VIS-E2001: There is something wrong with transform "
78  "matrix, inverse = 0");
79 
80  aa[0][0] = a[1][1] * a[2][2] - a[1][2] * a[2][1];
81  aa[0][1] = -(a[0][1] * a[2][2] - a[2][1] * a[0][2]);
82  aa[0][2] = a[0][1] * a[1][2] - a[1][1] * a[0][2];
83  aa[1][0] = -(a[1][0] * a[2][2] - a[2][0] * a[1][2]);
84  aa[1][1] = a[0][0] * a[2][2] - a[2][0] * a[0][2];
85  aa[1][2] = -(a[0][0] * a[1][2] - a[1][0] * a[0][2]);
86  aa[2][0] = a[1][0] * a[2][1] - a[2][0] * a[1][1];
87  aa[2][1] = -(a[0][0] * a[2][1] - a[2][0] * a[0][1]);
88  aa[2][2] = a[0][0] * a[1][1] - a[1][0] * a[0][1];
89  for (i = 0; i < 3; i++)
90  for (j = 0; j < 3; j++) inv_matrix[i][j] = aa[i][j] / norm_a;
91  return;
92 }
93 
94 void transform_frame(double screen_point[3], double vertex[24],
95  double coff_matrix[3][3], double n_vertex[24]) {
96  int i, j;
97  double xx, yy, zz;
98 
99  for (i = 0; i < 24; i++) n_vertex[i] = vertex[i];
100 
101  for (i = 0; i < 8; i++)
102  for (j = 0; j < 3; j++) n_vertex[i * 3 + j] -= screen_point[j];
103 
104  for (i = 0; i < 8; i++) {
105  xx = n_vertex[i * 3];
106  yy = n_vertex[i * 3 + 1];
107  zz = n_vertex[i * 3 + 2];
108  n_vertex[i * 3] = xx * coff_matrix[0][0] + yy * coff_matrix[1][0] +
109  zz * coff_matrix[2][0];
110  n_vertex[i * 3 + 1] = xx * coff_matrix[0][1] + yy * coff_matrix[1][1] +
111  zz * coff_matrix[2][1];
112  n_vertex[i * 3 + 2] = xx * coff_matrix[0][2] + yy * coff_matrix[1][2] +
113  zz * coff_matrix[2][2];
114  }
115  return;
116 }
117 
118 void transform_frame3(double screen_point[3], double f[3][3],
119  double coff_matrix[3][3], double n_f[3][3]) {
120  int i, j;
121  double xx, yy, zz;
122 
123  for (i = 0; i < 3; i++)
124  for (j = 0; j < 3; j++) n_f[i][j] = f[i][j];
125 
126  for (i = 0; i < 3; i++)
127  for (j = 0; j < 3; j++) n_f[i][j] -= screen_point[j];
128 
129  for (i = 0; i < 3; i++) {
130  xx = n_f[i][0];
131  yy = n_f[i][1];
132  zz = n_f[i][2];
133  n_f[i][0] = xx * coff_matrix[0][0] + yy * coff_matrix[1][0] +
134  zz * coff_matrix[2][0];
135  n_f[i][1] = xx * coff_matrix[0][1] + yy * coff_matrix[1][1] +
136  zz * coff_matrix[2][1];
137  n_f[i][2] = xx * coff_matrix[0][2] + yy * coff_matrix[1][2] +
138  zz * coff_matrix[2][2];
139  }
140  return;
141 }
142 
143 void transform2_frame(double coff_matrix[3][3], double view_point[3]) {
144  double xx, yy, zz;
145 
146  xx = view_point[0];
147  yy = view_point[1];
148  zz = view_point[2];
149  view_point[0] =
150  xx * coff_matrix[0][0] + yy * coff_matrix[1][0] + zz * coff_matrix[2][0];
151  view_point[1] =
152  xx * coff_matrix[0][1] + yy * coff_matrix[1][1] + zz * coff_matrix[2][1];
153  view_point[2] =
154  xx * coff_matrix[0][2] + yy * coff_matrix[1][2] + zz * coff_matrix[2][2];
155 
156  return;
157 }
158 
159 void tranverse_transform(double screen_point[3], double point_s[3],
160  double inv_matrix[3][3], double point_o[3]) {
161  int i;
162  double xx, yy, zz;
163 
164  xx = point_s[0];
165  yy = point_s[1];
166  zz = point_s[2];
167  point_o[0] =
168  xx * inv_matrix[0][0] + yy * inv_matrix[1][0] + zz * inv_matrix[2][0];
169  point_o[1] =
170  xx * inv_matrix[0][1] + yy * inv_matrix[1][1] + zz * inv_matrix[2][1];
171  point_o[2] =
172  xx * inv_matrix[0][2] + yy * inv_matrix[1][2] + zz * inv_matrix[2][2];
173 
174  /* transform (x0, y0, z0)*/
175  for (i = 0; i < 3; i++) point_o[i] += screen_point[i];
176  return;
177 }
178 /*
179 void output_frame(Parameter_rendering *vr, double view_point[3], double
180 n_vertex[24], double scr_area[4],
181  double xd, double yd)
182 {
183 
184  int i, pp[8][2];
185  int start_x, start_y;
186  double p[8][2];
187  FILE *f1;
188 
189  f1=fopen("frame.dat", "w");
190  if(f1==NULL) {
191  fprintf(stderr, "cannot open the frame output file\n");
192  HECMW_vis_print_exit("cannot open the frame output file");
193  }
194  for(i=0;i<8;i++) {
195  if(fabs(n_vertex[i*3+2]-view_point[2])<EPSILON) {
196  fprintf(stderr, " The viewpoint position is not\ncorrect\n");
197  HECMW_vis_print_exit("The viewpoint position is not correct");
198  }
199  p[i][0]=view_point[0]-view_point[2]/(n_vertex[i*3+2]-view_point[2])*
200  (n_vertex[i*3]-view_point[0]);
201  p[i][1]=view_point[1]-view_point[2]/(n_vertex[i*3+2]-view_point[2])*
202  (n_vertex[i*3+1]-view_point[1]);
203  }
204  if((vr->color_mapping_bar_on==0) && (vr->scale_marking_on==0)) {
205  start_x=10; start_y=10;
206  }
207  else if((vr->color_mapping_bar_on==1) && (vr->scale_marking_on==0)) {
208  start_x=30; start_y=10;
209  }
210  else if((vr->color_mapping_bar_on==1) && (vr->scale_marking_on==1)) {
211  start_x=45; start_y=10;
212  }
213  for(i=0;i<8;i++) {
214  pp[i][0]=(int)((p[i][0]-scr_area[0])/xd)+start_x;
215  pp[i][1]=(int)((p[i][1]-scr_area[2])/yd)+start_y;
216  fprintf(f1, "%d %d\n", pp[i][0], pp[i][1]);
217  }
218  fclose(f1);
219  return;
220 }
221 
222  */
223 void transform_frame4(double screen_point[3], double iso_p[6],
224  double coff_matrix[3][3], double n_iso[6]) {
225  int i, j;
226  double xx, yy, zz;
227 
228  for (i = 0; i < 6; i++) n_iso[i] = iso_p[i];
229 
230  for (i = 0; i < 2; i++)
231  for (j = 0; j < 3; j++) n_iso[i * 3 + j] -= screen_point[j];
232 
233  for (i = 0; i < 2; i++) {
234  xx = n_iso[i * 3 + 0];
235  yy = n_iso[i * 3 + 1];
236  zz = n_iso[i * 3 + 2];
237  n_iso[i * 3 + 0] = xx * coff_matrix[0][0] + yy * coff_matrix[1][0] +
238  zz * coff_matrix[2][0];
239  n_iso[i * 3 + 1] = xx * coff_matrix[0][1] + yy * coff_matrix[1][1] +
240  zz * coff_matrix[2][1];
241  n_iso[i * 3 + 2] = xx * coff_matrix[0][2] + yy * coff_matrix[1][2] +
242  zz * coff_matrix[2][2];
243  }
244  return;
245 }
246 
247 void find_projection_range3(double view_point[3], double n_iso[6],
248  double pixel_d[2][2], double iso_p[6]) {
249  int i;
250  double tmp_d;
251 
252  for (i = 0; i < 2; i++) {
253  if (fabs(n_iso[i * 3 + 2] - view_point[2]) < EPSILON)
255  "ERROR: HEC-MW-VIS-E2002: The viewpoint position is not correct");
256  pixel_d[i][0] = view_point[0] -
257  view_point[2] / (n_iso[i * 3 + 2] - view_point[2]) *
258  (n_iso[i * 3 + 0] - view_point[0]);
259  pixel_d[i][1] = view_point[1] -
260  view_point[2] / (n_iso[i * 3 + 2] - view_point[2]) *
261  (n_iso[i * 3 + 1] - view_point[1]);
262  }
263  if (pixel_d[0][0] > pixel_d[1][0]) {
264  for (i = 0; i < 2; i++) {
265  tmp_d = pixel_d[1][i];
266  pixel_d[1][i] = pixel_d[0][i];
267  pixel_d[0][i] = tmp_d;
268  }
269  for (i = 0; i < 3; i++) {
270  tmp_d = n_iso[3 + i];
271  n_iso[3 + i] = n_iso[i];
272  n_iso[i] = tmp_d;
273  }
274  for (i = 0; i < 3; i++) {
275  tmp_d = iso_p[3 + i];
276  iso_p[3 + i] = iso_p[i];
277  iso_p[i] = tmp_d;
278  }
279  }
280 
281  return;
282 }
283 
284 void find_projection_range2(double view_point[3], double n_f[3][3],
285  double scr_area[4]) {
286  int i;
287  double p[3][2];
288 
289  for (i = 0; i < 3; i++) {
290  if (fabs(n_f[i][2] - view_point[2]) < EPSILON)
292  "ERROR: HEC-MW-VIS-E2002: The viewpoint position is not correct");
293  p[i][0] = view_point[0] -
294  view_point[2] / (n_f[i][2] - view_point[2]) *
295  (n_f[i][0] - view_point[0]);
296  p[i][1] = view_point[1] -
297  view_point[2] / (n_f[i][2] - view_point[2]) *
298  (n_f[i][1] - view_point[1]);
299  }
300  scr_area[0] = scr_area[1] = p[0][0];
301  scr_area[2] = scr_area[3] = p[0][1];
302  for (i = 0; i < 3; i++) {
303  if (p[i][0] < scr_area[0]) scr_area[0] = p[i][0];
304  if (p[i][0] > scr_area[1]) scr_area[1] = p[i][0];
305  if (p[i][1] < scr_area[2]) scr_area[2] = p[i][1];
306  if (p[i][1] > scr_area[3]) scr_area[3] = p[i][1];
307  }
308  return;
309 }
310 
311 void find_projection_range(double view_point[3], double n_vertex[24],
312  double scr_area[4]) {
313  int i;
314  double p[8][2];
315 
316  for (i = 0; i < 8; i++) {
317  if (fabs(n_vertex[i * 3 + 2] - view_point[2]) < EPSILON)
319  "ERROR: HEC-MW-VIS-E2002: The viewpoint position is not correct");
320  p[i][0] = view_point[0] -
321  view_point[2] / (n_vertex[i * 3 + 2] - view_point[2]) *
322  (n_vertex[i * 3] - view_point[0]);
323  p[i][1] = view_point[1] -
324  view_point[2] / (n_vertex[i * 3 + 2] - view_point[2]) *
325  (n_vertex[i * 3 + 1] - view_point[1]);
326  }
327  scr_area[0] = scr_area[1] = p[0][0];
328  scr_area[2] = scr_area[3] = p[0][1];
329  for (i = 0; i < 8; i++) {
330  if (p[i][0] < scr_area[0]) scr_area[0] = p[i][0];
331  if (p[i][0] > scr_area[1]) scr_area[1] = p[i][0];
332  if (p[i][1] < scr_area[2]) scr_area[2] = p[i][1];
333  if (p[i][1] > scr_area[3]) scr_area[3] = p[i][1];
334  }
335  return;
336 }
337 
338 void view_parameter_define(int ii, int num_of_frames, int rotate_style,
339  double view_point_d[3], double screen_point[3],
340  double up[3], int num_of_lights, double *light_point,
341  double trange[6]) {
342  int i, j;
343  double center[3], t[3], angle, tminx, tmaxx, tminy, tmaxy, tminz, tmaxz;
344 
345  for (i = 0; i < 3; i++) center[i] = (trange[i * 2] + trange[i * 2 + 1]) / 2.0;
346  angle = 2.0 * PI / (double)num_of_frames;
347  if (rotate_style != 0) {
348  if (rotate_style == 1) { /*rotate 30 along x axis */
349  /* rotate viewpoint */
350  up[0] = 1.0;
351  up[1] = 0.0;
352  up[2] = 0.0;
353  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
354  view_point_d[0] = t[0];
355  view_point_d[1] = t[1] * cos(angle) + t[2] * sin(angle);
356  view_point_d[2] = -t[1] * sin(angle) + t[2] * cos(angle);
357  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
358  /* rotate screen_point if it is not in center */
359  /* if((fabs(screen_point[1]-center[1])>EPSILON) ||
360  (fabs(screen_point[2]-center[2])>EPSILON)) {
361  for(i=0;i<3;i++)
362  t[i]=screen_point[i]-center[i];
363  screen_point[0]=t[0];
364  screen_point[1]=t[1]*cos(angle)+t[2]*sin(angle);
365  screen_point[2]=-t[1]*sin(angle)+t[2]*cos(angle);
366  for(i=0;i<3;i++)
367  screen_point[i]+=center[i];
368  }
369  */
370  /* rotate light_position */
371  for (j = 0; j < num_of_lights; j++) {
372  for (i = 0; i < 3; i++) t[i] = light_point[j * 3 + i] - center[i];
373  light_point[j * 3 + 0] = t[0];
374  light_point[j * 3 + 1] = t[1] * cos(angle) + t[2] * sin(angle);
375  light_point[j * 3 + 2] = -t[1] * sin(angle) + t[2] * cos(angle);
376  for (i = 0; i < 3; i++) light_point[j * 3 + i] += center[i];
377  }
378  /* rotate up_direction */
379  for (i = 0; i < 3; i++) t[i] = up[i];
380  up[0] = t[0];
381  up[1] = t[1] * cos(angle) + t[2] * sin(angle);
382  up[2] = -t[1] * sin(angle) + t[2] * cos(angle);
383  }
384  if (rotate_style == 2) { /*rotate 30 along y axis */
385  /* rotate viewpoint */
386  up[0] = 0.0;
387  up[1] = 1.0;
388  up[2] = 0.0;
389  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
390  view_point_d[0] = t[0] * cos(angle) + t[2] * sin(angle);
391  view_point_d[1] = t[1];
392  view_point_d[2] = -t[0] * sin(angle) + t[2] * cos(angle);
393  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
394  /* rotate screen_point if it is not in center */
395  /* if((fabs(screen_point[0]-center[0])>EPSILON) ||
396  (fabs(screen_point[2]-center[2])>EPSILON)) {
397  for(i=0;i<3;i++)
398  t[i]=screen_point[i]-center[i];
399  screen_point[0]=t[0]*cos(angle)+t[2]*sin(angle);
400  screen_point[1]=t[1];
401  screen_point[2]=-t[0]*sin(angle)+t[2]*cos(angle);
402  for(i=0;i<3;i++)
403  screen_point[i]+=center[i];
404  }
405  */
406  /* rotate light_position */
407  for (j = 0; j < num_of_lights; j++) {
408  for (i = 0; i < 3; i++) t[i] = light_point[j * 3 + i] - center[i];
409  light_point[j * 3 + 0] = t[0] * cos(angle) + t[2] * sin(angle);
410  light_point[j * 3 + 1] = t[1];
411  light_point[j * 3 + 2] = -t[0] * sin(angle) + t[2] * cos(angle);
412  for (i = 0; i < 3; i++) light_point[j * 3 + i] += center[i];
413  }
414  /* rotate up direction */
415  for (i = 0; i < 3; i++) t[i] = up[i];
416  up[0] = t[0] * cos(angle) + t[2] * sin(angle);
417  up[1] = t[1];
418  up[2] = -t[0] * sin(angle) + t[2] * cos(angle);
419  }
420  if (rotate_style == 3) { /*rotate 30 along z axis */
421  /* rotate viewpoint */
422  /* up[0]=0.0;
423  up[1]=0.0;
424  up[2]=1.0;
425  */
426  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
427  view_point_d[0] = t[0] * cos(angle) + t[1] * sin(angle);
428  view_point_d[1] = -t[0] * sin(angle) + t[1] * cos(angle);
429  view_point_d[2] = t[2];
430  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
431  /* rotate screen_point if it is not in center */
432  /* if((fabs(screen_point[0]-center[0])>EPSILON) ||
433 (fabs(screen_point[1]-center[1])>EPSILON)) {
434  for(i=0;i<3;i++)
435  t[i]=screen_point[i]-center[i];
436 screen_point[0]=t[0]*cos(angle)+t[1]*sin(angle);
437  screen_point[1]=-t[0]*sin(angle)+t[1]*cos(angle);
438  screen_point[2]=t[2];
439  for(i=0;i<3;i++)
440  screen_point[i]+=center[i];
441  }
442  */
443  /* rotate light_position */
444  for (j = 0; j < num_of_lights; j++) {
445  for (i = 0; i < 3; i++) t[i] = light_point[j * 3 + i] - center[i];
446  light_point[j * 3 + 0] = t[0] * cos(angle) + t[1] * sin(angle);
447  light_point[j * 3 + 1] = -t[0] * sin(angle) + t[1] * cos(angle);
448  light_point[j * 3 + 2] = t[2];
449  for (i = 0; i < 3; i++) light_point[j * 3 + i] += center[i];
450  }
451  /* rotate up direction */
452  for (i = 0; i < 3; i++) t[i] = up[i];
453  up[0] = t[0] * cos(angle) + t[1] * sin(angle);
454  up[1] = -t[0] * sin(angle) + t[1] * cos(angle);
455  up[2] = t[2];
456  }
457  if (rotate_style == 4) {
458  if (ii > 0) {
459  tminx = trange[0];
460  tmaxx = trange[1];
461  tminy = trange[2];
462  tmaxy = trange[3];
463  tminz = trange[4];
464  tmaxz = trange[5];
465  for (i = 0; i < 3; i++) screen_point[i] = center[i];
466  num_of_lights = 1;
467  if (ii == 1) {
468  view_point_d[0] = (tminx + tmaxx) / 2.0;
469  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
470  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
471  light_point[0] = (tminx + tmaxx) / 2.0;
472  light_point[1] = tmaxy + 0.1 * (tmaxy - tminy);
473  light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
474  up[0] = 0.0;
475  up[1] = 0.0;
476  up[2] = 1.0;
477  } else if (ii == 2) {
478  view_point_d[0] = (tminx + tmaxx) / 2.0;
479  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
480  view_point_d[2] = (tmaxz + tminz) / 2.0;
481  light_point[0] = (tminx + tmaxx) / 2.0;
482  light_point[1] = tmaxy + 0.1 * (tmaxy - tminy);
483  light_point[2] = tmaxz + (tmaxz - tminz) * 0.5;
484  up[0] = 0.0;
485  up[1] = 0.0;
486  up[2] = 1.0;
487  } else if (ii == 3) {
488  view_point_d[0] = (tminx + tmaxx) / 2.0;
489  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
490  view_point_d[2] = tminz - 1.5 * (tmaxz - tminz);
491  light_point[0] = (tminx + tmaxx) / 2.0;
492  light_point[1] = tmaxy + 0.1 * (tmaxy - tminy);
493  light_point[2] = tminz - (tmaxz - tminz) * 2.0;
494  up[0] = 0.0;
495  up[1] = 0.0;
496  up[2] = 1.0;
497  } else if (ii == 4) {
498  view_point_d[0] = (tminx + tmaxx) / 2.0;
499  view_point_d[1] = 0.5 * (tmaxy + tminy);
500  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
501  light_point[0] = (tminx + tmaxx) / 2.0;
502  light_point[1] = 0.7 * (tmaxy + tminy);
503  light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
504  up[0] = 0.0;
505  up[1] = -1.0;
506  up[2] = 0.0;
507  } else if (ii == 5) {
508  view_point_d[0] = tmaxx + 1.5 * (tmaxx - tminx);
509  view_point_d[1] = 0.5 * (tmaxy + tminy);
510  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
511  light_point[0] = tmaxx + 0.5 * (tmaxx - tminx);
512  light_point[1] = 0.5 * (tmaxy + tminy);
513  light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
514  up[0] = 0.0;
515  up[1] = 0.0;
516  up[2] = 1.0;
517  } else if (ii == 6) {
518  view_point_d[0] = tminx - 1.5 * (tmaxx - tminx);
519  view_point_d[1] = 0.5 * (tmaxy + tminy);
520  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
521  light_point[0] = tminx - 0.5 * (tmaxx - tminx);
522  light_point[1] = 0.5 * (tmaxy + tminy);
523  light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
524  up[0] = 0.0;
525  up[1] = 0.0;
526  up[2] = 1.0;
527  } else if (ii == 7) {
528  view_point_d[0] = (tmaxx + tminx) / 2.0;
529  view_point_d[1] = tminy - 1.5 * (tmaxy - tminy);
530  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
531  light_point[0] = (tmaxx + tminx) / 2.0;
532  light_point[1] = tminy - 0.5 * (tmaxy - tminy);
533  light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
534  up[0] = 0.0;
535  up[1] = 0.0;
536  up[2] = 1.0;
537  }
538  }
539  }
540  }
541  return;
542 }
543 
544 void view1_parameter_define(int ii, int num_of_frames, int rotate_style,
545  double view_point_d[3], double screen_point[3],
546  int num_of_lights, double *light_point,
547  double up[3], double trange[6])
548 
549 {
550  int i;
551  double center[3], t[3], angle, tminx, tmaxx, tminy, tmaxy, tminz, tmaxz;
552 
553  for (i = 0; i < 3; i++) center[i] = (trange[i * 2] + trange[i * 2 + 1]) / 2.0;
554  angle = 2.0 * PI / (double)num_of_frames;
555  if (rotate_style != 0) {
556  if (rotate_style == 1) { /*rotate 30 along x axis */
557  /* rotate viewpoint */
558  up[0] = 1.0;
559  up[1] = 0.0;
560  up[2] = 0.0;
561  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
562  view_point_d[0] = t[0];
563  view_point_d[1] = t[1] * cos(angle) + t[2] * sin(angle);
564  view_point_d[2] = -t[1] * sin(angle) + t[2] * cos(angle);
565  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
566  /* rotate screen_point if it is not in center */
567  /* if((fabs(screen_point[1]-center[1])>EPSILON) ||
568  (fabs(screen_point[2]-center[2])>EPSILON)) {
569  for(i=0;i<3;i++)
570  t[i]=screen_point[i]-center[i];
571  screen_point[0]=t[0];
572  screen_point[1]=t[1]*cos(angle)+t[2]*sin(angle);
573  screen_point[2]=-t[1]*sin(angle)+t[2]*cos(angle);
574  for(i=0;i<3;i++)
575  screen_point[i]+=center[i];
576  }
577  */
578  /* rotate light_position */
579  /* for(j=0;j<num_of_lights;j++) {
580  for(i=0;i<3;i++)
581  t[i]=light_point[j*3+i]-center[i];
582  light_point[j*3+0]=t[0];
583  light_point[j*3+1]=t[1]*cos(angle)+t[2]*sin(angle);
584  light_point[j*3+2]=-t[1]*sin(angle)+t[2]*cos(angle);
585  for(i=0;i<3;i++)
586  light_point[j*3+i]+=center[i];
587  }
588  */
589  }
590  if (rotate_style == 2) { /*rotate 30 along y axis */
591  /* rotate viewpoint */
592  up[0] = 0.0;
593  up[1] = 1.0;
594  up[2] = 0.0;
595  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
596  view_point_d[0] = t[0] * cos(angle) + t[2] * sin(angle);
597  view_point_d[1] = t[1];
598  view_point_d[2] = -t[0] * sin(angle) + t[2] * cos(angle);
599  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
600  /* rotate screen_point if it is not in center */
601  if ((fabs(screen_point[0] - center[0]) > EPSILON) ||
602  (fabs(screen_point[2] - center[2]) > EPSILON)) {
603  for (i = 0; i < 3; i++) t[i] = screen_point[i] - center[i];
604  screen_point[0] = t[0] * cos(angle) + t[2] * sin(angle);
605  screen_point[1] = t[1];
606  screen_point[2] = -t[0] * sin(angle) + t[2] * cos(angle);
607  for (i = 0; i < 3; i++) screen_point[i] += center[i];
608  }
609  /* rotate light_position */
610  /* for(j=0;j<num_of_lights;j++) {
611  for(i=0;i<3;i++)
612  t[i]=light_point[j*3+i]-center[i];
613  light_point[j*3+0]=t[0]*cos(angle)+t[2]*sin(angle);
614  light_point[j*3+1]=t[1];
615  light_point[j*3+2]=-t[0]*sin(angle)+t[2]*cos(angle);
616  for(i=0;i<3;i++)
617  light_point[j*3+i]+=center[i];
618  }
619  */
620  }
621  if (rotate_style == 3) { /*rotate 30 along z axis */
622  /* up[0]=0.0;
623  up[1]=0.0;
624  up[2]=1.0;
625  */
626  /* rotate viewpoint */
627  for (i = 0; i < 3; i++) t[i] = view_point_d[i] - center[i];
628  view_point_d[0] = t[0] * cos(angle) + t[1] * sin(angle);
629  view_point_d[1] = -t[0] * sin(angle) + t[1] * cos(angle);
630  view_point_d[2] = t[2];
631  for (i = 0; i < 3; i++) view_point_d[i] += center[i];
632  /* rotate screen_point if it is not in center */
633  if ((fabs(screen_point[0] - center[0]) > EPSILON) ||
634  (fabs(screen_point[1] - center[1]) > EPSILON)) {
635  for (i = 0; i < 3; i++) t[i] = screen_point[i] - center[i];
636  screen_point[0] = t[0] * cos(angle) + t[1] * sin(angle);
637  screen_point[1] = -t[0] * sin(angle) + t[1] * cos(angle);
638  screen_point[2] = t[2];
639  for (i = 0; i < 3; i++) screen_point[i] += center[i];
640  }
641  /* rotate light_position */
642  /* for(j=0;j<num_of_lights;j++) {
643  for(i=0;i<3;i++)
644  t[i]=light_point[j*3+i]-center[i];
645  light_point[j*3+0]=t[0]*cos(angle)+t[1]*sin(angle);
646  light_point[j*3+1]=-t[0]*sin(angle)+t[1]*cos(angle);
647  light_point[j*3+2]=t[2];
648  for(i=0;i<3;i++)
649  light_point[j*3+i]+=center[i];
650  }
651  */
652  }
653  if (rotate_style == 4) {
654  if (ii > 0) {
655  tminx = trange[0];
656  tmaxx = trange[1];
657  tminy = trange[2];
658  tmaxy = trange[3];
659  tminz = trange[4];
660  tmaxz = trange[5];
661  if (ii == 1) {
662  view_point_d[0] = (tminx + tmaxx) / 2.0;
663  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
664  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
665  up[0] = 0.0;
666  up[1] = 0.0;
667  up[2] = 1.0;
668  } else if (ii == 2) {
669  view_point_d[0] = (tminx + tmaxx) / 2.0;
670  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
671  view_point_d[2] = (tmaxz + tminz) / 2.0;
672  up[0] = 0.0;
673  up[1] = 0.0;
674  up[2] = 1.0;
675  } else if (ii == 3) {
676  view_point_d[0] = (tminx + tmaxx) / 2.0;
677  view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
678  view_point_d[2] = tminz - 1.5 * (tmaxz - tminz);
679  up[0] = 0.0;
680  up[1] = 0.0;
681  up[2] = 1.0;
682  } else if (ii == 4) {
683  view_point_d[0] = (tminx + tmaxx) / 2.0;
684  view_point_d[1] = 0.5 * (tmaxy + tminy);
685  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
686  up[0] = 0.0;
687  up[1] = -1.0;
688  up[2] = 0.0;
689  } else if (ii == 5) {
690  view_point_d[0] = tmaxx + 1.5 * (tmaxx - tminx);
691  view_point_d[1] = 0.5 * (tmaxy + tminy);
692  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
693  up[0] = 0.0;
694  up[1] = 0.0;
695  up[2] = 1.0;
696  } else if (ii == 6) {
697  view_point_d[0] = tminx - 1.5 * (tmaxx - tminx);
698  view_point_d[1] = 0.5 * (tmaxy + tminy);
699  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
700  up[0] = 0.0;
701  up[1] = 0.0;
702  up[2] = 1.0;
703  } else if (ii == 7) {
704  view_point_d[0] = (tmaxx + tminx) / 2.0;
705  view_point_d[1] = tminy - 1.5 * (tmaxy - tminy);
706  view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
707  up[0] = 0.0;
708  up[1] = 0.0;
709  up[2] = 1.0;
710  }
711  }
712  }
713  }
714  return;
715 }
#define EPSILON
void find_projection_range(double view_point[3], double n_vertex[24], double scr_area[4])
void view1_parameter_define(int ii, int num_of_frames, int rotate_style, double view_point_d[3], double screen_point[3], int num_of_lights, double *light_point, double up[3], double trange[6])
void transform_frame4(double screen_point[3], double iso_p[6], double coff_matrix[3][3], double n_iso[6])
void find_projection_range3(double view_point[3], double n_iso[6], double pixel_d[2][2], double iso_p[6])
void tranverse_transform(double screen_point[3], double point_s[3], double inv_matrix[3][3], double point_o[3])
void find_inverse_matrix(double coff_matrix[3][3], double inv_matrix[3][3])
void get_frame_transform_matrix(double view_point_d[3], double screen_point[3], double up[3], double coff_matrix[3][3])
void view_parameter_define(int ii, int num_of_frames, int rotate_style, double view_point_d[3], double screen_point[3], double up[3], int num_of_lights, double *light_point, double trange[6])
void transform2_frame(double coff_matrix[3][3], double view_point[3])
void find_projection_range2(double view_point[3], double n_f[3][3], double scr_area[4])
void transform_range_vertex(double range[6], double vertex[24])
void transform_frame(double screen_point[3], double vertex[24], double coff_matrix[3][3], double n_vertex[24])
void transform_frame3(double screen_point[3], double f[3][3], double coff_matrix[3][3], double n_f[3][3])
void HECMW_vis_print_exit(char *var)