Skip to content

Commit 2917652

Browse files
authored
Merge pull request #1622 from SCIInstitute/showstring-positioning
Showstring positioning
2 parents 2d4bcf2 + 0e31a0a commit 2917652

File tree

9 files changed

+65
-45
lines changed

9 files changed

+65
-45
lines changed

src/Core/Datatypes/Color.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace Datatypes {
8282
{
8383
Geometry::Transform transform;
8484
std::string selectionName;
85+
std::tuple<int,int> windowSize;
8586
};
8687

8788
}}}

src/Dataflow/Network/Module.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@ std::vector<DatatypeHandleOption> Module::get_dynamic_input_handles(const PortId
576576
}
577577

578578
{
579-
LOG_DEBUG(id_ << " :: inputsChanged is " << inputsChanged_ << ", querying port for value.");
579+
LOG_DEBUG(get_id() << " :: inputsChanged is " << impl_->inputsChanged_ << ", querying port for value.");
580580
// NOTE: don't use short-circuited boolean OR here, we need to call hasChanged each time since it updates the port's cache flag.
581581
bool startingVal = impl_->inputsChanged_;
582582
impl_->inputsChanged_ = std::accumulate(portsWithName.begin(), portsWithName.end(), startingVal, [](bool acc, InputPortHandle input) { return input->hasChanged() || acc; });
583-
LOG_DEBUG(get_id() << ":: inputsChanged is now " << inputsChanged_);
583+
LOG_DEBUG(get_id() << ":: inputsChanged is now " << impl_->inputsChanged_);
584584
}
585585

586586
std::vector<DatatypeHandleOption> options;

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DEALINGS IN THE SOFTWARE.
3939
#include <Graphics/Glyphs/GlyphGeom.h>
4040
#include <Graphics/Datatypes/GeometryImpl.h>
4141
#include <Core/GeometryPrimitives/Transform.h>
42+
#include <boost/timer.hpp>
4243

4344
using namespace SCIRun::Gui;
4445
using namespace SCIRun::Dataflow::Networks;
@@ -144,6 +145,9 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
144145
std::string sep;
145146
sep += boost::filesystem::path::preferred_separator;
146147
Modules::Visualization::TextBuilder::setFSStrings(filesystemRoot, sep);
148+
149+
resizeTimer_.setSingleShot(true);
150+
connect(&resizeTimer_, SIGNAL(timeout()), this, SLOT(resizingDone()));
147151
}
148152

149153
void ViewSceneDialog::pullSpecial()
@@ -211,6 +215,19 @@ void ViewSceneDialog::mousePressEvent(QMouseEvent* event)
211215
}
212216
}
213217

218+
void ViewSceneDialog::resizeEvent(QResizeEvent *event)
219+
{
220+
resizeTimer_.start(400);
221+
ModuleDialogGeneric::resizeEvent(event);
222+
}
223+
224+
void ViewSceneDialog::resizingDone()
225+
{
226+
ViewSceneFeedback vsf;
227+
vsf.windowSize = std::make_tuple(size().width(), size().height());
228+
state_->setTransientValue(Parameters::GeometryFeedbackInfo, vsf);
229+
}
230+
214231
std::string ViewSceneDialog::restoreObjColor()
215232
{
216233
LOG_DEBUG("ViewSceneDialog::asyncExecute before locking");
@@ -1031,7 +1048,7 @@ GeometryHandle ViewSceneDialog::buildGeometryScaleBar()
10311048
oneline = ss.str();
10321049
double text_len = 0.0;
10331050
if (textBuilder_.isReady())
1034-
text_len = textBuilder_.getStringLen(oneline);
1051+
text_len = std::get<0>(textBuilder_.getStringDims(oneline));
10351052
text_len += 5;//add a 5-pixel gap
10361053

10371054
std::vector<Vector> points;
@@ -1670,8 +1687,8 @@ namespace //TODO: move to appropriate location
16701687

16711688
void ViewSceneDialog::sendGeometryFeedbackToState(int x, int y, const std::string& selName)
16721689
{
1673-
std::shared_ptr<SRInterface> spire = mSpire.lock();
1674-
glm::mat4 trans = spire->getWidgetTransform().transform;
1690+
auto spire = mSpire.lock();
1691+
auto trans = spire->getWidgetTransform().transform;
16751692

16761693
ViewSceneFeedback vsf;
16771694
vsf.transform = toSciTransform(trans);

src/Interface/Modules/Render/ViewScene.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace SCIRun {
7070
void newGeometryValueForwarder();
7171
void mousePressSignalForTestingGeometryObjectFeedback(int x, int y, const std::string& selName);
7272

73-
protected Q_SLOTS:
73+
protected Q_SLOTS:
7474
void menuMouseControlChanged(int index);
7575
void autoViewClicked();
7676
void newGeometryValue();
@@ -139,6 +139,7 @@ namespace SCIRun {
139139
void toggleLight1(bool value);
140140
void toggleLight2(bool value);
141141
void toggleLight3(bool value);
142+
void resizingDone();
142143

143144
protected:
144145
void mousePressEvent(QMouseEvent* event) override;
@@ -151,6 +152,7 @@ namespace SCIRun {
151152
void showEvent(QShowEvent* evt) override;
152153
void hideEvent(QHideEvent* evt) override;
153154
void contextMenuEvent(QContextMenuEvent* evt) override {}
155+
void resizeEvent(QResizeEvent *event) override;
154156

155157
void pullSpecial() override;
156158

@@ -231,6 +233,7 @@ namespace SCIRun {
231233
class Screenshot* screenshotTaker_;
232234
bool saveScreenshotOnNewGeometry_;
233235
bool pulledSavedVisibility_ {false};
236+
QTimer resizeTimer_;
234237

235238
//geometries
236239
Modules::Visualization::TextBuilder textBuilder_;

src/Modules/Visualization/ShowColorMapModule.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ GeometryBaseHandle ShowColorMap::buildGeometryObject(ColorMapHandle cm, ModuleSt
114114
uint32_t vboSize = sizeof(float) * 7 * static_cast<uint32_t>(points.size());
115115

116116
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr(
117-
new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
118-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr(
119117
new CPM_VAR_BUFFER_NS::VarBuffer(iboSize));
118+
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr(
119+
new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
120120

121121
CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer = iboBufferSPtr.get();
122122
CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer = vboBufferSPtr.get();
@@ -205,7 +205,7 @@ GeometryBaseHandle ShowColorMap::buildGeometryObject(ColorMapHandle cm, ModuleSt
205205
double dash_size = 18.;
206206
double pipe_size = 18.;
207207
size_t text_size = static_cast<size_t>(textSize);
208-
208+
209209
if (!textBuilder_.initialize(text_size))
210210
return geom;
211211

src/Modules/Visualization/ShowString.cc

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,30 @@ void ShowString::setStateDefaults()
7676
state->setValue(Parameters::FixedVertical, std::string("Top"));
7777
state->setValue(Parameters::CoordinateHorizontal, 0.5);
7878
state->setValue(Parameters::CoordinateVertical, 0.5);
79+
80+
getOutputPort(RenderedString)->connectConnectionFeedbackListener([this](const ModuleFeedback& var) { processWindowResizeFeedback(var); });
81+
}
82+
83+
void ShowString::processWindowResizeFeedback(const ModuleFeedback& var)
84+
{
85+
auto vsf = static_cast<const ViewSceneFeedback&>(var);
86+
if (lastWindowSize_ != vsf.windowSize)
87+
{
88+
lastWindowSize_ = vsf.windowSize;
89+
needReexecute_ = true;
90+
enqueueExecuteAgain(false);
91+
}
7992
}
8093

8194
void ShowString::execute()
8295
{
8396
auto str = getRequiredInput(String);
8497

85-
if (needToExecute())
98+
if (needToExecute() || needReexecute_)
8699
{
87100
auto geom = buildGeometryObject(str->value());
88101
sendOutput(RenderedString, geom);
102+
needReexecute_ = false;
89103
}
90104
}
91105

@@ -112,6 +126,8 @@ std::tuple<double, double> ShowString::getTextPosition()
112126
else // "Bottom"
113127
y = 0.3;
114128

129+
state->setValue(Parameters::CoordinateHorizontal, x / 2.0);
130+
state->setValue(Parameters::CoordinateVertical, y / 2.0);
115131
return std::make_tuple(x, y);
116132
}
117133
else if ("Coordinates" == positionChoice)
@@ -128,33 +144,8 @@ std::tuple<double, double> ShowString::getTextPosition()
128144
// TODO: clean up duplication here and in ShowColorMap
129145
GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
130146
{
131-
std::vector<Vector> points;
132-
std::vector<ColorRGB> colors;
133-
std::vector<uint32_t> indices;
134-
auto numVBOElements = 0;
135-
136-
// IBO/VBOs and sizes
137-
uint32_t iboSize = sizeof(uint32_t) * static_cast<uint32_t>(indices.size());
138-
uint32_t vboSize = sizeof(float) * 7 * static_cast<uint32_t>(points.size());
139-
140-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr(new CPM_VAR_BUFFER_NS::VarBuffer(vboSize));
141-
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr(new CPM_VAR_BUFFER_NS::VarBuffer(iboSize));
142-
143-
CPM_VAR_BUFFER_NS::VarBuffer* iboBuffer = iboBufferSPtr.get();
144-
CPM_VAR_BUFFER_NS::VarBuffer* vboBuffer = vboBufferSPtr.get();
145-
146-
for (auto a : indices) iboBuffer->write(a);
147-
148-
for (size_t i = 0; i < points.size(); i++)
149-
{
150-
vboBuffer->write(static_cast<float>(points[i].x()));
151-
vboBuffer->write(static_cast<float>(points[i].y()));
152-
vboBuffer->write(static_cast<float>(points[i].z()));
153-
vboBuffer->write(static_cast<float>(colors[i].r()));
154-
vboBuffer->write(static_cast<float>(colors[i].g()));
155-
vboBuffer->write(static_cast<float>(colors[i].b()));
156-
vboBuffer->write(static_cast<float>(1.f));
157-
}
147+
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> iboBufferSPtr(new CPM_VAR_BUFFER_NS::VarBuffer(0));
148+
std::shared_ptr<CPM_VAR_BUFFER_NS::VarBuffer> vboBufferSPtr(new CPM_VAR_BUFFER_NS::VarBuffer(0));
158149

159150
auto uniqueNodeID = get_id().id_ + "_showString_" + text;
160151
auto vboName = uniqueNodeID + "VBO";
@@ -168,14 +159,13 @@ GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
168159
attribs.push_back(SpireVBO::AttributeData("aColor", 4 * sizeof(float)));
169160
std::vector<SpireSubPass::Uniform> uniforms;
170161

171-
auto position = getTextPosition();
172-
auto xTrans = std::get<0>(position);
173-
auto yTrans = std::get<1>(position);
162+
double xTrans, yTrans;
163+
std::tie(xTrans, yTrans) = getTextPosition();
174164

175165
uniforms.push_back(SpireSubPass::Uniform("uXTranslate", xTrans));
176166
uniforms.push_back(SpireSubPass::Uniform("uYTranslate", yTrans));
177167

178-
SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, numVBOElements, BBox(), true);
168+
SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, 0, BBox(), true);
179169
SpireIBO geomIBO(iboName, SpireIBO::PRIMITIVE::TRIANGLES, sizeof(uint32_t), iboBufferSPtr);
180170

181171
RenderState renState;
@@ -220,6 +210,12 @@ GeometryBaseHandle ShowString::buildGeometryObject(const std::string& text)
220210
textBuilder_->setColor(r, g, b, a);
221211
}
222212

213+
auto dims = textBuilder_->getStringDims(text);
214+
auto length = std::get<0>(dims) + 20;
215+
auto width = std::get<1>(dims) + 10;
216+
xTrans *= 1 - length / std::get<0>(lastWindowSize_);
217+
yTrans *= 1 - width / std::get<1>(lastWindowSize_);
218+
223219
Vector trans(xTrans, yTrans, 0.0);
224220
textBuilder_->printString(text, trans, Vector(), text, *geom);
225221

src/Modules/Visualization/ShowString.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ namespace Visualization {
7272
boost::shared_ptr<class TextBuilder> textBuilder_;
7373
Core::Datatypes::GeometryBaseHandle buildGeometryObject(const std::string& text);
7474
std::tuple<double, double> getTextPosition();
75+
void processWindowResizeFeedback(const Core::Datatypes::ModuleFeedback& var);
76+
std::tuple<int,int> lastWindowSize_ { 450, 1000 };
77+
bool needReexecute_ {true};
7578
};
7679
}}}
7780

src/Modules/Visualization/TextBuilder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ void TextBuilder::printString(const std::string& oneline,
260260
}
261261
}
262262

263-
double TextBuilder::getStringLen(const std::string& oneline) const
263+
std::tuple<double, double> TextBuilder::getStringDims(const std::string& oneline) const
264264
{
265265
if (!ftValid_)
266-
return 0.0;
266+
return {};
267267

268268
auto len = 0.0;
269269
auto rows = 0;
@@ -275,7 +275,7 @@ double TextBuilder::getStringLen(const std::string& oneline) const
275275
len += g->bitmap.width;
276276
rows = g->bitmap.rows;
277277
}
278-
return len;
278+
return std::make_tuple(len, rows);
279279
}
280280

281281
bool TextBuilder::initialize(size_t textSize)

src/Modules/Visualization/TextBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace SCIRun {
6767

6868
//get string length based on current settings
6969
//return value in pixels
70-
double getStringLen(const std::string& oneline) const;
70+
std::tuple<double,double> getStringDims(const std::string& oneline) const;
7171

7272
private:
7373
std::string getUniqueFontString(char p, double x, double y, double z, double w, double h) const;

0 commit comments

Comments
 (0)