Skip to content

Commit f8dea30

Browse files
committed
Merge branch 'master' into pythonSetData
2 parents 4ef1e31 + f93f426 commit f8dea30

File tree

10 files changed

+240
-92
lines changed

10 files changed

+240
-92
lines changed

src/Core/Datatypes/Color.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ namespace Datatypes {
4848
explicit ColorRGB(const std::string& rgb);
4949
ColorRGB(double r, double g, double b);
5050
ColorRGB(double r, double g, double b, double a);
51+
//adjust alpha while copying
52+
ColorRGB(const ColorRGB& color, double a);
5153

5254
// These equality operations should use floating point comparisons.
5355
inline bool operator==(const ColorRGB& c) const {

src/Core/Datatypes/ColorMap.cc

Lines changed: 91 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
#include <Core/Datatypes/ColorMap.h>
3232
#include <iostream>
3333

34+
using namespace SCIRun;
3435
using namespace SCIRun::Core::Datatypes;
3536
using 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+
5090
ColorMapHandle 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_; }
261309
size_t ColorMap::getColorMapResolution() const { return resolution_; }
262310
double ColorMap::getColorMapShift() const { return shift_; }
263311
bool ColorMap::getColorMapInvert() const { return invert_; }

src/Core/Datatypes/ColorMap.h

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2015 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -27,7 +27,7 @@
2727
*/
2828
/// @todo Documentation Core/Datatypes/ColorMap.h
2929
#ifndef CORE_DATATYPES_COLORMAP_H
30-
#define CORE_DATATYPES_COLORMAP_H
30+
#define CORE_DATATYPES_COLORMAP_H
3131

3232
#include <Core/Datatypes/Datatype.h>
3333
#include <boost/noncopyable.hpp>
@@ -40,44 +40,43 @@ namespace SCIRun {
4040
namespace Core {
4141
namespace Datatypes {
4242

43+
class ColorMapStrategy;
44+
typedef boost::shared_ptr<ColorMapStrategy> ColorMapStrategyHandle;
45+
4346
class SCISHARE ColorMap : public Datatype
4447
{
4548
public:
4649
// Because colors need to be in the range [0,1], and SCIRun4 used [-1,1] for it's
4750
// default input range, we need to transform by default the data into [0,1] range.
48-
explicit ColorMap(const std::string& name = "Rainbow", const size_t resolution = 256,
51+
explicit ColorMap(ColorMapStrategyHandle color,
52+
const std::string& name = "Rainbow", const size_t resolution = 256,
4953
const double shift = 0.0, const bool invert = false,
5054
const double rescale_scale = .5, const double rescale_shift = 1.);
51-
55+
//TODO: pass in alpha vector
5256
virtual ColorMap* clone() const;
5357

58+
ColorMapStrategyHandle getColorStrategy() const { return color_; }
5459
std::string getColorMapName() const;
5560
size_t getColorMapResolution() const;
5661
double getColorMapShift() const;
5762
bool getColorMapInvert() const;
5863
double getColorMapRescaleScale() const;
5964
double getColorMapRescaleShift() const;
60-
65+
6166
Core::Datatypes::ColorRGB valueToColor(double scalar) const;
6267
Core::Datatypes::ColorRGB valueToColor(const Core::Geometry::Tensor &tensor) const;
6368
Core::Datatypes::ColorRGB valueToColor(const Core::Geometry::Vector &vector) const;
6469

6570
virtual std::string dynamic_type_name() const override { return "ColorMap"; }
66-
71+
6772
private:
6873
///<< Internal functions.
6974
Core::Datatypes::ColorRGB getColorMapVal(double v) const;
70-
double getTransformedColor(double v) const;
71-
72-
Core::Datatypes::ColorRGB getRainbowColorMapVal(double f) const;
73-
Core::Datatypes::ColorRGB getOldRainbowColorMapVal(double f) const;
74-
Core::Datatypes::ColorRGB getBlackbodyColorMapVal(double f) const;
75-
Core::Datatypes::ColorRGB getGrayscaleColorMapVal(double f) const;
76-
Core::Datatypes::ColorRGB getOrangeBlackLimeColorMapVal(double f) const;
77-
Core::Datatypes::ColorRGB getDarkhueColorMapVal(double f) const;
78-
75+
double getTransformedValue(double v) const;
76+
77+
ColorMapStrategyHandle color_;
7978
///<< The colormap's name.
80-
std::string name_;
79+
std::string nameInfo_;
8180
///<< The resolution of the map [2,256].
8281
size_t resolution_;
8382
///<< The gamma shift.
@@ -88,6 +87,23 @@ namespace Datatypes {
8887
double rescale_scale_;
8988
///<< Rescaling shift (usually -data_min). Shift happens before scale.
9089
double rescale_shift_;
90+
91+
std::vector<double> alphaLookup_;
92+
};
93+
94+
class SCISHARE ColorMapStrategy
95+
{
96+
public:
97+
virtual ~ColorMapStrategy() {}
98+
virtual Core::Datatypes::ColorRGB getColorMapVal(double v) const = 0;
99+
};
100+
101+
//TODO: not sure this needs to be abstract
102+
class SCISHARE AlphaMapping
103+
{
104+
public:
105+
virtual ~AlphaMapping() {}
106+
virtual double alpha(double transformedValue) const = 0;
91107
};
92108

93109
class SCISHARE StandardColorMapFactory : boost::noncopyable

0 commit comments

Comments
 (0)