3131#include < Core/Datatypes/ColorMap.h>
3232#include < iostream>
3333
34+ using namespace SCIRun ;
3435using namespace SCIRun ::Core::Datatypes;
3536using namespace SCIRun ::Core::Geometry;
3637
37- ColorMap::ColorMap (const std::string& name, const size_t resolution, const double shift,
38+ ColorMap::ColorMap (ColorMapStrategyHandle color, const std::string& name, const size_t resolution, const double shift,
3839 const bool invert, const double rescale_scale, const double rescale_shift)
39- : name_ (name), resolution_(resolution), shift_(shift),
40+ : color_(color), nameInfo_ (name), resolution_(resolution), shift_(shift),
4041 invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift)
4142{
4243
@@ -47,19 +48,73 @@ ColorMap* ColorMap::clone() const
4748 return new ColorMap (*this );
4849}
4950
51+ namespace detail
52+ {
53+ class Rainbow : public ColorMapStrategy
54+ {
55+ public:
56+ virtual ColorRGB getColorMapVal (double v) const override ;
57+ };
58+
59+ class OldRainbow : public ColorMapStrategy
60+ {
61+ public:
62+ virtual ColorRGB getColorMapVal (double v) const override ;
63+ };
64+
65+ class Blackbody : public ColorMapStrategy
66+ {
67+ public:
68+ virtual ColorRGB getColorMapVal (double v) const override ;
69+ };
70+
71+ class Grayscale : public ColorMapStrategy
72+ {
73+ public:
74+ virtual ColorRGB getColorMapVal (double v) const override ;
75+ };
76+
77+ class OrangeBlackLime : public ColorMapStrategy
78+ {
79+ public:
80+ virtual ColorRGB getColorMapVal (double v) const override ;
81+ };
82+
83+ class Darkhue : public ColorMapStrategy
84+ {
85+ public:
86+ virtual Core::Datatypes::ColorRGB getColorMapVal (double v) const override ;
87+ };
88+ }
89+
5090ColorMapHandle StandardColorMapFactory::create (const std::string& name, const size_t &res,
5191 const double &shift, const bool &invert,
5292 const double &rescale_scale, const double &rescale_shift)
5393{
54- if (!(name == " Rainbow" ||
55- name == " Old Rainbow" ||
56- name == " Blackbody" ||
57- name == " Grayscale" ||
58- name == " Orange,Black,Lime" ||
59- name == " Darkhue" ))
60- THROW_INVALID_ARGUMENT (" Color map name not implemented/recognized." );
61-
62- return boost::make_shared<ColorMap>(name, res, shift, invert, rescale_scale, rescale_shift);
94+ ColorMapStrategyHandle color;
95+ if (name == " Rainbow" ) {
96+ color.reset (new detail::Rainbow);
97+ }
98+ else if (name == " Old Rainbow" ) {
99+ color.reset (new detail::OldRainbow);
100+ }
101+ else if (name == " Blackbody" ) {
102+ color.reset (new detail::Blackbody);
103+ }
104+ else if (name == " Grayscale" ) {
105+ color.reset (new detail::Grayscale);
106+ }
107+ else if (name == " Orange,Black,Lime" ) {
108+ color.reset (new detail::OrangeBlackLime);
109+ }
110+ else if (name == " Darkhue" ) {
111+ color.reset (new detail::Darkhue);
112+ }
113+ else
114+ THROW_INVALID_ARGUMENT (" Color map name not implemented/recognized." );
115+
116+
117+ return boost::make_shared<ColorMap>(color, name, res, shift, invert, rescale_scale, rescale_shift);
63118}
64119/* *
65120 * @name getTransformedColor
@@ -68,7 +123,7 @@ ColorMapHandle StandardColorMapFactory::create(const std::string& name, const si
68123 * @param v The input value from raw data that will be transformed (usually into [0,1] space).
69124 * @return The scalar double value transformed into ColorMap space from raw data.
70125 */
71- double ColorMap::getTransformedColor (double f) const
126+ double ColorMap::getTransformedValue (double f) const
72127{
73128 // ///////////////////////////////////////////////
74129 // TODO: this seemingly useless code fixes a nasty crash bug on Windows. Don't delete it until a proper fix is implemented!
@@ -104,39 +159,32 @@ double ColorMap::getTransformedColor(double f) const
104159 * @name getColorMapVal
105160 * @brief This method returns the RGB value for the current colormap parameters.
106161 * The input comes from raw data values. To scale to data, ColorMap
107- * must be created with those parameters. The input is transformed, then
108- * used to select a color from a set of color maps (currently defined by
162+ * must be created with those parameters. The input is transformed, then
163+ * used to select a color from a set of color maps (currently defined by
109164 * strings.
110165 * @param v The input value from raw data that will be mapped to a color.
111166 * @return The RGB value mapped from the transformed input into the ColorMap's named map.
112167 */
113- ColorRGB ColorMap::getColorMapVal (double v) const
168+ ColorRGB ColorMap::getColorMapVal (double v) const
114169{
115- double f = getTransformedColor (v);
170+ double f = getTransformedValue (v);
116171 // now grab the RGB
117- ColorRGB col;
172+ auto colorWithoutAlpha = color_->getColorMapVal (f);
173+ // TODO:
174+ // return applyAlpha(f, colorWithoutAlpha);
175+ return colorWithoutAlpha;
176+ }
177+ /*
178+ ColorRGB applyAlpha(double transformed, colorWithoutAlpha)
179+ ...easy
118180
119- if (name_ == " Rainbow" ) {
120- col = getRainbowColorMapVal (f);
121- }
122- else if (name_ == " Old Rainbow" ) {
123- col = getOldRainbowColorMapVal (f);
124- }
125- else if (name_ == " Blackbody" ) {
126- col = getBlackbodyColorMapVal (f);
127- }
128- else if (name_ == " Grayscale" ) {
129- col = getGrayscaleColorMapVal (f);
130- }
131- else if (name_ == " Orange,Black,Lime" ) {
132- col = getOrangeBlackLimeColorMapVal (f);
133- }
134- else if (name_ == " Darkhue" ) {
135- col = getDarkhueColorMapVal (f);
136- }
137181
138- return col;
182+ double alpha(double transformedValue)
183+ {
184+ // interpolate in alphaLookup_
139185}
186+ */
187+
140188/* *
141189 * @name valueToColor
142190 * @brief Takes a scalar value and directly passes into getColorMap.
@@ -178,7 +226,7 @@ ColorRGB ColorMap::valueToColor(const Vector &vector) const {
178226// be "brighter" than the other colors. All colors "appear" to be the
179227// same brightness.
180228// Blue -> Dark Cyan -> Green -> Orange -> Red
181- ColorRGB ColorMap::getRainbowColorMapVal (double f) const
229+ ColorRGB detail::Rainbow::getColorMapVal (double f) const
182230{
183231 ColorRGB col;
184232 if (f < 0.25 )
@@ -194,7 +242,7 @@ ColorRGB ColorMap::getRainbowColorMapVal(double f) const
194242
195243// The Old Rainbow that simply transitions from blue to red 1 color at a time.
196244// Blue -> Cyan -> Green -> Yellow -> Red
197- ColorRGB ColorMap::getOldRainbowColorMapVal (double f) const
245+ ColorRGB detail::OldRainbow::getColorMapVal (double f) const
198246{
199247 ColorRGB col;
200248 if (f < 0.25 )
@@ -211,7 +259,7 @@ ColorRGB ColorMap::getOldRainbowColorMapVal(double f) const
211259// This map is designed to appear like a heat-map, where "cooler" (lower) values
212260// are darker and approach black, and "hotter" (higher) values are lighter
213261// and approach white. In between, you have the red, orange, and yellow transitions.
214- ColorRGB ColorMap::getBlackbodyColorMapVal (double f) const
262+ ColorRGB detail::Blackbody::getColorMapVal (double f) const
215263{
216264 ColorRGB col;
217265 if (f < 0.333333 )
@@ -224,7 +272,7 @@ ColorRGB ColorMap::getBlackbodyColorMapVal(double f) const
224272}
225273
226274// A very simple black to white map with grays in between.
227- ColorRGB ColorMap::getGrayscaleColorMapVal (double f) const
275+ ColorRGB detail::Grayscale::getColorMapVal (double f) const
228276{
229277 ColorRGB col;
230278 col = ColorRGB (f, f, f);
@@ -233,7 +281,7 @@ ColorRGB ColorMap::getGrayscaleColorMapVal(double f) const
233281
234282// This color scheme sets a transition of color that goes
235283// Orange -> Black -> Lime
236- ColorRGB ColorMap::getOrangeBlackLimeColorMapVal (double f) const
284+ ColorRGB detail::OrangeBlackLime::getColorMapVal (double f) const
237285{
238286 ColorRGB col;
239287 if (f < 0.5 )
@@ -243,7 +291,7 @@ ColorRGB ColorMap::getOrangeBlackLimeColorMapVal(double f) const
243291 return col;
244292}
245293
246- ColorRGB ColorMap::getDarkhueColorMapVal (double f) const
294+ ColorRGB detail::Darkhue::getColorMapVal (double f) const
247295{
248296 ColorRGB col;
249297 if (f < 0.25 )
@@ -257,7 +305,7 @@ ColorRGB ColorMap::getDarkhueColorMapVal(double f) const
257305 return col;
258306}
259307
260- std::string ColorMap::getColorMapName () const { return name_ ; }
308+ std::string ColorMap::getColorMapName () const { return nameInfo_ ; }
261309size_t ColorMap::getColorMapResolution () const { return resolution_; }
262310double ColorMap::getColorMapShift () const { return shift_; }
263311bool ColorMap::getColorMapInvert () const { return invert_; }
0 commit comments