Skip to content

Commit 3188548

Browse files
author
Haydelj
committed
made suggested changes
1 parent 00a13ed commit 3188548

File tree

5 files changed

+83
-71
lines changed

5 files changed

+83
-71
lines changed

src/Core/Datatypes/ColorMap.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ double alpha(double transformedValue)
215215
* @return The RGB value mapped from the scalar.
216216
*/
217217
ColorRGB ColorMap::valueToColor(double scalar) const {
218-
return getColorMapVal(scalar);
218+
ColorRGB color = getColorMapVal(scalar);
219+
return color;
220+
//float alpha = 0.5;
221+
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
219222
}
220223
/**
221224
* @name valueToColor
@@ -227,7 +230,10 @@ ColorRGB ColorMap::valueToColor(Tensor &tensor) const {
227230
double eigen1, eigen2, eigen3;
228231
tensor.get_eigenvalues(eigen1, eigen2, eigen3);
229232
double magnitude = Vector(eigen1, eigen2, eigen3).length();
230-
return getColorMapVal(magnitude);
233+
ColorRGB color = getColorMapVal(magnitude);
234+
return color;
235+
//float alpha = 0.5;
236+
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
231237
}
232238
/**
233239
* @name valueToColor
@@ -238,7 +244,10 @@ ColorRGB ColorMap::valueToColor(Tensor &tensor) const {
238244
ColorRGB ColorMap::valueToColor(const Vector &vector) const {
239245
//TODO this is probably not implemented correctly.
240246
// return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z())));
241-
return getColorMapVal(vector.length());
247+
ColorRGB color = getColorMapVal(vector.length());
248+
return color;
249+
//float alpha = 0.5;
250+
//return ColorRGB(color.r(), color.g(), color.b(), alpha);
242251
}
243252

244253
// This Rainbow takes into account scientific visualization recommendations.

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,29 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
7272
uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f));
7373
}
7474

75+
SpireText text;
76+
SpireTexture2D texture;
7577
if (useColor)
7678
{
7779
if(colorMap)
7880
{
7981
numAttributes += 2;
8082
shader += "_ColorMap";
8183
attribs.push_back(SpireVBO::AttributeData("aTexCoords", 2 * sizeof(float)));
84+
85+
const static int colorMapResolution = 256;
86+
for(int i = 0; i < colorMapResolution; ++i)
87+
{
88+
ColorRGB color = colorMap->valueToColor(static_cast<float>(i)/colorMapResolution * 2.0f - 1.0f);
89+
texture.bitmap.push_back(color.r()*255.99f);
90+
texture.bitmap.push_back(color.g()*255.99f);
91+
texture.bitmap.push_back(color.b()*255.99f);
92+
texture.bitmap.push_back(color.a()*255.99f);
93+
}
94+
95+
texture.name = "ColorMap";
96+
texture.height = 1;
97+
texture.width = colorMapResolution;
8298
}
8399
else
84100
{
@@ -105,7 +121,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
105121
std::string iboName = passID + "IBO";
106122
std::string passName = passID + "Pass";
107123

108-
const static size_t maxPointsPerPass = 3 << 24; //must be a numebr divisible by 2, 3 and, 4
124+
const static size_t maxPointsPerPass = 3 << 24; //must be a number divisible by 2, 3 and, 4
109125
uint32_t pointsInThisPass = std::min(pointsLeft, maxPointsPerPass);
110126
size_t endOfPass = startOfPass + pointsInThisPass;
111127
pointsLeft -= pointsInThisPass;
@@ -123,31 +139,34 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
123139
BBox newBBox;
124140
for (size_t i = startOfPass; i < endOfPass; ++i)
125141
{
126-
newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z()));
127-
vboBuffer->write(static_cast<float>(points_.at(i).x()));
128-
vboBuffer->write(static_cast<float>(points_.at(i).y()));
129-
vboBuffer->write(static_cast<float>(points_.at(i).z()));
142+
Vector point = points_.at(i);
143+
newBBox.extend(Point(point.x(), point.y(), point.z()));
144+
vboBuffer->write(static_cast<float>(point.x()));
145+
vboBuffer->write(static_cast<float>(point.y()));
146+
vboBuffer->write(static_cast<float>(point.z()));
130147

131148
if (useNormals)
132149
{
133-
vboBuffer->write(static_cast<float>(normals_.at(i).x()));
134-
vboBuffer->write(static_cast<float>(normals_.at(i).y()));
135-
vboBuffer->write(static_cast<float>(normals_.at(i).z()));
150+
Vector normal = normals_.at(i);
151+
vboBuffer->write(static_cast<float>(normal.x()));
152+
vboBuffer->write(static_cast<float>(normal.y()));
153+
vboBuffer->write(static_cast<float>(normal.z()));
136154
}
137155

138156
if (useColor)
139157
{
158+
ColorRGB color = colors_.at(i);
140159
if(!colorMap)
141160
{
142-
vboBuffer->write(static_cast<float>(colors_.at(i).r()));
143-
vboBuffer->write(static_cast<float>(colors_.at(i).g()));
144-
vboBuffer->write(static_cast<float>(colors_.at(i).b()));
145-
vboBuffer->write(static_cast<float>(colors_.at(i).a()));
161+
vboBuffer->write(static_cast<float>(color.r()));
162+
vboBuffer->write(static_cast<float>(color.g()));
163+
vboBuffer->write(static_cast<float>(color.b()));
164+
vboBuffer->write(static_cast<float>(color.a()));
146165
}
147166
else
148167
{
149-
vboBuffer->write(static_cast<float>(colors_.at(i).r()));
150-
vboBuffer->write(static_cast<float>(colors_.at(i).r()));
168+
vboBuffer->write(static_cast<float>(color.r()));
169+
vboBuffer->write(static_cast<float>(color.r()));
151170
}
152171
}
153172
}
@@ -160,25 +179,6 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
160179

161180
state.set(RenderState::IS_ON, true);
162181
state.set(RenderState::HAS_DATA, true);
163-
164-
SpireTexture2D texture;
165-
if (colorMap)
166-
{
167-
const static int colorMapResolution = 256;
168-
for(int i = 0; i < colorMapResolution; ++i)
169-
{
170-
ColorRGB color = colorMap->valueToColor(static_cast<float>(i)/colorMapResolution * 2.0 - 1.0);
171-
texture.bitmap.push_back(color.r()*255);
172-
texture.bitmap.push_back(color.g()*255);
173-
texture.bitmap.push_back(color.b()*255);
174-
texture.bitmap.push_back(255);
175-
}
176-
texture.name = "ColorMap";
177-
texture.height = 1;
178-
texture.width = colorMapResolution;
179-
}
180-
181-
SpireText text;
182182
SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture);
183183

184184
for (const auto& uniform : uniforms) pass.addUniform(uniform);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ void main()
114114
}
115115
}
116116

117-
vec3 diffuseColor;
118-
if(gl_FrontFacing) diffuseColor = texture2D(uTX0, vec2(vTexCoords.y, 0.0)).rgb;
119-
else diffuseColor = texture2D(uTX0, vec2(vTexCoords.x, 0.0)).rgb;
117+
vec4 colorMapValue;
118+
if(gl_FrontFacing) colorMapValue = texture2D(uTX0, vec2(vTexCoords.y, 0.0));
119+
else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0));
120+
121+
vec3 diffuseColor = colorMapValue.rgb;
120122
float transparency = uTransparency;
121123

122124
gl_FragColor = vec4(diffuseColor, transparency);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ void main()
136136
}
137137
}
138138

139-
vec3 diffuseColor;
140-
if(gl_FrontFacing) diffuseColor = texture2D(uTX0, vec2(vTexCoords.y, 0.0)).rgb;
141-
else diffuseColor = texture2D(uTX0, vec2(vTexCoords.x, 0.0)).rgb;
139+
vec4 colorMapValue;
140+
if(gl_FrontFacing) colorMapValue = texture2D(uTX0, vec2(vTexCoords.y, 0.0));
141+
else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0));
142+
143+
vec3 diffuseColor = colorMapValue.rgb;
142144
vec3 specularColor = uSpecularColor.rgb;
143145
vec3 ambientColor = uAmbientColor.rgb;
144146
float transparency = uTransparency;

src/Modules/Visualization/ShowField.cc

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,23 @@ namespace
469469
{
470470
return ((int)writeQuads << 2) | ((int)writeNormals << 1) | ((int)writeTexCoords);
471471
}
472+
473+
void spiltColorMapToTextureAndCoordinates(
474+
const boost::optional<boost::shared_ptr<ColorMap>>& colorMap,
475+
ColorMapHandle& textureMap, ColorMapHandle& coordinateMap)
476+
{
477+
ColorMapHandle realColorMap = nullptr;
478+
479+
if(colorMap) realColorMap = colorMap.get();
480+
else realColorMap = StandardColorMapFactory::create();
481+
482+
textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(),
483+
realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(),
484+
realColorMap->getColorMapInvert());
485+
486+
coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false,
487+
realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift());
488+
}
472489
}
473490

474491

@@ -522,12 +539,9 @@ void GeometryBuilder::renderFacesLinear(
522539

523540
ColorScheme colorScheme = ColorScheme::COLOR_UNIFORM;
524541

525-
ColorMapHandle realColorMap;
526-
if(colorMap) realColorMap = colorMap.get();
527-
if(!realColorMap) realColorMap = StandardColorMapFactory::create();
528542

529-
auto coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false,
530-
realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift());
543+
ColorMapHandle textureMap, coordinateMap;
544+
spiltColorMapToTextureAndCoordinates(colorMap, textureMap, coordinateMap);
531545

532546
if (useColorMap)
533547
{
@@ -773,18 +787,14 @@ void GeometryBuilder::renderFacesLinear(
773787
shader += "_ColorMap";
774788
attribs.push_back(SpireVBO::AttributeData("aTexCoords", 2 * sizeof(float)));
775789

776-
auto map = StandardColorMapFactory::create(realColorMap->getColorMapName(),
777-
realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(),
778-
realColorMap->getColorMapInvert());
779-
780790
const static int colorMapResolution = 256;
781791
for(int i = 0; i < colorMapResolution; ++i)
782792
{
783-
ColorRGB color = map->valueToColor(static_cast<float>(i)/colorMapResolution * 2.0 - 1.0);
784-
texture.bitmap.push_back(color.r()*255);
785-
texture.bitmap.push_back(color.g()*255);
786-
texture.bitmap.push_back(color.b()*255);
787-
texture.bitmap.push_back(255);
793+
ColorRGB color = textureMap->valueToColor(static_cast<float>(i)/colorMapResolution * 2.0 - 1.0);
794+
texture.bitmap.push_back(color.r()*255.99f);
795+
texture.bitmap.push_back(color.g()*255.99f);
796+
texture.bitmap.push_back(color.b()*255.99f);
797+
texture.bitmap.push_back(color.a()*255.99f);
788798
}
789799
texture.name = "ColorMap";
790800
texture.height = 1;
@@ -908,6 +918,7 @@ void GeometryBuilder::renderNodes(
908918
}
909919

910920

921+
911922
void GeometryBuilder::renderEdges(
912923
FieldHandle field,
913924
boost::optional<boost::shared_ptr<ColorMap>> colorMap,
@@ -926,12 +937,8 @@ void GeometryBuilder::renderEdges(
926937
ColorScheme colorScheme;
927938
ColorRGB edge_colors[2];
928939

929-
ColorMapHandle realColorMap = nullptr;
930-
if(colorMap) realColorMap = colorMap.get();
931-
if(!realColorMap) realColorMap = StandardColorMapFactory::create();
932-
933-
auto coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false,
934-
realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift());
940+
ColorMapHandle textureMap, coordinateMap;
941+
spiltColorMapToTextureAndCoordinates(colorMap, textureMap, coordinateMap);
935942

936943
if (fld->basis_order() < 0 ||
937944
(fld->basis_order() == 0 && mesh->dimensionality() != 0) ||
@@ -1046,16 +1053,8 @@ void GeometryBuilder::renderEdges(
10461053
++eiter;
10471054
}
10481055

1049-
ColorMapHandle map = nullptr;
1050-
if(realColorMap)
1051-
{
1052-
map = StandardColorMapFactory::create(realColorMap->getColorMapName(),
1053-
realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(),
1054-
realColorMap->getColorMapInvert());
1055-
}
1056-
10571056
glyphs.buildObject(*geom, uniqueNodeID, state.get(RenderState::USE_TRANSPARENT_EDGES), edgeTransparencyValue_,
1058-
colorScheme, state, primIn, mesh->get_bounding_box(), true, map);
1057+
colorScheme, state, primIn, mesh->get_bounding_box(), true, textureMap);
10591058
}
10601059

10611060
void ShowField::updateAvailableRenderOptions(FieldHandle field)

0 commit comments

Comments
 (0)