25 #include <Utils/ColourGradient.hh>
31 template <
class StorageType>
36 std::vector<StorageType> black(3, 0);
37 std::vector<StorageType> white(3, 1);
42 GradientStep<StorageType> left;
45 gradientSteps_.push_front(left);
47 GradientStep<StorageType> right;
50 gradientSteps_.push_back(right);
54 template <
class StorageType>
57 const StorageType max)
64 AddRGBColour(0.0f, 0, 0, 0);
65 AddRGBColour(1.0f, max, max, max);
68 AddRGBColour(0.0f, 0, max, max);
69 AddRGBColour(1.0f, max, 0, max);
72 AddRGBColour(0.00f, (StorageType)(41.0/255.0 * max), 0, 0);
73 AddRGBColour(0.33f, max, 0, 0);
74 AddRGBColour(0.73f, max, max, 0);
75 AddRGBColour(1.00f, max, max, max);
78 AddRGBColour(0.00f, 0, 0, (StorageType)(5.0/255.0 * max));
79 AddRGBColour(0.33f, (StorageType)(74.0/255.0 * max),
80 (StorageType)(74.0/255.0 * max),
81 (StorageType)(106.0/255.0 * max));
82 AddRGBColour(0.73f, (StorageType)(164.0/255.0 * max),
83 (StorageType)(196.0/255.0 * max),
84 (StorageType)(196.0/255.0 * max));
85 AddRGBColour(1.00f, max, max, max);
88 AddRGBColour(0.00f, 0, 0, (StorageType)(189.0/255.0 * max));
89 AddRGBColour(0.33f, 0, max, max);
90 AddRGBColour(0.60f, max, max, 0);
91 AddRGBColour(0.87f, max, 0, 0);
92 AddRGBColour(1.00f, (StorageType)(132.0/255.0 * max), 0, 0);
95 cerr <<
"unknown colour gradient type! using gray scale..." << endl;
96 AddRGBColour(0.0f, 0, 0, 0);
97 AddRGBColour(1.0f, max, max, max);
103 template <
class StorageType>
106 std::vector<StorageType> colourRight)
108 BIASASSERT(colourLeft.size() == colourRight.size())
109 BIASASSERT(colourLeft.size() > 0)
111 numChannels_ = colourLeft.size();
113 GradientStep<StorageType> left;
115 left.colour = colourLeft;
116 gradientSteps_.push_front(left);
118 GradientStep<StorageType> right;
120 right.colour = colourRight;
121 gradientSteps_.push_back(right);
125 template <
class StorageType>
128 const std::vector<StorageType> &colour)
130 BIASASSERT(pos >= 0.0 && pos <= 1.0);
131 BIASASSERT(colour.size() == numChannels_);
133 if (gradientSteps_.size() == 0)
135 GradientStep<StorageType> step;
137 step.colour = colour;
138 gradientSteps_.push_back(step);
142 typename list<GradientStep<StorageType> >::iterator it = gradientSteps_.begin();
144 bool itLargerEqual =
false;
146 while (it != gradientSteps_.end() && !itLargerEqual)
154 itLargerEqual =
true;
164 GradientStep<StorageType> step;
166 step.colour = colour;
167 gradientSteps_.insert(it, step);
172 template <
class StorageType>
175 std::vector<StorageType> &colour)
177 BIASASSERT(pos >= 0.0f && pos <= 1.0f)
180 colour.resize(numChannels_);
182 typename std::list<GradientStep<StorageType> >::iterator left
183 = gradientSteps_.begin();
184 typename std::list<GradientStep<StorageType> >::iterator right
185 = ++(gradientSteps_.begin());
189 if (pos >= left->pos && pos <= right->pos)
191 const float delta = right->pos - left->pos;
192 const float weight = (pos - left->pos) / delta;
194 for (
unsigned int c = 0; c < numChannels_; c++)
196 colour[c] = (StorageType)(((1.0f - weight) * left->colour[c]) +
197 (weight * right->colour[c]));
207 while (right != gradientSteps_.end());
211 template <
class StorageType>
214 const StorageType r,
const StorageType g,
const StorageType b)
216 vector<StorageType> colour(3);
220 AddColour(pos, colour);
229 #define INSTANCE_ColourGradient(type)\
230 template class BIASUtils_EXPORT ColourGradient<type>;
233 INSTANCE_ColourGradient(
unsigned char)
234 INSTANCE_ColourGradient(
float)
235 #ifdef BUILD_IMAGE_INT
236 INSTANCE_ColourGradient(
int)
238 #ifdef BUILD_IMAGE_CHAR
239 INSTANCE_ColourGradient(
char)
241 #ifdef BUILD_IMAGE_SHORT
242 INSTANCE_ColourGradient(
short)
244 #if defined(BUILD_IMAGE_USHORT)
245 INSTANCE_ColourGradient(
unsigned short)
247 #ifdef BUILD_IMAGE_DOUBLE
248 INSTANCE_ColourGradient(
double)
250 #ifdef BUILD_IMAGE_UINT
251 INSTANCE_ColourGradient(
unsigned int)
Represents a colour gradient.
ColourGradient()
Default Constructor.
ColourGradientType
Different types of predefined color gradients that can be generated.
void AddRGBColour(float pos, const StorageType r, const StorageType g, const StorageType b)
Convenience wrapper.
void GetColour(float pos, std::vector< StorageType > &colour)
Returns the interpolated colour at a given position.