Skip to content

Commit 6d29873

Browse files
author
Haydelj
committed
in progress
1 parent 4b28c9b commit 6d29873

File tree

3 files changed

+64
-29
lines changed

3 files changed

+64
-29
lines changed

src/Core/Datatypes/ColorMap.cc

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ using namespace SCIRun::Core::Geometry;
4242
using namespace SCIRun::Core::Logging;
4343

4444
ColorMap::ColorMap(ColorMapStrategyHandle color, const std::string& name, const size_t resolution, const double shift,
45-
const bool invert, const double rescale_scale, const double rescale_shift)
45+
const bool invert, const double rescale_scale, const double rescale_shift, const std::vector<double>& alphaPoints)
4646
: color_(color), nameInfo_(name), resolution_(resolution), shift_(shift),
47-
invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift)
47+
invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift),
48+
alphaLookup_(alphaPoints)
4849
{
4950

5051
}
@@ -116,7 +117,7 @@ namespace detail
116117

117118
ColorMapHandle StandardColorMapFactory::create(const std::string& name, const size_t &res,
118119
const double &shift, const bool &invert,
119-
const double &rescale_scale, const double &rescale_shift)
120+
const double &rescale_scale, const double &rescale_shift, const std::vector<double>& alphaPoints)
120121
{
121122
using namespace detail;
122123
ColorMapStrategyHandle color;
@@ -129,7 +130,7 @@ ColorMapHandle StandardColorMapFactory::create(const std::string& name, const si
129130
color.reset(new Rainbow);
130131
}
131132

132-
return boost::make_shared<ColorMap>(color, name, res, shift, invert, rescale_scale, rescale_shift);
133+
return boost::make_shared<ColorMap>(color, name, res, shift, invert, rescale_scale, rescale_shift, alphaPoints);
133134
}
134135

135136
StandardColorMapFactory::NameList StandardColorMapFactory::getList()
@@ -194,60 +195,83 @@ ColorRGB ColorMap::getColorMapVal(double v) const
194195
//now grab the RGB
195196
auto colorWithoutAlpha = color_->getColorMapVal(f);
196197
//TODO:
197-
//return applyAlpha(f, colorWithoutAlpha);
198-
return colorWithoutAlpha;
198+
return applyAlpha(f, colorWithoutAlpha);
199+
//return colorWithoutAlpha;
199200
}
200-
/*
201-
ColorRGB applyAlpha(double transformed, colorWithoutAlpha)
202-
...easy
203201

202+
ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha)
203+
{
204+
double a = alpha(transformed);
205+
return ColorRGB(colorWithoutAlpha.r(), colorWithoutAlpha.g(), colorWithoutAlpha.b(), a);
206+
}
204207

205-
double alpha(double transformedValue)
208+
double ColorMap::alpha(double transformedValue)
206209
{
207-
// interpolate in alphaLookup_
210+
std::cout << transformedValue << "\n";
211+
int i;
212+
for(i = 0; (i < alphaLookup_.size()) && (transformedValue < alphaLookup_[i]); i += 2);
213+
214+
double startx = 0.0;
215+
double starty = 40.0;
216+
double endx = 360.0;
217+
double endy = 40.0;
218+
219+
if(i == 0)
220+
{
221+
endx = alphaLookup_[0];
222+
endy = alphaLookup_[1];
223+
}
224+
else if(i == alphaLookup_.size())
225+
{
226+
startx = alphaLookup_[i];
227+
starty = alphaLookup_[i - 1];
228+
}
229+
else
230+
{
231+
startx = alphaLookup_[i - 2];
232+
starty = alphaLookup_[i - 1];
233+
endx = alphaLookup_[i + 0];
234+
endy = alphaLookup_[i + 1];
235+
}
208236
}
209-
*/
237+
210238

211239
/**
212240
* @name valueToColor
213241
* @brief Takes a scalar value and directly passes into getColorMap.
214242
* @param The raw data value as a scalar double.
215243
* @return The RGB value mapped from the scalar.
216244
*/
217-
ColorRGB ColorMap::valueToColor(double scalar) const {
218-
ColorRGB color = getColorMapVal(scalar);
219-
return color;
220-
//float alpha = 0.5;
221-
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
245+
ColorRGB ColorMap::valueToColor(double scalar) const
246+
{
247+
return getColorMapVal(scalar);
222248
}
249+
223250
/**
224251
* @name valueToColor
225252
* @brief Takes a tensor value and creates an RGB value based on the magnitude of the eigenvalues.
226253
* @param The raw data value as a tensor.
227254
* @return The RGB value mapped from the tensor.
228255
*/
229-
ColorRGB ColorMap::valueToColor(Tensor &tensor) const {
256+
ColorRGB ColorMap::valueToColor(Tensor &tensor) const
257+
{
230258
double eigen1, eigen2, eigen3;
231259
tensor.get_eigenvalues(eigen1, eigen2, eigen3);
232260
double magnitude = Vector(eigen1, eigen2, eigen3).length();
233-
ColorRGB color = getColorMapVal(magnitude);
234-
return color;
235-
//float alpha = 0.5;
236-
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
261+
return getColorMapVal(magnitude);
237262
}
263+
238264
/**
239265
* @name valueToColor
240266
* @brief Takes a vector value and creates an RGB value.
241267
* @param The raw data value as a vector.
242268
* @return The RGB value mapped from the vector.
243269
*/
244-
ColorRGB ColorMap::valueToColor(const Vector &vector) const {
270+
ColorRGB ColorMap::valueToColor(const Vector &vector) const
271+
{
245272
//TODO this is probably not implemented correctly.
246273
// return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z())));
247-
ColorRGB color = getColorMapVal(vector.length());
248-
return color;
249-
//float alpha = 0.5;
250-
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
274+
return getColorMapVal(vector.length());
251275
}
252276

253277
// This Rainbow takes into account scientific visualization recommendations.

src/Core/Datatypes/ColorMap.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ namespace Datatypes {
5151
explicit ColorMap(ColorMapStrategyHandle color,
5252
const std::string& name = "Rainbow", const size_t resolution = 256,
5353
const double shift = 0.0, const bool invert = false,
54-
const double rescale_scale = .5, const double rescale_shift = 1.);
54+
const double rescale_scale = .5, const double rescale_shift = 1.0,
55+
const std::vector<double>& alphaPoints = std::vector<double>());
5556
//TODO cbright: pass in alpha vector
5657
virtual ColorMap* clone() const override;
5758

@@ -73,6 +74,8 @@ namespace Datatypes {
7374
///<< Internal functions.
7475
Core::Datatypes::ColorRGB getColorMapVal(double v) const;
7576
double getTransformedValue(double v) const;
77+
ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha);
78+
double alpha(double transformedValue);
7679

7780
ColorMapStrategyHandle color_;
7881
///<< The colormap's name.
@@ -112,7 +115,8 @@ namespace Datatypes {
112115
// See explanation for defaults above in ColorMap Constructor
113116
static ColorMapHandle create(const std::string& name = "Rainbow", const size_t &resolution = 256,
114117
const double &shift = 0.0, const bool &invert = false,
115-
const double &rescale_scale = .5, const double &rescale_shift = 1.);
118+
const double &rescale_scale = .5, const double &rescale_shift = 1.0,
119+
const std::vector<double>& alphaPoints = std::vector<double>());
116120
typedef std::vector<std::string> NameList;
117121
static NameList getList();
118122
private:

src/Modules/Visualization/CreateStandardColorMap.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ void CreateStandardColorMap::execute()
6666

6767
//TODO cbright: pass computed alpha function from transient state to factory
6868
auto alphaPoints = state->getValue(Parameters::AlphaUserPointsVector).toVector();
69+
std::cout << alphaPoints << "\n";
70+
std::vector<double> points;
71+
for(auto point : alphaPoints)
72+
{
73+
points.push_back(point.toVector()[0].toDouble());
74+
points.push_back(point.toVector()[1].toDouble());
75+
}
6976

7077
//just in case there is a problem with the QT values...
7178
res = std::min(std::max(res,2),256);

0 commit comments

Comments
 (0)