Skip to content

Commit

Permalink
Merge branch 'master' into stale-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dcwhite committed Oct 9, 2019
2 parents 8815e44 + 040a02b commit 6620805
Show file tree
Hide file tree
Showing 13 changed files with 535 additions and 524 deletions.
83 changes: 50 additions & 33 deletions src/Core/Datatypes/ColorMap.cc
Expand Up @@ -42,9 +42,10 @@ using namespace SCIRun::Core::Geometry;
using namespace SCIRun::Core::Logging;

ColorMap::ColorMap(ColorMapStrategyHandle color, const std::string& name, const size_t resolution, const double shift,
const bool invert, const double rescale_scale, const double rescale_shift)
const bool invert, const double rescale_scale, const double rescale_shift, const std::vector<double>& alphaPoints)
: color_(color), nameInfo_(name), resolution_(resolution), shift_(shift),
invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift)
invert_(invert), rescale_scale_(rescale_scale), rescale_shift_(rescale_shift),
alphaLookup_(alphaPoints)
{

}
Expand Down Expand Up @@ -116,7 +117,7 @@ namespace detail

ColorMapHandle StandardColorMapFactory::create(const std::string& name, const size_t &res,
const double &shift, const bool &invert,
const double &rescale_scale, const double &rescale_shift)
const double &rescale_scale, const double &rescale_shift, const std::vector<double>& alphaPoints)
{
using namespace detail;
ColorMapStrategyHandle color;
Expand All @@ -129,7 +130,7 @@ ColorMapHandle StandardColorMapFactory::create(const std::string& name, const si
color.reset(new Rainbow);
}

return boost::make_shared<ColorMap>(color, name, res, shift, invert, rescale_scale, rescale_shift);
return boost::make_shared<ColorMap>(color, name, res, shift, invert, rescale_scale, rescale_shift, alphaPoints);
}

StandardColorMapFactory::NameList StandardColorMapFactory::getList()
Expand All @@ -148,16 +149,6 @@ StandardColorMapFactory::NameList StandardColorMapFactory::getList()
*/
double ColorMap::getTransformedValue(double f) const
{
/////////////////////////////////////////////////
//TODO: this seemingly useless code fixes a nasty crash bug on Windows. Don't delete it until a proper fix is implemented!
static bool x = true;
if (x)
{
std::cout << "";// this;// << " " << name_ << " " << resolution_ << " " << shift_ << " " << invert_ << std::endl;
x = false;
}
/////////////////////////////////////////////////

const double rescaled01 = static_cast<double>((f + rescale_shift_) * rescale_scale_);

double v = std::min(std::max(0., rescaled01), 1.);
Expand Down Expand Up @@ -191,57 +182,83 @@ double ColorMap::getTransformedValue(double f) const
ColorRGB ColorMap::getColorMapVal(double v) const
{
double f = getTransformedValue(v);
//now grab the RGB
auto colorWithoutAlpha = color_->getColorMapVal(f);
//TODO:
//return applyAlpha(f, colorWithoutAlpha);
return colorWithoutAlpha;
return applyAlpha(f, colorWithoutAlpha);
}
/*
ColorRGB applyAlpha(double transformed, colorWithoutAlpha)
...easy

ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const
{
double a = alpha(transformed);
return ColorRGB(colorWithoutAlpha.r(), colorWithoutAlpha.g(), colorWithoutAlpha.b(), a);
}

double alpha(double transformedValue)
double ColorMap::alpha(double transformedValue) const
{
// interpolate in alphaLookup_
if(alphaLookup_.size() == 0) return 0.5;
int i;
for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2);

double startx = 0.0f, starty, endx = 1.0f, endy;
if(i == 0)
{
endx = alphaLookup_[0];
starty = endy = alphaLookup_[1];
}
else if(i == alphaLookup_.size())
{
startx = alphaLookup_[i - 2];
endy = starty = alphaLookup_[i - 1];
}
else
{
startx = alphaLookup_[i - 2];
starty = alphaLookup_[i - 1];
endx = alphaLookup_[i + 0];
endy = alphaLookup_[i + 1];
}

double interp = (transformedValue - startx) / (endx - startx);
double value = ((1.0f - interp) * starty + (interp) * endy);
return value;
}
*/


/**
* @name valueToColor
* @brief Takes a scalar value and directly passes into getColorMap.
* @param The raw data value as a scalar double.
* @return The RGB value mapped from the scalar.
*/
ColorRGB ColorMap::valueToColor(double scalar) const {
ColorRGB color = getColorMapVal(scalar);
return color;
ColorRGB ColorMap::valueToColor(double scalar) const
{
return getColorMapVal(scalar);
}

/**
* @name valueToColor
* @brief Takes a tensor value and creates an RGB value based on the magnitude of the eigenvalues.
* @param The raw data value as a tensor.
* @return The RGB value mapped from the tensor.
*/
ColorRGB ColorMap::valueToColor(Tensor &tensor) const {
ColorRGB ColorMap::valueToColor(Tensor &tensor) const
{
double eigen1, eigen2, eigen3;
tensor.get_eigenvalues(eigen1, eigen2, eigen3);
double magnitude = Vector(eigen1, eigen2, eigen3).length();
ColorRGB color = getColorMapVal(magnitude);
return color;
return getColorMapVal(magnitude);
}

/**
* @name valueToColor
* @brief Takes a vector value and creates an RGB value.
* @param The raw data value as a vector.
* @return The RGB value mapped from the vector.
*/
ColorRGB ColorMap::valueToColor(const Vector &vector) const {
ColorRGB ColorMap::valueToColor(const Vector &vector) const
{
//TODO this is probably not implemented correctly.
// return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z())));
ColorRGB color = getColorMapVal(vector.length());
return color;
return getColorMapVal(vector.length());
}

// This Rainbow takes into account scientific visualization recommendations.
Expand Down
9 changes: 7 additions & 2 deletions src/Core/Datatypes/ColorMap.h
Expand Up @@ -51,7 +51,8 @@ namespace Datatypes {
explicit ColorMap(ColorMapStrategyHandle color,
const std::string& name = "Rainbow", const size_t resolution = 256,
const double shift = 0.0, const bool invert = false,
const double rescale_scale = .5, const double rescale_shift = 1.);
const double rescale_scale = .5, const double rescale_shift = 1.0,
const std::vector<double>& alphaPoints = {});
//TODO cbright: pass in alpha vector
virtual ColorMap* clone() const override;

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

ColorRGB valueToColor(double scalar) const;
ColorRGB valueToColor(Core::Geometry::Tensor &tensor) const;
Expand All @@ -73,6 +75,8 @@ namespace Datatypes {
///<< Internal functions.
Core::Datatypes::ColorRGB getColorMapVal(double v) const;
double getTransformedValue(double v) const;
ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const;
double alpha(double transformedValue) const;

ColorMapStrategyHandle color_;
///<< The colormap's name.
Expand Down Expand Up @@ -112,7 +116,8 @@ namespace Datatypes {
// See explanation for defaults above in ColorMap Constructor
static ColorMapHandle create(const std::string& name = "Rainbow", const size_t &resolution = 256,
const double &shift = 0.0, const bool &invert = false,
const double &rescale_scale = .5, const double &rescale_shift = 1.);
const double &rescale_scale = .5, const double &rescale_shift = 1.0,
const std::vector<double>& alphaPoints = {});
typedef std::vector<std::string> NameList;
static NameList getList();
private:
Expand Down
9 changes: 7 additions & 2 deletions src/Externals/spire/arc-ball/ArcBall.cpp
Expand Up @@ -60,7 +60,7 @@ void ArcBall::drag(const glm::vec2& msc)
glm::vec3 mVSphereNow = mouseOnSphere((mScreenToTCS * glm::vec4(msc, 0.0, 1.0)).xyz());

// Construct a quaternion from two points on the unit sphere.
glm:: quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow);
glm::quat mQDrag = quatFromUnitSphere(mVSphereDown, mVSphereNow);
mQNow = mQDrag * mQDown;
if(glm::dot(mVSphereDown, mVSphereNow) < 0.0)
beginDrag(msc);
Expand All @@ -77,9 +77,14 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up)
glm::quat ArcBall::quatFromUnitSphere(const glm::vec3& from, const glm::vec3& to)
{
glm::vec3 axis = glm::normalize(glm::cross(from, to));

// Give arbitrary non-zero vector because no rotation
if (std::isnan(axis[0]))
axis = from;

float angle = std::acos(glm::dot(from, to));

if(angle <= 0.00001)
if(angle <= 0.00001 || std::isnan(angle))
return glm::quat(1.0, 0.0, 0.0, 0.0);

return glm::angleAxis(angle, axis);
Expand Down
2 changes: 1 addition & 1 deletion src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs
Expand Up @@ -119,7 +119,7 @@ void main()
else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0));

vec3 diffuseColor = colorMapValue.rgb;
float transparency = uTransparency;
float transparency = colorMapValue.a;

gl_FragColor = vec4(diffuseColor, transparency);

Expand Down
2 changes: 1 addition & 1 deletion src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs
Expand Up @@ -137,7 +137,7 @@ void main()
vec3 diffuseColor = pow(colorMapValue.rgb, vec3(2.2));
vec3 specularColor = uSpecularColor.rgb;
vec3 ambientColor = uAmbientColor.rgb;
float transparency = uTransparency;
float transparency = colorMapValue.a;

vec3 normal = normalize(vNormal);
if(gl_FrontFacing) normal = -normal;
Expand Down

0 comments on commit 6620805

Please sign in to comment.