FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_vis_rendering.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 <stdio.h>
9#include <stdlib.h>
10#include <math.h>
11#include "hecmw_vis_bmp.h"
12#include "hecmw_vis_mem_util.h"
13#include "hecmw_vis_comm_util.h"
22#include "hecmw_malloc.h"
23
24double *image;
25int ms, ns;
26
29 struct hecmwST_local_mesh *mesh,
30 struct hecmwST_result_data *data, int tvertex,
31 int tpatch, int *color_list, double *minvalue,
32 double *maxvalue, Result *result,
33 char *outfile, int stat_para[NUM_CONTROL_PSF],
34 HECMW_Comm VIS_COMM, int timestep)
35
36{
37 char fname[128];
38 int i, j, k, m, ii, iii, m1, m2, mmm, mmm1, jjj;
39 int pesize, mynode;
40 FILE *outfp;
41 double view_n[3], nview_n, vertex[3 * 8];
42 double point_s[3], point_o[3];
43 double range[6], xd, yd;
44 double coff_matrix[3][3], n_vertex[3 * 8], inv_matrix[3][3];
45 double view_point[3], scr_area[4], x, y;
46 double tmincolor, tmaxcolor, trange[6], svertex[3 * 8], sn_vertex[3 * 8],
47 sscr_area[4];
48 int intersection;
49 double accum_rgba[4];
50 /* double *accum_opa; */
51 int pix_num, pix0_num, pixn;
52 double *n_subimage, *n_subopa, *subimage, *subopa;
53 double *subimage1, *subopa1;
54 HECMW_Status stat;
55 int starti, startj, endi, endj, start_x, start_y;
56 double minx, miny, minz, maxx, maxy, maxz, tminx, tminy, tminz, tmaxx, tmaxy,
57 tmaxz;
58 int num_img, base_x, base_y;
59 double o_v_point[3], m_scr[4];
60 double mincolor, maxcolor, *mivalue, *mavalue, color_iso[3], org_mincolor,
61 org_maxcolor;
62
63 BITMAPFILEHEADER header; /* File header */
64 unsigned char r, g, b;
65 int ri, gi, bi;
67 int scale, scale_type;
68 double *z_buffer, scr_f[4], f[3][3], n_f[3][3], inter_point[3], normal[9];
69 double value, c_value[3], depth;
70 double deltac, iso_p[6], isocolor, n_iso[6], pixel_d[2][2], slip_y;
71 double *iso_value, *iso_rgb;
72 int pixel_i[2][2], flag, tmp_i, last_j, next_j;
73 int normal_flag;
74 double *v_normal;
75 double *p_normal;
76 int *v_num;
77
78 double f_f[4], norm, v_f[9];
79 int end_timestep;
80 double start_time, time_interval;
81 int len_step;
82 double f_disp[3][3];
83 int deform_flag, count_dash_num;
84
85 HECMW_Comm_rank(VIS_COMM, &mynode);
86 HECMW_Comm_size(VIS_COMM, &pesize);
87 if (mynode == 0) {
88 /* t1=HECMW_Wtime();
89fprintf(stderr, "Start rendering patches\n");
90 */
91 }
92 /* start_time=0.0;
93time_interval=0.01;
94start_timestep=1;
95end_timestep=1000;
96 */
97 mivalue = (double *)HECMW_calloc(data->nn_component, sizeof(double));
98 mavalue = (double *)HECMW_calloc(data->nn_component, sizeof(double));
99 if ((mivalue == NULL) || (mavalue == NULL))
100 HECMW_vis_memory_exit("mivalue, mavalue");
101 if (pesize > 1) {
102 HECMW_Allreduce(minvalue, mivalue, data->nn_component, HECMW_DOUBLE,
103 HECMW_MIN, VIS_COMM);
104 HECMW_Allreduce(maxvalue, mavalue, data->nn_component, HECMW_DOUBLE,
105 HECMW_MAX, VIS_COMM);
106 } else {
107 for (i = 0; i < data->nn_component; i++) {
108 mivalue[i] = minvalue[i];
109 mavalue[i] = maxvalue[i];
110 }
111 }
112
113 for (i = 0; i < data->nn_component; i++) {
114 if (color_list[i] == 1) {
115 org_mincolor = tmincolor = mivalue[i];
116 org_maxcolor = tmaxcolor = mavalue[i];
117 if (mynode == 0)
118 fprintf(stderr,
119 "For data attribute %s, the minimum value is %lf, the maximum "
120 "value is %lf\n",
121 data->node_label[i], tmincolor, tmaxcolor);
122 if (sr->fixed_range_on == 1) {
123 mivalue[i] = sr->range_value[0];
124 mavalue[i] = sr->range_value[1];
125 tmincolor = sr->range_value[0];
126 tmaxcolor = sr->range_value[1];
127 }
128 }
129 }
130
131 if (sr->histogram_on == 1)
132 output_histogram_sf(sf, color_list, data, mivalue, mavalue, result, mynode,
133 pesize, VIS_COMM);
134 if (sr->histogram_on == 2)
135 generate_histogram_graph_sf(sf, color_list, data, mivalue, mavalue, result,
136 mynode, pesize, VIS_COMM,
138 if (sr->color_mapping_style == 4) {
139 sr->interval_mapping_num = 10;
140 sr->interval_point = (double *)HECMW_calloc(22, sizeof(double));
141 generate_interval_point_sf(sf, color_list, data, mivalue, mavalue, result,
142 mynode, pesize, VIS_COMM, sr->interval_point);
143 }
144 if (stat_para[70] == 0) {
145 if (sr->boundary_line_on == 1)
146 find_minmax_sf(mesh, mynode, range);
147 else
148 find_patch_minmax_sf(result, sf, range);
149 for (i = 0; i < 6; i++) trange[i] = 0.0;
150 minx = range[0];
151 maxx = range[1];
152 miny = range[2];
153 maxy = range[3];
154 minz = range[4];
155 maxz = range[5];
156 HECMW_Barrier(VIS_COMM);
157 if (pesize > 1) {
158 HECMW_Allreduce(&minx, &tminx, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
159
160 HECMW_Allreduce(&maxx, &tmaxx, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
161 HECMW_Allreduce(&miny, &tminy, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
162 HECMW_Allreduce(&maxy, &tmaxy, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
163 HECMW_Allreduce(&minz, &tminz, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
164 HECMW_Allreduce(&maxz, &tmaxz, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
165 } else {
166 tminx = minx;
167 tmaxx = maxx;
168 tminy = miny;
169 tmaxy = maxy;
170 tminz = minz;
171 tmaxz = maxz;
172 }
173 fprintf(stderr,
174 "trange: minx=%lf maxx=%lf miny=%lf maxy=%lf minz=%lf maxz=%lf\n",
175 tminx, tmaxx, tminy, tmaxy, tminz, tmaxz);
176 } else {
177 find_patch_minmax_sf(result, sf, range);
178
179 for (i = 0; i < 6; i++) trange[i] = sr->fixed_mesh_range[i];
180 tminx = trange[0];
181 tmaxx = trange[1];
182 tminy = trange[2];
183 tmaxy = trange[3];
184 tminz = trange[4];
185 tmaxz = trange[5];
186
187 fprintf(stderr,
188 "Fixed range is used for dynamic dataset: minx=%lf maxx=%lf "
189 "miny=%lf maxy=%lf minz=%lf maxz=%lf\n",
190 tminx, tmaxx, tminy, tmaxy, tminz, tmaxz);
191 }
192 deform_flag = 0;
193 for (iii = 0; iii < sf[0].surface_style; iii++) {
194 if (sf[iii + 1].deform_display_on == 1) {
195 if (stat_para[69] == 0)
196 get_deform_scale(sf, iii + 1, tmaxx - tminx, tmaxy - tminy,
197 tmaxz - tminz, mesh, data, pesize, VIS_COMM);
198 else
199 sf[iii + 1].disp_scale = sf[iii + 1].real_disp_scale;
200 deform_flag = 1;
201 }
202 }
203 if (deform_flag == 1) {
204 find_new_patch_minmax_sf(result, sf, range);
205 if (stat_para[70] == 0) {
206 for (i = 0; i < 6; i++) trange[i] = 0.0;
207 minx = range[0];
208 maxx = range[1];
209 miny = range[2];
210 maxy = range[3];
211 minz = range[4];
212 maxz = range[5];
213 HECMW_Barrier(VIS_COMM);
214 if (pesize > 1) {
215 HECMW_Allreduce(&minx, &tminx, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
216
217 HECMW_Allreduce(&maxx, &tmaxx, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
218 HECMW_Allreduce(&miny, &tminy, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
219 HECMW_Allreduce(&maxy, &tmaxy, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
220 HECMW_Allreduce(&minz, &tminz, 1, HECMW_DOUBLE, HECMW_MIN, VIS_COMM);
221 HECMW_Allreduce(&maxz, &tmaxz, 1, HECMW_DOUBLE, HECMW_MAX, VIS_COMM);
222 } else {
223 tminx = minx;
224 tmaxx = maxx;
225 tminy = miny;
226 tmaxy = maxy;
227 tminz = minz;
228 tmaxz = maxz;
229 }
230 }
231 }
232
233 if (stat_para[26] == 0) {
234 sr->light_point = (double *)HECMW_calloc(3, sizeof(double));
235 if (sr->light_point == NULL) HECMW_vis_memory_exit("sr: light_point");
236
237 sr->light_point[0] = (tminx + tmaxx) / 2.0;
238 sr->light_point[1] = tmaxy + 0.1 * (tmaxy - tminy);
239 sr->light_point[2] = tmaxz + (tmaxz - tminz) * 2.0;
240 }
241 if (stat_para[27] == 0) {
242 sr->view_point_d[0] = (tminx + tmaxx) / 2.0;
243 sr->view_point_d[1] = tmaxy + 1.5 * (tmaxy - tminy);
244 sr->view_point_d[2] = tmaxz + 1.5 * (tmaxz - tminz);
245 }
246 if (stat_para[28] == 0) {
247 sr->screen_point[0] = (tminx + tmaxx) / 2.0;
248 sr->screen_point[1] = (tminy + tmaxy) / 2.0;
249 sr->screen_point[2] = (tminz + tmaxz) / 2.0;
250 }
251
252 trange[0] = tminx;
253 trange[1] = tmaxx;
254 trange[2] = tminy;
255 trange[3] = tmaxy;
256 trange[4] = tminz;
257 trange[5] = tmaxz;
258
259 HECMW_Barrier(VIS_COMM);
260 /*----------------------------------------
261Define the sampling and projection parameters
262 */
263 /* First, define the equation of screen */
264 if (mesh->elem_type[0] < 300) {
265 sr->up[0] = 0.0;
266 sr->up[1] = 1.0;
267 sr->up[2] = 0.0;
268 sr->view_point_d[0] = (tminx + tmaxx) / 2.0;
269 sr->view_point_d[1] = (tminy + tmaxy) / 2.0;
270 sr->view_point_d[2] = -(tmaxx - tminx) * 1000000.0;
271 sr->screen_point[0] = sr->view_point_d[0];
272 sr->screen_point[1] = sr->view_point_d[1];
273 sr->screen_point[2] = 0.0;
274 }
275 /* if(mynode==0) {
276fprintf(stderr, "up_direction=%lf %lf %lf\n", sr->up[0], sr->up[1], sr->up[2]);
277 fprintf(stderr, "rotate_style=%d num_of_frames=%d\n", sr->rotate_style,
278sr->rotate_num_of_frames);
279}
280 */
281 if (mynode == 0) {
282 fprintf(stderr,
283 "viewpoint=%lf %lf %lf screen_point=%lf %lf %lfup=%lf %lf %lf\n",
284 sr->view_point_d[0], sr->view_point_d[1], sr->view_point_d[2],
285 sr->screen_point[0], sr->screen_point[1], sr->screen_point[2],
286 sr->up[0], sr->up[1], sr->up[2]);
287 fprintf(stderr, "rotate_style=%d num_of_frames=%d\n", sr->rotate_style,
289 }
290 if (sr->rotate_style == 0)
291 num_img = 1;
292 else if ((sr->rotate_style >= 1) && (sr->rotate_style <= 4)) {
293 num_img = sr->rotate_num_of_frames;
294 for (i = 0; i < 3; i++)
295 sr->screen_point[i] = (trange[i * 2] + trange[i * 2 + 1]) / 2.0;
296 /*find the range of projection */
297 for (i = 0; i < 3; i++) o_v_point[i] = sr->view_point_d[i];
298 m_scr[0] = m_scr[2] = 1.0E+17;
299 m_scr[1] = m_scr[3] = -1.0E+17;
300
301 for (ii = 0; ii < num_img; ii++) {
302 /* if(ii!=0)
303 */
306 sr->screen_point, sr->num_of_lights, sr->light_point, sr->up, trange);
307 for (i = 0; i < 3; i++)
308 view_n[i] = sr->screen_point[i] - sr->view_point_d[i];
309 nview_n = sqrt(SQR(view_n[0]) + SQR(view_n[1]) + SQR(view_n[2]));
310 if (fabs(nview_n) > EPSILON)
311 for (i = 0; i < 3; i++) view_n[i] /= nview_n;
312 transform_range_vertex(trange, vertex);
313
315 coff_matrix);
316 transform_frame(sr->screen_point, vertex, coff_matrix, n_vertex);
317 for (i = 0; i < 3; i++)
318 view_point[i] = sr->view_point_d[i] - sr->screen_point[i];
319 transform2_frame(coff_matrix, view_point);
320 find_projection_range(view_point, n_vertex, scr_area);
321 if (scr_area[0] < m_scr[0]) m_scr[0] = scr_area[0];
322 if (scr_area[1] > m_scr[1]) m_scr[1] = scr_area[1];
323 if (scr_area[2] < m_scr[2]) m_scr[2] = scr_area[2];
324 if (scr_area[3] > m_scr[3]) m_scr[3] = scr_area[3];
325 }
326
327 for (i = 0; i < 3; i++) sr->view_point_d[i] = o_v_point[i];
328 }
329
330 for (ii = 0; ii < num_img; ii++) {
331 /* if(ii!=0)
332 */
333 if (num_img > 1)
334 if (mynode == 0) {
335 fprintf(stderr, "Start rendering rotation frame %d\n", ii);
336 fprintf(
337 stderr,
338 "viewpoint=%lf %lf %lf screen_point=%lf %lf %lf up=%lf %lf %lf\n",
339 sr->view_point_d[0], sr->view_point_d[1], sr->view_point_d[2],
340 sr->screen_point[0], sr->screen_point[1], sr->screen_point[2],
341 sr->up[0], sr->up[1], sr->up[2]);
342 fprintf(stderr, "rotate_style=%d num_of_frames=%d\n", sr->rotate_style,
344 }
345 if (sr->rotate_style > 0)
347 sr->view_point_d, sr->screen_point, sr->up,
348 sr->num_of_lights, sr->light_point, trange);
349 for (i = 0; i < 3; i++)
350 view_n[i] = sr->screen_point[i] - sr->view_point_d[i];
351 nview_n = sqrt(SQR(view_n[0]) + SQR(view_n[1]) + SQR(view_n[2]));
352 if (fabs(nview_n) > EPSILON)
353 for (i = 0; i < 3; i++) view_n[i] /= nview_n;
354 /* for(i=0;i<3;i++)
355p_screen[i]=view_n[i];
356p_screen[3]=-view_n[0]*vr->screen_point[0]-view_n[1]*vr->screen_point[1]-
357view_n[2]*vr->screen_point[2];
358 */
359
360 /* Second, find the projection of the dataset in each PE */
361 transform_range_vertex(trange, vertex);
362 if (mynode == 0)
363 fprintf(stderr, "viewpoint=%lf %lf %lf screen_point=%lf %lf %lf\n",
364 sr->view_point_d[0], sr->view_point_d[1], sr->view_point_d[2],
365 sr->screen_point[0], sr->screen_point[1], sr->screen_point[2]);
367 coff_matrix);
368 transform_frame(sr->screen_point, vertex, coff_matrix, n_vertex);
369 /* if(mynode==0){
370for(i=0;i<3;i++)
371for(j=0;j<3;j++)
372}
373 */
374 for (i = 0; i < 3; i++)
375 view_point[i] = sr->view_point_d[i] - sr->screen_point[i];
376 transform2_frame(coff_matrix, view_point);
377 find_projection_range(view_point, n_vertex, scr_area);
378 /* for multi-PEs, should find minx, maxx, miny, maxy in scr_area for all PE
379 */
380 if (ii == 0) {
381 if ((sr->color_mapping_bar_on == 0) && (sr->scale_marking_on == 0) &&
382 (sr->time_mark_on == 0)) {
383 start_x = 10;
384 start_y = 10;
385
386 if (num_img == 1) {
387 xd = (scr_area[1] - scr_area[0]) / (sr->xr - 20);
388 yd = (scr_area[3] - scr_area[2]) / (sr->yr - 20);
389 }
390 if (num_img > 1) {
391 xd = (m_scr[1] - m_scr[0]) / (sr->xr - 20);
392 yd = (m_scr[3] - m_scr[2]) / (sr->yr - 20);
393 }
394
395 if (xd >= yd) {
396 yd = xd;
397 if (num_img == 1)
398 sr->yr =
399 (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
400 10;
401 else if (num_img > 1)
402 sr->yr =
403 (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
404 }
405 if (xd < yd) {
406 xd = yd;
407
408 if (num_img == 1)
409 sr->xr =
410 (int)((int)(20 + (scr_area[1] - scr_area[0]) / xd) / 8) * 8 + 8;
411 else if (num_img > 1)
412 sr->xr = (int)((int)(20 + (m_scr[1] - m_scr[0]) / xd) / 8) * 8 + 8;
413 }
414 } else if ((sr->color_mapping_bar_on == 0) &&
415 (sr->scale_marking_on == 0) && (sr->time_mark_on == 1)) {
416 char buf3[128];
417 sprintf(buf3, "%d",
418 (int)(start_time + time_interval * (double)end_timestep));
419 len_step = strlen(buf3);
420 scale_type = 2;
421 scale = (int)sr->font_size;
422 start_x = 10;
423 start_y = 10 + 7 * scale + 5;
424 if (sr->yr < start_y + 10)
426 "The resolution for yr is not enough, please specify a larger "
427 "one");
428 if (sr->xr < start_x + (len_step + 3 + 3) * scale)
430 "The resolution for xr is not enough, please specify a larger "
431 "one ");
432 if (num_img == 1) {
433 xd = (scr_area[1] - scr_area[0]) / (sr->xr - (start_x + 10));
434 yd = (scr_area[3] - scr_area[2]) / (sr->yr - (start_y + 10));
435 } else if (num_img > 1) {
436 xd = (m_scr[1] - m_scr[0]) / (sr->xr - (start_x + 10));
437 yd = (m_scr[3] - m_scr[2]) / (sr->yr - (start_y + 10));
438 }
439 if (xd >= yd) {
440 yd = xd;
441 if (num_img == 1)
442 sr->yr =
443 (int)((int)(start_y + 10 + (scr_area[3] - scr_area[2]) / yd) /
444 10) *
445 10 +
446 10;
447 else if (num_img > 1)
448 sr->yr =
449 (int)((int)(start_y + 10 + (m_scr[3] - m_scr[2]) / yd) / 10) *
450 10 +
451 10;
452 }
453 if (xd < yd) {
454 xd = yd;
455
456 if (num_img == 1)
457 sr->xr =
458 (int)((int)(20 + (scr_area[1] - scr_area[0]) / xd) / 8) * 8 + 8;
459 else if (num_img > 1)
460 sr->xr = (int)((int)(20 + (m_scr[1] - m_scr[0]) / xd) / 8) * 8 + 8;
461 }
462 }
463
464 else if ((sr->color_mapping_bar_on == 1) && (sr->scale_marking_on == 0)) {
465 start_x = 30;
466 start_y = 10;
467 if (num_img == 1) {
468 xd = (scr_area[1] - scr_area[0]) / (sr->xr - 40);
469 yd = (scr_area[3] - scr_area[2]) / (sr->yr - 20);
470 } else if (num_img > 1) {
471 xd = (m_scr[1] - m_scr[0]) / (sr->xr - 40);
472 yd = (m_scr[3] - m_scr[2]) / (sr->yr - 20);
473 }
474
475 if (xd >= yd) {
476 yd = xd;
477 if (num_img == 1)
478 sr->yr =
479 (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
480 10;
481 else if (num_img > 1)
482 sr->yr =
483 (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
484 } else if (xd < yd) {
485 xd = yd;
486 if (num_img == 1)
487 sr->xr =
488 (int)((int)(40 + (scr_area[1] - scr_area[0]) / xd) / 8) * 8 + 8;
489 else if (num_img > 1)
490 sr->xr = (int)((int)(40 + (m_scr[1] - m_scr[0]) / xd) / 8) * 8 + 8;
491 }
492 } else if ((sr->color_mapping_bar_on == 1) &&
493 (sr->scale_marking_on == 1)) {
494 scale = (int)sr->font_size;
495 if ((sr->font_size - scale) < 0.5 - EPSILON)
496 scale_type = 1;
497 else
498 scale_type = 2;
499 if (scale_type == 1) {
500 start_x = 20 + 45 * scale;
501 if (sr->color_bar_style == 2) start_x = 20 + 45 * scale + 15;
502 } else if (scale_type == 2) {
503 start_x = 20 + 63 * scale;
504 if (sr->color_bar_style == 2) start_x = 20 + 63 * scale + 15;
505 }
506
507 start_y = 10;
508 if (sr->xr < start_x + 10) {
509 fprintf(stderr,
510 "The image x_resolution cannot write such size charaters\n");
512 "Please reduce the font size or enlarge x_resolution and run "
513 "again");
514 }
515 if (num_img == 1) {
516 xd = (scr_area[1] - scr_area[0]) / (sr->xr - (start_x + 10));
517 yd = (scr_area[3] - scr_area[2]) / (sr->yr - 20);
518 } else if (num_img > 1) {
519 xd = (m_scr[1] - m_scr[0]) / (sr->xr - (start_x + 10));
520 yd = (m_scr[3] - m_scr[2]) / (sr->yr - 20);
521 }
522
523 if (xd >= yd) {
524 yd = xd;
525 if (num_img == 1)
526 sr->yr =
527 (int)((int)(20 + (scr_area[3] - scr_area[2]) / yd) / 10) * 10 +
528 10;
529 else if (num_img > 1)
530 sr->yr =
531 (int)((int)(20 + (m_scr[3] - m_scr[2]) / yd) / 10) * 10 + 10;
532 } else if (xd < yd) {
533 xd = yd;
534 if (num_img == 1)
535 sr->xr =
536 (int)((int)(start_x + 10 + (scr_area[1] - scr_area[0]) / xd) /
537 8) *
538 8 +
539 8;
540 else if (num_img > 1)
541 sr->xr =
542 (int)((int)(start_x + 10 + (m_scr[1] - m_scr[0]) / xd) / 8) *
543 8 +
544 8;
545 }
546 }
547 }
548 if (ii > 0) {
549 start_x -= base_x;
550 start_y -= base_y;
551 }
552 if (num_img > 1) {
553 base_x = (int)((scr_area[0] - m_scr[0]) / xd);
554 base_y = (int)((scr_area[2] - m_scr[2]) / yd);
555
556 start_x += base_x;
557 start_y += base_y;
558 }
559 /* find the subimage range for this PE */
560 transform_range_vertex(range, svertex);
561 /* output_frame(vr, view_point, n_vertex, scr_area, xd, yd);
562 */
563 transform_frame(sr->screen_point, svertex, coff_matrix, sn_vertex);
564 find_projection_range(view_point, sn_vertex, sscr_area);
565 /* starti=(int)((sscr_area[0]-scr_area[0]+EPSILON)/xd);
566endi=(int)((sscr_area[1]-scr_area[0]-EPSILON)/xd)+1;
567startj=(int)((sscr_area[2]-scr_area[2]+EPSILON)/yd);
568endj=(int)((sscr_area[3]-scr_area[2]-EPSILON)/yd)+1;
569if(starti<0) starti=0;
570if(startj<0) startj=0;
571if(endi>vr->xr) endi=vr->xr;
572if(endj>vr->yr) endj=vr->yr;
573
574starti=(int)((sscr_area[0]-scr_area[0])/xd)+start_x-1;
575endi=(int)((sscr_area[1]-scr_area[0])/xd)+start_x+1;
576startj=(int)((sscr_area[2]-scr_area[2])/yd)+start_y-1;
577endj=(int)((sscr_area[3]-scr_area[2])/yd)+start_y+1;
578 */
579
580 HECMW_Barrier(VIS_COMM);
581#ifdef later
582 grad_minmax[0] = 1.0E17;
583 grad_minmax[1] = -1.0E17;
584 if (transfer_function_style == 2) {
585 }
586 feap_minmax[0] = 1.0E17;
587 feap_minmax[1] = -1.0E17;
588 if (transfer_function_style == 3) {
589 find_feap_minmax(num_of_features, fea_point, tmincolor, tmaxcolor,
590 feap_minmax);
591 HECMW_Barrier(VIS_COMM);
592 HECMW_Allreduce(&feap_minmax[0], &tfeap_minmax[0], 1, HECMW_DOUBLE,
593 HECMW_MIN, VIS_COMM);
594 HECMW_Allreduce(&feap_minmax[1], &tfeap_minmax[1], 1, HECMW_DOUBLE,
595 HECMW_MAX, VIS_COMM);
596 feap_minmax[0] = tfeap_minmax[0];
597 feap_minmax[1] = tfeap_minmax[1];
598 }
599 feai_minmax[0] = 1.0E17;
600 feai_minmax[1] = -1.0E17;
601 if (transfer_function_style == 4) {
602 /* find_feai_minmax(num_of_features, fea_point, tmincolor,
603tmaxcolor, feai_minmax);
604HECMW_Barrier(VIS_COMM);
605HECMW_Allreduce(&feai_minmax[0], &tfeai_minmax[0], 1, HECMW_DOUBLE, HECMW_MIN,
606VIS_COMM);
607HECMW_Allreduce(&feai_minmax[1], &tfeai_minmax[1], 1, HECMW_DOUBLE, HECMW_MAX,
608VIS_COMM);
609feai_minmax[0]=tfeai_minmax[0]; feai_minmax[1]=tfeai_minmax[1];
610 */
611 }
612 dis_minmax[0] = 1.0E17;
613 dis_minmax[1] = -1.0E17;
614 if ((transfer_function_style == 5) || (transfer_function_style == 6))
615 find_dis_minmax(view_point_d, vertex, dis_minmax);
616#endif
617 /* Build hierachical tree*/
618 for (jjj = 0; jjj < sr->deform_num_of_frames; jjj++) {
619 if (sr->deform_num_of_frames > 1)
620 fprintf(stderr, "Start rendering deformation frame %d\n", jjj);
621 image = (double *)HECMW_calloc(sr->xr * sr->yr * 3, sizeof(double));
622 if (image == NULL) HECMW_vis_memory_exit("image");
623 /* accum_opa=(double *)HECMW_calloc(sr->xr*sr->yr, sizeof(double));
624if(accum_opa==NULL) {
625fprintf(stderr, "There is no enough memory: image\n");
626exit(0);
627}
628 */
629 /*}
630 */
631 /*---------new change for vec ---------*/
632 for (j = 0; j < sr->yr * sr->xr * 3; j++) image[j] = 0.0;
633 /* for(j=0;j<sr->yr*sr->xr;j++)
634accum_opa[j]=0.0;
635 */
636 /* for(j=0;j<yr;j++)
637for(i=0;i<xr;i++) {
638image[(j*xr+i)*3] =image[(j*xr+i)*3+1] = image[(j*xr+i)*3+2]=0.0;
639 accum_opa[j*xr+i]=0.0;
640}
641 */
642 z_buffer = (double *)HECMW_calloc(sr->xr * sr->yr, sizeof(double));
643 if (z_buffer == NULL) HECMW_vis_memory_exit("z_buffer");
644 for (j = 0; j < sr->xr * sr->yr; j++) z_buffer[j] = 1.0E16;
645
646 HECMW_Barrier(VIS_COMM);
647 /* t3=HECMW_Wtime();
648if(mynode==0) {
649fprintf(stderr, "The time for preprocessing of pvr is %lf, the total time up to
650now is %lf\n", t3-t2, t3-t1);
651t2=t3;
652}
653 */
654 find_inverse_matrix(coff_matrix, inv_matrix);
655 for (i = 0; i < data->nn_component; i++) {
656 if (color_list[i] == 1) {
657 mincolor = mivalue[i];
658 maxcolor = mavalue[i];
659 }
660 }
661
662 if (sr->color_mapping_style == 2) {
663 mincolor = sr->interval_point[0];
664 maxcolor = sr->interval_point[1];
665 }
666 if (sr->color_mapping_style == 3) {
667 mincolor = sr->interval_point[0];
668 maxcolor = sr->interval_point[2 * sr->interval_mapping_num];
669 }
670 for (iii = 0; iii < sf[0].surface_style; iii++) {
671 if (sf[iii + 1].deform_display_on == 1) {
672 if ((sf[iii + 1].initial_style == 2) ||
673 (sf[iii + 1].initial_style == 3)) {
674 if (sr->smooth_shading == 1) {
675 v_normal = (double *)HECMW_calloc(result[iii].n_vertex * 3,
676 sizeof(double));
677 p_normal = (double *)HECMW_calloc(result[iii].n_patch * 4,
678 sizeof(double));
679 v_num = (int *)HECMW_calloc(result[iii].n_vertex, sizeof(int));
680 if ((v_normal == NULL) || (v_num == NULL) || (p_normal == NULL))
681 HECMW_vis_memory_exit("v_normal, p_normal");
682 for (k = 0; k < result[iii].n_vertex; k++) v_num[k] = 0;
683 for (k = 0; k < result[iii].n_vertex * 3; k++) v_normal[k] = 0.0;
684 for (k = 0; k < result[iii].n_patch; k++) {
685 for (i = 0; i < 3; i++) {
686 for (j = 0; j < 3; j++)
687 f[i][j] =
688 result[iii]
689 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
690 }
691 p_normal[k * 4 + 0] =
692 (f[1][1] - f[0][1]) * (f[2][2] - f[0][2]) -
693 (f[2][1] - f[0][1]) * (f[1][2] - f[0][2]);
694 p_normal[k * 4 + 1] =
695 -(f[1][0] - f[0][0]) * (f[2][2] - f[0][2]) +
696 (f[2][0] - f[0][0]) * (f[1][2] - f[0][2]);
697 p_normal[k * 4 + 2] =
698 (f[1][0] - f[0][0]) * (f[2][1] - f[0][1]) -
699 (f[2][0] - f[0][0]) * (f[1][1] - f[0][1]);
700 norm = sqrt(p_normal[k * 4 + 0] * p_normal[k * 4 + 0] +
701 p_normal[k * 4 + 1] * p_normal[k * 4 + 1] +
702 p_normal[k * 4 + 2] * p_normal[k * 4 + 2]);
703 if (fabs(norm) > EPSILON) {
704 for (j = 0; j < 3; j++) p_normal[k * 4 + j] /= norm;
705 }
706 p_normal[k * 4 + 3] = -p_normal[k * 4 + 0] * f[0][0] -
707 p_normal[k * 4 + 1] * f[0][1] -
708 p_normal[k * 4 + 2] * f[0][2];
709 for (i = 0; i < 3; i++) {
710 v_num[result[iii].patch[k * 3 + i] - 1]++;
711 for (j = 0; j < 3; j++)
712 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j] +=
713 p_normal[k * 4 + j];
714 }
715 }
716 for (k = 0; k < result[iii].n_vertex; k++) {
717 if (v_num[k] != 0) {
718 for (j = 0; j < 3; j++) v_normal[k * 3 + j] /= v_num[k];
719 }
720 }
721 }
722 normal_flag = 1;
723 for (k = 0; k < result[iii].n_patch; k++) {
724 for (i = 0; i < 3; i++) {
725 for (j = 0; j < 3; j++)
726 f[i][j] =
727 result[iii]
728 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
729 c_value[i] =
730 result[iii].color[result[iii].patch[k * 3 + i] - 1];
731 }
732 if (sr->smooth_shading == 1) {
733 for (i = 0; i < 3; i++)
734 for (j = 0; j < 3; j++)
735 normal[i * 3 + j] =
736 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
737 }
738
739 transform_frame3(sr->screen_point, f, coff_matrix, n_f);
740 find_projection_range2(view_point, n_f, scr_f);
741 starti = (int)((scr_f[0] - scr_area[0]) / xd) + start_x - 1;
742 endi = (int)((scr_f[1] - scr_area[0]) / xd) + start_x + 1;
743 startj = (int)((scr_f[2] - scr_area[2]) / yd) + start_y - 1;
744 endj = (int)((scr_f[3] - scr_area[2]) / yd) + start_y + 1;
745 for (j = startj; j < endj; j++)
746 for (i = starti; i < endi; i++) {
747 x = xd * (i - start_x + 0.5) + scr_area[0];
748 y = yd * (j - start_y + 0.5) + scr_area[2];
749 /*transform to the original frame */
750 point_s[0] = x;
751 point_s[1] = y;
752 point_s[2] = 0.0;
753 tranverse_transform(sr->screen_point, point_s, inv_matrix,
754 point_o);
755
756 intersection = find_surface_point(
757 f, point_o, sr->view_point_d, inter_point, f_f, v_f,
758 c_value, &value, normal, normal_flag, sr->smooth_shading);
759 if (intersection == 1) {
760 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
761 SQR(inter_point[1] - sr->view_point_d[1]) +
762 SQR(inter_point[2] - sr->view_point_d[2]));
763 if (depth < z_buffer[j * sr->xr + i]) {
764 z_buffer[j * sr->xr + i] = depth;
765 if (sf[iii + 1].initial_style == 2) {
766 value = (mincolor + maxcolor) / 2.0;
768 inter_point, value, normal, sr->color_mapping_style,
771 sr->light_point, sr->k_ads, accum_rgba, mincolor,
772 maxcolor, sf[iii + 1].display_method);
773 } else
775 inter_point, value, normal, sr->color_mapping_style,
778 sr->num_of_lights, sr->light_point, sr->k_ads,
779 accum_rgba, mincolor, maxcolor,
780 sf[iii + 1].display_method);
781 image[(j * sr->xr + i) * 3] = accum_rgba[0];
782 image[(j * sr->xr + i) * 3 + 1] = accum_rgba[1];
783 image[(j * sr->xr + i) * 3 + 2] = accum_rgba[2];
784 }
785 }
786 }
787 }
788 } /* end if (initial_style=2 or 3) */
789 if ((sf[iii + 1].deform_style == 2) ||
790 (sf[iii + 1].deform_style == 3)) {
791 normal_flag = 1;
792 if (sr->smooth_shading == 1) {
793 v_normal = (double *)HECMW_calloc(result[iii].n_vertex * 3,
794 sizeof(double));
795 p_normal = (double *)HECMW_calloc(result[iii].n_patch * 4,
796 sizeof(double));
797 v_num = (int *)HECMW_calloc(result[iii].n_vertex, sizeof(int));
798 if ((v_normal == NULL) || (v_num == NULL) || (p_normal == NULL))
799 HECMW_vis_memory_exit("v_normal_d, p_normal");
800 for (k = 0; k < result[iii].n_vertex; k++) v_num[k] = 0;
801 for (k = 0; k < result[iii].n_vertex * 3; k++) v_normal[k] = 0.0;
802 for (k = 0; k < result[iii].n_patch; k++) {
803 for (i = 0; i < 3; i++) {
804 if (stat_para[70] == 0) {
805 for (j = 0; j < 3; j++)
806 f[i][j] =
807 result[iii]
808 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
809 j] +
810 result[iii]
811 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
812 j] *
813 (sf[iii + 1].disp_scale /
814 (sr->deform_num_of_frames) * (jjj + 1));
815 } else {
816 for (j = 0; j < 3; j++)
817 f[i][j] =
818 result[iii]
819 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
820 j] +
821 result[iii]
822 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
823 j] *
824 sf[iii + 1].disp_scale;
825 }
826 }
827 p_normal[k * 4 + 0] =
828 (f[1][1] - f[0][1]) * (f[2][2] - f[0][2]) -
829 (f[2][1] - f[0][1]) * (f[1][2] - f[0][2]);
830 p_normal[k * 4 + 1] =
831 -(f[1][0] - f[0][0]) * (f[2][2] - f[0][2]) +
832 (f[2][0] - f[0][0]) * (f[1][2] - f[0][2]);
833 p_normal[k * 4 + 2] =
834 (f[1][0] - f[0][0]) * (f[2][1] - f[0][1]) -
835 (f[2][0] - f[0][0]) * (f[1][1] - f[0][1]);
836 norm = sqrt(p_normal[k * 4 + 0] * p_normal[k * 4 + 0] +
837 p_normal[k * 4 + 1] * p_normal[k * 4 + 1] +
838 p_normal[k * 4 + 2] * p_normal[k * 4 + 2]);
839 if (fabs(norm) > EPSILON) {
840 for (j = 0; j < 3; j++) p_normal[k * 4 + j] /= norm;
841 }
842 p_normal[k * 4 + 3] = -p_normal[k * 4 + 0] * f[0][0] -
843 p_normal[k * 4 + 1] * f[0][1] -
844 p_normal[k * 4 + 2] * f[0][2];
845 for (i = 0; i < 3; i++) {
846 v_num[result[iii].patch[k * 3 + i] - 1]++;
847 for (j = 0; j < 3; j++)
848 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j] +=
849 p_normal[k * 4 + j];
850 }
851 }
852 for (k = 0; k < result[iii].n_vertex; k++) {
853 if (v_num[k] != 0) {
854 for (j = 0; j < 3; j++) v_normal[k * 3 + j] /= v_num[k];
855 }
856 }
857 }
858
859 for (k = 0; k < result[iii].n_patch; k++) {
860 for (i = 0; i < 3; i++) {
861 if (stat_para[70] == 0) {
862 for (j = 0; j < 3; j++)
863 f_disp[i][j] =
864 result[iii]
865 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
866 j] +
867 result[iii]
868 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
869 j] *
870 (sf[iii + 1].disp_scale /
871 (sr->deform_num_of_frames) * (jjj + 1));
872 } else {
873 for (j = 0; j < 3; j++)
874 f_disp[i][j] =
875 result[iii]
876 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
877 j] +
878 result[iii]
879 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
880 j] *
881 sf[iii + 1].disp_scale;
882 }
883
884 c_value[i] =
885 result[iii].color[result[iii].patch[k * 3 + i] - 1];
886 }
887 if (sr->smooth_shading == 1) {
888 for (i = 0; i < 3; i++)
889 for (j = 0; j < 3; j++)
890 normal[i * 3 + j] =
891 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
892 }
893
894 transform_frame3(sr->screen_point, f_disp, coff_matrix, n_f);
895 find_projection_range2(view_point, n_f, scr_f);
896 starti = (int)((scr_f[0] - scr_area[0]) / xd) + start_x - 1;
897 endi = (int)((scr_f[1] - scr_area[0]) / xd) + start_x + 1;
898 startj = (int)((scr_f[2] - scr_area[2]) / yd) + start_y - 1;
899 endj = (int)((scr_f[3] - scr_area[2]) / yd) + start_y + 1;
900 for (j = startj; j < endj; j++)
901 for (i = starti; i < endi; i++) {
902 x = xd * (i - start_x + 0.5) + scr_area[0];
903 y = yd * (j - start_y + 0.5) + scr_area[2];
904 /*transform to the original frame */
905 point_s[0] = x;
906 point_s[1] = y;
907 point_s[2] = 0.0;
908 tranverse_transform(sr->screen_point, point_s, inv_matrix,
909 point_o);
910
911 intersection = find_surface_point(
912 f_disp, point_o, sr->view_point_d, inter_point, f_f, v_f,
913 c_value, &value, normal, normal_flag, sr->smooth_shading);
914 if (intersection == 1) {
915 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
916 SQR(inter_point[1] - sr->view_point_d[1]) +
917 SQR(inter_point[2] - sr->view_point_d[2]));
918 if (depth < z_buffer[j * sr->xr + i]) {
919 z_buffer[j * sr->xr + i] = depth;
920
921 if (sf[iii + 1].deform_style == 2) {
922 value = (mincolor + maxcolor) / 2.0;
924 inter_point, value, normal, sr->color_mapping_style,
927 sr->light_point, sr->k_ads, accum_rgba, mincolor,
928 maxcolor, sf[iii + 1].display_method);
929 } else
931 inter_point, value, normal, sr->color_mapping_style,
934 sr->num_of_lights, sr->light_point, sr->k_ads,
935 accum_rgba, mincolor, maxcolor,
936 sf[iii + 1].display_method);
937 image[(j * sr->xr + i) * 3] = accum_rgba[0];
938 image[(j * sr->xr + i) * 3 + 1] = accum_rgba[1];
939 image[(j * sr->xr + i) * 3 + 2] = accum_rgba[2];
940 }
941 }
942 }
943 }
944 }
945 if ((sf[iii + 1].initial_style == 1) ||
946 (sf[iii + 1].initial_style == 4)) {
947 normal_flag = 1;
948 for (k = 0; k < result[iii].n_patch; k++) {
949 for (i = 0; i < 3; i++) {
950 for (j = 0; j < 3; j++)
951 f[i][j] =
952 result[iii]
953 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
954 c_value[i] =
955 result[iii].color[result[iii].patch[k * 3 + i] - 1];
956 }
957 for (mmm = 0; mmm < 3; mmm++) {
958 mmm1 = mmm + 1;
959 if (mmm1 == 3) mmm1 = 0;
960 for (j = 0; j < 3; j++) {
961 iso_p[j] = f[mmm][j];
962 iso_p[j + 3] = f[mmm1][j];
963 }
964
965 count_dash_num = -1;
966 transform_frame4(sr->screen_point, iso_p, coff_matrix, n_iso);
967 find_projection_range3(view_point, n_iso, pixel_d, iso_p);
968 pixel_i[0][0] =
969 (int)((pixel_d[0][0] - scr_area[0]) / xd - 0.5) + start_x;
970 pixel_i[0][1] =
971 (int)((pixel_d[0][1] - scr_area[2]) / yd - 0.5) + start_y;
972 pixel_i[1][0] =
973 (int)((pixel_d[1][0] - scr_area[0]) / xd + 0.5) + start_x;
974 pixel_i[1][1] =
975 (int)((pixel_d[1][1] - scr_area[2]) / yd + 0.5) + start_y;
976 if (pixel_i[1][0] != pixel_i[0][0]) {
977 slip_y = (double)(pixel_i[1][1] - pixel_i[0][1]) /
978 (double)(pixel_i[1][0] - pixel_i[0][0]);
979 last_j = pixel_i[0][1];
980 for (i = pixel_i[0][0]; i <= pixel_i[1][0]; i++) {
981 next_j = (int)(pixel_i[0][1] +
982 slip_y * (double)(i - pixel_i[0][0]));
983 if (last_j <= next_j) {
984 for (j = last_j; j <= next_j; j++) {
985 x = xd * (i - start_x + 0.5) + scr_area[0];
986 y = yd * (j - start_y + 0.5) + scr_area[2];
987 point_s[0] = x;
988 point_s[1] = y;
989 point_s[2] = 0.0;
991 inv_matrix, point_o);
992
993 intersection =
994 find_point_depth(f, point_o, sr->view_point_d, f_f,
995 inter_point, normal_flag);
996 if (intersection == 1)
997 depth =
998 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
999 SQR(inter_point[1] - sr->view_point_d[1]) +
1000 SQR(inter_point[2] - sr->view_point_d[2]));
1001 else
1002 depth = 1.0E17;
1003 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1004 if (sf[iii + 1].initial_style == 4) {
1005 count_dash_num++;
1006 if ((count_dash_num % 4) < 1) {
1007 image[(j * sr->xr + i) * 3] =
1008 sf[iii + 1].initial_line_color[0];
1009 image[(j * sr->xr + i) * 3 + 1] =
1010 sf[iii + 1].initial_line_color[1];
1011 image[(j * sr->xr + i) * 3 + 2] =
1012 sf[iii + 1].initial_line_color[2];
1013 z_buffer[j * sr->xr + i] = depth;
1014 }
1015 } else if (sf[iii + 1].initial_style == 1) {
1016 image[(j * sr->xr + i) * 3] =
1017 sf[iii + 1].initial_line_color[0];
1018 image[(j * sr->xr + i) * 3 + 1] =
1019 sf[iii + 1].initial_line_color[1];
1020 image[(j * sr->xr + i) * 3 + 2] =
1021 sf[iii + 1].initial_line_color[2];
1022 z_buffer[j * sr->xr + i] = depth;
1023 }
1024 }
1025 }
1026 } else {
1027 for (j = last_j; j >= next_j; j--) {
1028 x = xd * (i - start_x + 0.5) + scr_area[0];
1029 y = yd * (j - start_y + 0.5) + scr_area[2];
1030 point_s[0] = x;
1031 point_s[1] = y;
1032 point_s[2] = 0.0;
1033 tranverse_transform(sr->screen_point, point_s,
1034 inv_matrix, point_o);
1035
1036 intersection =
1037 find_point_depth(f, point_o, sr->view_point_d, f_f,
1038 inter_point, normal_flag);
1039 if (intersection == 1)
1040 depth =
1041 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1042 SQR(inter_point[1] - sr->view_point_d[1]) +
1043 SQR(inter_point[2] - sr->view_point_d[2]));
1044 else
1045 depth = 1.0E17;
1046 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1047 if (sf[iii + 1].initial_style == 4) {
1048 count_dash_num++;
1049 if ((count_dash_num % 4) < 1) {
1050 image[(j * sr->xr + i) * 3] =
1051 sf[iii + 1].initial_line_color[0];
1052 image[(j * sr->xr + i) * 3 + 1] =
1053 sf[iii + 1].initial_line_color[1];
1054 image[(j * sr->xr + i) * 3 + 2] =
1055 sf[iii + 1].initial_line_color[2];
1056 z_buffer[j * sr->xr + i] = depth;
1057 }
1058 } else if (sf[iii + 1].initial_style == 1) {
1059 image[(j * sr->xr + i) * 3] =
1060 sf[iii + 1].initial_line_color[0];
1061 image[(j * sr->xr + i) * 3 + 1] =
1062 sf[iii + 1].initial_line_color[1];
1063 image[(j * sr->xr + i) * 3 + 2] =
1064 sf[iii + 1].initial_line_color[2];
1065 z_buffer[j * sr->xr + i] = depth;
1066 }
1067 }
1068 }
1069 }
1070
1071 last_j = next_j;
1072 }
1073 } else {
1074 i = pixel_i[0][0];
1075 if (pixel_i[0][1] <= pixel_i[1][1]) {
1076 for (j = pixel_i[0][1]; j <= pixel_i[1][1]; j++) {
1077 x = xd * (i - start_x + 0.5) + scr_area[0];
1078 y = yd * (j - start_y + 0.5) + scr_area[2];
1079 /*transform to the original frame */
1080 point_s[0] = x;
1081 point_s[1] = y;
1082 point_s[2] = 0.0;
1083 tranverse_transform(sr->screen_point, point_s, inv_matrix,
1084 point_o);
1085
1086 intersection =
1087 find_point_depth(f, point_o, sr->view_point_d, f_f,
1088 inter_point, normal_flag);
1089 if (intersection == 1)
1090 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1091 SQR(inter_point[1] - sr->view_point_d[1]) +
1092 SQR(inter_point[2] - sr->view_point_d[2]));
1093 else
1094 depth = 1.0E17;
1095 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1096 if (sf[iii + 1].initial_style == 4) {
1097 count_dash_num++;
1098 if ((count_dash_num % 4) < 1) {
1099 image[(j * sr->xr + i) * 3] =
1100 sf[iii + 1].initial_line_color[0];
1101 image[(j * sr->xr + i) * 3 + 1] =
1102 sf[iii + 1].initial_line_color[1];
1103 image[(j * sr->xr + i) * 3 + 2] =
1104 sf[iii + 1].initial_line_color[2];
1105 z_buffer[j * sr->xr + i] = depth;
1106 }
1107 } else if (sf[iii + 1].initial_style == 1) {
1108 image[(j * sr->xr + i) * 3] =
1109 sf[iii + 1].initial_line_color[0];
1110 image[(j * sr->xr + i) * 3 + 1] =
1111 sf[iii + 1].initial_line_color[1];
1112 image[(j * sr->xr + i) * 3 + 2] =
1113 sf[iii + 1].initial_line_color[2];
1114 z_buffer[j * sr->xr + i] = depth;
1115 }
1116 }
1117 }
1118 } else if (pixel_i[0][1] > pixel_i[1][1]) {
1119 for (j = pixel_i[1][1]; j <= pixel_i[0][1]; j++) {
1120 x = xd * (i - start_x + 0.5) + scr_area[0];
1121 y = yd * (j - start_y + 0.5) + scr_area[2];
1122 /*transform to the original frame */
1123 point_s[0] = x;
1124 point_s[1] = y;
1125 point_s[2] = 0.0;
1126 tranverse_transform(sr->screen_point, point_s, inv_matrix,
1127 point_o);
1128
1129 intersection =
1130 find_point_depth(f, point_o, sr->view_point_d, f_f,
1131 inter_point, normal_flag);
1132 if (intersection == 1)
1133 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1134 SQR(inter_point[1] - sr->view_point_d[1]) +
1135 SQR(inter_point[2] - sr->view_point_d[2]));
1136 else
1137 depth = 1.0E17;
1138 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1139 if (sf[iii + 1].initial_style == 4) {
1140 count_dash_num++;
1141 if ((count_dash_num % 4) < 1) {
1142 image[(j * sr->xr + i) * 3] =
1143 sf[iii + 1].initial_line_color[0];
1144 image[(j * sr->xr + i) * 3 + 1] =
1145 sf[iii + 1].initial_line_color[1];
1146 image[(j * sr->xr + i) * 3 + 2] =
1147 sf[iii + 1].initial_line_color[2];
1148 z_buffer[j * sr->xr + i] = depth;
1149 }
1150 } else if (sf[iii + 1].initial_style == 1) {
1151 image[(j * sr->xr + i) * 3] =
1152 sf[iii + 1].initial_line_color[0];
1153 image[(j * sr->xr + i) * 3 + 1] =
1154 sf[iii + 1].initial_line_color[1];
1155 image[(j * sr->xr + i) * 3 + 2] =
1156 sf[iii + 1].initial_line_color[2];
1157 z_buffer[j * sr->xr + i] = depth;
1158 }
1159 }
1160 }
1161 }
1162 }
1163 }
1164 }
1165 }
1166
1167 if ((sf[iii + 1].deform_style == 1) ||
1168 (sf[iii + 1].deform_style == 4)) {
1169 normal_flag = 1;
1170 for (k = 0; k < result[iii].n_patch; k++) {
1171 for (i = 0; i < 3; i++) {
1172 if (stat_para[70] == 0) {
1173 for (j = 0; j < 3; j++)
1174 f_disp[i][j] =
1175 result[iii]
1176 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
1177 j] +
1178 result[iii]
1179 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
1180 j] *
1181 (sf[iii + 1].disp_scale /
1182 (sr->deform_num_of_frames) * (jjj + 1));
1183 } else {
1184 for (j = 0; j < 3; j++)
1185 f_disp[i][j] =
1186 result[iii]
1187 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 +
1188 j] +
1189 result[iii]
1190 .disp[(result[iii].patch[k * 3 + i] - 1) * 3 +
1191 j] *
1192 sf[iii + 1].disp_scale;
1193 }
1194 c_value[i] =
1195 result[iii].color[result[iii].patch[k * 3 + i] - 1];
1196 }
1197 for (mmm = 0; mmm < 3; mmm++) {
1198 mmm1 = mmm + 1;
1199 if (mmm1 == 3) mmm1 = 0;
1200 for (j = 0; j < 3; j++) {
1201 iso_p[j] = f_disp[mmm][j];
1202 iso_p[j + 3] = f_disp[mmm1][j];
1203 }
1204
1205 transform_frame4(sr->screen_point, iso_p, coff_matrix, n_iso);
1206 find_projection_range3(view_point, n_iso, pixel_d, iso_p);
1207 for (j = 0; j < 2; j++) {
1208 pixel_i[j][0] =
1209 (int)((pixel_d[j][0] - scr_area[0]) / xd - 0.5) + start_x;
1210 pixel_i[j][1] =
1211 (int)((pixel_d[j][1] - scr_area[2]) / yd + 0.5) + start_y;
1212 }
1213 if (pixel_i[1][0] != pixel_i[0][0]) {
1214 slip_y = (double)(pixel_i[1][1] - pixel_i[0][1]) /
1215 (double)(pixel_i[1][0] - pixel_i[0][0]);
1216 last_j = pixel_i[0][1];
1217 for (i = pixel_i[0][0]; i <= pixel_i[1][0]; i++) {
1218 next_j = (int)(pixel_i[0][1] +
1219 slip_y * (double)(i - pixel_i[0][0]));
1220 if (last_j <= next_j) {
1221 for (j = last_j; j <= next_j; j++) {
1222 x = xd * (i - start_x + 0.5) + scr_area[0];
1223 y = yd * (j - start_y + 0.5) + scr_area[2];
1224 point_s[0] = x;
1225 point_s[1] = y;
1226 point_s[2] = 0.0;
1227 tranverse_transform(sr->screen_point, point_s,
1228 inv_matrix, point_o);
1229
1230 intersection =
1231 find_point_depth(f_disp, point_o, sr->view_point_d,
1232 f_f, inter_point, normal_flag);
1233 if (intersection == 1)
1234 depth =
1235 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1236 SQR(inter_point[1] - sr->view_point_d[1]) +
1237 SQR(inter_point[2] - sr->view_point_d[2]));
1238 else
1239 depth = 1.0E17;
1240 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1241 if (sf[iii + 1].deform_style == 4) {
1242 count_dash_num++;
1243 if ((count_dash_num % 4) < 1) {
1244 image[(j * sr->xr + i) * 3] =
1245 sf[iii + 1].deform_line_color[0];
1246 image[(j * sr->xr + i) * 3 + 1] =
1247 sf[iii + 1].deform_line_color[1];
1248 image[(j * sr->xr + i) * 3 + 2] =
1249 sf[iii + 1].deform_line_color[2];
1250 z_buffer[j * sr->xr + i] = depth;
1251 }
1252 } else if (sf[iii + 1].deform_style == 1) {
1253 image[(j * sr->xr + i) * 3] =
1254 sf[iii + 1].deform_line_color[0];
1255 image[(j * sr->xr + i) * 3 + 1] =
1256 sf[iii + 1].deform_line_color[1];
1257 image[(j * sr->xr + i) * 3 + 2] =
1258 sf[iii + 1].deform_line_color[2];
1259 z_buffer[j * sr->xr + i] = depth;
1260 }
1261 }
1262 }
1263 } else {
1264 for (j = last_j; j >= next_j; j--) {
1265 x = xd * (i - start_x + 0.5) + scr_area[0];
1266 y = yd * (j - start_y + 0.5) + scr_area[2];
1267 point_s[0] = x;
1268 point_s[1] = y;
1269 point_s[2] = 0.0;
1270 tranverse_transform(sr->screen_point, point_s,
1271 inv_matrix, point_o);
1272
1273 intersection =
1274 find_point_depth(f_disp, point_o, sr->view_point_d,
1275 f_f, inter_point, normal_flag);
1276 if (intersection == 1)
1277 depth =
1278 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1279 SQR(inter_point[1] - sr->view_point_d[1]) +
1280 SQR(inter_point[2] - sr->view_point_d[2]));
1281 else
1282 depth = 1.0E17;
1283 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1284 if (sf[iii + 1].deform_style == 4) {
1285 count_dash_num++;
1286 if ((count_dash_num % 4) < 1) {
1287 image[(j * sr->xr + i) * 3] =
1288 sf[iii + 1].deform_line_color[0];
1289 image[(j * sr->xr + i) * 3 + 1] =
1290 sf[iii + 1].deform_line_color[1];
1291 image[(j * sr->xr + i) * 3 + 2] =
1292 sf[iii + 1].deform_line_color[2];
1293 z_buffer[j * sr->xr + i] = depth;
1294 }
1295 } else if (sf[iii + 1].deform_style == 1) {
1296 image[(j * sr->xr + i) * 3] =
1297 sf[iii + 1].deform_line_color[0];
1298 image[(j * sr->xr + i) * 3 + 1] =
1299 sf[iii + 1].deform_line_color[1];
1300 image[(j * sr->xr + i) * 3 + 2] =
1301 sf[iii + 1].deform_line_color[2];
1302 z_buffer[j * sr->xr + i] = depth;
1303 }
1304 }
1305 }
1306 }
1307
1308 last_j = next_j;
1309 }
1310 } else {
1311 i = pixel_i[0][0];
1312 if (pixel_i[0][1] <= pixel_i[1][1]) {
1313 for (j = pixel_i[0][1]; j <= pixel_i[1][1]; j++) {
1314 x = xd * (i - start_x + 0.5) + scr_area[0];
1315 y = yd * (j - start_y + 0.5) + scr_area[2];
1316 /*transform to the original frame */
1317 point_s[0] = x;
1318 point_s[1] = y;
1319 point_s[2] = 0.0;
1320 tranverse_transform(sr->screen_point, point_s, inv_matrix,
1321 point_o);
1322
1323 intersection =
1324 find_point_depth(f_disp, point_o, sr->view_point_d,
1325 f_f, inter_point, normal_flag);
1326 if (intersection == 1)
1327 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1328 SQR(inter_point[1] - sr->view_point_d[1]) +
1329 SQR(inter_point[2] - sr->view_point_d[2]));
1330 else
1331 depth = 1.0E17;
1332 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1333 if (sf[iii + 1].deform_style == 4) {
1334 count_dash_num++;
1335 if ((count_dash_num % 4) < 1) {
1336 image[(j * sr->xr + i) * 3] =
1337 sf[iii + 1].deform_line_color[0];
1338 image[(j * sr->xr + i) * 3 + 1] =
1339 sf[iii + 1].deform_line_color[1];
1340 image[(j * sr->xr + i) * 3 + 2] =
1341 sf[iii + 1].deform_line_color[2];
1342 z_buffer[j * sr->xr + i] = depth;
1343 }
1344 } else if (sf[iii + 1].deform_style == 1) {
1345 image[(j * sr->xr + i) * 3] =
1346 sf[iii + 1].deform_line_color[0];
1347 image[(j * sr->xr + i) * 3 + 1] =
1348 sf[iii + 1].deform_line_color[1];
1349 image[(j * sr->xr + i) * 3 + 2] =
1350 sf[iii + 1].deform_line_color[2];
1351 z_buffer[j * sr->xr + i] = depth;
1352 }
1353 }
1354 }
1355 } else if (pixel_i[0][1] > pixel_i[1][1]) {
1356 for (j = pixel_i[1][1]; j <= pixel_i[0][1]; j++) {
1357 x = xd * (i - start_x + 0.5) + scr_area[0];
1358 y = yd * (j - start_y + 0.5) + scr_area[2];
1359 /*transform to the original frame */
1360 point_s[0] = x;
1361 point_s[1] = y;
1362 point_s[2] = 0.0;
1363 tranverse_transform(sr->screen_point, point_s, inv_matrix,
1364 point_o);
1365
1366 intersection =
1367 find_point_depth(f_disp, point_o, sr->view_point_d,
1368 f_f, inter_point, normal_flag);
1369 if (intersection == 1)
1370 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1371 SQR(inter_point[1] - sr->view_point_d[1]) +
1372 SQR(inter_point[2] - sr->view_point_d[2]));
1373 else
1374 depth = 1.0E17;
1375 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1376 if (sf[iii + 1].deform_style == 4) {
1377 count_dash_num++;
1378 if ((count_dash_num % 4) < 1) {
1379 image[(j * sr->xr + i) * 3] =
1380 sf[iii + 1].deform_line_color[0];
1381 image[(j * sr->xr + i) * 3 + 1] =
1382 sf[iii + 1].deform_line_color[1];
1383 image[(j * sr->xr + i) * 3 + 2] =
1384 sf[iii + 1].deform_line_color[2];
1385 z_buffer[j * sr->xr + i] = depth;
1386 }
1387 } else if (sf[iii + 1].deform_style == 1) {
1388 image[(j * sr->xr + i) * 3] =
1389 sf[iii + 1].deform_line_color[0];
1390 image[(j * sr->xr + i) * 3 + 1] =
1391 sf[iii + 1].deform_line_color[1];
1392 image[(j * sr->xr + i) * 3 + 2] =
1393 sf[iii + 1].deform_line_color[2];
1394 z_buffer[j * sr->xr + i] = depth;
1395 }
1396 }
1397 }
1398 }
1399 }
1400 }
1401 }
1402 }
1403
1404 } /* if deform_display=1 */
1405 else if (sf[iii + 1].deform_display_on == 0) {
1406 if ((sf[iii + 1].display_method != 1) &&
1407 (sf[iii + 1].display_method != 4)) {
1408 deltac = (maxcolor - mincolor) / (sf[iii + 1].isoline_number + 1);
1409 iso_value = (double *)HECMW_calloc(sf[iii + 1].isoline_number,
1410 sizeof(double));
1411 iso_rgb = (double *)HECMW_calloc(sf[iii + 1].isoline_number * 3,
1412 sizeof(double));
1413 for (m = 0; m < sf[iii + 1].isoline_number; m++) {
1414 iso_value[m] = mincolor + deltac * (m + 1);
1415 if (sr->isoline_color[0] == -1.0) {
1416 value_to_rgb(iso_value[m], color_iso, mincolor, maxcolor,
1419 iso_rgb[m * 3] = color_iso[0];
1420 iso_rgb[m * 3 + 1] = color_iso[1];
1421 iso_rgb[m * 3 + 2] = color_iso[2];
1422 } else {
1423 iso_rgb[m * 3] = sr->isoline_color[0];
1424 iso_rgb[m * 3 + 1] = sr->isoline_color[1];
1425 iso_rgb[m * 3 + 2] = sr->isoline_color[2];
1426 }
1427 }
1428 }
1429 if ((sf[iii + 1].surface_style == 3) && (sf[iii + 1].coef[0] == 0) &&
1430 (sf[iii + 1].coef[1] == 0) && (sf[iii + 1].coef[2] == 0) &&
1431 (sf[iii + 1].coef[3] == 0) && (sf[iii + 1].coef[4] == 0) &&
1432 (sf[iii + 1].coef[5] == 0)) {
1433 f_f[0] = sf[iii + 1].coef[6];
1434 f_f[1] = sf[iii + 1].coef[7];
1435 f_f[2] = sf[iii + 1].coef[8];
1436 f_f[3] = sf[iii + 1].coef[9];
1437 norm = sqrt(f_f[0] * f_f[0] + f_f[1] * f_f[1] + f_f[2] * f_f[2]);
1438 for (m = 0; m < 4; m++) f_f[m] /= norm;
1439 normal_flag = 0;
1440 } else {
1441 normal_flag = 1;
1442 if (sr->smooth_shading == 1) {
1443 v_normal = (double *)HECMW_calloc(result[iii].n_vertex * 3,
1444 sizeof(double));
1445 p_normal = (double *)HECMW_calloc(result[iii].n_patch * 4,
1446 sizeof(double));
1447 v_num = (int *)HECMW_calloc(result[iii].n_vertex, sizeof(int));
1448 if ((v_normal == NULL) || (v_num == NULL) || (p_normal == NULL))
1449 HECMW_vis_memory_exit("v_normal, p_normal");
1450 for (k = 0; k < result[iii].n_vertex; k++) v_num[k] = 0;
1451 for (k = 0; k < result[iii].n_vertex * 3; k++) v_normal[k] = 0.0;
1452 for (k = 0; k < result[iii].n_patch; k++) {
1453 for (i = 0; i < 3; i++) {
1454 for (j = 0; j < 3; j++)
1455 f[i][j] =
1456 result[iii]
1457 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
1458 }
1459 p_normal[k * 4 + 0] =
1460 (f[1][1] - f[0][1]) * (f[2][2] - f[0][2]) -
1461 (f[2][1] - f[0][1]) * (f[1][2] - f[0][2]);
1462 p_normal[k * 4 + 1] =
1463 -(f[1][0] - f[0][0]) * (f[2][2] - f[0][2]) +
1464 (f[2][0] - f[0][0]) * (f[1][2] - f[0][2]);
1465 p_normal[k * 4 + 2] =
1466 (f[1][0] - f[0][0]) * (f[2][1] - f[0][1]) -
1467 (f[2][0] - f[0][0]) * (f[1][1] - f[0][1]);
1468 norm = sqrt(p_normal[k * 4 + 0] * p_normal[k * 4 + 0] +
1469 p_normal[k * 4 + 1] * p_normal[k * 4 + 1] +
1470 p_normal[k * 4 + 2] * p_normal[k * 4 + 2]);
1471 if (fabs(norm) > EPSILON) {
1472 for (j = 0; j < 3; j++) p_normal[k * 4 + j] /= norm;
1473 }
1474 p_normal[k * 4 + 3] = -p_normal[k * 4 + 0] * f[0][0] -
1475 p_normal[k * 4 + 1] * f[0][1] -
1476 p_normal[k * 4 + 2] * f[0][2];
1477 for (i = 0; i < 3; i++) {
1478 v_num[result[iii].patch[k * 3 + i] - 1]++;
1479 for (j = 0; j < 3; j++)
1480 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j] +=
1481 p_normal[k * 4 + j];
1482 }
1483 }
1484 for (k = 0; k < result[iii].n_vertex; k++) {
1485 if (v_num[k] != 0) {
1486 for (j = 0; j < 3; j++) v_normal[k * 3 + j] /= v_num[k];
1487 }
1488 }
1489 }
1490 }
1491
1492 for (k = 0; k < result[iii].n_patch; k++) {
1493 for (i = 0; i < 3; i++) {
1494 for (j = 0; j < 3; j++)
1495 f[i][j] =
1496 result[iii]
1497 .vertex[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
1498 c_value[i] = result[iii].color[result[iii].patch[k * 3 + i] - 1];
1499 }
1500 if (sf[iii + 1].display_method != 2) {
1501 if (sr->smooth_shading == 1) {
1502 for (i = 0; i < 3; i++)
1503 for (j = 0; j < 3; j++)
1504 normal[i * 3 + j] =
1505 v_normal[(result[iii].patch[k * 3 + i] - 1) * 3 + j];
1506 }
1507
1508 transform_frame3(sr->screen_point, f, coff_matrix, n_f);
1509 find_projection_range2(view_point, n_f, scr_f);
1510 starti = (int)((scr_f[0] - scr_area[0]) / xd) + start_x - 1;
1511 endi = (int)((scr_f[1] - scr_area[0]) / xd) + start_x + 1;
1512 startj = (int)((scr_f[2] - scr_area[2]) / yd) + start_y - 1;
1513 endj = (int)((scr_f[3] - scr_area[2]) / yd) + start_y + 1;
1514 for (j = startj; j < endj; j++)
1515 for (i = starti; i < endi; i++) {
1516 x = xd * (i - start_x + 0.5) + scr_area[0];
1517 y = yd * (j - start_y + 0.5) + scr_area[2];
1518 /*transform to the original frame */
1519 point_s[0] = x;
1520 point_s[1] = y;
1521 point_s[2] = 0.0;
1522 tranverse_transform(sr->screen_point, point_s, inv_matrix,
1523 point_o);
1524
1525 intersection = find_surface_point(
1526 f, point_o, sr->view_point_d, inter_point, f_f, v_f,
1527 c_value, &value, normal, normal_flag, sr->smooth_shading);
1528 if (intersection == 1) {
1529 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1530 SQR(inter_point[1] - sr->view_point_d[1]) +
1531 SQR(inter_point[2] - sr->view_point_d[2]));
1532 if (depth < z_buffer[j * sr->xr + i]) {
1533 z_buffer[j * sr->xr + i] = depth;
1534 if (sf[iii + 1].display_method == 5) {
1535 tmp_i =
1536 (int)((value - mincolor) / (maxcolor - mincolor) *
1537 (sf[iii + 1].isoline_number + 1));
1538 value = (maxcolor - mincolor) /
1539 (sf[iii + 1].isoline_number + 1) *
1540 (double)tmp_i +
1541 mincolor;
1542 }
1543
1545 inter_point, value, normal, sr->color_mapping_style,
1548 sr->num_of_lights, sr->light_point, sr->k_ads,
1549 accum_rgba, mincolor, maxcolor,
1550 sf[iii + 1].display_method);
1551 image[(j * sr->xr + i) * 3] = accum_rgba[0];
1552 image[(j * sr->xr + i) * 3 + 1] = accum_rgba[1];
1553 image[(j * sr->xr + i) * 3 + 2] = accum_rgba[2];
1554 }
1555 }
1556 }
1557 }
1558
1559 if ((sf[iii + 1].display_method == 2) ||
1560 (sf[iii + 1].display_method == 3)) {
1561 for (m = 0; m < sf[iii + 1].isoline_number; m++) {
1562 isocolor = iso_value[m];
1563 flag = 0;
1564 flag = find_line_segment(f, c_value, isocolor, iso_p);
1565 if (flag == 1) {
1566 transform_frame4(sr->screen_point, iso_p, coff_matrix, n_iso);
1567 find_projection_range3(view_point, n_iso, pixel_d, iso_p);
1568 for (j = 0; j < 2; j++) {
1569 pixel_i[j][0] =
1570 (int)((pixel_d[j][0] - scr_area[0]) / xd - 0.5) +
1571 start_x;
1572 pixel_i[j][1] =
1573 (int)((pixel_d[j][1] - scr_area[2]) / yd + 0.5) +
1574 start_y;
1575 }
1576 if (pixel_i[1][0] != pixel_i[0][0]) {
1577 slip_y = (double)(pixel_i[1][1] - pixel_i[0][1]) /
1578 (double)(pixel_i[1][0] - pixel_i[0][0]);
1579 last_j = pixel_i[0][1];
1580 for (i = pixel_i[0][0]; i <= pixel_i[1][0]; i++) {
1581 next_j = (int)(pixel_i[0][1] +
1582 slip_y * (double)(i - pixel_i[0][0]));
1583 if (last_j <= next_j) {
1584 for (j = last_j; j <= next_j; j++) {
1585 x = xd * (i - start_x + 0.5) + scr_area[0];
1586 y = yd * (j - start_y + 0.5) + scr_area[2];
1587 point_s[0] = x;
1588 point_s[1] = y;
1589 point_s[2] = 0.0;
1590 tranverse_transform(sr->screen_point, point_s,
1591 inv_matrix, point_o);
1592
1593 intersection =
1594 find_point_depth(f, point_o, sr->view_point_d,
1595 f_f, inter_point, normal_flag);
1596 if (intersection == 1)
1597 depth =
1598 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1599 SQR(inter_point[1] - sr->view_point_d[1]) +
1600 SQR(inter_point[2] - sr->view_point_d[2]));
1601 else
1602 depth = 1.0E17;
1603 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1604 image[(j * sr->xr + i) * 3] = iso_rgb[m * 3];
1605 image[(j * sr->xr + i) * 3 + 1] =
1606 iso_rgb[m * 3 + 1];
1607 image[(j * sr->xr + i) * 3 + 2] =
1608 iso_rgb[m * 3 + 2];
1609 z_buffer[j * sr->xr + i] = depth;
1610 }
1611 }
1612 } else {
1613 for (j = last_j; j >= next_j; j--) {
1614 x = xd * (i - start_x + 0.5) + scr_area[0];
1615 y = yd * (j - start_y + 0.5) + scr_area[2];
1616 point_s[0] = x;
1617 point_s[1] = y;
1618 point_s[2] = 0.0;
1619 tranverse_transform(sr->screen_point, point_s,
1620 inv_matrix, point_o);
1621
1622 intersection =
1623 find_point_depth(f, point_o, sr->view_point_d,
1624 f_f, inter_point, normal_flag);
1625 if (intersection == 1)
1626 depth =
1627 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1628 SQR(inter_point[1] - sr->view_point_d[1]) +
1629 SQR(inter_point[2] - sr->view_point_d[2]));
1630 else
1631 depth = 1.0E17;
1632 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1633 image[(j * sr->xr + i) * 3] = iso_rgb[m * 3];
1634 image[(j * sr->xr + i) * 3 + 1] =
1635 iso_rgb[m * 3 + 1];
1636 image[(j * sr->xr + i) * 3 + 2] =
1637 iso_rgb[m * 3 + 2];
1638 z_buffer[j * sr->xr + i] = depth;
1639 }
1640 }
1641 }
1642
1643 last_j = next_j;
1644 }
1645 } else {
1646 i = pixel_i[0][0];
1647 if (pixel_i[0][1] <= pixel_i[1][1]) {
1648 for (j = pixel_i[0][1]; j <= pixel_i[1][1]; j++) {
1649 x = xd * (i - start_x + 0.5) + scr_area[0];
1650 y = yd * (j - start_y + 0.5) + scr_area[2];
1651 /*transform to the original frame */
1652 point_s[0] = x;
1653 point_s[1] = y;
1654 point_s[2] = 0.0;
1655 tranverse_transform(sr->screen_point, point_s,
1656 inv_matrix, point_o);
1657
1658 intersection =
1659 find_point_depth(f, point_o, sr->view_point_d, f_f,
1660 inter_point, normal_flag);
1661 if (intersection == 1)
1662 depth =
1663 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1664 SQR(inter_point[1] - sr->view_point_d[1]) +
1665 SQR(inter_point[2] - sr->view_point_d[2]));
1666 else
1667 depth = 1.0E17;
1668 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1669 image[(j * sr->xr + i) * 3] = iso_rgb[m * 3];
1670 image[(j * sr->xr + i) * 3 + 1] = iso_rgb[m * 3 + 1];
1671 image[(j * sr->xr + i) * 3 + 2] = iso_rgb[m * 3 + 2];
1672 z_buffer[j * sr->xr + i] = depth;
1673 }
1674 }
1675 } else if (pixel_i[0][1] > pixel_i[1][1]) {
1676 for (j = pixel_i[1][1]; j <= pixel_i[0][1]; j++) {
1677 x = xd * (i - start_x + 0.5) + scr_area[0];
1678 y = yd * (j - start_y + 0.5) + scr_area[2];
1679 /*transform to the original frame */
1680 point_s[0] = x;
1681 point_s[1] = y;
1682 point_s[2] = 0.0;
1683 tranverse_transform(sr->screen_point, point_s,
1684 inv_matrix, point_o);
1685
1686 intersection =
1687 find_point_depth(f, point_o, sr->view_point_d, f_f,
1688 inter_point, normal_flag);
1689 if (intersection == 1)
1690 depth =
1691 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
1692 SQR(inter_point[1] - sr->view_point_d[1]) +
1693 SQR(inter_point[2] - sr->view_point_d[2]));
1694 else
1695 depth = 1.0E17;
1696 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
1697 image[(j * sr->xr + i) * 3] = iso_rgb[m * 3];
1698 image[(j * sr->xr + i) * 3 + 1] = iso_rgb[m * 3 + 1];
1699 image[(j * sr->xr + i) * 3 + 2] = iso_rgb[m * 3 + 2];
1700 z_buffer[j * sr->xr + i] = depth;
1701 }
1702 }
1703 }
1704 }
1705 }
1706 }
1707 }
1708 }
1709 if ((sf[iii + 1].display_method != 1) &&
1710 (sf[iii + 1].display_method != 4)) {
1711 HECMW_free(iso_value);
1712 HECMW_free(iso_rgb);
1713 }
1714 } /* if deform_display=0 */
1715 }
1716
1717 HECMW_Barrier(VIS_COMM);
1718 fprintf(stderr, "Finish the computing on each PE\n");
1719 if (mynode == 0) {
1720 /*
1721fprintf(stderr, "Finish the computing on each PE\n");
1722t3=HECMW_Wtime();
1723fprintf(stderr, "The volume rendering on each PE is %lf the total time up to
1724now is %lf\n", t3-t2, t3-t1);
1725t2=t3;
1726 */
1727 }
1728 if (pesize > 1) {
1729 pix_num = (int)(sr->xr * sr->yr / pesize);
1730 pix0_num = sr->xr * sr->yr - pix_num * (pesize - 1);
1731 if (mynode == 0) pixn = pix0_num;
1732 if (mynode != 0) pixn = pix_num;
1733 n_subimage = (double *)HECMW_calloc(pesize * pixn * 3, sizeof(double));
1734 n_subopa = (double *)HECMW_calloc(pesize * pixn, sizeof(double));
1735 if ((n_subimage == NULL) || (n_subopa == NULL))
1736 HECMW_vis_memory_exit("n_subimage, n_subopa");
1737
1738 for (j = 0; j < pixn * 3; j++) {
1739 if (mynode == 0)
1740 n_subimage[j] = image[j];
1741 else if (mynode != 0)
1742 n_subimage[mynode * pixn * 3 + j] =
1743 image[pix0_num * 3 + (mynode - 1) * pix_num * 3 + j];
1744 }
1745 if (mynode == 0)
1746 for (j = 0; j < pixn; j++) n_subopa[j] = z_buffer[j];
1747 else if (mynode != 0)
1748 for (j = 0; j < pixn; j++)
1749 n_subopa[mynode * pixn + j] =
1750 z_buffer[pix0_num + (mynode - 1) * pix_num + j];
1751
1752 subimage = (double *)HECMW_calloc(pixn * 3, sizeof(double));
1753 subopa = (double *)HECMW_calloc(pixn, sizeof(double));
1754 if ((subimage == NULL) || (subopa == NULL))
1755 HECMW_vis_memory_exit("subimage, subopa");
1756 HECMW_Barrier(VIS_COMM);
1757
1758 for (i = 0; i < pesize; i++) {
1759 if (mynode == i) {
1760 for (k = 0; k < pesize; k++) {
1761 if (k != i) {
1762 if (k == 0) {
1763 subimage1 =
1764 (double *)HECMW_calloc(pix0_num * 3, sizeof(double));
1765 subopa1 = (double *)HECMW_calloc(pix0_num, sizeof(double));
1766 } else if (k != 0) {
1767 subimage1 =
1768 (double *)HECMW_calloc(pix_num * 3, sizeof(double));
1769 subopa1 = (double *)HECMW_calloc(pix_num, sizeof(double));
1770 }
1771
1772 if ((subimage1 == NULL) || (subopa1 == NULL))
1773 HECMW_vis_memory_exit("subimage1, subopa1");
1774 if (k == 0) {
1775 for (j = 0; j < pix0_num * 3; j++) subimage1[j] = image[j];
1776 for (j = 0; j < pix0_num; j++) subopa1[j] = z_buffer[j];
1777 } else if (k != 0) {
1778 for (j = 0; j < pix_num * 3; j++)
1779 subimage1[j] =
1780 image[pix0_num * 3 + (k - 1) * pix_num * 3 + j];
1781 for (j = 0; j < pix_num; j++)
1782 subopa1[j] = z_buffer[pix0_num + (k - 1) * pix_num + j];
1783 }
1784 if (k == 0) {
1785 HECMW_Send(subimage1, pix0_num * 3, HECMW_DOUBLE, k, 0,
1786 VIS_COMM);
1787 HECMW_Send(subopa1, pix0_num, HECMW_DOUBLE, k, 0, VIS_COMM);
1788 } else if (k != 0) {
1789 HECMW_Send(subimage1, pix_num * 3, HECMW_DOUBLE, k, 0,
1790 VIS_COMM);
1791 HECMW_Send(subopa1, pix_num, HECMW_DOUBLE, k, 0, VIS_COMM);
1792 }
1793
1794 HECMW_free(subimage1);
1795 HECMW_free(subopa1);
1796 } /*if k!=i */
1797 } /*loop k*/
1798 }
1799 if (mynode != i) {
1800 HECMW_Recv(subimage, pixn * 3, HECMW_DOUBLE, i, HECMW_ANY_TAG,
1801 VIS_COMM, &stat);
1802 HECMW_Recv(subopa, pixn, HECMW_DOUBLE, i, HECMW_ANY_TAG, VIS_COMM,
1803 &stat);
1804 for (j = 0; j < pixn * 3; j++)
1805 n_subimage[i * pixn * 3 + j] = subimage[j];
1806 for (j = 0; j < pixn; j++) n_subopa[i * pixn + j] = subopa[j];
1807 }
1808 HECMW_Barrier(VIS_COMM);
1809 }
1810
1811 /* if(time_step==0) {
1812 */
1813
1814 composite_subimage_sf(pesize, pixn, n_subimage, n_subopa, subimage,
1815 subopa);
1816 HECMW_free(n_subimage);
1817 HECMW_free(n_subopa);
1818 /* HECMW_free(subopa);
1819 */
1820 /*send subimage to master PE */
1821 if (mynode != 0) {
1822 HECMW_Send(subimage, pixn * 3, HECMW_DOUBLE, 0, 0, VIS_COMM);
1823 HECMW_Send(subopa, pixn, HECMW_DOUBLE, 0, 0, VIS_COMM);
1824 }
1825
1826 if (mynode == 0) {
1827 for (j = 0; j < pix0_num * 3; j++) image[j] = subimage[j];
1828 for (j = 0; j < pix0_num; j++) z_buffer[j] = subopa[j];
1829 for (i = 1; i < pesize; i++) {
1830 HECMW_Recv(subimage, pix_num * 3, HECMW_DOUBLE, i, HECMW_ANY_TAG,
1831 VIS_COMM, &stat);
1832 HECMW_Recv(subopa, pix_num, HECMW_DOUBLE, i, HECMW_ANY_TAG,
1833 VIS_COMM, &stat);
1834
1835 for (j = 0; j < pix_num * 3; j++)
1836 image[pix0_num * 3 + (i - 1) * pix_num * 3 + j] = subimage[j];
1837 for (j = 0; j < pix_num; j++)
1838 z_buffer[pix0_num + (i - 1) * pix_num + j] = subopa[j];
1839 }
1840 if (sr->boundary_line_on == 1) { /* draw boundary line */
1841 fprintf(stderr,
1842 "Drawing boundary line: trange=%lf %lf %lf %lf %lf %lf\n",
1843 trange[0], trange[1], trange[2], trange[3], trange[4],
1844 trange[5]);
1845 for (m1 = 0; m1 < 6; m1++)
1846 for (m2 = 0; m2 < 4; m2++) {
1847 if (((m1 == 2) && (m2 == 0)) || ((m1 == 4) && (m2 == 1))) {
1848 iso_p[0] = trange[0];
1849 iso_p[1] = trange[2];
1850 iso_p[2] = trange[4];
1851 iso_p[3] = trange[1];
1852 iso_p[4] = trange[2];
1853 iso_p[5] = trange[4];
1854 } else if (((m1 == 0) && (m2 == 0)) ||
1855 ((m1 == 4) && (m2 == 0))) {
1856 iso_p[0] = trange[0];
1857 iso_p[1] = trange[2];
1858 iso_p[2] = trange[4];
1859 iso_p[3] = trange[0];
1860 iso_p[4] = trange[3];
1861 iso_p[5] = trange[4];
1862 } else if (((m1 == 0) && (m2 == 1)) ||
1863 ((m1 == 2) && (m2 == 3))) {
1864 iso_p[0] = trange[0];
1865 iso_p[1] = trange[2];
1866 iso_p[2] = trange[4];
1867 iso_p[3] = trange[0];
1868 iso_p[4] = trange[2];
1869 iso_p[5] = trange[5];
1870 } else if (((m1 == 1) && (m2 == 0)) ||
1871 ((m1 == 4) && (m2 == 2))) {
1872 iso_p[0] = trange[1];
1873 iso_p[1] = trange[2];
1874 iso_p[2] = trange[4];
1875 iso_p[3] = trange[1];
1876 iso_p[4] = trange[3];
1877 iso_p[5] = trange[4];
1878 } else if (((m1 == 1) && (m2 == 1)) ||
1879 ((m1 == 2) && (m2 == 1))) {
1880 iso_p[0] = trange[1];
1881 iso_p[1] = trange[2];
1882 iso_p[2] = trange[4];
1883 iso_p[3] = trange[1];
1884 iso_p[4] = trange[2];
1885 iso_p[5] = trange[5];
1886 } else if (((m1 == 2) && (m2 == 2)) ||
1887 ((m1 == 5) && (m2 == 1))) {
1888 iso_p[0] = trange[1];
1889 iso_p[1] = trange[2];
1890 iso_p[2] = trange[5];
1891 iso_p[3] = trange[0];
1892 iso_p[4] = trange[2];
1893 iso_p[5] = trange[5];
1894 } else if (((m1 == 1) && (m2 == 2)) ||
1895 ((m1 == 5) && (m2 == 2))) {
1896 iso_p[0] = trange[1];
1897 iso_p[1] = trange[2];
1898 iso_p[2] = trange[5];
1899 iso_p[3] = trange[1];
1900 iso_p[4] = trange[3];
1901 iso_p[5] = trange[5];
1902 } else if (((m1 == 0) && (m2 == 2)) ||
1903 ((m1 == 5) && (m2 == 0))) {
1904 iso_p[0] = trange[0];
1905 iso_p[1] = trange[2];
1906 iso_p[2] = trange[5];
1907 iso_p[3] = trange[0];
1908 iso_p[4] = trange[3];
1909 iso_p[5] = trange[5];
1910 } else if (((m1 == 0) && (m2 == 3)) ||
1911 ((m1 == 3) && (m2 == 0))) {
1912 iso_p[0] = trange[0];
1913 iso_p[1] = trange[3];
1914 iso_p[2] = trange[4];
1915 iso_p[3] = trange[0];
1916 iso_p[4] = trange[3];
1917 iso_p[5] = trange[5];
1918 } else if (((m1 == 3) && (m2 == 1)) ||
1919 ((m1 == 4) && (m2 == 3))) {
1920 iso_p[0] = trange[0];
1921 iso_p[1] = trange[3];
1922 iso_p[2] = trange[4];
1923 iso_p[3] = trange[1];
1924 iso_p[4] = trange[3];
1925 iso_p[5] = trange[4];
1926 } else if (((m1 == 1) && (m2 == 3)) ||
1927 ((m1 == 3) && (m2 == 2))) {
1928 iso_p[0] = trange[1];
1929 iso_p[1] = trange[3];
1930 iso_p[2] = trange[4];
1931 iso_p[3] = trange[1];
1932 iso_p[4] = trange[3];
1933 iso_p[5] = trange[5];
1934 } else if (((m1 == 3) && (m2 == 3)) ||
1935 ((m1 == 5) && (m2 == 3))) {
1936 iso_p[0] = trange[1];
1937 iso_p[1] = trange[3];
1938 iso_p[2] = trange[5];
1939 iso_p[3] = trange[0];
1940 iso_p[4] = trange[3];
1941 iso_p[5] = trange[5];
1942 }
1943
1944 if (m1 == 0) {
1945 f[0][0] = trange[0];
1946 f[0][1] = trange[2];
1947 f[0][2] = trange[4];
1948 f[1][0] = trange[0];
1949 f[1][1] = trange[3];
1950 f[1][2] = trange[4];
1951 f[2][0] = trange[0];
1952 f[2][1] = trange[3];
1953 f[2][2] = trange[5];
1954 } else if (m1 == 1) {
1955 f[0][0] = trange[1];
1956 f[0][1] = trange[2];
1957 f[0][2] = trange[4];
1958 f[1][0] = trange[1];
1959 f[1][1] = trange[2];
1960 f[1][2] = trange[5];
1961 f[2][0] = trange[1];
1962 f[2][1] = trange[3];
1963 f[2][2] = trange[4];
1964 } else if (m1 == 2) {
1965 f[0][0] = trange[0];
1966 f[0][1] = trange[2];
1967 f[0][2] = trange[4];
1968 f[1][0] = trange[0];
1969 f[1][1] = trange[2];
1970 f[1][2] = trange[5];
1971 f[2][0] = trange[1];
1972 f[2][1] = trange[2];
1973 f[2][2] = trange[5];
1974 } else if (m1 == 3) {
1975 f[0][0] = trange[0];
1976 f[0][1] = trange[3];
1977 f[0][2] = trange[4];
1978 f[1][0] = trange[1];
1979 f[1][1] = trange[3];
1980 f[1][2] = trange[4];
1981 f[2][0] = trange[1];
1982 f[2][1] = trange[3];
1983 f[2][2] = trange[5];
1984 }
1985
1986 else if (m1 == 4) {
1987 f[0][0] = trange[0];
1988 f[0][1] = trange[2];
1989 f[0][2] = trange[4];
1990 f[1][0] = trange[1];
1991 f[1][1] = trange[2];
1992 f[1][2] = trange[4];
1993 f[2][0] = trange[0];
1994 f[2][1] = trange[3];
1995 f[2][2] = trange[4];
1996 } else if (m1 == 5) {
1997 f[0][0] = trange[0];
1998 f[0][1] = trange[3];
1999 f[0][2] = trange[5];
2000 f[1][0] = trange[1];
2001 f[1][1] = trange[3];
2002 f[1][2] = trange[5];
2003 f[2][0] = trange[1];
2004 f[2][1] = trange[2];
2005 f[2][2] = trange[5];
2006 }
2007
2008 transform_frame4(sr->screen_point, iso_p, coff_matrix, n_iso);
2009 find_projection_range3(view_point, n_iso, pixel_d, iso_p);
2010 for (j = 0; j < 2; j++) {
2011 pixel_i[j][0] =
2012 (int)((pixel_d[j][0] - scr_area[0]) / xd - 0.5) + start_x;
2013 pixel_i[j][1] =
2014 (int)((pixel_d[j][1] - scr_area[2]) / yd + 0.5) + start_y;
2015 }
2016 if (pixel_i[1][0] != pixel_i[0][0]) {
2017 slip_y = (double)(pixel_i[1][1] - pixel_i[0][1]) /
2018 (double)(pixel_i[1][0] - pixel_i[0][0]);
2019 last_j = pixel_i[0][1];
2020 for (i = pixel_i[0][0]; i <= pixel_i[1][0]; i++) {
2021 next_j = (int)(pixel_i[0][1] +
2022 slip_y * (double)(i - pixel_i[0][0]));
2023 if (last_j <= next_j) {
2024 for (j = last_j; j <= next_j; j++) {
2025 x = xd * (i - start_x + 0.5) + scr_area[0];
2026 y = yd * (j - start_y + 0.5) + scr_area[2];
2027 point_s[0] = x;
2028 point_s[1] = y;
2029 point_s[2] = 0.0;
2030 tranverse_transform(sr->screen_point, point_s,
2031 inv_matrix, point_o);
2032 intersection = find2_point_depth(
2033 f, point_o, sr->view_point_d, inter_point);
2034 if (intersection == 1)
2035 depth =
2036 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
2037 SQR(inter_point[1] - sr->view_point_d[1]) +
2038 SQR(inter_point[2] - sr->view_point_d[2]));
2039 else
2040 depth = 1.0E17 + 1;
2041 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
2042 image[(j * sr->xr + i) * 3] = sr->font_color[0];
2043 image[(j * sr->xr + i) * 3 + 1] = sr->font_color[1];
2044 image[(j * sr->xr + i) * 3 + 2] = sr->font_color[2];
2045 z_buffer[j * sr->xr + i] = depth;
2046 }
2047 }
2048 } else {
2049 for (j = last_j; j >= next_j; j--) {
2050 x = xd * (i - start_x + 0.5) + scr_area[0];
2051 y = yd * (j - start_y + 0.5) + scr_area[2];
2052 point_s[0] = x;
2053 point_s[1] = y;
2054 point_s[2] = 0.0;
2055 tranverse_transform(sr->screen_point, point_s,
2056 inv_matrix, point_o);
2057 intersection = find2_point_depth(
2058 f, point_o, sr->view_point_d, inter_point);
2059 if (intersection == 1)
2060 depth =
2061 sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
2062 SQR(inter_point[1] - sr->view_point_d[1]) +
2063 SQR(inter_point[2] - sr->view_point_d[2]));
2064 else
2065 depth = 1.0E17 + 1;
2066 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
2067 image[(j * sr->xr + i) * 3] = sr->font_color[0];
2068 image[(j * sr->xr + i) * 3 + 1] = sr->font_color[1];
2069 image[(j * sr->xr + i) * 3 + 2] = sr->font_color[2];
2070 z_buffer[j * sr->xr + i] = depth;
2071 }
2072 }
2073 }
2074
2075 last_j = next_j;
2076 }
2077 } else {
2078 i = pixel_i[0][0];
2079 if (pixel_i[0][1] <= pixel_i[1][1]) {
2080 for (j = pixel_i[0][1]; j <= pixel_i[1][1]; j++) {
2081 x = xd * (i - start_x + 0.5) + scr_area[0];
2082 y = yd * (j - start_y + 0.5) + scr_area[2];
2083 /*transform to the original frame */
2084 point_s[0] = x;
2085 point_s[1] = y;
2086 point_s[2] = 0.0;
2087 tranverse_transform(sr->screen_point, point_s, inv_matrix,
2088 point_o);
2089 intersection = find2_point_depth(
2090 f, point_o, sr->view_point_d, inter_point);
2091 if (intersection == 1)
2092 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
2093 SQR(inter_point[1] - sr->view_point_d[1]) +
2094 SQR(inter_point[2] - sr->view_point_d[2]));
2095 else
2096 depth = 1.0E17 + 1;
2097 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
2098 image[(j * sr->xr + i) * 3] = sr->font_color[0];
2099 image[(j * sr->xr + i) * 3 + 1] = sr->font_color[1];
2100 image[(j * sr->xr + i) * 3 + 2] = sr->font_color[2];
2101 z_buffer[j * sr->xr + i] = depth;
2102 }
2103 }
2104 } else if (pixel_i[0][1] > pixel_i[1][1]) {
2105 for (j = pixel_i[1][1]; j <= pixel_i[0][1]; j++) {
2106 x = xd * (i - start_x + 0.5) + scr_area[0];
2107 y = yd * (j - start_y + 0.5) + scr_area[2];
2108 /*transform to the original frame */
2109 point_s[0] = x;
2110 point_s[1] = y;
2111 point_s[2] = 0.0;
2112 tranverse_transform(sr->screen_point, point_s, inv_matrix,
2113 point_o);
2114 intersection = find2_point_depth(
2115 f, point_o, sr->view_point_d, inter_point);
2116 if (intersection == 1)
2117 depth = sqrt(SQR(inter_point[0] - sr->view_point_d[0]) +
2118 SQR(inter_point[1] - sr->view_point_d[1]) +
2119 SQR(inter_point[2] - sr->view_point_d[2]));
2120 else
2121 depth = 1.0E17 + 1;
2122 if (depth <= z_buffer[j * sr->xr + i] + EPSILON) {
2123 image[(j * sr->xr + i) * 3] = sr->font_color[0];
2124 image[(j * sr->xr + i) * 3 + 1] = sr->font_color[1];
2125 image[(j * sr->xr + i) * 3 + 2] = sr->font_color[2];
2126 z_buffer[j * sr->xr + i] = depth;
2127 }
2128 }
2129 }
2130 }
2131 }
2132 }
2133 }
2134 HECMW_free(subimage);
2135 HECMW_free(subopa);
2136 }
2137 if (mynode == 0) {
2138 fprintf(stderr, " Finish combining \n");
2139 /*
2140t3=HECMW_Wtime();
2141fprintf(stderr, "The combining time is %lf the total time up to now is %lf\n",
2142t3-t2, t3-t1);
2143t2=t3;
2144 */
2145
2146 /*output result in image of master pe */
2147 /* sprintf(rname, "%s-%d", outfile,
2148step_start+time_step*step_interv);
2149
2150if ((outfp = fopen(rname, "w")) == NULL) {
2151fprintf(stderr, "There is no such an input data file:\n");
2152exit (0);
2153}
2154fprintf(outfp, "%d %d\n", vr->xr, vr->yr);
2155for(j=0;j<yr;j++)
2156for(i=xr-1;i>=0;i--)
2157 fprintf(outfp, "%lf %lf %lf\n", image[(j*xr+i)*3], image[(j*xr+i)*3+1],
2158 image[(j*xr+i)*3+2]);
2159fclose(outfp);
2160 */
2161 if (sr->fixed_scale_mark == 0)
2164 sr->mark_0_on, sr->color_mapping_bar_on, sr->xr, sr->yr,
2167 tmincolor, tmaxcolor, org_mincolor, org_maxcolor, image);
2168 if (sr->fixed_scale_mark == 1)
2171 sr->mark_0_on, sr->color_mapping_bar_on, sr->xr, sr->yr,
2174 tmincolor, tmaxcolor, tmincolor, tmaxcolor, image);
2175 /* fprintf(stderr, "time_mark_on is %d timestep is %d\n",
2176 * sr->time_mark_on, timestep);
2177 */
2178 if (sr->time_mark_on == 1)
2179 mark_time_label(sr->font_size, sr->xr, sr->yr, sr->font_color,
2180 sr->background_color, start_time, time_interval,
2181 timestep, len_step, image);
2182 /* (void)GEOFEM_file_translate_filename(geofem_output_file,
2183 fname, GEOFEM_INDEPENDENT);
2184{
2185int n = strlen(fname);
2186char *ptr = fname + n;
2187while(*ptr != '.') {
2188ptr--;
2189}
2190 *ptr = '\0';
2191}
2192
2193{
2194char buf[128];
2195strcat(fname, ".");
2196sprintf(buf, "%d.%d", v->count, ii);
2197strcat(fname, buf);
2198strcat(fname, ".bmp");
2199}
2200
2201 */
2202 if ((sr->rotate_style > 0) && (sr->deform_num_of_frames < 2)) {
2203 if (ii >= 10)
2204 sprintf(fname, "%s.%d.bmp", outfile, ii);
2205 else
2206 sprintf(fname, "%s.0%d.bmp", outfile, ii);
2207 }
2208 if ((sr->rotate_style > 0) && (sr->deform_num_of_frames > 1)) {
2209 if (jjj >= 10)
2210 sprintf(fname, "%s.%d.%d.bmp", outfile, ii, jjj);
2211 else
2212 sprintf(fname, "%s.%d.0%d.bmp", outfile, ii, jjj);
2213 }
2214 if ((sr->rotate_style == 0) && (sr->deform_num_of_frames > 1)) {
2215 if (jjj >= 10)
2216 sprintf(fname, "%s.%d.bmp", outfile, jjj);
2217 else
2218 sprintf(fname, "%s.0%d.bmp", outfile, jjj);
2219 }
2220
2221 if ((sr->rotate_style == 0) && (sr->deform_num_of_frames < 2))
2222 sprintf(fname, "%s.bmp", outfile);
2223
2224 outfp = fopen(fname, "wb");
2225
2226 if (!outfp)
2228 "ERROR: HEC-MW-VIS-E0009: Cannot open output file");
2229
2230 header.bfSize = 54 + 3 * sr->xr * sr->yr;
2231#ifdef CONVERSE_ORDER
2232 header.bfSize = change_unsigned_int_order(54 + 3 * sr->xr * sr->yr);
2233#endif
2234 header.bfReserved1 = 0;
2235#ifdef CONVERSE_ORDER
2237#endif
2238
2239 header.bfReserved2 = 0;
2240#ifdef CONVERSE_ORDER
2242#endif
2243
2244 header.bfOffBits = 54;
2245#ifdef CONVERSE_ORDER
2247#endif
2248
2249 info.biBitCount = 24;
2250#ifdef CONVERSE_ORDER
2252#endif
2253
2254 info.biSize = 40;
2255#ifdef CONVERSE_ORDER
2257#endif
2258
2259 info.biWidth = sr->xr;
2260#ifdef CONVERSE_ORDER
2261 info.biWidth = change_int_order(sr->xr);
2262#endif
2263
2264 info.biHeight = sr->yr;
2265#ifdef CONVERSE_ORDER
2266 info.biHeight = change_int_order(sr->yr);
2267#endif
2268
2269 info.biSizeImage = 3 * sr->xr * sr->yr;
2270#ifdef CONVERSE_ORDER
2271 info.biSizeImage = change_unsigned_int_order(3 * sr->xr * sr->yr);
2272#endif
2273
2274 info.biClrImportant = 0;
2275#ifdef CONVERSE_ORDER
2277#endif
2278
2279 info.biClrUsed = 0;
2280#ifdef CONVERSE_ORDER
2282#endif
2283
2284 info.biCompression = 0;
2285#ifdef CONVERSE_ORDER
2287#endif
2288
2289 info.biPlanes = 1;
2290#ifdef CONVERSE_ORDER
2292#endif
2293
2294 info.biXPelsPerMeter = 3780;
2295#ifdef CONVERSE_ORDER
2296 info.biXPelsPerMeter = change_int_order(3780);
2297#endif
2298
2299 info.biYPelsPerMeter = 3780;
2300#ifdef CONVERSE_ORDER
2301 info.biYPelsPerMeter = change_int_order(3780);
2302#endif
2303
2304 putc('B', outfp);
2305 putc('M', outfp);
2306 fwrite(&(header.bfSize), sizeof(unsigned int), 1, outfp);
2307 fwrite(&header.bfReserved1, sizeof(unsigned short int), 1, outfp);
2308 fwrite(&header.bfReserved2, sizeof(unsigned short int), 1, outfp);
2309 fwrite(&header.bfOffBits, sizeof(unsigned int), 1, outfp);
2310 fwrite(&info, 40, 1, outfp);
2311 for (j = 0; j < sr->yr; j++)
2312 for (i = sr->xr - 1; i >= 0; i--) {
2313 if ((image[(j * sr->xr + i) * 3] < 0.1) &&
2314 (image[(j * sr->xr + i) * 3 + 1] < 0.1) &&
2315 (image[(j * sr->xr + i) * 3 + 2] < 0.1)) {
2316 ri = (int)(sr->background_color[0] * 256);
2317 gi = (int)(sr->background_color[1] * 256);
2318 bi = (int)(sr->background_color[2] * 256);
2319 } else {
2320 ri = (int)(image[(j * sr->xr + i) * 3] * 256);
2321 gi = (int)(image[(j * sr->xr + i) * 3 + 1] * 256);
2322 bi = (int)(image[(j * sr->xr + i) * 3 + 2] * 256);
2323 }
2324 if (ri < 0) ri = 0;
2325 if (ri > 255) ri = 255;
2326 if (gi < 0) gi = 0;
2327 if (gi > 255) gi = 255;
2328 if (bi < 0) bi = 0;
2329 if (bi > 255) bi = 255;
2330 r = ri;
2331 g = gi;
2332 b = bi;
2333 putc(b, outfp);
2334 putc(g, outfp);
2335 putc(r, outfp);
2336 }
2337
2338 fclose(outfp);
2339 }
2341 HECMW_free(z_buffer);
2342 if (sr->smooth_shading == 1) {
2343 HECMW_free(v_normal);
2344 HECMW_free(p_normal);
2345 HECMW_free(v_num);
2346 }
2347 }
2348 } /*for jjj loop */
2349
2350 /*
2351if(pvr->surface_on==1) {
2352 HECMW_free(surface->color);
2353 HECMW_free(surface->vertex);
2354 HECMW_free(surface->patch);
2355 HECMW_free(surface);
2356}
2357 */
2358 /* fclose(fp2);
2359 */
2360 /* if(mynode==0) {
2361fprintf(stderr, " Finish rendering\n");
2362t3=HECMW_Wtime();
2363fprintf(stderr, " the time for rendering and output is %lf the total time of the
2364module is %lf\n", t3-t2, t3-t1);
2365}
2366 */
2367
2368 return;
2369}
if(!(yy_init))
Definition: hecmw_ablex.c:1305
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:364
int HECMW_Send(void *buffer, int count, HECMW_Datatype datatype, int dest, int tag, HECMW_Comm comm)
Definition: hecmw_comm.c:193
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:235
#define HECMW_MAX
Definition: hecmw_config.h:56
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:54
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 NUM_CONTROL_PSF
int find_surface_point(double fp[3][3], double point_o[3], double view_point_d[3], double point[3], double n_f[4], double v_f[9], double c_value[3], double *value, double normal[9], int normal_flag, int smooth_shading)
void compute_color_sf(double p[3], double value, double n[3], int color_mapping_style, double *interval_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 accum_rgba[4], double mincolor, double maxcolor, int display_method)
int find2_point_depth(double fp[3][3], double point_o[3], double view_point_d[3], double point[3])
int find_point_depth(double fp[3][3], double point_o[3], double view_point_d[3], double n_f[4], double point[3], int normal_flag)
#define EPSILON
void value_to_rgb(double value, double color[3], double mincolor, double maxcolor, int color_mapping_style, double *interval_point, int interval_mapping_num, int color_system_type)
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])
int change_int_order(int n)
void mark_time_label(double font_size, int xr, int yr, double font_color[3], double background_color[3], double start_time, double time_interval, int timestep, int max_len_step, double *image)
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 find_minmax_sf(struct hecmwST_local_mesh *mesh, int mynode, double range[6])
void find_new_patch_minmax_sf(Result *result, struct surface_module *sf, double range[6])
void get_deform_scale(struct surface_module *sf, int ii, double range_x, double range_y, double range_z, struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int pesize, HECMW_Comm VIS_COMM)
void output_histogram_sf(struct surface_module *sf, int *color_list, struct hecmwST_result_data *data, double *mivalue, double *mavalue, Result *result, int mynode, int pesize, HECMW_Comm VIS_COMM)
void generate_interval_point_sf(struct surface_module *sf, int *color_list, struct hecmwST_result_data *data, double *mivalue, double *mavalue, Result *result, int mynode, int pesize, HECMW_Comm VIS_COMM, double *interval_point)
void find_patch_minmax_sf(Result *result, struct surface_module *sf, double range[6])
void generate_histogram_graph_sf(struct surface_module *sf, int *color_list, struct hecmwST_result_data *data, double *mivalue, double *mavalue, Result *result, int mynode, int pesize, HECMW_Comm VIS_COMM, int color_system_type)
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 HECMW_vis_print_exit(char *var)
void HECMW_vis_memory_exit(char *var)
#define SQR(x)
int ms
int ns
void HECMW_vis_rendering_surface(struct surface_module *sf, Parameter_rendering *sr, struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int tvertex, int tpatch, int *color_list, double *minvalue, double *maxvalue, Result *result, char *outfile, int stat_para[NUM_CONTROL_PSF], HECMW_Comm VIS_COMM, int timestep)
double * image
void composite_subimage_sf(int pesize, int pixn, double *n_subimage, double *n_subopa, double *subimage, double *subopa)
int find_line_segment(double f[3][3], double c[3], double isocolor, double iso_p[6])
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