Project

General

Profile

SO3Engine
SO3ColourGradient.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25#ifndef __SO3_COLOUR_GRADIENT_H__
26#define __SO3_COLOUR_GRADIENT_H__
27
29
30namespace SO3
31{
32
36 class _SO3_Export SColourGradient
37 {
38 public:
39 protected:
40 private:
41 const bool fillBounds;
42 typedef std::map<float, Ogre::ColourValue> ColourFrames;
43 ColourFrames colourFrames;
44 const Ogre::ColourValue minBoundDefaultColour;
45 const Ogre::ColourValue maxBoundDefaultColour;
46 public:
47 typedef ColourFrames::value_type ColourFrame;
48
49 public:
54 SColourGradient(const bool& fillBoundsWithDefault=true);
55
61 SColourGradient(const Ogre::ColourValue& overridedMinDefaultColour, const Ogre::ColourValue& overridedMaxDefaultColour);
62
67
72 inline void AddColourFrame(const ColourFrame& colourFrame)
73 {
74 AddColourFrame(colourFrame.first, colourFrame.second);
75 }
76
82 inline void AddColourFrame(const float& gradientPosition, const Ogre::ColourValue& colour)
83 {
84 assert((gradientPosition >= 0.0f)&&(gradientPosition<=1.0f));
85 if(colourFrames.find(gradientPosition) == colourFrames.end())
86 colourFrames.insert(ColourFrames::value_type(gradientPosition, colour));
87 else
88 colourFrames[gradientPosition] = colour;
89 }
90
94 inline void Clear()
95 {
96 colourFrames.clear();
97 }
98
104 const Ogre::ColourValue GetColour(const float& gradientPosition) const;
105 protected:
106 private:
110 Ogre::ColourValue Interpolate(const ColourFrame& minColourFrame, const ColourFrame& maxColourFrame, const float& mediumRangeValue) const;
111 };
112
113 /****************/
114 /* Test cases */
115 /****************/
116 /*
117 // Test filling bounds (white/red/green/blue/black)
118 Ogre::ColourValue resultColour;
119 SColourGradient myTest;
120 myTest.AddColourFrame(0.3, Ogre::ColourValue::Red);
121 myTest.AddColourFrame(0.5, Ogre::ColourValue::Green);
122 myTest.AddColourFrame(0.7, Ogre::ColourValue::Blue);
123 resultColour = myTest.GetColour(0.0); // (0.0, 0.0, 0.0, 1.0)
124 resultColour = myTest.GetColour(0.15); // (0.5, 0.0, 0.0, 1.0)
125 resultColour = myTest.GetColour(0.3); // (1.0, 0.0, 0.0, 1.0)
126 resultColour = myTest.GetColour(0.4); // (0.5, 0.5, 0.0, 1.0)
127 resultColour = myTest.GetColour(0.5); // (0.0, 1.0, 0.0, 1.0)
128 resultColour = myTest.GetColour(0.6); // (0.0, 0.5, 0.5, 1.0)
129 resultColour = myTest.GetColour(0.7); // (0.0, 0.0, 1.0, 1.0)
130 resultColour = myTest.GetColour(0.85); // (0.5, 0.5, 1.0, 1.0)
131 resultColour = myTest.GetColour(1.0); // (1.0, 1.0, 1.0, 1.0)
132
133 // Test no filling bounds (red/green/blue)
134 SColourGradient myTest2(false);
135 myTest2.AddColourFrame(0.3, Ogre::ColourValue::Red);
136 myTest2.AddColourFrame(0.5, Ogre::ColourValue::Green);
137 myTest2.AddColourFrame(0.7, Ogre::ColourValue::Blue);
138 resultColour = myTest2.GetColour(0.0); // (1.0, 0.0, 0.0, 1.0)
139 resultColour = myTest2.GetColour(0.15); // (1.0, 0.0, 0.0, 1.0)
140 resultColour = myTest2.GetColour(0.3); // (1.0, 0.0, 0.0, 1.0)
141 resultColour = myTest2.GetColour(0.4); // (0.5, 0.5, 0.0, 1.0)
142 resultColour = myTest2.GetColour(0.5); // (0.0, 1.0, 0.0, 1.0)
143 resultColour = myTest2.GetColour(0.6); // (0.0, 0.5, 0.5, 1.0)
144 resultColour = myTest2.GetColour(0.7); // (0.0, 0.0, 1.0, 1.0)
145 resultColour = myTest2.GetColour(0.85); // (0.0, 0.0, 1.0, 1.0)
146 resultColour = myTest2.GetColour(1.0); // (0.0, 0.0, 1.0, 1.0)
147
148 // Test filling bounds 2 (red/green/blue)
149 SColourGradient myTest3;
150 myTest3.AddColourFrame(0.0, Ogre::ColourValue::Red);
151 myTest3.AddColourFrame(0.5, Ogre::ColourValue::Green);
152 myTest3.AddColourFrame(1.0, Ogre::ColourValue::Blue);
153 resultColour = myTest3.GetColour(0.0); // (1.0, 0.0, 0.0, 1.0)
154 resultColour = myTest3.GetColour(0.25); // (0.5, 0.5, 0.0, 1.0)
155 resultColour = myTest3.GetColour(0.5); // (0.0, 1.0, 0.0, 1.0)
156 resultColour = myTest3.GetColour(0.75); // (0.0, 0.5, 0.5, 1.0)
157 resultColour = myTest3.GetColour(1.0); // (0.0, 0.0, 1.0, 1.0)
158
159 // Test no filling bounds 2 (red/green/blue)
160 SColourGradient myTest4(false);
161 myTest4.AddColourFrame(0.0, Ogre::ColourValue::Red);
162 myTest4.AddColourFrame(0.5, Ogre::ColourValue::Green);
163 myTest4.AddColourFrame(1.0, Ogre::ColourValue::Blue);
164 resultColour = myTest4.GetColour(0.0); // (1.0, 0.0, 0.0, 1.0)
165 resultColour = myTest4.GetColour(0.25); // (0.5, 0.5, 0.0, 1.0)
166 resultColour = myTest4.GetColour(0.5); // (0.0, 1.0, 0.0, 1.0)
167 resultColour = myTest4.GetColour(0.75); // (0.0, 0.5, 0.5, 1.0)
168 resultColour = myTest4.GetColour(1.0); // (0.0, 0.0, 1.0, 1.0)
169
170 // Test filling bounds 3 (black/red/white)
171 SColourGradient myTest5;
172 myTest5.AddColourFrame(0.5, Ogre::ColourValue::Red);
173 resultColour = myTest5.GetColour(0.0); // (0.0, 0.0, 0.0, 1.0)
174 resultColour = myTest5.GetColour(0.25); // (0.5, 0.0, 0.0, 1.0)
175 resultColour = myTest5.GetColour(0.5); // (1.0, 0.0, 0.0, 1.0)
176 resultColour = myTest5.GetColour(0.75); // (1.0, 0.5, 0.5, 1.0)
177 resultColour = myTest5.GetColour(1.0); // (1.0, 1.0, 1.0, 1.0)
178
179 // Test no filling bounds 3 (all red)
180 SColourGradient myTest6(false);
181 myTest6.AddColourFrame(0.5, Ogre::ColourValue::Red);
182 resultColour = myTest6.GetColour(0.0); // (1.0, 0.0, 0.0, 1.0)
183 resultColour = myTest6.GetColour(0.25); // (1.0, 0.0, 0.0, 1.0)
184 resultColour = myTest6.GetColour(0.5); // (1.0, 0.0, 0.0, 1.0)
185 resultColour = myTest6.GetColour(0.75); // (1.0, 0.0, 0.0, 1.0)
186 resultColour = myTest6.GetColour(1.0); // (1.0, 0.0, 0.0, 1.0)
187
188 // Test filling bounds 4 (black/white)
189 SColourGradient myTest7;
190 resultColour = myTest7.GetColour(0.0); // (0.0, 0.0, 0.0, 1.0)
191 resultColour = myTest7.GetColour(0.5); // (0.5, 0.5, 0.5, 1.0)
192 resultColour = myTest7.GetColour(1.0); // (1.0, 1.0, 1.0, 1.0)
193
194 // Test no filling bounds 4 (no valid value, all black)
195 SColourGradient myTest8(false);
196 resultColour = myTest8.GetColour(0.0); // (0.0, 0.0, 0.0, 1.0)
197 resultColour = myTest8.GetColour(0.5); // (0.0, 0.0, 0.0, 1.0)
198 resultColour = myTest8.GetColour(1.0); // (0.0, 0.0, 0.0, 1.0)
199
200 // Test filling bounds 5 (red/green)
201 SColourGradient myTest9(Ogre::ColourValue::Red, Ogre::ColourValue::Green);
202 resultColour = myTest9.GetColour(0.0); // (1.0, 0.0, 0.0, 1.0)
203 resultColour = myTest9.GetColour(0.5); // (0.5, 0.5, 0.0, 1.0)
204 resultColour = myTest9.GetColour(1.0); // (0.0, 1.0, 0.0, 1.0)
205 */
206
207}
208
209#endif
librairies include
void AddColourFrame(const ColourFrame &colourFrame)
ColourFrames::value_type ColourFrame
A single colour frame.
void AddColourFrame(const float &gradientPosition, const Ogre::ColourValue &colour)