Skip to content

Commit e146681

Browse files
committed
moved scale bar to viewscene
1 parent 5cc8ba9 commit e146681

File tree

9 files changed

+303
-194
lines changed

9 files changed

+303
-194
lines changed

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 15 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <Interface/Modules/Render/ES/SRCamera.h>
3636

3737
#include <Core/Application/Application.h>
38-
#include <Modules/Visualization/ShowColorMapModule.h>
38+
//#include <Modules/Visualization/ShowColorMapModule.h>
3939
#include <Graphics/Glyphs/GlyphGeom.h>
4040

4141
// CPM modules.
@@ -144,10 +144,6 @@ namespace SCIRun {
144144
mCore.addStaticComponent(iface);
145145
}
146146

147-
std::string filesystemRoot = Core::Application::Instance().executablePath().string();
148-
std::string sep;
149-
sep += boost::filesystem::path::preferred_separator;
150-
Modules::Visualization::TextBuilder::setFSStrings(filesystemRoot, sep);
151147
}
152148

153149
//------------------------------------------------------------------------------
@@ -247,11 +243,6 @@ namespace SCIRun {
247243
void SRInterface::inputMouseWheel(int32_t delta)
248244
{
249245
mCamera->mouseWheelEvent(delta, mZoomSpeed);
250-
if (scaleBar_.visible)
251-
{
252-
updateScaleBarLength();
253-
updateGeometryScaleBar();
254-
}
255246
}
256247

257248
//------------------------------------------------------------------------------
@@ -634,8 +625,20 @@ namespace SCIRun {
634625
updateClippingPlanes();
635626
}
636627

628+
const glm::mat4& SRInterface::getWorldToProjection() const
629+
{ return mCamera->getWorldToProjection(); }
630+
631+
const glm::mat4& SRInterface::getWorldToView() const
632+
{ return mCamera->getWorldToView(); }
633+
634+
const glm::mat4& SRInterface::getViewToWorld() const
635+
{ return mCamera->getViewToWorld(); }
636+
637+
const glm::mat4& SRInterface::getViewToProjection() const
638+
{ return mCamera->getViewToProjection(); }
639+
637640
//------------------------------------------------------------------------------
638-
void SRInterface::setScaleBar(const ScaleBar &scaleBarData)
641+
/*void SRInterface::setScaleBar(const ScaleBar &scaleBarData)
639642
{
640643
scaleBar_.visible = scaleBarData.visible;
641644
scaleBar_.fontSize = scaleBarData.fontSize;
@@ -650,7 +653,7 @@ namespace SCIRun {
650653
updateScaleBarLength();
651654
updateGeometryScaleBar();
652655
}
653-
}
656+
}*/
654657

655658
//------------------------------------------------------------------------------
656659
void SRInterface::inputMouseUp(const glm::ivec2& /*pos*/, MouseButton /*btn*/)
@@ -1399,143 +1402,6 @@ namespace SCIRun {
13991402
handleGeomObject(geom2, 0);*/
14001403
}
14011404

1402-
// update scale bar geometries
1403-
void SRInterface::updateGeometryScaleBar()
1404-
{
1405-
const int numTicks = scaleBar_.numTicks;
1406-
const double mult = scaleBar_.multiplier;
1407-
double length = scaleBar_.projLength;
1408-
const double height = scaleBar_.height;
1409-
glm::vec4 color(1.0);
1410-
glm::vec4 shift(1.9, 0.1, 0.0, 0.0);
1411-
1412-
std::vector<Vector> points;
1413-
std::vector<uint32_t> indices;
1414-
int32_t numVBOElements = 0;
1415-
uint32_t index = 0;
1416-
//base line
1417-
points.push_back(Vector(-length, 0.0, 0.0));
1418-
points.push_back(Vector(0.0, 0.0, 0.0));
1419-
numVBOElements += 2;
1420-
indices.push_back(index++);
1421-
indices.push_back(index++);
1422-
if (numTicks > 1)
1423-
{
1424-
for (int i = 0; i < numTicks; ++i)
1425-
{
1426-
double x = -length + i*length / (numTicks-1);
1427-
points.push_back(Vector(x, 0.0, 0.0));
1428-
points.push_back(Vector(x, height, 0.0));
1429-
numVBOElements += 2;
1430-
indices.push_back(index++);
1431-
indices.push_back(index++);
1432-
}
1433-
}
1434-
1435-
// IBO/VBOs and sizes
1436-
uint32_t iboSize = sizeof(uint32_t) * static_cast<uint32_t>(indices.size());
1437-
uint32_t vboSize = sizeof(float) * 3 * static_cast<uint32_t>(points.size());
1438-
1439-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr(
1440-
new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
1441-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr(
1442-
new CPM_VAR_BUFFER_NS::VarBuffer(iboSize));
1443-
1444-
CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer = iboBufferSPtr.get();
1445-
CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer = vboBufferSPtr.get();
1446-
1447-
for (auto a : indices) iboBuffer->write(a);
1448-
1449-
for (size_t i = 0; i < points.size(); i++) {
1450-
vboBuffer->write(static_cast<float>(points[i].x()));
1451-
vboBuffer->write(static_cast<float>(points[i].y()));
1452-
vboBuffer->write(static_cast<float>(points[i].z()));
1453-
}
1454-
1455-
std::stringstream ss;
1456-
ss << "scale_bar";
1457-
std::string uniqueNodeID = ss.str();
1458-
std::string vboName = uniqueNodeID + "VBO";
1459-
std::string iboName = uniqueNodeID + "IBO";
1460-
std::string passName = uniqueNodeID + "Pass";
1461-
1462-
// Construct VBO.
1463-
std::string shader = "Shaders/HudUniform";
1464-
std::vector<SpireVBO::AttributeData> attribs;
1465-
attribs.push_back(SpireVBO::AttributeData("aPos", 3 * sizeof(float)));
1466-
std::vector<SpireSubPass::Uniform> uniforms;
1467-
uniforms.push_back(SpireSubPass::Uniform("uTrans", shift));
1468-
uniforms.push_back(SpireSubPass::Uniform("uColor", color));
1469-
SpireVBO geomVBO = SpireVBO(vboName, attribs, vboBufferSPtr,
1470-
numVBOElements, BBox(), true);
1471-
1472-
// Construct IBO.
1473-
1474-
SpireIBO geomIBO(iboName, SpireIBO::LINES, sizeof(uint32_t), iboBufferSPtr);
1475-
1476-
RenderState renState;
1477-
renState.set(RenderState::IS_ON, true);
1478-
renState.set(RenderState::HAS_DATA, true);
1479-
renState.set(RenderState::USE_COLORMAP, false);
1480-
renState.set(RenderState::USE_TRANSPARENCY, false);
1481-
1482-
SpireText text;
1483-
1484-
SpireSubPass pass(passName, vboName, iboName, shader,
1485-
COLOR_MAP, renState, RENDER_VBO_IBO, geomVBO, geomIBO, text);
1486-
1487-
// Add all uniforms generated above to the pass.
1488-
for (const auto& uniform : uniforms) { pass.addUniform(uniform); }
1489-
1490-
GeometryHandle geom(new GeometryObjectSpire(uniqueNodeID));
1491-
1492-
geom->mIBOs.push_back(geomIBO);
1493-
geom->mVBOs.push_back(geomVBO);
1494-
geom->mPasses.push_back(pass);
1495-
1496-
//text
1497-
size_t text_size = size_t(scaleBar_.fontSize);
1498-
if (!textBuilder_.isInit())
1499-
textBuilder_.initFreeType("FreeSans.ttf", text_size);
1500-
else if (!textBuilder_.isValid())
1501-
textBuilder_.loadNewFace("FreeSans.ttf", text_size);
1502-
if (textBuilder_.isInit() && textBuilder_.isValid())
1503-
{
1504-
if (textBuilder_.getFaceSize() != text_size)
1505-
textBuilder_.setFaceSize(text_size);
1506-
textBuilder_.setColor(glm::vec4(1.0, 1.0, 1.0, 1.0));
1507-
std::stringstream ss;
1508-
std::string oneline;
1509-
ss << length << " " << scaleBar_.unit;
1510-
oneline = ss.str();
1511-
Vector shift(1.9, 0.1, 0.0);
1512-
Vector trans(10.0, 0.0, 0.0);
1513-
textBuilder_.printString(oneline, shift, trans, uniqueNodeID, geom);
1514-
}
1515-
1516-
handleGeomObject(geom, 0);
1517-
}
1518-
1519-
void SRInterface::updateScaleBarLength()
1520-
{
1521-
glm::vec4 p1(-scaleBar_.length / 2.0, 0.0, 0.0, 1.0);
1522-
glm::vec4 p2(scaleBar_.length / 2.0, 0.0, 0.0, 1.0);
1523-
glm::mat4 matIV = mCamera->getWorldToView();
1524-
matIV[0][0] = 1.0; matIV[0][1] = 0.0; matIV[0][2] = 0.0;
1525-
matIV[1][0] = 0.0; matIV[1][1] = 1.0; matIV[1][2] = 0.0;
1526-
matIV[2][0] = 0.0; matIV[2][1] = 0.0; matIV[2][2] = 1.0;
1527-
glm::mat4 matProj = mCamera->getViewToProjection();
1528-
p1 = matProj * matIV * p1;
1529-
p2 = matProj * matIV * p2;
1530-
glm::vec2 p(p1.x/p1.w-p2.x/p2.w, p1.y/p1.w-p2.y/p2.w);
1531-
glm::vec2 pp(p.x*mScreenWidth / 2.0,
1532-
p.y*mScreenHeight / 2.0);
1533-
scaleBar_.projLength = glm::length(pp);
1534-
//std::cout << "p1:\t" << p1.x << "\t" << p1.y << "\t" << p1.z << "\t" << p1.w << "\n";
1535-
//std::cout << "p2:\t" << p2.x << "\t" << p2.y << "\t" << p2.z << "\t" << p2.w << "\n";
1536-
//std::cout << "pp:\t" << pp.x << "\t" << pp.y << "\n";
1537-
}
1538-
15391405
//------------------------------------------------------------------------------
15401406
void SRInterface::renderCoordinateAxes()
15411407
{

src/Interface/Modules/Render/ES/SRInterface.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <es-render/comp/CommonUniforms.hpp>
4545

4646
#include <Graphics/Datatypes/GeometryImpl.h>
47-
#include <Modules/Visualization/TextBuilder.h>
4847
#include <Interface/Modules/Render/share.h>
4948

5049
namespace SCIRun {
@@ -167,16 +166,11 @@ namespace SCIRun {
167166
void setClippingPlaneZ(double value);
168167
void setClippingPlaneD(double value);
169168

170-
struct ScaleBar {
171-
bool visible;
172-
int fontSize;
173-
double length, height, multiplier, numTicks, lineWidth;
174-
std::string unit;
175-
double projLength;
176-
};
177-
178-
//scale bar
179-
void setScaleBar(const ScaleBar &scaleBarData);
169+
//camera matrices
170+
const glm::mat4& getWorldToProjection() const;
171+
const glm::mat4& getWorldToView() const;
172+
const glm::mat4& getViewToWorld() const;
173+
const glm::mat4& getViewToProjection() const;
180174

181175
private:
182176

@@ -305,10 +299,6 @@ namespace SCIRun {
305299
// update clipping plane geometries
306300
void updateGeometryClippingPlane(int index, glm::vec4 plane);
307301

308-
// update scale bar geometries
309-
void updateGeometryScaleBar();
310-
void updateScaleBarLength();
311-
312302
bool showOrientation_; ///< Whether the coordinate axes will render or not.
313303
bool autoRotate_; ///< Whether the scene will continue to rotate.
314304
bool selectWidget_; ///< Whether mouse click will select a widget.
@@ -336,23 +326,23 @@ namespace SCIRun {
336326

337327
ESCore mCore; ///< Entity system core.
338328

339-
Modules::Visualization::TextBuilder mTextBuilder; /// text builder
329+
//Modules::Visualization::TextBuilder mTextBuilder; /// text builder
340330
std::string mArrowVBOName; ///< VBO for one axis of the coordinate axes.
341331
std::string mArrowIBOName; ///< IBO for one axis of the coordinate axes.
342332
std::string mArrowObjectName; ///< Object name for profile arrow.
343333

344334
std::vector<ClippingPlane> clippingPlanes_;
345335
int clippingPlaneIndex_;
346336

347-
ScaleBar scaleBar_;
337+
//ScaleBar scaleBar_;
348338

349339
ren::ShaderVBOAttribs<5> mArrowAttribs; ///< Pre-applied shader / VBO attributes.
350340
ren::CommonUniforms mArrowUniforms; ///< Common uniforms used in the arrow shader.
351341
RenderState::TransparencySortType mRenderSortType; ///< Which strategy will be used to render transparency
352342
const int frameInitLimit_;
353343
std::unique_ptr<SRCamera> mCamera; ///< Primary camera.
354344

355-
Modules::Visualization::TextBuilder textBuilder_; ///
345+
//Modules::Visualization::TextBuilder textBuilder_; ///
356346
};
357347

358348
} // namespace Render

src/Interface/Modules/Render/ES/systems/RenderTransBasicSys.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,16 @@ class RenderBasicSysTrans :
244244
return;
245245
}
246246

247-
if (!srstate.front().state.get(RenderState::USE_TRANSPARENCY) &&
248-
!srstate.front().state.get(RenderState::USE_TRANSPARENT_EDGES) &&
249-
!srstate.front().state.get(RenderState::USE_TRANSPARENT_NODES) &&
250-
!srstate.front().state.get(RenderState::IS_TEXT))
247+
if (srstate.front().state.get(RenderState::IS_TEXT))
248+
{
249+
return;
250+
}
251+
252+
bool doRender = srstate.front().state.get(RenderState::USE_TRANSPARENCY) ||
253+
srstate.front().state.get(RenderState::USE_TRANSPARENT_EDGES) ||
254+
srstate.front().state.get(RenderState::USE_TRANSPARENT_NODES);
255+
256+
if (!doRender)
251257
{
252258
return;
253259
}

src/Interface/Modules/Render/GLWidget.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event)
137137
void GLWidget::wheelEvent(QWheelEvent * event)
138138
{
139139
mGraphics->inputMouseWheel(event->delta());
140+
event->ignore();
140141
}
141142

142143
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)