Skip to content

Commit 3c2803a

Browse files
author
Haydelj
committed
added transparency to colormaps
1 parent 6d29873 commit 3c2803a

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

src/Core/Datatypes/ColorMap.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,23 @@ ColorRGB ColorMap::getColorMapVal(double v) const
199199
//return colorWithoutAlpha;
200200
}
201201

202-
ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha)
202+
ColorRGB ColorMap::applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const
203203
{
204204
double a = alpha(transformed);
205205
return ColorRGB(colorWithoutAlpha.r(), colorWithoutAlpha.g(), colorWithoutAlpha.b(), a);
206206
}
207207

208-
double ColorMap::alpha(double transformedValue)
208+
double ColorMap::alpha(double transformedValue) const
209209
{
210+
transformedValue *= 364.0;
210211
std::cout << transformedValue << "\n";
212+
if(alphaLookup_.size() == 0) return 0.5;
211213
int i;
212-
for(i = 0; (i < alphaLookup_.size()) && (transformedValue < alphaLookup_[i]); i += 2);
214+
for(i = 0; (i < alphaLookup_.size()) && (alphaLookup_[i] < transformedValue); i += 2);
213215

214216
double startx = 0.0;
215217
double starty = 40.0;
216-
double endx = 360.0;
218+
double endx = 364.0;
217219
double endy = 40.0;
218220

219221
if(i == 0)
@@ -223,16 +225,22 @@ double ColorMap::alpha(double transformedValue)
223225
}
224226
else if(i == alphaLookup_.size())
225227
{
226-
startx = alphaLookup_[i];
228+
startx = alphaLookup_[i - 2];
227229
starty = alphaLookup_[i - 1];
228230
}
229231
else
230232
{
233+
std::cout << "normal\n";
231234
startx = alphaLookup_[i - 2];
232235
starty = alphaLookup_[i - 1];
233236
endx = alphaLookup_[i + 0];
234237
endy = alphaLookup_[i + 1];
235238
}
239+
240+
double interp = (transformedValue - startx) / (endx - startx);
241+
double value = ((1.0f - interp) * starty + (interp) * endy) / 80.0;
242+
std::cout << startx << " : " << endx << " : " << interp << "\n";
243+
return value;
236244
}
237245

238246

src/Core/Datatypes/ColorMap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace Datatypes {
6363
bool getColorMapInvert() const;
6464
double getColorMapRescaleScale() const;
6565
double getColorMapRescaleShift() const;
66+
std::vector<double> getAlphaLookup() const {return alphaLookup_;}
6667

6768
ColorRGB valueToColor(double scalar) const;
6869
ColorRGB valueToColor(Core::Geometry::Tensor &tensor) const;
@@ -74,8 +75,8 @@ namespace Datatypes {
7475
///<< Internal functions.
7576
Core::Datatypes::ColorRGB getColorMapVal(double v) const;
7677
double getTransformedValue(double v) const;
77-
ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha);
78-
double alpha(double transformedValue);
78+
ColorRGB applyAlpha(double transformed, ColorRGB colorWithoutAlpha) const;
79+
double alpha(double transformedValue) const;
7980

8081
ColorMapStrategyHandle color_;
8182
///<< The colormap's name.

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
@@ -143,7 +143,7 @@ void main()
143143
vec3 diffuseColor = colorMapValue.rgb;
144144
vec3 specularColor = uSpecularColor.rgb;
145145
vec3 ambientColor = uAmbientColor.rgb;
146-
float transparency = uTransparency;
146+
float transparency = colorMapValue.a;
147147

148148
vec3 normal = normalize(vNormal);
149149
if (gl_FrontFacing) normal = -normal;

src/Modules/Visualization/CreateStandardColorMap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void CreateStandardColorMap::execute()
7777
//just in case there is a problem with the QT values...
7878
res = std::min(std::max(res,2),256);
7979
shift = std::min(std::max(shift,-1.),1.);
80-
sendOutput(ColorMapObject, StandardColorMapFactory::create(name, res, shift, inv));
80+
sendOutput(ColorMapObject, StandardColorMapFactory::create(name, res, shift, inv, 0.5, 1.0, points));
8181
}
8282
}
8383

src/Modules/Visualization/ShowField.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ namespace
481481

482482
textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(),
483483
realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(),
484-
realColorMap->getColorMapInvert());
484+
realColorMap->getColorMapInvert(), 0.5, 1.0, realColorMap->getAlphaLookup());
485485

486486
coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false,
487487
realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift());

0 commit comments

Comments
 (0)