41 template <
typename PValue,
43 int PDefaultFirstColor,
44 int PDefaultLastColor >
47 (
const PValue & minV,
50 const Color firstColor,
51 const Color lastColor )
52 : myMin( minV ), myMax( maxV )
56 myColors.push_back( Color::Black );
57 myColors.push_back( Color::White );
60 myColors.push_back(
Color( 255, 0, 255 ));
61 myColors.push_back(
Color( 255, 255, 0 ));
64 myColors.push_back(
Color( 0, 132, 100 ));
65 myColors.push_back(
Color( 255, 255, 100 ));
68 myColors.push_back(
Color( 255, 0, 0 ));
69 myColors.push_back(
Color( 255, 255, 0));
72 myColors.push_back(
Color( 0, 0, 255 ));
73 myColors.push_back(
Color( 0, 255, 132 ));
76 myColors.push_back(
Color( 0, 255, 255 ));
77 myColors.push_back(
Color( 255, 0, 255 ));
80 myColors.push_back(
Color( 0, 0, 0 ));
81 myColors.push_back(
Color( 255, 198, 123 ));
84 myColors.push_back( Color::Black );
85 myColors.push_back( Color::Red );
86 myColors.push_back(
Color( 255, 140, 0 ) );
87 myColors.push_back( Color::Yellow );
88 myColors.push_back( Color::White );
91 myColors.push_back( Color::Blue );
92 myColors.push_back( Color::Cyan );
93 myColors.push_back( Color::Yellow );
94 myColors.push_back(
Color( 255, 140, 0 ) );
95 myColors.push_back( Color::Red );
96 myColors.push_back(
Color( 132, 0, 0 ) );
99 if ( firstColor != Color::None
100 && lastColor != Color::None ) {
101 myColors.push_back( firstColor );
102 myColors.push_back( lastColor );
108 template <
typename PValue,
110 int PDefaultFirstColor,
111 int PDefaultLastColor >
119 template <
typename PValue,
121 int PDefaultFirstColor,
122 int PDefaultLastColor >
128 template <
typename PValue,
130 int PDefaultFirstColor,
131 int PDefaultLastColor >
136 if ( &other !=
this ) {
148 template<
typename PValue,
150 int PDefaultFirstColor,
151 int PDefaultLastColor >
157 myColors.push_back( color );
160 template<
typename PValue,
162 int PDefaultFirstColor,
163 int PDefaultLastColor >
171 template<
typename PValue,
173 int PDefaultFirstColor,
174 int PDefaultLastColor >
182 template<
typename PValue,
184 int PDefaultFirstColor,
185 int PDefaultLastColor >
193 template<
typename PValue,
195 int PDefaultFirstColor,
196 int PDefaultLastColor >
212 template <
typename PValue,
214 int PDefaultFirstColor,
215 int PDefaultLastColor >
219 ( std::ostream & out )
const
221 out <<
"[GradientColorMap "
224 std::vector<Color>::iterator it = myColors.begin();
225 while ( it != myColors.end() ) {
228 << it->green() <<
","
229 << it->blue() <<
") ";
239 template <
typename PValue,
241 int PDefaultFirstColor,
242 int PDefaultLastColor >
250 template <
typename PValue,
252 int PDefaultFirstColor,
253 int PDefaultLastColor >
257 (
const std::vector<Color> & colors,
260 const Value & value )
262 if ( colors.size() < 2 )
264 double scale =
static_cast<double>( value - min ) / (max - min);
265 const int intervals = (
const int)colors.size() - 1;
266 int upper_index =
static_cast<int>( ceil( intervals * scale ) );
269 const Color & firstColor = colors[ upper_index - 1 ];
270 const Color & lastColor = colors[ upper_index ];
271 scale = ( scale * intervals ) - (upper_index - 1);
273 const unsigned char red =
static_cast<unsigned char>( firstColor.
red() +
274 scale * ( lastColor.
red() -
276 const unsigned char green =
static_cast<unsigned char>( firstColor.
green() +
277 scale * ( lastColor.
green() -
278 firstColor.
green() ));
279 const unsigned char blue =
static_cast<unsigned char>( firstColor.
blue() +
280 scale * ( lastColor.
blue() -
281 firstColor.
blue() ));
282 return Color( red, green, blue );
288 template <
typename PValue,
290 int PDefaultFirstColor,
291 int PDefaultLastColor >
297 object.selfDisplay( out );