Skip to content

Commit 640aa59

Browse files
committed
Attempt to turn on SCM text labels
1 parent 2049032 commit 640aa59

File tree

1 file changed

+107
-105
lines changed

1 file changed

+107
-105
lines changed

src/Modules/Visualization/ShowColorMapModule.cc

Lines changed: 107 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -194,114 +194,116 @@ ShowColorMapModule::buildGeometryObject(ColorMapHandle cm, ModuleStateHandle sta
194194
geom->mIBOs.push_back(geomIBO);
195195
geom->mVBOs.push_back(geomVBO);
196196
geom->mPasses.push_back(pass);
197-
//########################################
198-
// Now render the numbers for the scale bar
199-
200-
char str2[128];
201-
std::stringstream sd;
202-
sd << "%." << sigdig << "f";
203-
points.clear();
204-
indices.clear();
205-
std::vector<Vector> txt_coords;
206-
numVBOElements = 0;
207-
uint32_t count = 0;
208-
double increment = 1. / static_cast<double>(numlabel - 1);
209-
double textSize = 10. * static_cast<double>(txtsize + 3);
210-
const double dash_size = 20.;
211-
const double pipe_size = 40.;
212-
213-
for (double i = 0.; i <= 1.000000001; i += increment) {
214-
std::stringstream ss;
215-
sprintf(str2, sd.str().c_str(), i / cm->getColorMapRescaleScale() - cm->getColorMapRescaleShift());
216-
ss << str2 << " " << st->getValue(Units).toString();
217-
//flip the text to the side with more space depending on xTrans/yTrans > 50%
218-
//text offsets vary depending on side of bar and left vs. bottom. Might need to vary per platform.
219-
text_.reset(ss.str(), textSize, Vector((displaySide == 0) ?
220-
(xTrans>50?-(textSize*strlen(ss.str().c_str())):4.*dash_size) : 0.,
221-
(displaySide == 0) ?
222-
0. : (yTrans>50?(-textSize-pipe_size/2.):pipe_size), i));
223-
std::vector<Vector> tmp;
224-
std::vector<Vector> coords;
225-
text_.getStringVerts(tmp, coords);
226-
if (displaySide != 0)
227-
//pipe texture is 18 pixels too far right, move dash down a bit if closer to the top
228-
text_.reset("|", pipe_size, Vector(-18., yTrans>50?-15.:0., i));
229-
else
230-
text_.reset("____", dash_size, Vector(xTrans>50?-15.:0., 0., i)); //move dashed over if bar on the right
231-
text_.getStringVerts(tmp, coords);
232-
233-
for (auto a : tmp) {
234-
points.push_back(a);
235-
indices.push_back(count);
236-
count++;
197+
{
198+
//########################################
199+
// Now render the numbers for the scale bar
200+
201+
char str2[128];
202+
std::stringstream sd;
203+
sd << "%." << sigdig << "f";
204+
points.clear();
205+
indices.clear();
206+
std::vector<Vector> txt_coords;
207+
numVBOElements = 0;
208+
uint32_t count = 0;
209+
double increment = 1. / static_cast<double>(numlabel - 1);
210+
double textSize = 10. * static_cast<double>(txtsize + 3);
211+
const double dash_size = 20.;
212+
const double pipe_size = 40.;
213+
214+
for (double i = 0.; i <= 1.000000001; i += increment) {
215+
std::stringstream ss;
216+
sprintf(str2, sd.str().c_str(), i / cm->getColorMapRescaleScale() - cm->getColorMapRescaleShift());
217+
ss << str2 << " " << st->getValue(Units).toString();
218+
//flip the text to the side with more space depending on xTrans/yTrans > 50%
219+
//text offsets vary depending on side of bar and left vs. bottom. Might need to vary per platform.
220+
text_.reset(ss.str(), textSize, Vector((displaySide == 0) ?
221+
(xTrans > 50 ? -(textSize*strlen(ss.str().c_str())) : 4.*dash_size) : 0.,
222+
(displaySide == 0) ?
223+
0. : (yTrans > 50 ? (-textSize - pipe_size / 2.) : pipe_size), i));
224+
std::vector<Vector> tmp;
225+
std::vector<Vector> coords;
226+
text_.getStringVerts(tmp, coords);
227+
if (displaySide != 0)
228+
//pipe texture is 18 pixels too far right, move dash down a bit if closer to the top
229+
text_.reset("|", pipe_size, Vector(-18., yTrans > 50 ? -15. : 0., i));
230+
else
231+
text_.reset("____", dash_size, Vector(xTrans > 50 ? -15. : 0., 0., i)); //move dashed over if bar on the right
232+
text_.getStringVerts(tmp, coords);
233+
234+
for (auto a : tmp) {
235+
points.push_back(a);
236+
indices.push_back(count);
237+
count++;
238+
}
239+
for (auto a : coords)
240+
txt_coords.push_back(a);
241+
}
242+
numVBOElements = (uint32_t)points.size();
243+
244+
// IBO/VBOs and sizes
245+
iboSize = sizeof(uint32_t) * (uint32_t)indices.size();
246+
vboSize = sizeof(float) * 5 * (uint32_t)points.size();
247+
248+
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr2(
249+
new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
250+
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr2(
251+
new CPM_VAR_BUFFER_NS::VarBuffer(iboSize));
252+
253+
CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer2 = iboBufferSPtr2.get();
254+
CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer2 = vboBufferSPtr2.get();
255+
256+
for (auto a : indices) iboBuffer2->write(a);
257+
for (size_t i = 0; i < points.size(); i++) {
258+
vboBuffer2->write(static_cast<float>(points[i].x()));
259+
vboBuffer2->write(static_cast<float>(points[i].y()));
260+
vboBuffer2->write(static_cast<float>(points[i].z()));
261+
vboBuffer2->write(static_cast<float>(txt_coords[i].x()));
262+
vboBuffer2->write(static_cast<float>(txt_coords[i].y()));
237263
}
238-
for (auto a : coords)
239-
txt_coords.push_back(a);
240-
}
241-
numVBOElements = (uint32_t)points.size();
242-
243-
// IBO/VBOs and sizes
244-
iboSize = sizeof(uint32_t) * (uint32_t)indices.size();
245-
vboSize = sizeof(float) * 5 * (uint32_t)points.size();
246-
247-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr2(
248-
new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
249-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr2(
250-
new CPM_VAR_BUFFER_NS::VarBuffer(iboSize));
251-
252-
CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer2 = iboBufferSPtr2.get();
253-
CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer2 = vboBufferSPtr2.get();
254264

255-
for (auto a : indices) iboBuffer2->write(a);
256-
for (size_t i = 0; i < points.size(); i++) {
257-
vboBuffer2->write(static_cast<float>(points[i].x()));
258-
vboBuffer2->write(static_cast<float>(points[i].y()));
259-
vboBuffer2->write(static_cast<float>(points[i].z()));
260-
vboBuffer2->write(static_cast<float>(txt_coords[i].x()));
261-
vboBuffer2->write(static_cast<float>(txt_coords[i].y()));
265+
//add the actual points and colors
266+
267+
uniqueNodeID = id + "colorMapLegendTextFont" + ss.str();
268+
vboName = uniqueNodeID + "VBO";
269+
iboName = uniqueNodeID + "IBO";
270+
passName = uniqueNodeID + "Pass2";
271+
272+
// NOTE: Attributes will depend on the color scheme. We will want to
273+
// normalize the colors if the color scheme is COLOR_IN_SITU.
274+
275+
// Construct VBO.
276+
shader = "Shaders/ColorMapLegendText";
277+
attribs.clear();
278+
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aPos", 3 * sizeof(float)));
279+
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aTexCoord", 2 * sizeof(float)));
280+
uniforms.clear();
281+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uXTranslate", static_cast<float>(xTrans)));
282+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uYTranslate", static_cast<float>(yTrans)));
283+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uDisplaySide", static_cast<float>(displaySide)));
284+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uDisplayLength", static_cast<float>(displayLength)));
285+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uColor", glm::vec4(red, green, blue, 1.0f)));
286+
GeometryObject::SpireVBO geomVBO2 = GeometryObject::SpireVBO(vboName, attribs, vboBufferSPtr2,
287+
numVBOElements, Core::Geometry::BBox(), true);
288+
289+
geom->mVBOs.push_back(geomVBO2);
290+
291+
// Construct IBO.
292+
293+
GeometryObject::SpireIBO geomIBO2(iboName, GeometryObject::SpireIBO::TRIANGLES, sizeof(uint32_t), iboBufferSPtr2);
294+
geom->mIBOs.push_back(geomIBO2);
295+
renState.set(RenderState::USE_COLORMAP, false);
296+
renState.set(RenderState::USE_TRANSPARENCY, true);
297+
GeometryObject::SpireSubPass pass2(passName, vboName, iboName, shader,
298+
GeometryObject::COLOR_MAP, renState, GeometryObject::RENDER_VBO_IBO, geomVBO2, geomIBO2);
299+
300+
// Add all uniforms generated above to the pass.
301+
for (const auto& uniform : uniforms) { pass2.addUniform(uniform); }
302+
//******************************************************************************************
303+
// TODO we're not adding this geometry (font) until we debug for it to work on Windows.
304+
geom->mPasses.push_back(pass2);
305+
//******************************************************************************************
262306
}
263-
264-
//add the actual points and colors
265-
266-
uniqueNodeID = id + "colorMapLegendTextFont" + ss.str();
267-
vboName = uniqueNodeID + "VBO";
268-
iboName = uniqueNodeID + "IBO";
269-
passName = uniqueNodeID + "Pass2";
270-
271-
// NOTE: Attributes will depend on the color scheme. We will want to
272-
// normalize the colors if the color scheme is COLOR_IN_SITU.
273-
274-
// Construct VBO.
275-
shader = "Shaders/ColorMapLegendText";
276-
attribs.clear();
277-
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aPos", 3 * sizeof(float)));
278-
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aTexCoord", 2 * sizeof(float)));
279-
uniforms.clear();
280-
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uXTranslate",static_cast<float>(xTrans)));
281-
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uYTranslate",static_cast<float>(yTrans)));
282-
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uDisplaySide", static_cast<float>(displaySide)));
283-
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uDisplayLength", static_cast<float>(displayLength)));
284-
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uColor", glm::vec4(red,green,blue,1.0f)));
285-
GeometryObject::SpireVBO geomVBO2 = GeometryObject::SpireVBO(vboName, attribs, vboBufferSPtr2,
286-
numVBOElements, Core::Geometry::BBox(), true);
287-
288-
geom->mVBOs.push_back(geomVBO2);
289-
290-
// Construct IBO.
291-
292-
GeometryObject::SpireIBO geomIBO2(iboName, GeometryObject::SpireIBO::TRIANGLES, sizeof(uint32_t), iboBufferSPtr2);
293-
geom->mIBOs.push_back(geomIBO2);
294-
renState.set(RenderState::USE_COLORMAP, false);
295-
renState.set(RenderState::USE_TRANSPARENCY, true);
296-
GeometryObject::SpireSubPass pass2(passName, vboName, iboName, shader,
297-
GeometryObject::COLOR_MAP, renState, GeometryObject::RENDER_VBO_IBO, geomVBO2, geomIBO2);
298-
299-
// Add all uniforms generated above to the pass.
300-
for (const auto& uniform : uniforms) { pass2.addUniform(uniform); }
301-
/*******************************************************************************************
302-
// TODO we're not adding this geometry (font) until we debug for it to work on Windows.
303-
geom->mPasses.push_back(pass2);
304-
*******************************************************************************************/
305307
return geom;
306308
}
307309

0 commit comments

Comments
 (0)