Skip to content

Commit 6620805

Browse files
authored
Merge branch 'master' into stale-issues
2 parents 8815e44 + 040a02b commit 6620805

File tree

13 files changed

+535
-524
lines changed

13 files changed

+535
-524
lines changed

src/Core/Datatypes/ColorMap.cc

Lines changed: 50 additions & 33 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()
@@ -148,16 +149,6 @@ StandardColorMapFactory::NameList StandardColorMapFactory::getList()
148149
*/
149150
double 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
191182
ColorRGB 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.

src/Core/Datatypes/ColorMap.h

Lines changed: 7 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 = {});
5556
//TODO cbright: pass in alpha vector
5657
virtual ColorMap* clone() const override;
5758

@@ -62,6 +63,7 @@ namespace Datatypes {
6263
bool getColorMapInvert() const;
6364
double getColorMapRescaleScale() const;
6465
double getColorMapRescaleShift() const;
66+
std::vector<double> getAlphaLookup() const {return alphaLookup_;}
6567

6668
ColorRGB valueToColor(double scalar) const;
6769
ColorRGB valueToColor(Core::Geometry::Tensor &tensor) const;
@@ -73,6 +75,8 @@ namespace Datatypes {
7375
///<< Internal functions.
7476
Core::Datatypes::ColorRGB getColorMapVal(double v) const;
7577
double getTransformedValue(double v) const;
78+
ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const;
79+
double alpha(double transformedValue) const;
7680

7781
ColorMapStrategyHandle color_;
7882
///<< The colormap's name.
@@ -112,7 +116,8 @@ namespace Datatypes {
112116
// See explanation for defaults above in ColorMap Constructor
113117
static ColorMapHandle create(const std::string& name = "Rainbow", const size_t &resolution = 256,
114118
const double &shift = 0.0, const bool &invert = false,
115-
const double &rescale_scale = .5, const double &rescale_shift = 1.);
119+
const double &rescale_scale = .5, const double &rescale_shift = 1.0,
120+
const std::vector<double>& alphaPoints = {});
116121
typedef std::vector<std::string> NameList;
117122
static NameList getList();
118123
private:

src/Externals/spire/arc-ball/ArcBall.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void ArcBall::drag(const glm::vec2& msc)
6060
glm::vec3 mVSphereNow = mouseOnSphere((mScreenToTCS * glm::vec4(msc, 0.0, 1.0)).xyz());
6161

6262
// Construct a quaternion from two points on the unit sphere.
63-
glm:: quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow);
63+
glm::quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow);
6464
mQNow = mQDrag * mQDown;
6565
if(glm::dot(mVSphereDown, mVSphereNow) < 0.0)
6666
beginDrag(msc);
@@ -77,9 +77,14 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up)
7777
glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to)
7878
{
7979
glm::vec3 axis = glm::normalize(glm::cross(from, to));
80+
81+
// Give arbitrary non-zero vector because no rotation
82+
if (std::isnan(axis[0]))
83+
axis = from;
84+
8085
float angle = std::acos(glm::dot(from, to));
8186

82-
if(angle <= 0.00001)
87+
if(angle <= 0.00001 || std::isnan(angle))
8388
return glm::quat(1.0, 0.0, 0.0, 0.0);
8489

8590
return glm::angleAxis(angle, axis);

src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void main()
119119
else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0));
120120

121121
vec3 diffuseColor = colorMapValue.rgb;
122-
float transparency = uTransparency;
122+
float transparency = colorMapValue.a;
123123

124124
gl_FragColor = vec4(diffuseColor, transparency);
125125

src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void main()
137137
vec3 diffuseColor = pow(colorMapValue.rgb, vec3(2.2));
138138
vec3 specularColor = uSpecularColor.rgb;
139139
vec3 ambientColor = uAmbientColor.rgb;
140-
float transparency = uTransparency;
140+
float transparency = colorMapValue.a;
141141

142142
vec3 normal = normalize(vNormal);
143143
if(gl_FrontFacing) normal = -normal;

0 commit comments

Comments
 (0)