@@ -42,9 +42,10 @@ using namespace SCIRun::Core::Geometry;
4242using namespace SCIRun ::Core::Logging;
4343
4444ColorMap::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
117118ColorMapHandle 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
135136StandardColorMapFactory::NameList StandardColorMapFactory::getList ()
@@ -148,16 +149,6 @@ StandardColorMapFactory::NameList StandardColorMapFactory::getList()
148149 */
149150double ColorMap::getTransformedValue (double f) const
150151{
151- // ///////////////////////////////////////////////
152- // TODO: this seemingly useless code fixes a nasty crash bug on Windows. Don't delete it until a proper fix is implemented!
153- static bool x = true ;
154- if (x)
155- {
156- std::cout << " " ;// this;// << " " << name_ << " " << resolution_ << " " << shift_ << " " << invert_ << std::endl;
157- x = false ;
158- }
159- // ///////////////////////////////////////////////
160-
161152 const double rescaled01 = static_cast <double >((f + rescale_shift_) * rescale_scale_);
162153
163154 double v = std::min (std::max (0 ., rescaled01), 1 .);
@@ -191,57 +182,83 @@ double ColorMap::getTransformedValue(double f) const
191182ColorRGB ColorMap::getColorMapVal (double v) const
192183{
193184 double f = getTransformedValue (v);
194- // now grab the RGB
195185 auto colorWithoutAlpha = color_->getColorMapVal (f);
196- // TODO:
197- // return applyAlpha(f, colorWithoutAlpha);
198- return colorWithoutAlpha;
186+ return applyAlpha (f, colorWithoutAlpha);
199187}
200- /*
201- ColorRGB applyAlpha(double transformed, colorWithoutAlpha)
202- ...easy
203188
189+ ColorRGB ColorMap::applyAlpha (double transformed, ColorRGB colorWithoutAlpha) const
190+ {
191+ double a = alpha (transformed);
192+ return ColorRGB (colorWithoutAlpha.r (), colorWithoutAlpha.g (), colorWithoutAlpha.b (), a);
193+ }
204194
205- double alpha(double transformedValue)
195+ double ColorMap:: alpha (double transformedValue) const
206196{
207- // interpolate in alphaLookup_
197+ if (alphaLookup_.size () == 0 ) return 0.5 ;
198+ int i;
199+ for (i = 0 ; (i < alphaLookup_.size ()) && (alphaLookup_[i] < transformedValue); i += 2 );
200+
201+ double startx = 0 .0f , starty, endx = 1 .0f , endy;
202+ if (i == 0 )
203+ {
204+ endx = alphaLookup_[0 ];
205+ starty = endy = alphaLookup_[1 ];
206+ }
207+ else if (i == alphaLookup_.size ())
208+ {
209+ startx = alphaLookup_[i - 2 ];
210+ endy = starty = alphaLookup_[i - 1 ];
211+ }
212+ else
213+ {
214+ startx = alphaLookup_[i - 2 ];
215+ starty = alphaLookup_[i - 1 ];
216+ endx = alphaLookup_[i + 0 ];
217+ endy = alphaLookup_[i + 1 ];
218+ }
219+
220+ double interp = (transformedValue - startx) / (endx - startx);
221+ double value = ((1 .0f - interp) * starty + (interp) * endy);
222+ return value;
208223}
209- */
224+
210225
211226/* *
212227 * @name valueToColor
213228 * @brief Takes a scalar value and directly passes into getColorMap.
214229 * @param The raw data value as a scalar double.
215230 * @return The RGB value mapped from the scalar.
216231 */
217- ColorRGB ColorMap::valueToColor (double scalar) const {
218- ColorRGB color = getColorMapVal (scalar);
219- return color ;
232+ ColorRGB ColorMap::valueToColor (double scalar) const
233+ {
234+ return getColorMapVal (scalar) ;
220235}
236+
221237/* *
222238 * @name valueToColor
223239 * @brief Takes a tensor value and creates an RGB value based on the magnitude of the eigenvalues.
224240 * @param The raw data value as a tensor.
225241 * @return The RGB value mapped from the tensor.
226242 */
227- ColorRGB ColorMap::valueToColor (Tensor &tensor) const {
243+ ColorRGB ColorMap::valueToColor (Tensor &tensor) const
244+ {
228245 double eigen1, eigen2, eigen3;
229246 tensor.get_eigenvalues (eigen1, eigen2, eigen3);
230247 double magnitude = Vector (eigen1, eigen2, eigen3).length ();
231- ColorRGB color = getColorMapVal (magnitude);
232- return color;
248+ return getColorMapVal (magnitude);
233249}
250+
234251/* *
235252 * @name valueToColor
236253 * @brief Takes a vector value and creates an RGB value.
237254 * @param The raw data value as a vector.
238255 * @return The RGB value mapped from the vector.
239256 */
240- ColorRGB ColorMap::valueToColor (const Vector &vector) const {
257+ ColorRGB ColorMap::valueToColor (const Vector &vector) const
258+ {
241259 // TODO this is probably not implemented correctly.
242260 // return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z())));
243- ColorRGB color = getColorMapVal (vector.length ());
244- return color;
261+ return getColorMapVal (vector.length ());
245262}
246263
247264// This Rainbow takes into account scientific visualization recommendations.
0 commit comments