1 // COLOR.H : some common (inline-)functions for color selections.
2
3 // Copyright (C) 1999 Tommi Hassinen.
4
5 // This package is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 /*################################################################################################*/
20
21 #ifndef COLOR_H
22 #define COLOR_H
23
24 //#include "ghemicalconfig2.h"
25
26 /*################################################################################################*/
27
28 #include <ghemical/typedef.h>
29
30 class engine; // engine.h
31
32 /*################################################################################################*/
33
34 // these should be done generic, to give any desired color range...
35 // these should be done generic, to give any desired color range...
36 // these should be done generic, to give any desired color range...
37
38 void GetRBRange1(fGL, fGL, fGL *);
39 void GetRBRange2(fGL, fGL, fGL *);
40
41 void GetRedColor(fGL, fGL, fGL *);
42 void GetGreenColor(fGL, fGL, fGL *);
43 void GetBlueColor(fGL, fGL, fGL *);
44
45 fGL GetUnity(engine *, fGL *, fGL *);
46
47 /*################################################################################################*/
48
49 /** A color function: white -> red -> green -> blue -> white, constant alpha.
50 This is best suited for opaque/transparent planes...
51 */
GetRBRange1(fGL value1,fGL alpha1,fGL * rgb)52 inline void GetRBRange1(fGL value1, fGL alpha1, fGL * rgb)
53 {
54 fGL value2 = fabs(value1);
55
56 if (value2 < 1.0)
57 {
58 if (value1 < 0.0)
59 {
60 rgb[0] = 0.0;
61 rgb[2] = value2;
62 }
63 else
64 {
65 rgb[0] = value2;
66 rgb[2] = 0.0;
67 }
68
69 rgb[1] = 1.0 - value2;
70 rgb[3] = alpha1;
71 }
72 else
73 {
74 value2 = 1.0 - 1.0 / value2;
75
76 if (value1 < 0.0)
77 {
78 rgb[0] = value2;
79 rgb[2] = 1.0;
80 }
81 else
82 {
83 rgb[0] = 1.0;
84 rgb[2] = value2;
85 }
86
87 rgb[1] = value2;
88 rgb[3] = alpha1;
89 }
90 }
91
92 /** A color function: white -> red -> [SHARP CHANGE] -> blue -> white, variable alpha.
93 This is best suited for transparent objects (volume rendering)...
94 */
GetRBRange2(fGL value1,fGL alpha1,fGL * rgb)95 inline void GetRBRange2(fGL value1, fGL alpha1, fGL * rgb)
96 {
97 fGL value2 = fabs(value1);
98
99 fGL alpha2 = alpha1 * value2;
100 if (alpha2 > 1.0) alpha2 = 1.0;
101
102 if (value2 < 1.0)
103 {
104 if (value1 < 0.0)
105 {
106 rgb[0] = 0.0;
107 rgb[2] = 1.0;
108 }
109 else
110 {
111 rgb[0] = 1.0;
112 rgb[2] = 0.0;
113 }
114
115 rgb[1] = 0.0;
116 rgb[3] = alpha2;
117 }
118 else
119 {
120 value2 = 1.0 - 1.0 / value2;
121
122 if (value1 < 0.0)
123 {
124 rgb[0] = value2;
125 rgb[2] = 1.0;
126 }
127 else
128 {
129 rgb[0] = 1.0;
130 rgb[2] = value2;
131 }
132
133 rgb[1] = value2;
134 rgb[3] = alpha2;
135 }
136 }
137
GetRedColor(fGL value,fGL alpha,fGL * rgb)138 inline void GetRedColor(fGL value, fGL alpha, fGL * rgb)
139 {
140 rgb[0] = value;
141 rgb[1] = rgb[2] = 0.0;
142
143 rgb[3] = alpha;
144 }
145
GetGreenColor(fGL value,fGL alpha,fGL * rgb)146 inline void GetGreenColor(fGL value, fGL alpha, fGL * rgb)
147 {
148 rgb[1] = value;
149 rgb[0] = rgb[2] = 0.0;
150
151 rgb[3] = alpha;
152 }
153
GetBlueColor(fGL value,fGL alpha,fGL * rgb)154 inline void GetBlueColor(fGL value, fGL alpha, fGL * rgb)
155 {
156 rgb[2] = value;
157 rgb[0] = rgb[1] = 0.0;
158
159 rgb[3] = alpha;
160 }
161
GetUnity(engine *,fGL *,fGL *)162 inline fGL GetUnity(engine *, fGL *, fGL *)
163 {
164 return 1.0;
165 }
166
167 /*################################################################################################*/
168
169 #endif // COLOR_H
170
171 // eof
172