@@ -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 ()
@@ -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.
0 commit comments