FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_vis_color_mapping.c
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
7
8#include <math.h>
9
10#define EPSILON 0.00000001
11
12void value_to_rgb(double value, double color[3], double mincolor,
13 double maxcolor, int color_mapping_style,
14 double *interval_point, int interval_mapping_num,
15 int color_system_type) {
16 double r, g, b;
17 int i;
18 if (color_mapping_style == 1) {
19 if (fabs(maxcolor - mincolor) > EPSILON)
20 value = (value - mincolor) / (maxcolor - mincolor);
21 }
22
23 if (color_mapping_style == 2) {
24 mincolor = interval_point[0];
25 maxcolor = interval_point[1];
26 if (fabs(maxcolor - mincolor) > EPSILON)
27 value = (value - mincolor) / (maxcolor - mincolor);
28 }
29 if ((color_mapping_style == 3) || (color_mapping_style == 4)) {
30 if (value < interval_point[0])
31 value = 0.0;
32 else if (value > interval_point[interval_mapping_num * 2])
33 value = 1.0;
34 else {
35 for (i = 1; i < interval_mapping_num + 1; i++) {
36 if ((value <= interval_point[i * 2]) &&
37 (value > interval_point[(i - 1) * 2])) {
38 value = (value - interval_point[(i - 1) * 2]) /
39 (interval_point[i * 2] - interval_point[(i - 1) * 2]) *
40 (interval_point[i * 2 + 1] -
41 interval_point[(i - 1) * 2 + 1]) +
42 interval_point[(i - 1) * 2 + 1];
43 }
44 }
45 }
46 }
47
48 if (color_system_type == 1) {
49 if (value < 0.0) value = 0.0;
50 if (value > 1.0) value = 1.0;
51 if (value <= 0.25) {
52 r = 0.0;
53 g = value * 4.0;
54 b = 1.0;
55 } else if ((value > 0.25) && (value <= 0.5)) {
56 r = 0.0;
57 g = 1.0;
58 b = (0.5 - value) * 4.0;
59 } else if ((value > 0.5) && (value <= 0.75)) {
60 r = (value - 0.5) * 4.0;
61 g = 1.0;
62 b = 0.0;
63 } else if (value > 0.75) {
64 r = 1.0;
65 g = (1.0 - value) * 4.0;
66 b = 0.0;
67 }
68
69 } else if (color_system_type == 2) {
70 if (value < 0.0) value = 0.0;
71 if (value > 1.0) value = 1.0;
72 if (value <= 0.2) {
73 g = 0.0;
74 b = 1.0;
75 r = (0.2 - value) * 5.0;
76 } else if ((value > 0.2) && (value <= 0.4)) {
77 r = 0.0;
78 b = 1.0;
79 g = (value - 0.2) * 5.0;
80 } else if ((value > 0.4) && (value <= 0.6)) {
81 r = 0.0;
82 g = 1.0;
83 b = 1.0 - (value - 0.4) * 5.0;
84 } else if ((value > 0.6) && (value <= 0.8)) {
85 r = (value - 0.6) * 5.0;
86 g = 1.0;
87 b = 0.0;
88 } else if (value > 0.0) {
89 r = 1.0;
90 g = 1.0 - (value - 0.8) * 5.0;
91 b = 0.0;
92 }
93 } else if (color_system_type == 3) {
94 r = g = b = value;
95 }
96
97 color[0] = r;
98 color[1] = g;
99 color[2] = b;
100 return;
101}
#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)