Skip to content

Commit 1d9dab9

Browse files
committed
Work on integration new two-dimensional renderer
1 parent 9ae2f71 commit 1d9dab9

4 files changed

Lines changed: 38 additions & 167 deletions

File tree

src/NavigationAction.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void NavigationAction::initialize(ScatterplotWidget* scatterplotWidget)
4949
_scatterplotWidget = scatterplotWidget;
5050

5151
_scatterplotWidget->addAction(&_zoomDataExtentsAction);
52-
53-
connect(&_zoomDataExtentsAction, &TriggerAction::triggered, _scatterplotWidget, &ScatterplotWidget::resetView);
5452
}
5553

5654
void NavigationAction::connectToPublicAction(WidgetAction* publicAction, bool recursive)

src/ScatterplotPlugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void ScatterplotPlugin::selectPoints()
360360
auto& pixelSelectionTool = _scatterPlotWidget->getPixelSelectionTool();
361361

362362
// Only proceed with a valid points position dataset and when the pixel selection tool is active
363-
if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !pixelSelectionTool.isEnabled())
363+
if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->_pointRenderer.getNavigator().isNavigating() || !pixelSelectionTool.isEnabled())
364364
return;
365365

366366
auto selectionAreaImage = pixelSelectionTool.getAreaPixmap().toImage();
@@ -450,7 +450,7 @@ void ScatterplotPlugin::samplePoints()
450450
{
451451
auto& samplerPixelSelectionTool = _scatterPlotWidget->getSamplerPixelSelectionTool();
452452

453-
if (!_positionDataset.isValid() || !samplerPixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !samplerPixelSelectionTool.isEnabled())
453+
if (!_positionDataset.isValid() || !samplerPixelSelectionTool.isActive() || _scatterPlotWidget->_pointRenderer.getNavigator().isNavigating() || !samplerPixelSelectionTool.isEnabled())
454454
return;
455455

456456
auto selectionAreaImage = samplerPixelSelectionTool.getAreaPixmap().toImage();

src/ScatterplotWidget.cpp

Lines changed: 32 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ namespace
4949
}
5050

5151
ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
52-
QOpenGLWidget(),
53-
_pointRenderer(),
5452
_densityRenderer(DensityRenderer::RenderMode::DENSITY),
5553
_isInitialized(false),
5654
_renderMode(SCATTERPLOT),
@@ -59,21 +57,17 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
5957
_widgetSizeInfo(),
6058
_dataRectangleAction(this, "Data rectangle"),
6159
_navigationAction(this, "Navigation"),
62-
_colorMapImage(),
6360
_pixelSelectionTool(this),
6461
_samplerPixelSelectionTool(this),
6562
_pixelRatio(1.0),
66-
_mousePositions(),
67-
_isNavigating(false),
6863
_weightDensity(false),
6964
_parentPlugin(parentPlugin)
7065
{
7166
setContextMenuPolicy(Qt::CustomContextMenu);
7267
setAcceptDrops(true);
7368
setMouseTracking(true);
74-
setFocusPolicy(Qt::ClickFocus);
69+
//setFocusPolicy(Qt::ClickFocus);
7570
grabGesture(Qt::PinchGesture);
76-
//setAttribute(Qt::WA_TranslucentBackground);
7771
installEventFilter(this);
7872

7973
_navigationAction.initialize(this);
@@ -146,159 +140,58 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
146140

147141
update();
148142
});
149-
}
150143

151-
bool ScatterplotWidget::event(QEvent* event)
152-
{
153-
if (!event)
154-
return QOpenGLWidget::event(event);
144+
connect(&_navigationAction.getZoomDataExtentsAction(), &TriggerAction::triggered, this, [this]() -> void {
145+
_pointRenderer.getNavigator().resetView();
146+
});
155147

156-
auto setIsNavigating = [this](bool isNavigating) -> void {
157-
_isNavigating = isNavigating;
148+
connect(&_pointRenderer.getNavigator(), &Navigator2D::isNavigatingChanged, this, [this](bool isNavigating) -> void {
158149
_pixelSelectionTool.setEnabled(!isNavigating);
159-
if (isNavigating) {
150+
151+
if (isNavigating) {
160152
_samplerPixelSelectionTool.setEnabled(false);
161153
}
162-
else if (_parentPlugin) { // reset to UI-setting
154+
else if (_parentPlugin) {
163155
_samplerPixelSelectionTool.setEnabled(_parentPlugin->getSamplerAction().getEnabledAction().isChecked());
164156
}
157+
});
165158

166-
};
167-
168-
// Set navigation flag on Alt press/release
169-
if (event->type() == QEvent::KeyRelease) {
170-
if (const auto* keyEvent = static_cast<QKeyEvent*>(event)) {
171-
if (keyEvent->key() == Qt::Key_Alt) {
172-
setIsNavigating(false);
173-
}
174-
}
175-
176-
}
177-
else if (event->type() == QEvent::KeyPress) {
178-
if (const auto* keyEvent = static_cast<QKeyEvent*>(event)) {
179-
if (keyEvent->key() == Qt::Key_Alt) {
180-
setIsNavigating(true);
181-
}
182-
}
159+
connect(&_pointRenderer, &Renderer2D::zoomRectangleChanged, this, [this]() -> void { update(); });
183160

184-
}
161+
//auto setIsNavigating = [this](bool isNavigating) -> void {
162+
// _isNavigating = isNavigating;
163+
// _pixelSelectionTool.setEnabled(!isNavigating);
164+
// if (isNavigating) {
165+
// _samplerPixelSelectionTool.setEnabled(false);
166+
// }
167+
// else if (_parentPlugin) { // reset to UI-setting
168+
// _samplerPixelSelectionTool.setEnabled(_parentPlugin->getSamplerAction().getEnabledAction().isChecked());
169+
// }
185170

186-
// Interactions when Alt is pressed
187-
if (isInitialized() && QGuiApplication::keyboardModifiers() == Qt::AltModifier) {
171+
// };
188172

189-
switch (event->type())
190-
{
191-
case QEvent::Wheel:
192-
{
193-
// Scroll to zoom
194-
if (auto* wheelEvent = static_cast<QWheelEvent*>(event))
195-
zoomAround(wheelEvent->position().toPoint(), wheelEvent->angleDelta().x() / 1200.f);
196-
197-
break;
198-
}
199-
200-
case QEvent::MouseButtonPress:
201-
{
202-
if (const auto* mouseEvent = static_cast<QMouseEvent*>(event))
203-
{
204-
if(mouseEvent->button() == Qt::MiddleButton)
205-
resetView();
206-
207-
// Navigation
208-
if (mouseEvent->buttons() == Qt::LeftButton)
209-
{
210-
setIsNavigating(true);
211-
setCursor(Qt::ClosedHandCursor);
212-
_mousePositions << mouseEvent->pos();
213-
update();
214-
}
215-
}
216-
217-
break;
218-
}
219-
220-
case QEvent::MouseButtonRelease:
221-
{
222-
setIsNavigating(false);
223-
setCursor(Qt::ArrowCursor);
224-
_mousePositions.clear();
225-
update();
226-
227-
break;
228-
}
229-
230-
case QEvent::MouseMove:
231-
{
232-
if (const auto* mouseEvent = static_cast<QMouseEvent*>(event))
233-
{
234-
_mousePositions << mouseEvent->pos();
173+
_pointRenderer.getNavigator().initialize(this);
174+
}
235175

236-
if (mouseEvent->buttons() == Qt::LeftButton && _mousePositions.size() >= 2)
237-
{
238-
const auto& previousMousePosition = _mousePositions[_mousePositions.size() - 2];
239-
const auto& currentMousePosition = _mousePositions[_mousePositions.size() - 1];
240-
const auto panVector = currentMousePosition - previousMousePosition;
176+
bool ScatterplotWidget::event(QEvent* event)
177+
{
178+
if (!event)
179+
return QOpenGLWidget::event(event);
241180

242-
panBy(panVector);
243-
}
244-
}
181+
// Need this to receive key release events in the two-dimensional renderer
182+
if (event->type() == QEvent::ShortcutOverride) {
183+
const auto keyEvent = dynamic_cast<QKeyEvent*>(event);
245184

246-
break;
247-
}
185+
if (keyEvent->key() == Qt::Key_Alt) {
186+
event->accept();
248187

188+
return QOpenGLWidget::event(event);
249189
}
250-
251190
}
252191

253192
return QOpenGLWidget::event(event);
254193
}
255194

256-
void ScatterplotWidget::resetView()
257-
{
258-
_navigationAction.getZoomRectangleAction().setBounds(_dataRectangleAction.getBounds());
259-
}
260-
261-
void ScatterplotWidget::panBy(const QPointF& to)
262-
{
263-
auto& zoomRectangleAction = _navigationAction.getZoomRectangleAction();
264-
265-
const auto moveBy = QPointF(to.x() / _widgetSizeInfo.width * zoomRectangleAction.getWidth() * _widgetSizeInfo.ratioWidth * -1.f,
266-
to.y() / _widgetSizeInfo.height * zoomRectangleAction.getHeight() * _widgetSizeInfo.ratioHeight);
267-
268-
zoomRectangleAction.translateBy({ moveBy.x(), moveBy.y() });
269-
270-
update();
271-
}
272-
273-
void ScatterplotWidget::zoomAround(const QPointF& at, float factor)
274-
{
275-
auto& zoomRectangleAction = _navigationAction.getZoomRectangleAction();
276-
277-
// the widget might have a different aspect ratio than the square opengl viewport
278-
const auto offsetBounds = QPointF(zoomRectangleAction.getWidth() * (0.5f * (1 - _widgetSizeInfo.ratioWidth)),
279-
zoomRectangleAction.getHeight() * (0.5f * (1 - _widgetSizeInfo.ratioHeight)) * -1.f);
280-
281-
const auto originBounds = QPointF(zoomRectangleAction.getLeft(), zoomRectangleAction.getTop());
282-
283-
// translate mouse point in widget to mouse point in bounds coordinates
284-
const auto atTransformed = QPointF(at.x() / _widgetSizeInfo.width * zoomRectangleAction.getWidth() * _widgetSizeInfo.ratioWidth,
285-
at.y() / _widgetSizeInfo.height * zoomRectangleAction.getHeight() * _widgetSizeInfo.ratioHeight * -1.f);
286-
287-
const auto atInBounds = originBounds + offsetBounds + atTransformed;
288-
289-
// ensure mouse position is the same after zooming
290-
const auto currentBoundCenter = zoomRectangleAction.getCenter();
291-
292-
float moveMouseX = (atInBounds.x() - currentBoundCenter.first) * factor;
293-
float moveMouseY = (atInBounds.y() - currentBoundCenter.second) * factor;
294-
295-
// zoom and move view
296-
zoomRectangleAction.translateBy({ moveMouseX, moveMouseY });
297-
zoomRectangleAction.expandBy(-1.f * factor);
298-
299-
update();
300-
}
301-
302195
bool ScatterplotWidget::isInitialized() const
303196
{
304197
return _isInitialized;

src/ScatterplotWidget.h

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,8 @@ class ScatterplotWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_C
123123
return _dataRectangleAction.getBounds();
124124
}
125125

126-
/*
127-
mv::Bounds getZoomBounds() const {
128-
return _zoomBounds;
129-
}
130-
131-
void setZoomBounds(const mv::Bounds& newBounds) {
132-
_zoomBounds = newBounds;
133-
_pointRenderer.setBounds(_zoomBounds);
134-
emit zoomBoundsChanged(_zoomBounds);
135-
update();
136-
}
137-
*/
138-
139126
NavigationAction& getNavigationAction() { return _navigationAction; }
140127

141-
bool isNavigating() const {
142-
return _isNavigating;
143-
}
144-
145128
mv::Vector3f getColorMapRange() const;
146129
void setColorMapRange(const float& min, const float& max);
147130

@@ -258,10 +241,6 @@ class ScatterplotWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_C
258241

259242
bool event(QEvent* event) override;
260243

261-
void zoomAround(const QPointF& at, float factor);
262-
void panBy(const QPointF& to);
263-
void resetView();
264-
265244
public: // Const access to renderers
266245

267246
const PointRenderer& getPointRenderer() const {
@@ -308,9 +287,11 @@ public slots:
308287
private slots:
309288
void updatePixelRatio();
310289

311-
private:
290+
protected:
312291
PointRenderer _pointRenderer; /** For rendering point data as points */
313292
DensityRenderer _densityRenderer; /** For rendering point data as a density plot */
293+
294+
private:
314295
bool _isInitialized; /** Boolean determining whether the widget it properly initialized or not */
315296
RenderMode _renderMode; /** Current render mode */
316297
QColor _backgroundColor; /** Background color */
@@ -322,11 +303,10 @@ private slots:
322303
PixelSelectionTool _pixelSelectionTool; /** 2D pixel selection tool */
323304
PixelSelectionTool _samplerPixelSelectionTool; /** 2D pixel selection tool */
324305
float _pixelRatio; /** Current pixel ratio */
325-
QVector<QPoint> _mousePositions; /** Recorded mouse positions */
326-
bool _isNavigating; /** Boolean determining whether view navigation is currently taking place or not */
327306
bool _weightDensity; /** Use point scalar sizes to weight density */
328307

329308
mv::plugin::ViewPlugin* _parentPlugin = nullptr;
330309

310+
friend class ScatterplotPlugin;
331311
friend class NavigationAction;
332312
};

0 commit comments

Comments
 (0)