FrontISTR  6.0.0
Large-scale structural analysis program with finit element method
hecmw_vis_pvr_main.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 
6 #include "hecmw_vis_pvr_main.h"
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <math.h>
11 #include "hecmw_vis_mem_util.h"
12 #include "hecmw_vis_comm_util.h"
13 #include "hecmw_vis_bmp.h"
14 #include "hecmw_vis_read_voxel.h"
15 #include "hecmw_vis_ucd_trans.h"
16 #include "hecmw_vis_mesh_extent.h"
17 #include "hecmw_vis_new_refine.h"
21 #include "hecmw_vis_font_texture.h"
22 #include "hecmw_vis_resampling.h"
23 #include "hecmw_malloc.h"
24 
27 double *extent;
28 
30  struct hecmwST_result_data *data, int *timestep,
31  int *init_flag, int num_of_pvr, Parameter_vr *vr,
32  int stat_para[NUM_CONTROL_PVR], char *outfile,
33  HECMW_Comm VIS_COMM) {
34  int mynode, pesize;
35  char fname[HECMW_FILENAME_LEN];
36 
37  FILE *FP;
38 
39  int time_step;
40  double t1, t2, t3;
41  int n_voxel;
42  /*
43 int max_level, xr, yr, projection_style, num_of_lights, color_mapping_style,
44 interval_mapping_num,
45  num_of_features, rotate_style, transfer_function_style,
46 color_mapping_bar_on, scale_marking_on, num_of_frames,
47  color_system_type,color_bar_style, fixed_range_on, num_of_scale, mark_0_on,
48 specified_level[3],
49  nv_xyz[3], remove_0_display_on, histogram_on;
50 char name_lookup[128], name_voxelfile[128],color_comp_name[128],
51 color_subcomp_name[5];
52 
53 double *light_point, view_point_d[3], screen_point[3], up[3], k_ads[3],
54 *interval_point, opa_value, *fea_point,
55  background_color[3], font_color[3], font_size, range_value[2],
56 display_range[6];
57  */
58  double view_n[3], nview_n;
59  double vertex[3 * 8];
60  double point_s[3], point_o[3], ray_direction[3];
61  int i, j, k, m;
62  double range[6], xd, yd;
63  double coff_matrix[3][3], n_vertex[3 * 8], inv_matrix[3][3];
64  double mincolor, maxcolor, view_point[3], scr_area[4], x, y, nn;
65  double tmincolor, tmaxcolor, trange[6], svertex[3 * 8], sn_vertex[3 * 8],
66  sscr_area[4];
67  int intersection;
68  double accum_rgba[4];
69  double grad_minmax[2], dis_minmax[2], feap_minmax[2], feai_minmax[2];
70  double tfeap_minmax[2];
71  double *opa_table;
72  extern void HECMW_vis_memory_exit(char *var);
73  extern void HECMW_vis_print_exit(char *var);
74  double *accum_opa;
75  double *image;
76  double center[3], dis_c_v, *ndis_c_v, tmpd;
77  int *pe_id, tmpi, pix_num, pix0_num, pixn;
78  double *n_subimage, *n_subopa, *subimage, *subopa;
79  double *subimage1, *subopa1;
80  double first_p[3];
81  HECMW_Status stat;
82  int starti, startj, endi, endj;
83  int start_x, start_y;
84  double minx, miny, minz, maxx, maxy, maxz, tminx, tminy, tminz, tmaxx, tmaxy,
85  tmaxz;
86  double av_length, tav_length;
87  int first_ijk[3];
88  int num_img, ii, base_x, base_y;
89  double o_v_point[3], m_scr[4];
90  int trace_flag;
91  BITMAPFILEHEADER header; /* File header */
92 
93  unsigned char r, g, b;
94  int ri, gi, bi;
95  BITMAPINFOHEADER info;
96  int scale, scale_type;
97 
98  char timestep_str[128], rotate_str[128];
99 
100  /* --------new variables for vectorization --------*/
101 
102  double *node1;
103  /*
104 double *voxel_dxyz;
105 double *voxel_orig_xyz;
106 int *level;
107 int *voxel_n_neighbor_pe;
108 int **voxel_neighbor_pe;
109  */
110  int x_specified_l, y_specified_l, z_specified_l;
111 
112  int nx, ny, nz, *empty_flag;
113  double *var, *grad_var;
114  int r_level[3];
115  double r_dxyz[3], dxyz[3], orig_xyz[3];
116  double org_mincolor, org_maxcolor;
117 
118  HECMW_Comm_size(VIS_COMM, &pesize);
119  HECMW_Comm_rank(VIS_COMM, &mynode);
120  n_voxel = pesize;
121  /* if(*init_flag==1) {
122 contfile1[0] = '\0';
123  j=0;
124 while (contfile[j] == ' ')
125  j++;
126 k = 0;
127 while (contfile[j] != ' ') {
128  contfile1[k] = contfile[j];
129  k++;
130  j++;
131 }
132 contfile1[k] = '\0';
133 if((contfp=fopen(contfile1,"r"))== NULL) {
134  fprintf(stderr, "There is not such a control file:%s\n", contfile1);
135  exit (0);
136  }
137 vr=(Parameter_vr *)HECMW_malloc(sizeof(Parameter_vr));
138  if(vr==NULL)
139  HECMW_vis_memory_exit("vr");
140 
141 
142 if(strncmp(contfile1, "NULL", 4)==0)
143  set_default_vr(vr, stat_para, pesize);
144 else {
145 if((contfp=fopen(contfile1,"r"))== NULL)
146  HECMW_vis_print_exit("There is not such a control file:\n");
147 read_control_file(contfp, vr, stat_para, pesize);
148 fprintf(stderr, "max_level=%d xr=%d yr=%d num_of_light=%d\n", vr->max_level,
149 vr->xr, vr->yr, vr->num_of_lights);
150 fclose(contfp);
151 }
152  */
153 
154  if ((*init_flag == 1) || (num_of_pvr > 1)) {
155  voxel_dxyz = (double *)HECMW_calloc(pesize * 3, sizeof(double));
156  voxel_orig_xyz = (double *)HECMW_calloc(pesize * 3, sizeof(double));
157  level = (int *)HECMW_calloc(pesize * 3, sizeof(int));
158  voxel_n_neighbor_pe = (int *)HECMW_calloc(pesize, sizeof(int));
159  voxel_neighbor_pe = (int **)HECMW_calloc(pesize, sizeof(int *));
160  if ((voxel_dxyz == NULL) || (voxel_orig_xyz == NULL) || (level == NULL) ||
162  HECMW_vis_memory_exit("voxel information");
163 
164  for (j = 0; j < pesize; j++) {
165  voxel_neighbor_pe[j] = (int *)HECMW_calloc(pesize, sizeof(int));
166  if (voxel_neighbor_pe[j] == NULL)
167  HECMW_vis_memory_exit("voxel_neighbor_pe[j]");
168  for (k = 0; k < pesize; k++) voxel_neighbor_pe[j][k] = 0;
169  }
170  n_voxel = pesize;
171 
172  if (stat_para[22] == 1) {
173  /* fprintf(stderr, "voxel file is %s\n", vr->name_voxelfile);
174  */
177  }
178  } /* end of *init_flag=1 */
179 
180  node1 = (double *)HECMW_calloc(mesh->n_node, sizeof(double));
181 
182  transform_ucd_pvr(data, node1, mesh, vr, mynode, pesize, VIS_COMM, voxel_dxyz,
184  voxel_neighbor_pe, stat_para[22], stat_para[46], *init_flag,
185  num_of_pvr);
186  if (*init_flag == 1) {
187  extent = (double *)HECMW_calloc(mesh->n_elem * 6, sizeof(double));
188  if (extent == NULL) HECMW_vis_memory_exit("extent");
190 
192  VIS_COMM);
193  if (mynode == 0)
194  for (i = 0; i < n_voxel; i++)
195  fprintf(stderr, "voxel %d level: %d %d %d \n", i, level[i * 3],
196  level[i * 3 + 1], level[i * 3 + 2]);
197  if (vr->specified_level[0] > 0) {
198  x_specified_l = vr->specified_level[0];
199  for (i = 0; i < n_voxel; i++) level[i * 3] = x_specified_l;
200  } else if (vr->max_level > 0) {
201  for (i = 0; i < n_voxel; i++) {
202  if (level[i * 3] > vr->max_level) level[i * 3] = vr->max_level;
203  }
204  }
205  if (vr->specified_level[1] > 0) {
206  y_specified_l = vr->specified_level[1];
207  for (i = 0; i < n_voxel; i++) level[i * 3 + 1] = y_specified_l;
208  } else if (vr->max_level > 0) {
209  for (i = 0; i < n_voxel; i++) {
210  if (level[i * 3 + 1] > vr->max_level) level[i * 3 + 1] = vr->max_level;
211  }
212  }
213  if (vr->specified_level[2] > 0) {
214  z_specified_l = vr->specified_level[2];
215  for (i = 0; i < n_voxel; i++) level[i * 3 + 2] = z_specified_l;
216  } else if (vr->max_level > 0) {
217  for (i = 0; i < n_voxel; i++) {
218  if (level[i * 3 + 2] > vr->max_level) level[i * 3 + 2] = vr->max_level;
219  }
220  }
221  }
222 
223 #ifdef slow
224  phi_x = (double *)HECMW_calloc(n_node, sizeof(double));
225  phi_y = (double *)HECMW_calloc(n_node, sizeof(double));
226  phi_z = (double *)HECMW_calloc(n_node, sizeof(double));
227  for (i = 0; i < n_node; i++) {
228  phi_x[i] = 0.0;
229  phi_y[i] = 0.0;
230  phi_z[i] = 0.0;
231  }
232 
233 #endif
234  HECMW_Barrier(VIS_COMM);
235  /* t2=HECMW_Wtime();
236 if (mynode == 0){
237 fprintf(stderr, "finish reading files\n");
238 fprintf(stderr, "the time for reading file is %lf the total time up to now is
239 %lf\n", t2-t1, t2-t1);
240 }
241  */
242  t1 = HECMW_Wtime();
243  if (mynode == 0) {
244  fprintf(stderr, "Start parallel volume rendering module\n");
245  }
246  t2 = t1;
247 
248  if (mynode == 0) fprintf(stderr, "calc_gradient\n");
249 #ifdef slow
250  calc_gradient(n_node, n_internal, n_elem, node, elem, node1, n_neighbor_pe,
251  neighbor_pe, import_index, import_node, export_index,
252  export_node, phi_x, phi_y, phi_z, mynode, VIS_COMM);
253  t3 = HECMW_Wtime();
254  if (mynode == 0) {
255  fprintf(stderr,
256  "The time for computing gradient is %lf the total time up to now "
257  "is %lf\n",
258  t3 - t2, t3 - t1);
259  t2 = t3;
260  }
261  HECMW_Barrier(VIS_COMM);
262  fprintf(stderr, "refinement\n");
263 #endif
264  nx = level[mynode * 3];
265  ny = level[mynode * 3 + 1];
266  nz = level[mynode * 3 + 2];
267  empty_flag = (int *)HECMW_calloc((nx + 1) * (ny + 1) * (nz + 1), sizeof(int));
268  var = (double *)HECMW_calloc((nx + 1) * (ny + 1) * (nz + 1), sizeof(double));
269 #ifdef slow
270  grad_var = (double *)HECMW_calloc((nx + 1) * (ny + 1) * (nz + 1) * 3,
271  sizeof(double));
272  if ((grad_var == NULL) || (var == NULL) || (empty_flag == NULL)) {
273  fprintf(stderr, "There is no enough memory: empty_flag, var, gradient\n");
274  exit(0);
275  }
276 
277 #endif
278  refinement(mesh, node1, n_voxel, voxel_dxyz, voxel_orig_xyz, level,
279  voxel_n_neighbor_pe, voxel_neighbor_pe, extent, mynode, VIS_COMM,
280  empty_flag, var);
281 #ifdef slow
282  HECMW_free(phi_x);
283  HECMW_free(phi_y);
284  HECMW_free(phi_z);
285 #endif
286  HECMW_Barrier(VIS_COMM);
287 
288  t3 = HECMW_Wtime();
289  if (mynode == 0) {
290  fprintf(stderr, " Finish refinement now, refinement level: \n");
291  fprintf(stderr,
292  " The time for refinement is %lf the total time up to now is %lf\n",
293  t3 - t2, t3 - t1);
294  t2 = t3;
295  }
296  HECMW_free(node1);
297  mincolor = tmincolor = 1.0E17;
298  maxcolor = tmaxcolor = -1.0E17;
299  find_color_minmax_vr(var, empty_flag, nx, ny, nz, &mincolor, &maxcolor);
300  HECMW_Barrier(VIS_COMM);
301  if (pesize > 1) {
302  HECMW_Allreduce(&mincolor, &tmincolor, 1, HECMW_DOUBLE, HECMW_MIN,
303  VIS_COMM);
304  HECMW_Allreduce(&maxcolor, &tmaxcolor, 1, HECMW_DOUBLE, HECMW_MAX,
305  VIS_COMM);
306  } else {
307  tmincolor = mincolor;
308  tmaxcolor = maxcolor;
309  }
310  org_mincolor = tmincolor;
311  org_maxcolor = tmaxcolor;
312  if (vr->fixed_range_on == 1) {
313  tmincolor = vr->range_value[0];
314  tmaxcolor = vr->range_value[1];
315  }
316 
317  /* fprintf(stderr, "mincolor= %lf maxcolor= %lf\n", tmincolor, tmaxcolor);
318  */
319  if (vr->histogram_on == 1)
320  output_histogram_vr(tmincolor, tmaxcolor, var, empty_flag, nx, ny, nz,
321  mynode, pesize, VIS_COMM);
322  if (vr->histogram_on == 2)
323  generate_histogram_graph_vr(tmincolor, tmaxcolor, var, empty_flag, nx, ny,
324  nz, mynode, pesize, VIS_COMM,
325  vr->color_system_type);
326  if (vr->color_mapping_style == 4)
327  generate_interval_point_vr(tmincolor, tmaxcolor, var, empty_flag, nx, ny,
328  nz, mynode, pesize, VIS_COMM,
329  vr->interval_point);
330 
331  find_minmax_vr(voxel_dxyz, voxel_orig_xyz, mynode, range);
332  for (i = 0; i < 6; i++) trange[i] = 0.0;
333  minx = range[0];
334  maxx = range[1];
335  miny = range[2];
336  maxy = range[3];
337  minz = range[4];
338  maxz = range[5];
339  HECMW_Barrier(VIS_COMM);
340  if (pesize > 1) {
341  HECMW_Allreduce(&minx, &tminx, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
342 
343  HECMW_Allreduce(&maxx, &tmaxx, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
344  HECMW_Allreduce(&miny, &tminy, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
345  HECMW_Allreduce(&maxy, &tmaxy, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
346  HECMW_Allreduce(&minz, &tminz, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
347  HECMW_Allreduce(&maxz, &tmaxz, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
348  } else {
349  tminx = minx;
350  tmaxx = maxx;
351  tminy = miny;
352  tmaxy = maxy;
353  tminz = minz;
354  tmaxz = maxz;
355  }
356  if (mynode == 0)
357  fprintf(stderr, "the range of the field is %lf %lf %lf %lf %lf %lf\n",
358  tminx, tmaxx, tminy, tmaxy, tminz, tmaxz);
359  trange[0] = tminx;
360  trange[1] = tmaxx;
361  trange[2] = tminy;
362  trange[3] = tmaxy;
363  trange[4] = tminz;
364  trange[5] = tmaxz;
365  if ((*init_flag == 1) || (num_of_pvr > 1)) {
366  if (stat_para[4] == 0) {
367  vr->light_point = (double *)HECMW_calloc(3, sizeof(double));
368  if (vr->light_point == NULL) HECMW_vis_memory_exit("light_point");
369 
370  vr->light_point[0] = (tminx + tmaxx) / 2.0;
371  vr->light_point[1] = tmaxy + 0.1 * (tmaxy - tminy);
372  vr->light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
373  }
374  if (stat_para[5] == 0) {
375  vr->view_point_d[0] = (tminx + tmaxx) / 2.0;
376  vr->view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
377  vr->view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
378  }
379  if (stat_para[6] == 0) {
380  vr->screen_point[0] = (tminx + tmaxx) / 2.0;
381  vr->screen_point[1] = (tminy + tmaxy) / 2.0;
382  vr->screen_point[2] = (tminz + tmaxz) / 2.0;
383  }
384  }
385  HECMW_Barrier(VIS_COMM);
386 
387  /*----------------------------------------
388 Define the sampling and projection parameters
389  */
390  /* First, define the equation of screen */
391  if (vr->rotate_style == 0)
392  num_img = 1;
393  else if ((vr->rotate_style >= 1) && (vr->rotate_style <= 4)) {
394  num_img = vr->num_of_frames;
395  for (i = 0; i < 3; i++)
396  vr->screen_point[i] = (trange[i * 2] + trange[i * 2 + 1]) / 2.0;
397  /*find the range of projection */
398  for (i = 0; i < 3; i++) o_v_point[i] = vr->view_point_d[i];
399  m_scr[0] = m_scr[2] = 1.0E+17;
400  m_scr[1] = m_scr[3] = -1.0E+17;
401 
402  for (ii = 0; ii < num_img; ii++) {
403  if (ii != 0)
405  vr->view_point_d, vr->screen_point,
406  vr->num_of_lights, vr->light_point, vr->up,
407  trange);
408  for (i = 0; i < 3; i++)
409  view_n[i] = vr->screen_point[i] - vr->view_point_d[i];
410  nview_n = sqrt(SQR(view_n[0]) + SQR(view_n[1]) + SQR(view_n[2]));
411  if (fabs(nview_n) > EPSILON)
412  for (i = 0; i < 3; i++) view_n[i] /= nview_n;
413  transform_range_vertex(trange, vertex);
414 
416  coff_matrix);
417  transform_frame(vr->screen_point, vertex, coff_matrix, n_vertex);
418  for (i = 0; i < 3; i++)
419  view_point[i] = vr->view_point_d[i] - vr->screen_point[i];
420  transform2_frame(coff_matrix, view_point);
421  find_projection_range(view_point, n_vertex, scr_area);
422  if (scr_area[0] < m_scr[0]) m_scr[0] = scr_area[0];
423  if (scr_area[1] > m_scr[1]) m_scr[1] = scr_area[1];
424  if (scr_area[2] < m_scr[2]) m_scr[2] = scr_area[2];
425  if (scr_area[3] > m_scr[3]) m_scr[3] = scr_area[3];
426  }
427 
428  for (i = 0; i < 3; i++) vr->view_point_d[i] = o_v_point[i];
429  }
430 
431  for (ii = 0; ii < num_img; ii++) {
432  if (ii != 0)
434  vr->view_point_d, vr->screen_point, vr->up,
435  vr->num_of_lights, vr->light_point, trange);
436  for (i = 0; i < 3; i++)
437  view_n[i] = vr->screen_point[i] - vr->view_point_d[i];
438  nview_n = sqrt(SQR(view_n[0]) + SQR(view_n[1]) + SQR(view_n[2]));
439  if (fabs(nview_n) > EPSILON)
440  for (i = 0; i < 3; i++) view_n[i] /= nview_n;
441  /* for(i=0;i<3;i++)
442 p_screen[i]=view_n[i];
443 p_screen[3]=-view_n[0]*vr->screen_point[0]-view_n[1]*vr->screen_point[1]-
444 view_n[2]*vr->screen_point[2];
445  */
446 
447  /* Second, find the projection of the dataset in each PE */
448  transform_range_vertex(trange, vertex);
449  if (mynode == 0)
450  fprintf(stderr,
451  "viewpoint=%lf %lf %lf screen_point=%lf %lf %lfup=%lf %lf %lf\n",
452  vr->view_point_d[0], vr->view_point_d[1], vr->view_point_d[2],
453  vr->screen_point[0], vr->screen_point[1], vr->screen_point[2],
454  vr->up[0], vr->up[1], vr->up[2]);
456  coff_matrix);
457  transform_frame(vr->screen_point, vertex, coff_matrix, n_vertex);
458  /* if(mynode==0){
459 for(i=0;i<3;i++)
460 for(j=0;j<3;j++)
461 }
462  */
463  for (i = 0; i < 3; i++)
464  view_point[i] = vr->view_point_d[i] - vr->screen_point[i];
465  transform2_frame(coff_matrix, view_point);
466  find_projection_range(view_point, n_vertex, scr_area);
467  /* for multi-PEs, should find minx, maxx, miny, maxy in scr_area for all PE
468  */
469  if (ii == 0) {
470  if ((vr->color_mapping_bar_on == 0) && (vr->scale_marking_on == 0)) {
471  start_x = 10;
472  start_y = 10;
473  /* if((vr->xr<=20) || (vr->yr<=20)) {
474 fprintf(stderr, "The resolution cannot be less than 20\n");
475 exit(0);
476 }
477  */
478  if (num_img == 1) {
479  xd = (scr_area[1] - scr_area[0]) / (vr->xr - 20);
480  yd = (scr_area[3] - scr_area[2]) / (vr->yr - 20);
481  }
482  if (num_img > 1) {
483  xd = (m_scr[1] - m_scr[0]) / (vr->xr - 20);
484  yd = (m_scr[3] - m_scr[2]) / (vr->yr - 20);
485  }
486  if (xd >= yd) {
487  yd = xd;
488  if (num_img == 1)
489  vr->yr =
490  (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
491  10;
492  else if (num_img > 1)
493  vr->yr =
494  (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
495  }
496  if (xd < yd) {
497  xd = yd;
498  if (num_img == 1)
499  vr->xr =
500  (int)((int)(20 + (scr_area[1] - scr_area[0]) / xd) / 8) * 8 + 8;
501  else if (num_img > 1)
502  vr->xr = (int)((int)(20 + (m_scr[1] - m_scr[0]) / xd) / 8) * 8 + 8;
503  }
504  } else if ((vr->color_mapping_bar_on == 1) &&
505  (vr->scale_marking_on == 0)) {
506  start_x = 30;
507  start_y = 10;
508  if (num_img == 1) {
509  xd = (scr_area[1] - scr_area[0]) / (vr->xr - 40);
510  yd = (scr_area[3] - scr_area[2]) / (vr->yr - 20);
511  } else if (num_img > 1) {
512  xd = (m_scr[1] - m_scr[0]) / (vr->xr - 40);
513  yd = (m_scr[3] - m_scr[2]) / (vr->yr - 20);
514  }
515 
516  if (xd >= yd) {
517  yd = xd;
518  if (num_img == 1)
519  vr->yr =
520  (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
521  10;
522  else if (num_img > 1)
523  vr->yr =
524  (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
525  } else if (xd < yd) {
526  xd = yd;
527  if (num_img == 1)
528  vr->xr =
529  (int)((int)(40 + (scr_area[1] - scr_area[0]) / xd) / 8) * 8 + 8;
530  else if (num_img > 1)
531  vr->xr = (int)((int)(40 + (m_scr[1] - m_scr[0]) / xd) / 8) * 8 + 8;
532  }
533  } else if ((vr->color_mapping_bar_on == 1) &&
534  (vr->scale_marking_on == 1)) {
535  scale = (int)vr->font_size;
536  if ((vr->font_size - scale) < 0.5 - EPSILON)
537  scale_type = 1;
538  else
539  scale_type = 2;
540  if (scale_type == 1) {
541  start_x = 10 + 45 * scale;
542  if (vr->color_bar_style == 2) start_x = 10 + 45 * scale + 15;
543  } else if (scale_type == 2) {
544  start_x = 10 + 63 * scale;
545  if (vr->color_bar_style == 2) start_x = 10 + 63 * scale + 15;
546  }
547 
548  start_y = 10;
549  if (vr->xr < start_x + 10) {
550  fprintf(stderr,
551  "The image x_resolution cannot write such size characters\n");
552  fprintf(stderr,
553  "Please reduce the font size or enlarge x_resolution and run "
554  "again\n");
555  exit(0);
556  }
557  if (num_img == 1) {
558  xd = (scr_area[1] - scr_area[0]) / (vr->xr - (start_x + 10));
559  yd = (scr_area[3] - scr_area[2]) / (vr->yr - 20);
560  } else if (num_img > 1) {
561  xd = (m_scr[1] - m_scr[0]) / (vr->xr - (start_x + 10));
562  yd = (m_scr[3] - m_scr[2]) / (vr->yr - 20);
563  }
564 
565  if (xd >= yd) {
566  yd = xd;
567  if (num_img == 1)
568  vr->yr =
569  (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
570  10;
571  else if (num_img > 1)
572  vr->yr =
573  (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
574  } else if (xd < yd) {
575  xd = yd;
576  if (num_img == 1)
577  vr->xr =
578  (int)((int)(start_x + 10 + (scr_area[1] - scr_area[0]) / xd) /
579  8) *
580  8 +
581  8;
582  else if (num_img > 1)
583  vr->xr =
584  (int)((int)(start_x + 10 + (m_scr[1] - m_scr[0]) / xd) / 8) *
585  8 +
586  8;
587  }
588  }
589  }
590  if (ii > 0) {
591  start_x -= base_x;
592  start_y -= base_y;
593  }
594  if (num_img > 1) {
595  base_x = (int)((scr_area[0] - m_scr[0]) / xd);
596  base_y = (int)((scr_area[2] - m_scr[2]) / yd);
597 
598  start_x += base_x;
599  start_y += base_y;
600  }
601  /* find the subimage range for this PE */
602  transform_range_vertex(range, svertex);
603  /* output_frame(vr, view_point, n_vertex, scr_area, xd, yd);
604  */
605  transform_frame(vr->screen_point, svertex, coff_matrix, sn_vertex);
606  find_projection_range(view_point, sn_vertex, sscr_area);
607  /* starti=(int)((sscr_area[0]-scr_area[0]+EPSILON)/xd);
608 endi=(int)((sscr_area[1]-scr_area[0]-EPSILON)/xd)+1;
609 startj=(int)((sscr_area[2]-scr_area[2]+EPSILON)/yd);
610 endj=(int)((sscr_area[3]-scr_area[2]-EPSILON)/yd)+1;
611 if(starti<0) starti=0;
612 if(startj<0) startj=0;
613 if(endi>vr->xr) endi=vr->xr;
614 if(endj>vr->yr) endj=vr->yr;
615  */
616  starti = (int)((sscr_area[0] - scr_area[0]) / xd) + start_x - 1;
617  endi = (int)((sscr_area[1] - scr_area[0]) / xd) + start_x + 1;
618  startj = (int)((sscr_area[2] - scr_area[2]) / yd) + start_y - 1;
619  endj = (int)((sscr_area[3] - scr_area[2]) / yd) + start_y + 1;
620 
621  HECMW_Barrier(VIS_COMM);
622  grad_minmax[0] = 1.0E17;
623  grad_minmax[1] = -1.0E17;
624  if (vr->transfer_function_style == 2) {
625  /* find_grad_minmax(vr, grad_var, nx, ny, nz, grad_minmax);
626  HECMW_Barrier(VIS_COMM);
627  HECMW_Allreduce(&grad_minmax[0], &tgrad_minmax[0], 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
628  HECMW_Allreduce(&grad_minmax[1], &tgrad_minmax[1], 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
629  grad_minmax[0]=tgrad_minmax[0]; grad_minmax[1]=tgrad_minmax[1];
630  */ }
631  feap_minmax[0] = 1.0E17;
632  feap_minmax[1] = -1.0E17;
633  if (vr->transfer_function_style == 3) {
635  tmincolor, tmaxcolor, feap_minmax);
636  HECMW_Barrier(VIS_COMM);
637  HECMW_Allreduce(&feap_minmax[0], &tfeap_minmax[0], 1,
638  HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
639  HECMW_Allreduce(&feap_minmax[1], &tfeap_minmax[1], 1,
640  HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
641  feap_minmax[0] = tfeap_minmax[0];
642  feap_minmax[1] = tfeap_minmax[1];
643  }
644  feai_minmax[0] = 1.0E17;
645  feai_minmax[1] = -1.0E17;
646  if (vr->transfer_function_style == 4) {
647  /* find_feai_minmax(num_of_features, fea_point,
648  tmincolor, tmaxcolor, feai_minmax);
649  HECMW_Barrier(VIS_COMM);
650  HECMW_Allreduce(&feai_minmax[0], &tfeai_minmax[0], 1, HECMW_DOUBLE,
651  HECMW_MIN, VIS_COMM);
652  HECMW_Allreduce(&feai_minmax[1], &tfeai_minmax[1], 1, HECMW_DOUBLE,
653  HECMW_MAX, VIS_COMM);
654  feai_minmax[0]=tfeai_minmax[0]; feai_minmax[1]=tfeai_minmax[1];
655  */
656  }
657  dis_minmax[0] = 1.0E17;
658  dis_minmax[1] = -1.0E17;
659  if ((vr->transfer_function_style == 5) ||
660  (vr->transfer_function_style == 6))
661  find_dis_minmax(vr->view_point_d, vertex, dis_minmax);
662  /* HECMW_Allreduce(&dis_minmax[0], &dis_minmax[0],
663  1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
664  if(time_step==0) {
665 
666  if(transfer_function_style==7) {
667  opa_table=(double *)HECMW_calloc(256, sizeof(double));
668  if(opa_table==NULL) {
669  fprintf(stderr, " There is no enough memory:
670  opa_table\n");
671  exit(0);
672  }
673  if(mynode==0)
674  read_lookup_table(name_lookup, opa_table);
675  HECMW_Bcast(opa_table, 256, HECMW_DOUBLE, 0, VIS_COMM);
676  }
677 
678  } */
679  /*if(time_step==0) {
680  num_refine=1;
681  for(i=0;i<vd->leveltot;i++)
682  num_refine*=2;
683  */
684  av_length = sqrt(SQR(voxel_dxyz[mynode * 3] / nx) +
685  SQR(voxel_dxyz[mynode * 3 + 1] / ny) +
686  SQR(voxel_dxyz[mynode * 3 + 2] / nz));
687 
688  HECMW_Barrier(VIS_COMM);
689  if (pesize > 1)
690  HECMW_Allreduce(&av_length, &tav_length, 1,
691  HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
692  else
693  tav_length = av_length;
694 
695  /* Build hierarchical tree*/
696  image = (double *)HECMW_calloc(vr->xr * vr->yr * 3,
697  sizeof(double));
698  if (image == NULL) HECMW_vis_memory_exit("image");
699  accum_opa = (double *)HECMW_calloc(vr->xr * vr->yr,
700  sizeof(double));
701  if (accum_opa == NULL)
702  HECMW_vis_memory_exit("accum_opa");
703  /*}
704  */
705  /*---------new change for vec ---------*/
706  for (j = 0; j < vr->yr * vr->xr * 3; j++)
707  image[j] = 0.0;
708  for (j = 0; j < vr->yr * vr->xr; j++)
709  accum_opa[j] = 0.0;
710 
711  HECMW_Barrier(VIS_COMM);
712  t3 = HECMW_Wtime();
713  if (mynode == 0) {
714  fprintf(stderr,
715  "The time for preprocessing of pvr is %lf, "
716  "the total time up to now is %lf\n",
717  t3 - t2, t3 - t1);
718  t2 = t3;
719  }
720  find_inverse_matrix(coff_matrix, inv_matrix);
721  for (i = 0; i < 3; i++) {
722  r_level[i] = level[mynode * 3 + i];
723  dxyz[i] = voxel_dxyz[mynode * 3 + i];
724  r_dxyz[i] = dxyz[i] / r_level[i];
725  orig_xyz[i] = voxel_orig_xyz[mynode * 3 + i];
726  }
727  /* fprintf(stderr, "projection range is %d %d %d %d",
728  * starti, endi, startj, endj);
729  */
730  mincolor = tmincolor;
731  maxcolor = tmaxcolor;
732  if (vr->color_mapping_style == 2) {
733  mincolor = vr->interval_point[0];
734  maxcolor = vr->interval_point[1];
735  }
736  if (vr->color_mapping_style == 3) {
737  mincolor = vr->interval_point[0];
738  maxcolor =
740  }
741 
742  for (j = startj; j < endj; j++)
743  for (i = starti; i < endi; i++) {
744  /* for(j=0;j<yr;j++)
745  for(i=0;i<vr;i++) {
746 
747  */
748  /* for Multi-PEs, first must judge whether it is
749  within the PE projection range
750 
751  */
752  x = xd * (i - start_x + 0.5) + scr_area[0];
753  y = yd * (j - start_y + 0.5) + scr_area[2];
754  /*transform to the original frame */
755  point_s[0] = x;
756  point_s[1] = y;
757  point_s[2] = 0.0;
758  tranverse_transform(vr->screen_point, point_s,
759  inv_matrix, point_o);
760  /*find the first intersected voxel*/
761  for (m = 0; m < 3; m++)
762  ray_direction[m] =
763  point_o[m] - vr->view_point_d[m];
764  /* new---here----to remove the overlap pixel
765  * computation */
766  trace_flag = 1;
767  if (fabs(ray_direction[0]) < EPSILON) {
768  if (fabs(orig_xyz[0] + dxyz[0] -
769  vr->view_point_d[0]) < EPSILON) {
770  trace_flag = 0;
771  }
772  } else if (fabs(ray_direction[1]) < EPSILON) {
773  if (fabs(orig_xyz[1] + dxyz[1] -
774  vr->view_point_d[1]) < EPSILON) {
775  trace_flag = 0;
776  }
777  } else if (fabs(ray_direction[2]) < EPSILON) {
778  if (fabs(orig_xyz[2] + dxyz[2] -
779  vr->view_point_d[2]) < EPSILON) {
780  trace_flag = 0;
781  }
782  }
783  if (trace_flag == 1) {
784  nn = sqrt(SQR(ray_direction[0]) +
785  SQR(ray_direction[1]) +
786  SQR(ray_direction[2]));
787  if (fabs(nn) > EPSILON) {
788  for (m = 0; m < 3; m++) ray_direction[m] /= nn;
789  }
790  /*
791  intersection=find_first_inter(point_o, vr, vd, root_tree, &voxel_p,
792  ray_direction, first_p);
793  if(intersection==1) {
794  int connect[8][6];
795  ray_trace(vr, vd, root_tree, voxel_p, first_p, ray_direction,
796  tmincolor, tmaxcolor, connect,
797  local_face, accum_rgba, grad_minmax, feap_minmax, feai_minmax,
798  dis_minmax,
799  opa_table, tav_length,time_step);
800  */
801  intersection = find_first_inter(
802  point_o, vr->view_point_d, r_level, orig_xyz,
803  dxyz, r_dxyz, ray_direction, first_p,
804  first_ijk);
805  if (intersection == 1) {
806  ray_trace(
810  vr->num_of_features, vr->fea_point,
813  vr->light_point, vr->k_ads, orig_xyz, dxyz,
814  r_dxyz, r_level, empty_flag, var, grad_var,
815  first_p, first_ijk, ray_direction, mincolor,
816  maxcolor, accum_rgba, grad_minmax,
817  feap_minmax, feai_minmax, dis_minmax,
818  opa_table, tav_length, time_step, i, j);
819 
820  for (m = 0; m < 3; m++)
821  image[(j * vr->xr + i) * 3 + m] =
822  accum_rgba[m];
823  accum_opa[j * vr->xr + i] = accum_rgba[3];
824  }
825  }
826  }
827 
828  HECMW_Barrier(VIS_COMM);
829  if (mynode == 0) {
830  fprintf(stderr, "Finish the computing on each PE\n");
831  t3 = HECMW_Wtime();
832  fprintf(stderr,
833  "The volume rendering on each PE is %lf the "
834  "total time up to now is %lf\n",
835  t3 - t2, t3 - t1);
836  t2 = t3;
837  }
838 
839  if (pesize > 1) {
840  pix_num = (int)(vr->xr * vr->yr / pesize);
841  pix0_num = vr->xr * vr->yr - pix_num * (pesize - 1);
842  if (mynode == 0) pixn = pix0_num;
843  if (mynode != 0) pixn = pix_num;
844  n_subimage = (double *)HECMW_calloc(pesize * pixn * 3,
845  sizeof(double));
846  n_subopa = (double *)HECMW_calloc(pesize * pixn,
847  sizeof(double));
848  if ((n_subimage == NULL) || (n_subopa == NULL))
849  HECMW_vis_memory_exit("n_subimage, n_subopa");
850 
851  for (j = 0; j < pixn * 3; j++) {
852  if (mynode == 0)
853  n_subimage[j] = image[j];
854  else if (mynode != 0)
855  n_subimage[mynode * pixn * 3 + j] =
856  image[pix0_num * 3 +
857  (mynode - 1) * pix_num * 3 + j];
858  }
859  if (mynode == 0)
860  for (j = 0; j < pixn; j++)
861  n_subopa[j] = accum_opa[j];
862  else if (mynode != 0)
863  for (j = 0; j < pixn; j++)
864  n_subopa[mynode * pixn + j] =
865  accum_opa[pix0_num + (mynode - 1) * pix_num +
866  j];
867 
868  subimage =
869  (double *)HECMW_calloc(pixn * 3, sizeof(double));
870  subopa = (double *)HECMW_calloc(pixn, sizeof(double));
871  if ((subimage == NULL) || (subopa == NULL))
872  HECMW_vis_memory_exit("subimage, subopa");
873  HECMW_Barrier(VIS_COMM);
874 
875  for (i = 0; i < pesize; i++) {
876  if (mynode == i) {
877  /* fprintf(stderr, "in
878  * PE=%d \n", mynode);
879  */
880  for (k = 0; k < pesize; k++) {
881  if (k != i) {
882  if (k == 0) {
883  subimage1 = (double *)HECMW_calloc(
884  pix0_num * 3, sizeof(double));
885  subopa1 = (double *)HECMW_calloc(
886  pix0_num, sizeof(double));
887  } else if (k != 0) {
888  subimage1 = (double *)HECMW_calloc(
889  pix_num * 3, sizeof(double));
890  subopa1 = (double *)HECMW_calloc(
891  pix_num, sizeof(double));
892  }
893 
894  if ((subimage1 == NULL) || (subopa1 == NULL))
895  HECMW_vis_memory_exit("subimage1, subopa1");
896  if (k == 0) {
897  for (j = 0; j < pix0_num * 3; j++)
898  subimage1[j] = image[j];
899  for (j = 0; j < pix0_num; j++)
900  subopa1[j] = accum_opa[j];
901  } else if (k != 0) {
902  for (j = 0; j < pix_num * 3; j++)
903  subimage1[j] =
904  image[pix0_num * 3 +
905  (k - 1) * pix_num * 3 + j];
906  for (j = 0; j < pix_num; j++)
907  subopa1[j] =
908  accum_opa[pix0_num +
909  (k - 1) * pix_num + j];
910  }
911  if (k == 0) {
912  HECMW_Send(subimage1, pix0_num * 3,
913  HECMW_DOUBLE, k, 0, VIS_COMM);
914  HECMW_Send(subopa1, pix0_num, HECMW_DOUBLE,
915  k, 0, VIS_COMM);
916  } else if (k != 0) {
917  HECMW_Send(subimage1, pix_num * 3,
918  HECMW_DOUBLE, k, 0, VIS_COMM);
919  HECMW_Send(subopa1, pix_num, HECMW_DOUBLE,
920  k, 0, VIS_COMM);
921  }
922 
923  HECMW_free(subimage1);
924  HECMW_free(subopa1);
925  } /*if k!=i */
926  } /*loop k*/
927  }
928  if (mynode != i) {
929  HECMW_Recv(subimage, pixn * 3, HECMW_DOUBLE, i,
930  HECMW_ANY_TAG, VIS_COMM, &stat);
931  HECMW_Recv(subopa, pixn, HECMW_DOUBLE, i,
932  HECMW_ANY_TAG, VIS_COMM, &stat);
933  for (j = 0; j < pixn * 3; j++)
934  n_subimage[i * pixn * 3 + j] = subimage[j];
935  for (j = 0; j < pixn; j++)
936  n_subopa[i * pixn + j] = subopa[j];
937  }
938  HECMW_Barrier(VIS_COMM);
939  }
940 
941  /* if(time_step==0) {
942  */
943  for (i = 0; i < 3; i++)
944  center[i] = orig_xyz[i] + dxyz[i] / 2.0;
945  dis_c_v = sqrt(SQR(center[0] - vr->view_point_d[0]) +
946  SQR(center[1] - vr->view_point_d[1]) +
947  SQR(center[2] - vr->view_point_d[2]));
948  if (mynode != 0) {
949  HECMW_Send(&dis_c_v, 1, HECMW_DOUBLE, MASTER_PE, 0,
950  VIS_COMM);
951  pe_id = (int *)HECMW_calloc(pesize, sizeof(int));
952  if (pe_id == NULL) HECMW_vis_memory_exit("pe_id");
953  HECMW_Recv(pe_id, pesize, HECMW_INT, MASTER_PE,
954  HECMW_ANY_TAG, VIS_COMM, &stat);
955  }
956  if (mynode == 0) {
957  ndis_c_v =
958  (double *)HECMW_calloc(pesize, sizeof(double));
959  if (ndis_c_v == NULL)
960  HECMW_vis_memory_exit("ndis_c_v");
961  ndis_c_v[0] = dis_c_v;
962  for (i = 1; i < pesize; i++) {
963  HECMW_Recv(&dis_c_v, 1, HECMW_DOUBLE, i,
964  HECMW_ANY_TAG, VIS_COMM, &stat);
965  ndis_c_v[i] = dis_c_v;
966  }
967  pe_id = (int *)HECMW_calloc(pesize, sizeof(int));
968  if (pe_id == NULL) HECMW_vis_memory_exit("pe_id");
969  for (i = 0; i < pesize; i++) pe_id[i] = i;
970  for (i = 0; i < pesize - 1; i++)
971  for (j = i + 1; j < pesize; j++) {
972  if (ndis_c_v[i] > ndis_c_v[j]) {
973  tmpd = ndis_c_v[i];
974  ndis_c_v[i] = ndis_c_v[j];
975  ndis_c_v[j] = tmpd;
976  tmpi = pe_id[i];
977  pe_id[i] = pe_id[j];
978  pe_id[j] = tmpi;
979  }
980  }
981  for (i = 1; i < pesize; i++)
982  HECMW_Send(pe_id, pesize, HECMW_INT, i, 0,
983  VIS_COMM);
984  }
985  /* }
986  */
987 
988  composite_subimage_vr(pesize, pe_id, pixn, n_subimage,
989  n_subopa, subimage);
990  HECMW_free(n_subimage);
991  HECMW_free(n_subopa);
992  HECMW_free(subopa);
993  /*send subimage to master PE */
994  if (mynode != 0)
995  HECMW_Send(subimage, pixn * 3, HECMW_DOUBLE, 0, 0,
996  VIS_COMM);
997  if (mynode == 0) {
998  for (j = 0; j < pix0_num * 3; j++)
999  image[j] = subimage[j];
1000  for (i = 1; i < pesize; i++) {
1001  HECMW_Recv(subimage, pix_num * 3, HECMW_DOUBLE, i,
1002  HECMW_ANY_TAG, VIS_COMM, &stat);
1003  for (j = 0; j < pix_num * 3; j++)
1004  image[pix0_num * 3 + (i - 1) * pix_num * 3 +
1005  j] = subimage[j];
1006  }
1007  }
1008  HECMW_free(subimage);
1009  }
1010  if (mynode == 0) {
1011  fprintf(stderr, " Finish combining \n");
1012  t3 = HECMW_Wtime();
1013  fprintf(stderr,
1014  "The combining time is %lf the total time up "
1015  "to now is %lf\n",
1016  t3 - t2, t3 - t1);
1017  t2 = t3;
1018  if (vr->fixed_scale_mark == 1)
1020  vr->scale_marking_on, vr->font_size,
1021  vr->color_bar_style, vr->mark_0_on,
1022  vr->color_mapping_bar_on, vr->xr, vr->yr,
1023  vr->font_color, vr->color_system_type,
1026  tmincolor, tmaxcolor, tmincolor, tmaxcolor,
1027  image);
1028  else if (vr->fixed_scale_mark == 0)
1030  vr->scale_marking_on, vr->font_size,
1031  vr->color_bar_style, vr->mark_0_on,
1032  vr->color_mapping_bar_on, vr->xr, vr->yr,
1033  vr->font_color, vr->color_system_type,
1036  tmincolor, tmaxcolor, org_mincolor,
1037  org_maxcolor, image);
1038 
1039  /* outfile1[0] = '\0';
1040  j=0;
1041  while (outfile[j] == ' ')
1042  j++;
1043  k = 0;
1044  while (outfile[j] != ' ') {
1045  outfile1[k] = outfile[j];
1046  k++;
1047  j++;
1048  }
1049 
1050  outfile1[k] = '\0';
1051 
1052  snprintf(fname, sizeof(fname), "%s.%d.%d.bmp", outfile1, *timestep, ii);
1053  */
1054  if (*timestep >= 1000)
1055  snprintf(timestep_str, sizeof(timestep_str), "%d", *timestep);
1056  else if (*timestep >= 100)
1057  snprintf(timestep_str, sizeof(timestep_str), "0%d", *timestep);
1058  else if (*timestep >= 10)
1059  snprintf(timestep_str, sizeof(timestep_str), "00%d", *timestep);
1060  else
1061  snprintf(timestep_str, sizeof(timestep_str), "000%d", *timestep);
1062  if (ii >= 10)
1063  snprintf(rotate_str, sizeof(rotate_str), "%d", ii);
1064  else
1065  snprintf(rotate_str, sizeof(rotate_str), "0%d", ii);
1066  snprintf(fname, sizeof(fname), "%s.%s.%s.bmp", outfile, timestep_str,
1067  rotate_str);
1068 
1069  FP = fopen(fname, "wb");
1070 
1071  if (!FP)
1073  "ERROR: HEC-MW-VIS-E0009: Cannot open output "
1074  "file");
1075 
1076  header.bfSize = 54 + 3 * vr->xr * vr->yr;
1077 #ifdef CONVERSE_ORDER
1079  54 + 3 * vr->xr * vr->yr);
1080 #endif
1081  header.bfReserved1 = 0;
1082 #ifdef CONVERSE_ORDER
1083  header.bfReserved1 = change_short_int_order(0);
1084 #endif
1085 
1086  header.bfReserved2 = 0;
1087 #ifdef CONVERSE_ORDER
1088  header.bfReserved2 = change_short_int_order(0);
1089 #endif
1090 
1091  header.bfOffBits = 54;
1092 #ifdef CONVERSE_ORDER
1093  header.bfOffBits = change_unsigned_int_order(54);
1094 #endif
1095 
1096  info.biBitCount = 24;
1097 #ifdef CONVERSE_ORDER
1099 #endif
1100 
1101  info.biSize = 40;
1102 #ifdef CONVERSE_ORDER
1103  info.biSize = change_unsigned_int_order(40);
1104 #endif
1105 
1106  info.biWidth = vr->xr;
1107 #ifdef CONVERSE_ORDER
1108  info.biWidth = change_int_order(vr->xr);
1109 #endif
1110 
1111  info.biHeight = vr->yr;
1112 #ifdef CONVERSE_ORDER
1113  info.biHeight = change_int_order(vr->yr);
1114 #endif
1115 
1116  info.biSizeImage = 3 * vr->xr * vr->yr;
1117 #ifdef CONVERSE_ORDER
1118  info.biSizeImage =
1119  change_unsigned_int_order(3 * vr->xr * vr->yr);
1120 #endif
1121 
1122  info.biClrImportant = 0;
1123 #ifdef CONVERSE_ORDER
1125 #endif
1126 
1127  info.biClrUsed = 0;
1128 #ifdef CONVERSE_ORDER
1130 #endif
1131 
1132  info.biCompression = 0;
1133 #ifdef CONVERSE_ORDER
1135 #endif
1136 
1137  info.biPlanes = 1;
1138 #ifdef CONVERSE_ORDER
1139  info.biPlanes = change_short_int_order(1);
1140 #endif
1141 
1142  info.biXPelsPerMeter = 3780;
1143 #ifdef CONVERSE_ORDER
1144  info.biXPelsPerMeter = change_int_order(3780);
1145 #endif
1146 
1147  info.biYPelsPerMeter = 3780;
1148 #ifdef CONVERSE_ORDER
1149  info.biYPelsPerMeter = change_int_order(3780);
1150 #endif
1151 
1152  putc('B', FP);
1153  putc('M', FP);
1154  fwrite(&(header.bfSize), sizeof(unsigned int), 1, FP);
1155  fwrite(&header.bfReserved1,
1156  sizeof(unsigned short int), 1, FP);
1157  fwrite(&header.bfReserved2,
1158  sizeof(unsigned short int), 1, FP);
1159  fwrite(&header.bfOffBits, sizeof(unsigned int), 1,
1160  FP);
1161  fwrite(&info, 40, 1, FP);
1162  for (j = 0; j < vr->yr; j++)
1163  for (i = vr->xr - 1; i >= 0; i--) {
1164  if ((image[(j * vr->xr + i) * 3] < 0.1) &&
1165  (image[(j * vr->xr + i) * 3 + 1] < 0.1) &&
1166  (image[(j * vr->xr + i) * 3 + 2] < 0.1)) {
1167  ri = (int)(vr->background_color[0] * 256);
1168  gi = (int)(vr->background_color[1] * 256);
1169  bi = (int)(vr->background_color[2] * 256);
1170  } else {
1171  ri = (int)(image[(j * vr->xr + i) * 3] * 256);
1172  gi = (int)(image[(j * vr->xr + i) * 3 + 1] *
1173  256);
1174  bi = (int)(image[(j * vr->xr + i) * 3 + 2] *
1175  256);
1176  }
1177  if (ri < 0) ri = 0;
1178  if (ri > 255) ri = 255;
1179  if (gi < 0) gi = 0;
1180  if (gi > 255) gi = 255;
1181  if (bi < 0) bi = 0;
1182  if (bi > 255) bi = 255;
1183  r = ri;
1184  g = gi;
1185  b = bi;
1186  putc(b, FP);
1187  putc(g, FP);
1188  putc(r, FP);
1189  }
1190 
1191  fclose(FP);
1192  }
1193  }
1194  HECMW_free(var);
1195 #ifdef slow
1196  HECMW_free(grad_var);
1197 #endif
1198  HECMW_free(empty_flag);
1199  HECMW_free(image);
1200  HECMW_free(accum_opa);
1201  if (num_of_pvr > 1) {
1204  HECMW_free(level);
1207  HECMW_free(extent);
1208  }
1209  if (mynode == 0) {
1210  fprintf(stderr, " Finish the module\n");
1211  t3 = HECMW_Wtime();
1212  fprintf(stderr,
1213  " the time for output is %lf the total time of the module is %lf\n",
1214  t3 - t2, t3 - t1);
1215  }
1216  return;
1217 }
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
int HECMW_Allreduce(void *sendbuf, void *recvbuf, int count, HECMW_Datatype datatype, HECMW_Op op, HECMW_Comm comm)
Definition: hecmw_comm.c:404
int HECMW_Send(void *buffer, int count, HECMW_Datatype datatype, int dest, int tag, HECMW_Comm comm)
Definition: hecmw_comm.c:201
int HECMW_Barrier(HECMW_Comm comm)
Definition: hecmw_comm.c:95
int HECMW_Recv(void *buffer, int count, HECMW_Datatype datatype, int source, int tag, HECMW_Comm comm, HECMW_Status *status)
Definition: hecmw_comm.c:251
#define HECMW_INT
Definition: hecmw_config.h:48
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:87
#define HECMW_MAX
Definition: hecmw_config.h:58
MPI_Status HECMW_Status
Definition: hecmw_config.h:36
#define HECMW_DOUBLE
Definition: hecmw_config.h:50
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
#define HECMW_MIN
Definition: hecmw_config.h:56
if(!(yy_init))
int HECMW_ANY_TAG
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
#define NULL
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define MASTER_PE
Definition: hecmw_repart.h:17
double HECMW_Wtime(void)
Definition: hecmw_time.c:8
#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 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 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])
int change_int_order(int n)
unsigned short int change_short_int_order(unsigned short int n)
void generate_color_bar(int scale_marking_on, double font_size, int color_bar_style, int mark_0_on, int color_mapping_bar_on, int xr, int yr, double font_color[3], int color_system_type, int color_mapping_style, double *interval_point, int interval_mapping_num, int num_of_scale, double tmincolor, double tmaxcolor, double org_mincolor, double org_maxcolor, double *image)
unsigned int change_unsigned_int_order(unsigned int n)
void generate_interval_point_vr(double tmincolor, double tmaxcolor, double *var, int *empty_flag, int nx, int ny, int nz, int mynode, int pesize, HECMW_Comm VIS_COMM, double *interval_point)
void find_color_minmax_vr(double *var, int *empty_flag, int nx, int ny, int nz, double *mincolor, double *maxcolor)
void find_dis_minmax(double view_point_d[3], double vertex[24], double dis_minmax[2])
void find_feap_minmax(int num_of_features, double *fea_point, double mincolor, double maxcolor, double feap_minmax[2])
void output_histogram_vr(double tmincolor, double tmaxcolor, double *var, int *empty_flag, int nx, int ny, int nz, int mynode, int pesize, HECMW_Comm VIS_COMM)
void generate_histogram_graph_vr(double tmincolor, double tmaxcolor, double *var, int *empty_flag, int nx, int ny, int nz, int mynode, int pesize, HECMW_Comm VIS_COMM, int color_system_type)
void find_minmax_vr(double *voxel_dxyz, double *voxel_orig_xyz, int mynode, double range[6])
void HECMW_vis_print_exit(char *var)
void HECMW_vis_memory_exit(char *var)
int calc_voxel_level(int n_voxel, struct hecmwST_local_mesh *mesh, double *voxel_dxyz, double *voxel_orig_xyz, double *extent, int *level, HECMW_Comm VIS_COMM)
int calc_extent(struct hecmwST_local_mesh *mesh, double *extent)
void refinement(struct hecmwST_local_mesh *mesh, double *node1, int n_voxel, double *voxel_dxyz, double *voxel_orig_xyz, int *level, int *voxel_n_neighbor_pe, int **voxel_neighbor_pe, double *extent, int my_rank, HECMW_Comm VIS_COMM, int *empty_flag, double *var)
#define SQR(x)
int ** voxel_neighbor_pe
int * voxel_n_neighbor_pe
void HECMW_vis_pvr_rendering(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int *timestep, int *init_flag, int num_of_pvr, Parameter_vr *vr, int stat_para[NUM_CONTROL_PVR], char *outfile, HECMW_Comm VIS_COMM)
double * voxel_dxyz
double * extent
double * voxel_orig_xyz
int * level
int find_first_inter(double point_o[3], double view_point_d[3], int r_level[3], double orig_xyz[3], double dxyz[3], double r_dxyz[3], double ray_direction[3], double first_p[3], int ijk[3])
void ray_trace(int remove_0_display_on, int color_mapping_style, double *interval_point, int transfer_function_style, double opa_value, int num_of_features, double *fea_point, double view_point_d[3], int interval_mapping_num, int color_system_type, int num_of_lights, double *light_point, double k_ads[3], double orig_xyz[3], double dxyz[3], double r_dxyz[3], int r_level[3], int *empty_flag, double *var, double *grad_var, double first_p[3], int first_ijk[3], double ray_direction[3], double mincolor, double maxcolor, double accum_rgba[4], double grad_minmax[2], double feap_minmax[2], double feai_minmax[2], double dis_minmax[2], double *opa_table, double tav_length, int time_step, int test_i, int test_j)
#define NUM_CONTROL_PVR
int read_voxel_file(char *filename, int n_voxel, double *voxel_dxyz, double *voxel_orig_xyz, int *level, int *voxel_n_neighbor_pe, int **voxel_neighbor_pe)
double * image
void composite_subimage_vr(int pesize, int *pe_id, int pixn, double *n_subimage, double *n_subopa, double *subimage)
void transform_ucd_pvr(struct hecmwST_result_data *data, double *node1, struct hecmwST_local_mesh *mesh, Parameter_vr *vr, int my_rank, int pe_size, HECMW_Comm VIS_COMM, double *voxel_dxyz, double *voxel_orig_xyz, int *level, int *voxel_n_neighbor_pe, int **voxel_neighbor_pe, int voxel_on, int display_range_on, int init_flag, int num_of_pvr)
CNFData data
unsigned short bfReserved1
Definition: hecmw_vis_bmp.h:12
unsigned short bfReserved2
Definition: hecmw_vis_bmp.h:13
unsigned int bfSize
Definition: hecmw_vis_bmp.h:11
unsigned int bfOffBits
Definition: hecmw_vis_bmp.h:14
unsigned int biCompression
Definition: hecmw_vis_bmp.h:25
unsigned int biSizeImage
Definition: hecmw_vis_bmp.h:26
unsigned short biBitCount
Definition: hecmw_vis_bmp.h:24
unsigned short biPlanes
Definition: hecmw_vis_bmp.h:23
unsigned int biClrUsed
Definition: hecmw_vis_bmp.h:29
unsigned int biSize
Definition: hecmw_vis_bmp.h:20
unsigned int biClrImportant
Definition: hecmw_vis_bmp.h:30