FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_vis_font_texture.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 <string.h>
10 #include <math.h>
11 #include "hecmw_vis_mem_util.h"
13 
14 #define BAR_WIDTH 10
15 #define EPSILON 0.00000001
16 
17 static void font5_generate(char input, int output[5][5]) {
18  int output0[5][5] = {{0, 1, 1, 1, 0},
19  {0, 1, 0, 1, 0},
20  {0, 1, 0, 1, 0},
21  {0, 1, 0, 1, 0},
22  {0, 1, 1, 1, 0}},
23  output1[5][5] = {{0, 0, 1, 0, 0},
24  {0, 0, 1, 0, 0},
25  {0, 0, 1, 0, 0},
26  {0, 0, 1, 0, 0},
27  {0, 0, 1, 0, 0}},
28  output2[5][5] = {{0, 1, 1, 1, 0},
29  {0, 0, 0, 1, 0},
30  {0, 1, 1, 1, 0},
31  {0, 1, 0, 0, 0},
32  {0, 1, 1, 1, 0}},
33  output3[5][5] = {{0, 1, 1, 1, 0},
34  {0, 0, 0, 1, 0},
35  {0, 1, 1, 1, 0},
36  {0, 0, 0, 1, 0},
37  {0, 1, 1, 1, 0}},
38  output4[5][5] = {{0, 1, 0, 1, 0},
39  {0, 1, 0, 1, 0},
40  {0, 1, 1, 1, 0},
41  {0, 0, 0, 1, 0},
42  {0, 0, 0, 1, 0}},
43  output5[5][5] = {{0, 1, 1, 1, 0},
44  {0, 1, 0, 0, 0},
45  {0, 1, 1, 1, 0},
46  {0, 0, 0, 1, 0},
47  {0, 1, 1, 1, 0}},
48  output6[5][5] = {{0, 1, 1, 1, 0},
49  {0, 1, 0, 0, 0},
50  {0, 1, 1, 1, 0},
51  {0, 1, 0, 1, 0},
52  {0, 1, 1, 1, 0}},
53  output7[5][5] = {{0, 1, 1, 1, 0},
54  {0, 0, 0, 1, 0},
55  {0, 0, 0, 1, 0},
56  {0, 0, 0, 1, 0},
57  {0, 0, 0, 1, 0}},
58  output8[5][5] = {{0, 1, 1, 1, 0},
59  {0, 1, 0, 1, 0},
60  {0, 1, 1, 1, 0},
61  {0, 1, 0, 1, 0},
62  {0, 1, 1, 1, 0}},
63  output9[5][5] = {{0, 1, 1, 1, 0},
64  {0, 1, 0, 1, 0},
65  {0, 1, 1, 1, 0},
66  {0, 0, 0, 1, 0},
67  {0, 1, 1, 1, 0}},
68  outpute[5][5] = {{0, 1, 1, 1, 0},
69  {0, 1, 0, 0, 0},
70  {0, 1, 1, 1, 0},
71  {0, 1, 0, 0, 0},
72  {0, 1, 1, 1, 0}},
73  outputd[5][5] = {{0, 0, 0, 0, 0},
74  {0, 0, 0, 0, 0},
75  {0, 0, 0, 0, 0},
76  {0, 1, 1, 0, 0},
77  {0, 1, 1, 0, 0}},
78  outputa[5][5] = {{0, 0, 0, 0, 0},
79  {0, 0, 1, 0, 0},
80  {0, 1, 1, 1, 0},
81  {0, 0, 1, 0, 0},
82  {0, 0, 0, 0, 0}},
83  outputs[5][5] = {{0, 0, 0, 0, 0},
84  {0, 0, 0, 0, 0},
85  {0, 1, 1, 1, 0},
86  {0, 0, 0, 0, 0},
87  {0, 0, 0, 0, 0}},
88  outputt[5][5] = {{1, 1, 1, 1, 1},
89  {0, 0, 1, 0, 0},
90  {0, 0, 1, 0, 0},
91  {0, 0, 1, 0, 0},
92  {0, 0, 1, 0, 0}},
93  outputq[5][5] = {{0, 0, 0, 0, 0},
94  {0, 1, 1, 1, 0},
95  {0, 0, 0, 0, 0},
96  {0, 1, 1, 1, 0},
97  {0, 0, 0, 0, 0}},
98  outputf[5][5] = {{0, 1, 1, 1, 0},
99  {0, 1, 0, 0, 0},
100  {0, 1, 1, 1, 0},
101  {0, 0, 0, 1, 0},
102  {0, 1, 1, 1, 0}};
103  int i, j;
104 
105  switch (input) {
106  case '0':
107  for (i = 0; i < 5; i++)
108  for (j = 0; j < 5; j++) output[i][j] = output0[i][j];
109  break;
110  case '1':
111  for (i = 0; i < 5; i++)
112  for (j = 0; j < 5; j++) output[i][j] = output1[i][j];
113  break;
114  case '2':
115  for (i = 0; i < 5; i++)
116  for (j = 0; j < 5; j++) output[i][j] = output2[i][j];
117  break;
118  case '3':
119  for (i = 0; i < 5; i++)
120  for (j = 0; j < 5; j++) output[i][j] = output3[i][j];
121  break;
122  case '4':
123  for (i = 0; i < 5; i++)
124  for (j = 0; j < 5; j++) output[i][j] = output4[i][j];
125  break;
126  case '5':
127  for (i = 0; i < 5; i++)
128  for (j = 0; j < 5; j++) output[i][j] = output5[i][j];
129  break;
130  case '6':
131  for (i = 0; i < 5; i++)
132  for (j = 0; j < 5; j++) output[i][j] = output6[i][j];
133  break;
134  case '7':
135  for (i = 0; i < 5; i++)
136  for (j = 0; j < 5; j++) output[i][j] = output7[i][j];
137  break;
138  case '8':
139  for (i = 0; i < 5; i++)
140  for (j = 0; j < 5; j++) output[i][j] = output8[i][j];
141  break;
142  case '9':
143  for (i = 0; i < 5; i++)
144  for (j = 0; j < 5; j++) output[i][j] = output9[i][j];
145  break;
146  case 'E':
147  for (i = 0; i < 5; i++)
148  for (j = 0; j < 5; j++) output[i][j] = outpute[i][j];
149  break;
150  case '.':
151  for (i = 0; i < 5; i++)
152  for (j = 0; j < 5; j++) output[i][j] = outputd[i][j];
153  break;
154  case '+':
155  for (i = 0; i < 5; i++)
156  for (j = 0; j < 5; j++) output[i][j] = outputa[i][j];
157  break;
158  case '-':
159  for (i = 0; i < 5; i++)
160  for (j = 0; j < 5; j++) output[i][j] = outputs[i][j];
161  break;
162  case 'T':
163  for (i = 0; i < 5; i++)
164  for (j = 0; j < 5; j++) output[i][j] = outputt[i][j];
165  break;
166  case '=':
167  for (i = 0; i < 5; i++)
168  for (j = 0; j < 5; j++) output[i][j] = outputq[i][j];
169  break;
170  case 's':
171  for (i = 0; i < 5; i++)
172  for (j = 0; j < 5; j++) output[i][j] = outputf[i][j];
173  break;
174  default:
175  for (i = 0; i < 5; i++)
176  for (j = 0; j < 5; j++) output[i][j] = 0;
177  break;
178  }
179  return;
180 }
181 
182 void font7_generate(char input, int output[7][7]) {
183  int output0[7][7] = {{0, 0, 1, 1, 1, 0, 0}, {0, 1, 0, 0, 0, 1, 0},
184  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
185  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
186  {0, 0, 1, 1, 1, 0, 0}},
187  output1[7][7] = {{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
188  {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
189  {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
190  {0, 0, 0, 1, 0, 0, 0}},
191  output2[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
192  {0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 0},
193  {0, 1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0},
194  {0, 1, 1, 1, 1, 1, 0}},
195  output3[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
196  {0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 0},
197  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
198  {0, 1, 1, 1, 1, 1, 0}},
199  output4[7][7] = {{0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
200  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 0},
201  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
202  {0, 0, 0, 0, 0, 1, 0}},
203  output5[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0},
204  {0, 1, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
205  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
206  {0, 1, 1, 1, 1, 1, 0}},
207  output6[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0},
208  {0, 1, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
209  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
210  {0, 1, 1, 1, 1, 1, 0}},
211  output7[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
212  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
213  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
214  {0, 0, 0, 0, 0, 1, 0}},
215  output8[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
216  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 0},
217  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
218  {0, 1, 1, 1, 1, 1, 0}},
219  output9[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 1, 0},
220  {0, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 0},
221  {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1, 0},
222  {0, 1, 1, 1, 1, 1, 0}},
223  outpute[7][7] = {{0, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0},
224  {0, 1, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
225  {0, 1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0},
226  {0, 1, 1, 1, 1, 1, 0}},
227  outputd[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
228  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
229  {0, 0, 1, 1, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0},
230  {0, 0, 0, 0, 0, 0, 0}},
231  outputa[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
232  {0, 0, 0, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
233  {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
234  {0, 0, 0, 0, 0, 0, 0}},
235  outputs[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
236  {0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
237  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
238  {0, 0, 0, 0, 0, 0, 0}},
239  outputt[7][7] = {{1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 1, 0, 0, 0},
240  {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
241  {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
242  {0, 0, 0, 1, 0, 0, 0}},
243  outputq[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
244  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
245  {0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0},
246  {0, 0, 0, 0, 0, 0, 0}},
247  outputf[7][7] = {{0, 0, 1, 1, 1, 0, 0}, {0, 1, 0, 0, 0, 1, 0},
248  {0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0},
249  {0, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 0, 1, 0},
250  {0, 0, 1, 1, 1, 0, 0}};
251  int i, j;
252 
253  switch (input) {
254  case '0':
255  for (i = 0; i < 7; i++)
256  for (j = 0; j < 7; j++) output[i][j] = output0[i][j];
257  break;
258  case '1':
259  for (i = 0; i < 7; i++)
260  for (j = 0; j < 7; j++) output[i][j] = output1[i][j];
261  break;
262  case '2':
263  for (i = 0; i < 7; i++)
264  for (j = 0; j < 7; j++) output[i][j] = output2[i][j];
265  break;
266  case '3':
267  for (i = 0; i < 7; i++)
268  for (j = 0; j < 7; j++) output[i][j] = output3[i][j];
269  break;
270  case '4':
271  for (i = 0; i < 7; i++)
272  for (j = 0; j < 7; j++) output[i][j] = output4[i][j];
273  break;
274  case '5':
275  for (i = 0; i < 7; i++)
276  for (j = 0; j < 7; j++) output[i][j] = output5[i][j];
277  break;
278  case '6':
279  for (i = 0; i < 7; i++)
280  for (j = 0; j < 7; j++) output[i][j] = output6[i][j];
281  break;
282  case '7':
283  for (i = 0; i < 7; i++)
284  for (j = 0; j < 7; j++) output[i][j] = output7[i][j];
285  break;
286  case '8':
287  for (i = 0; i < 7; i++)
288  for (j = 0; j < 7; j++) output[i][j] = output8[i][j];
289  break;
290  case '9':
291  for (i = 0; i < 7; i++)
292  for (j = 0; j < 7; j++) output[i][j] = output9[i][j];
293  break;
294  case 'E':
295  for (i = 0; i < 7; i++)
296  for (j = 0; j < 7; j++) output[i][j] = outpute[i][j];
297  break;
298  case '.':
299  for (i = 0; i < 7; i++)
300  for (j = 0; j < 7; j++) output[i][j] = outputd[i][j];
301  break;
302  case '+':
303  for (i = 0; i < 7; i++)
304  for (j = 0; j < 7; j++) output[i][j] = outputa[i][j];
305  break;
306  case '-':
307  for (i = 0; i < 7; i++)
308  for (j = 0; j < 7; j++) output[i][j] = outputs[i][j];
309  break;
310  case 'T':
311  for (i = 0; i < 7; i++)
312  for (j = 0; j < 7; j++) output[i][j] = outputt[i][j];
313  break;
314  case '=':
315  for (i = 0; i < 7; i++)
316  for (j = 0; j < 7; j++) output[i][j] = outputq[i][j];
317  break;
318  case 's':
319  for (i = 0; i < 7; i++)
320  for (j = 0; j < 7; j++) output[i][j] = outputf[i][j];
321  break;
322  default:
323  for (i = 0; i < 7; i++)
324  for (j = 0; j < 7; j++) output[i][j] = 0;
325  break;
326  }
327  return;
328 }
329 
330 void mark_time_label(double font_size, int xr, int yr, double font_color[3],
331  double background_color[3], double start_time,
332  double time_interval, int timestep, int max_len_step,
333  double *image) {
334  int i, j, m;
335  int start_ys, start_xs, scale, len_step;
336  double vv;
337  char buf[128], buf1[128], buf2[128], buf3[128];
338  int output7[7][7], tmp1, tmp2;
339 
340  font_size = 2.5;
341  scale = (int)font_size;
342  start_xs = 30;
343  start_ys = yr - 25;
344  vv = start_time + (double)timestep * time_interval;
345  tmp1 = (int)vv;
346  tmp2 = (int)((vv - (double)tmp1) * 100.0);
347  sprintf(buf1, "%d", tmp1);
348  len_step = strlen(buf1);
349 
350  if (len_step < max_len_step) {
351  for (i = 0; i < max_len_step - len_step; i++) buf2[i] = ' ';
352 
353  for (i = max_len_step - len_step; i < max_len_step; i++)
354  buf2[i] = buf1[i - (max_len_step - len_step)];
355 
356  buf2[max_len_step] = '\0';
357  } else {
358  sprintf(buf2, "%s", buf1);
359  }
360 
361  sprintf(buf3, "%d", tmp2);
362 
363  if (strlen(buf3) < 2) {
364  buf3[2] = '\0';
365  buf3[1] = buf3[0];
366  buf3[0] = '0';
367  }
368 
369  sprintf(buf, "%s%s.%s%s", "T=", buf2, buf3, "s");
370 
371  for (m = 0; m < max_len_step + 6; m++) {
372  font7_generate(buf[max_len_step + 5 - m], output7);
373  for (j = 0; j < 7 * scale; j++)
374  for (i = 0; i < 7 * scale; i++) {
375  if (output7[6 - (int)(j / scale)][(int)(i / scale)] == 1) {
376  image[((start_ys + j) * xr + start_xs - i) * 3] = font_color[0];
377  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] = font_color[1];
378  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] = font_color[2];
379  } else {
380  image[((start_ys + j) * xr + start_xs - i) * 3] = background_color[0];
381  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
382  background_color[1];
383  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
384  background_color[2];
385  }
386  }
387  start_xs += 7 * scale;
388  }
389  return;
390 }
391 
392 void value2_to_rgb(double value, double color[3], int color_system_type) {
393  double r, g, b;
394 
395  if (color_system_type == 1) {
396  if (value < 0.0) value = 0.0;
397  if (value > 1.0) value = 1.0;
398 
399  if (value <= 0.25) {
400  r = 0.0;
401  g = value * 4.0;
402  b = 1.0;
403  } else if ((value > 0.25) && (value <= 0.5)) {
404  r = 0.0;
405  g = 1.0;
406  b = (0.5 - value) * 4.0;
407  } else if ((value > 0.5) && (value <= 0.75)) {
408  r = (value - 0.5) * 4.0;
409  g = 1.0;
410  b = 0.0;
411  } else if (value > 0.75) {
412  r = 1.0;
413  g = (1.0 - value) * 4.0;
414  b = 0.0;
415  }
416 
417  } else if (color_system_type == 2) {
418  if (value < 0.0) value = 0.0;
419  if (value > 1.0) value = 1.0;
420 
421  if (value <= 0.2) {
422  r = (0.2 - value) * 5.0;
423  g = 0.0;
424  b = 1.0;
425  } else if ((value > 0.2) && (value <= 0.4)) {
426  r = 0.0;
427  g = (value - 0.2) * 5.0;
428  b = 1.0;
429  } else if ((value > 0.4) && (value <= 0.6)) {
430  r = 0.0;
431  g = 1.0;
432  b = 1.0 - (value - 0.4) * 5.0;
433  } else if ((value > 0.6) && (value <= 0.8)) {
434  r = (value - 0.6) * 5.0;
435  g = 1.0;
436  b = 0.0;
437  } else if (value > 0.0) {
438  r = 1.0;
439  g = 1.0 - (value - 0.8) * 5.0;
440  b = 0.0;
441  }
442  } else if (color_system_type == 3) {
443  r = g = b = value;
444  }
445 
446  color[0] = r;
447  color[1] = g;
448  color[2] = b;
449 
450  return;
451 }
452 
453 static double rgb_to_value(double value_rgb, double mincolor, double maxcolor,
454  int color_mapping_style, double *interval_point,
455  int interval_mapping_num) {
456  double value;
457  int i;
458 
459  if (color_mapping_style == 1) {
460  if (fabs(maxcolor - mincolor) > EPSILON)
461  value = value_rgb * (maxcolor - mincolor) + mincolor;
462  } else if (color_mapping_style == 2) {
463  mincolor = interval_point[0];
464  maxcolor = interval_point[1];
465 
466  if (fabs(maxcolor - mincolor) > EPSILON)
467  value = value_rgb * (maxcolor - mincolor) + mincolor;
468  } else if ((color_mapping_style == 3) || (color_mapping_style == 4)) {
469  if (value_rgb <= interval_point[1]) {
470  value = mincolor;
471  } else if (value_rgb >= interval_point[interval_mapping_num * 2 + 1]) {
472  value = maxcolor;
473  } else {
474  for (i = 1; i < interval_mapping_num + 1; i++) {
475  if ((value_rgb <= interval_point[i * 2 + 1]) &&
476  (value_rgb > interval_point[(i - 1) * 2 + 1])) {
477  value = (value_rgb - interval_point[(i - 1) * 2 + 1]) /
478  (interval_point[i * 2 + 1] -
479  interval_point[(i - 1) * 2 + 1]) *
480  (interval_point[i * 2] - interval_point[(i - 1) * 2]) +
481  interval_point[(i - 1) * 2];
482  break;
483  }
484  }
485  }
486  }
487  return value;
488 }
489 
490 void generate_color_bar(int scale_marking_on, double font_size,
491  int color_bar_style, int mark_0_on,
492  int color_mapping_bar_on, int xr, int yr,
493  double font_color[3], int color_system_type,
494  int color_mapping_style, double *interval_point,
495  int interval_mapping_num, int num_of_scale,
496  double tmincolor, double tmaxcolor, double org_mincolor,
497  double org_maxcolor, double *image) {
498  int i, j, k, m;
499  int start_x, start_y, end_x, end_y, start_ys, start_xs, scale;
500  double value, color[3], delta_y;
501  double vv;
502  char buf[128];
503  int output5[5][5], output7[7][7], type;
504 
505  if (scale_marking_on == 1) {
506  if ((font_size - (int)font_size) < 0.5 - EPSILON)
507  type = 1;
508  else
509  type = 2;
510  }
511 
512  if (color_bar_style == 1) {
513  if (scale_marking_on == 0) {
514  start_x = 10;
515  } else if (scale_marking_on == 1) {
516  if (type == 1) {
517  start_x = 25;
518  if (mark_0_on == 1) start_x = 40;
519 
520  if (font_size >= 2.0) {
521  start_x = 25 + (int)(font_size - 1) * 20;
522  if (mark_0_on == 1) start_x = 40 + (int)(font_size - 1) * 20;
523  }
524  } else if (type == 2) {
525  start_x = 35;
526  if (mark_0_on == 1) start_x = 55;
527 
528  if (font_size >= 2.0) {
529  start_x = 35 + (int)(font_size - 1) * 30;
530  if (mark_0_on == 1) start_x = 55 + (int)(font_size - 1) * 30;
531  }
532  }
533  }
534  start_y = (yr - 20) / 10 + 10;
535  end_y = (yr - 20) / 10 * 5 + start_y;
536  end_x = start_x + BAR_WIDTH;
537  delta_y = 1.0 / (double)(end_y - start_y);
538 
539  if (color_mapping_bar_on == 1) {
540  for (j = start_y; j < end_y; j++) {
541  value = delta_y * (double)(j - start_y) * (tmaxcolor - tmincolor) +
542  tmincolor;
543  value_to_rgb(value, color, tmincolor, tmaxcolor, color_mapping_style,
544  interval_point, interval_mapping_num, color_system_type);
545 
546  for (i = start_x; i < end_x; i++)
547  for (k = 0; k < 3; k++) image[(j * xr + i) * 3 + k] = color[k];
548  }
549  }
550 
551  if (scale_marking_on == 1) {
552  /* transform tmincolor and tmaxcolor into scientific count */
553  scale = (int)font_size;
554  for (k = 0; k < 2; k++) {
555  if (k == 0) {
556  vv = org_mincolor;
557  if (type == 1)
558  start_ys = start_y - 4 - (int)font_size * 5;
559  else if (type == 2)
560  start_ys = start_y - 4 - (int)font_size * 7;
561  } else if (k == 1) {
562  vv = org_maxcolor;
563  start_ys = end_y + 4;
564  }
565 
566  start_xs = 10;
567  sprintf(buf, "%10.2E", vv);
568 
569  for (m = 0; m < 10; m++) {
570  if (type == 1) {
571  font5_generate(buf[9 - m], output5);
572  for (j = 0; j < 5 * scale; j++)
573  for (i = 0; i < 5 * scale; i++) {
574  image[((start_ys + j) * xr + start_xs - i) * 3] =
575  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
576  font_color[0];
577  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
578  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
579  font_color[1];
580  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
581  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
582  font_color[2];
583  }
584  start_xs += 5 * scale;
585  } else if (type == 2) {
586  font7_generate(buf[9 - m], output7);
587  for (j = 0; j < 7 * scale; j++)
588  for (i = 0; i < 7 * scale; i++) {
589  image[((start_ys + j) * xr + start_xs - i) * 3] =
590  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
591  font_color[0];
592  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
593  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
594  font_color[1];
595  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
596  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
597  font_color[2];
598  }
599  start_xs += 7 * scale;
600  }
601  }
602  }
603 
604  if (mark_0_on == 1) {
605  if ((tmincolor < 0) && (tmaxcolor > 0)) {
606  start_ys = (int)((0 - tmincolor) / (tmaxcolor - tmincolor) *
607  (end_y - start_y) +
608  start_y);
609  start_xs = 10;
610  buf[0] = '0';
611  buf[1] = '.';
612  buf[2] = '0';
613 
614  for (m = 0; m < 3; m++) {
615  if (type == 1) {
616  font5_generate(buf[2 - m], output5);
617  for (j = 0; j < 5 * scale; j++)
618  for (i = 0; i < 5 * scale; i++) {
619  image[((start_ys + j) * xr + start_xs - i) * 3] =
620  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
621  font_color[0];
622  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
623  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
624  font_color[1];
625  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
626  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
627  font_color[2];
628  }
629  start_xs += 5 * scale;
630  } else if (type == 2) {
631  font7_generate(buf[2 - m], output7);
632  for (j = 0; j < 7 * scale; j++)
633  for (i = 0; i < 7 * scale; i++) {
634  image[((start_ys + j) * xr + start_xs - i) * 3] =
635  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
636  font_color[0];
637  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
638  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
639  font_color[1];
640  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
641  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
642  font_color[2];
643  }
644  start_xs += 7 * scale;
645  }
646  }
647 
648  for (i = start_xs; i < start_x; i++)
649  for (j = 0; j < 3; j++)
650  image[(start_ys * xr + i) * 3 + j] = font_color[j];
651  }
652  }
653  }
654  } else if (color_bar_style == 2) {
655  if (scale_marking_on == 0) {
656  start_x = 10;
657  } else if (scale_marking_on == 1) {
658  scale = (int)font_size;
659  if (type == 1)
660  start_x = 45 * scale + 15;
661  else if (type == 2)
662  start_x = 63 * scale + 15;
663  }
664 
665  start_y = (yr - 20) / 10 + 10;
666  end_y = (yr - 20) / 10 * 5 + start_y;
667  end_x = start_x + BAR_WIDTH;
668  delta_y = 1.0 / (double)(end_y - start_y);
669 
670  if (color_mapping_bar_on == 1) {
671  for (j = start_y; j < end_y; j++) {
672  value = ((double)(j - start_y)) / (double)(end_y - start_y);
673  value2_to_rgb(value, color, color_system_type);
674 
675  for (i = start_x; i < end_x; i++)
676  for (k = 0; k < 3; k++) image[(j * xr + i) * 3 + k] = color[k];
677  }
678  }
679 
680  if (scale_marking_on == 1) {
681  /* transform tmincolor and tmaxcolor into scientific count */
682  scale = (int)font_size;
683  for (k = 0; k < num_of_scale; k++) {
684  if ((k != 0) && (k != num_of_scale - 1))
685  vv = rgb_to_value(1.0 / (num_of_scale - 1) * k, tmincolor, tmaxcolor,
686  color_mapping_style, interval_point,
687  interval_mapping_num);
688  else if (k == 0)
689  vv = org_mincolor;
690  else if (k == num_of_scale - 1)
691  vv = org_maxcolor;
692 
693  if (type == 1)
694  start_ys = start_y +
695  (int)((double)(end_y - start_y) / (num_of_scale - 1) * k) -
696  (int)5 * scale / 2;
697  else if (type == 2)
698  start_ys = start_y +
699  (int)((double)(end_y - start_y) / (num_of_scale - 1) * k) -
700  (int)7 * scale / 2;
701 
702  start_xs = 10;
703  sprintf(buf, "%10.2E", vv);
704  for (m = 0; m < 10; m++) {
705  if (type == 1) {
706  font5_generate(buf[9 - m], output5);
707  for (j = 0; j < 5 * scale; j++)
708  for (i = 0; i < 5 * scale; i++) {
709  image[((start_ys + j) * xr + start_xs - i) * 3] =
710  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
711  font_color[0];
712  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
713  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
714  font_color[1];
715  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
716  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
717  font_color[2];
718  }
719  start_xs += 5 * scale;
720  if ((vv >= 0) && (m == 9)) start_xs -= 5 * scale;
721  } else if (type == 2) {
722  font7_generate(buf[9 - m], output7);
723  for (j = 0; j < 7 * scale; j++)
724  for (i = 0; i < 7 * scale; i++) {
725  image[((start_ys + j) * xr + start_xs - i) * 3] =
726  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
727  font_color[0];
728  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
729  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
730  font_color[1];
731  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
732  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
733  font_color[2];
734  }
735  start_xs += 7 * scale;
736  if ((vv >= 0) && (m == 9)) start_xs -= 7 * scale;
737  }
738  }
739 
740  if ((k != 0) && (k != num_of_scale - 1)) {
741  if (type == 1)
742  start_ys += (int)5 * scale / 2;
743  else if (type == 2)
744  start_ys += (int)7 * scale / 2;
745 
746  for (i = start_x; i < end_x; i++)
747  for (j = 0; j < 3; j++)
748  image[(start_ys * xr + i) * 3 + j] = font_color[j];
749  }
750  }
751 
752  if (mark_0_on == 1) {
753  if ((tmincolor < 0) && (tmaxcolor > 0)) {
754  start_ys = (int)((0 - tmincolor) / (tmaxcolor - tmincolor) *
755  (end_y - start_y) +
756  start_y);
757  start_xs = 10;
758  sprintf(buf, "%10.2E", 0.0);
759 
760  for (m = 0; m < 10; m++) {
761  if (type == 1) {
762  font5_generate(buf[9 - m], output5);
763  for (j = 0; j < 5 * scale; j++)
764  for (i = 0; i < 5 * scale; i++) {
765  image[((start_ys + j) * xr + start_xs - i) * 3] =
766  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
767  font_color[0];
768  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
769  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
770  font_color[1];
771  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
772  (double)output5[4 - (int)(j / scale)][(int)(i / scale)] *
773  font_color[2];
774  }
775  start_xs += 5 * scale;
776  } else if (type == 2) {
777  font7_generate(buf[9 - m], output7);
778  for (j = 0; j < 7 * scale; j++)
779  for (i = 0; i < 7 * scale; i++) {
780  image[((start_ys + j) * xr + start_xs - i) * 3] =
781  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
782  font_color[0];
783  image[((start_ys + j) * xr + start_xs - i) * 3 + 1] =
784  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
785  font_color[1];
786  image[((start_ys + j) * xr + start_xs - i) * 3 + 2] =
787  (double)output7[6 - (int)(j / scale)][(int)(i / scale)] *
788  font_color[2];
789  }
790  start_xs += 7 * scale;
791  }
792  }
793 
794  for (i = start_xs + 1; i < start_xs + 5; i++)
795  for (j = 0; j < 3; j++)
796  image[(start_ys * xr + i) * 3 + j] = font_color[j];
797  }
798  }
799  }
800  }
801 
802  return;
803 }
804 
805 static unsigned short int transform_hex(char a) {
806  unsigned short int aa;
807 
808  switch (a) {
809  case 'a':
810  aa = 10;
811  break;
812  case 'b':
813  aa = 11;
814  break;
815  case 'c':
816  aa = 12;
817  break;
818  case 'd':
819  aa = 13;
820  break;
821  case 'e':
822  aa = 14;
823  break;
824  case 'f':
825  aa = 15;
826  break;
827  case '0':
828  aa = 0;
829  break;
830  case '1':
831  aa = 1;
832  break;
833  case '2':
834  aa = 2;
835  break;
836  case '3':
837  aa = 3;
838  break;
839  case '4':
840  aa = 4;
841  break;
842  case '5':
843  aa = 5;
844  break;
845  case '6':
846  aa = 6;
847  break;
848  case '7':
849  aa = 7;
850  break;
851  case '8':
852  aa = 8;
853  break;
854  case '9':
855  aa = 9;
856  break;
857  }
858  return (aa);
859 }
860 
861 unsigned short int change_short_int_order(unsigned short int n) {
862  char c_buf[10], newc_buf[10], changed_buf[10];
863  unsigned short int i, m, digit;
864 
865  sprintf(c_buf, "%x", n);
866  m = 0;
867 
868  while (c_buf[m] != '\0') m++;
869 
870  if (m > 4)
871  HECMW_vis_print_exit("there is something wrong for the unsigned short int");
872 
873  for (i = 0; i < 4 - m; i++) newc_buf[i] = '0';
874 
875  for (i = 0; i < m; i++) newc_buf[4 - m + i] = c_buf[i];
876 
877  newc_buf[4] = '\0';
878  changed_buf[0] = newc_buf[2];
879  changed_buf[1] = newc_buf[3];
880  changed_buf[2] = newc_buf[0];
881  changed_buf[3] = newc_buf[1];
882  changed_buf[4] = '\0';
883  digit = 0;
884 
885  for (i = 0; i < 4; i++) {
886  digit *= 16;
887  digit += transform_hex(changed_buf[i]);
888  }
889  return (digit);
890 }
891 
892 unsigned int change_unsigned_int_order(unsigned int n) {
893  char c_buf[10], newc_buf[10], changed_buf[10], changed2_buf[10];
894  unsigned int i, m, digit;
895 
896  sprintf(c_buf, "%x", n);
897  m = 0;
898 
899  for (i = 0; i < 8; i++) {
900  if (c_buf[i] == '\0')
901  break;
902  else
903  m++;
904  }
905 
906  if (m > 8)
907  HECMW_vis_print_exit("there is something wrong for the unsigned short int");
908 
909  for (i = 0; i < 8 - m; i++) newc_buf[i] = '0';
910 
911  for (i = 0; i < m; i++) newc_buf[8 - m + i] = c_buf[i];
912 
913  newc_buf[8] = '\0';
914 
915  for (i = 0; i < 4; i++) changed_buf[i] = newc_buf[i + 4];
916 
917  for (i = 0; i < 4; i++) changed_buf[i + 4] = newc_buf[i];
918 
919  changed2_buf[0] = changed_buf[2];
920  changed2_buf[1] = changed_buf[3];
921  changed2_buf[2] = changed_buf[0];
922  changed2_buf[3] = changed_buf[1];
923  changed2_buf[4] = changed_buf[6];
924  changed2_buf[5] = changed_buf[7];
925  changed2_buf[6] = changed_buf[4];
926  changed2_buf[7] = changed_buf[5];
927  changed2_buf[8] = '\0';
928  digit = 0;
929 
930  for (i = 0; i < 8; i++) {
931  digit *= 16;
932  digit += transform_hex(changed2_buf[i]);
933  }
934 
935  return (digit);
936 }
937 
938 int change_int_order(int n) {
939  char c_buf[10], newc_buf[10], changed_buf[10], changed2_buf[10];
940  int i, m, digit;
941 
942  sprintf(c_buf, "%x", n);
943  m = 0;
944 
945  for (i = 0; i < 8; i++) {
946  if (c_buf[i] == '\0')
947  break;
948  else
949  m++;
950  }
951 
952  if (m > 8)
953  HECMW_vis_print_exit("there is something wrong for the unsigned short int");
954 
955  for (i = 0; i < 8 - m; i++) newc_buf[i] = '0';
956 
957  for (i = 0; i < m; i++) newc_buf[8 - m + i] = c_buf[i];
958 
959  newc_buf[8] = '\0';
960 
961  for (i = 0; i < 4; i++) changed_buf[i] = newc_buf[i + 4];
962 
963  for (i = 0; i < 4; i++) changed_buf[i + 4] = newc_buf[i];
964 
965  changed2_buf[0] = changed_buf[2];
966  changed2_buf[1] = changed_buf[3];
967  changed2_buf[2] = changed_buf[0];
968  changed2_buf[3] = changed_buf[1];
969  changed2_buf[4] = changed_buf[6];
970  changed2_buf[5] = changed_buf[7];
971  changed2_buf[6] = changed_buf[4];
972  changed2_buf[7] = changed_buf[5];
973  changed2_buf[8] = '\0';
974  digit = 0;
975 
976  for (i = 0; i < 8; i++) {
977  digit *= 16;
978  digit += transform_hex(changed2_buf[i]);
979  }
980  return (digit);
981 }
image
double * image
Definition: hecmw_vis_rendering.c:24
hecmw_vis_mem_util.h
mark_time_label
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)
Definition: hecmw_vis_font_texture.c:330
change_int_order
int change_int_order(int n)
Definition: hecmw_vis_font_texture.c:938
HECMW_vis_print_exit
void HECMW_vis_print_exit(char *var)
Definition: hecmw_vis_mem_util.c:21
hecmw_vis_font_texture.h
hecmw_vis_color_mapping.h
change_unsigned_int_order
unsigned int change_unsigned_int_order(unsigned int n)
Definition: hecmw_vis_font_texture.c:892
font7_generate
void font7_generate(char input, int output[7][7])
Definition: hecmw_vis_font_texture.c:182
value2_to_rgb
void value2_to_rgb(double value, double color[3], int color_system_type)
Definition: hecmw_vis_font_texture.c:392
generate_color_bar
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)
Definition: hecmw_vis_font_texture.c:490
EPSILON
#define EPSILON
Definition: hecmw_vis_font_texture.c:15
value_to_rgb
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)
Definition: hecmw_vis_color_mapping.c:12
change_short_int_order
unsigned short int change_short_int_order(unsigned short int n)
Definition: hecmw_vis_font_texture.c:861
BAR_WIDTH
#define BAR_WIDTH
Definition: hecmw_vis_font_texture.c:14