Skip to content

Commit d7c66ca

Browse files
committed
Adhere to latest core renderer upgrade
1 parent 18aa5fa commit d7c66ca

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed

src/ScatterplotPlugin.cpp

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,24 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
5555

5656
shortcuts.add({ QKeySequence(Qt::Key_R), "Selection", "Rectangle (default)" });
5757
shortcuts.add({ QKeySequence(Qt::Key_L), "Selection", "Lasso" });
58+
shortcuts.add({ QKeySequence(Qt::Key_P), "Selection", "Polygon" });
5859
shortcuts.add({ QKeySequence(Qt::Key_B), "Selection", "Circular brush (mouse wheel adjusts the radius)" });
5960
shortcuts.add({ QKeySequence(Qt::SHIFT), "Selection", "Add to selection" });
6061
shortcuts.add({ QKeySequence(Qt::CTRL), "Selection", "Remove from selection" });
62+
shortcuts.add({ QKeySequence(Qt::Key_A), "Selection", "Select all" });
63+
shortcuts.add({ QKeySequence(Qt::Key_E), "Selection", "Clear selection" });
64+
shortcuts.add({ QKeySequence(Qt::Key_I), "Selection", "Invert selection" });
6165

6266
shortcuts.add({ QKeySequence(Qt::Key_S), "Render", "Scatter mode (default)" });
6367
shortcuts.add({ QKeySequence(Qt::Key_D), "Render", "Density mode" });
6468
shortcuts.add({ QKeySequence(Qt::Key_C), "Render", "Contour mode" });
6569

70+
shortcuts.add({ QKeySequence(Qt::Key_Plus), "Navigation", "Zoom in by 10%" });
71+
shortcuts.add({ QKeySequence(Qt::Key_Minus), "Navigation", "Zoom out by 10%" });
6672
shortcuts.add({ QKeySequence(Qt::ALT), "Navigation", "Pan (LMB down)" });
6773
shortcuts.add({ QKeySequence(Qt::ALT), "Navigation", "Zoom (mouse wheel)" });
6874
shortcuts.add({ QKeySequence(Qt::Key_O), "Navigation", "Original view" });
75+
shortcuts.add({ QKeySequence(Qt::Key_B), "Navigation", "Zoom to selection" });
6976

7077
_dropWidget = new DropWidget(_scatterPlotWidget);
7178

@@ -257,8 +264,11 @@ void ScatterplotPlugin::init()
257264

258265
renderersNavigationGroupAction->setShowLabels(false);
259266

260-
renderersNavigationGroupAction->addAction(const_cast<NavigationAction*>(&_scatterPlotWidget->getPointRenderer().getNavigator().getNavigationAction()));
261-
renderersNavigationGroupAction->addAction(const_cast<NavigationAction*>(&_scatterPlotWidget->getDensityRenderer().getNavigator().getNavigationAction()));
267+
renderersNavigationGroupAction->addAction(const_cast<NavigationAction*>(&_scatterPlotWidget->getPointRendererNavigator().getNavigationAction()));
268+
renderersNavigationGroupAction->addAction(const_cast<NavigationAction*>(&_scatterPlotWidget->getDensityRendererNavigator().getNavigationAction()));
269+
270+
_scatterPlotWidget->getPointRendererNavigator().getNavigationAction().setParent(&_settingsAction);
271+
_scatterPlotWidget->getDensityRendererNavigator().getNavigationAction().setParent(&_settingsAction);
262272

263273
navigationLayout->addWidget(renderersNavigationGroupAction->createWidget(&getWidget()));
264274
}
@@ -295,6 +305,11 @@ void ScatterplotPlugin::init()
295305

296306
getLearningCenterAction().getViewPluginOverlayWidget()->setTargetWidget(_scatterPlotWidget);
297307

308+
connect(&getScatterplotWidget().getPointRendererNavigator().getNavigationAction().getZoomSelectionAction(), &TriggerAction::triggered, this, [this]() -> void {
309+
if (_selectionBoundaries.isValid())
310+
_scatterPlotWidget->getPointRendererNavigator().setZoomRectangleWorld(_selectionBoundaries);
311+
});
312+
298313
#ifdef VIEW_SAMPLING_HTML
299314
getSamplerAction().setHtmlViewGeneratorFunction([this](const ViewPluginSamplerAction::SampleContext& toolTipContext) -> QString {
300315
QStringList localPointIndices, globalPointIndices;
@@ -400,27 +415,43 @@ void ScatterplotPlugin::selectPoints()
400415
const auto zoomRectangleWorld = navigator.getZoomRectangleWorld();
401416
const auto screenRectangle = QRect(QPoint(), pointRenderer.getRenderSize());
402417

418+
float boundaries[4]{
419+
std::numeric_limits<float>::max(),
420+
std::numeric_limits<float>::lowest(),
421+
std::numeric_limits<float>::max(),
422+
std::numeric_limits<float>::lowest()
423+
};
424+
403425
// Go over all points in the dataset to see if they are selected
404426
for (std::uint32_t localPointIndex = 0; localPointIndex < _positions.size(); localPointIndex++) {
405-
406-
// Compute the offset of the point in the world space
407-
const auto pointOffsetWorld = QPointF(_positions[localPointIndex].x - zoomRectangleWorld.left(), _positions[localPointIndex].y - zoomRectangleWorld.top());
427+
const auto& point = _positions[localPointIndex];
408428

409-
// Normalize it
410-
const auto pointOffsetWorldNormalized = QPointF(pointOffsetWorld.x() / zoomRectangleWorld.width(), pointOffsetWorld.y() / zoomRectangleWorld.height());
429+
// Compute the offset of the point in the world space
430+
const auto pointOffsetWorld = QPointF(point.x - zoomRectangleWorld.left(), point.y - zoomRectangleWorld.top());
411431

412-
// Convert it to screen space
413-
const auto pointOffsetScreen = QPoint(pointOffsetWorldNormalized.x() * screenRectangle.width(), screenRectangle.height() - pointOffsetWorldNormalized.y() * screenRectangle.height());
432+
// Normalize it
433+
const auto pointOffsetWorldNormalized = QPointF(pointOffsetWorld.x() / zoomRectangleWorld.width(), pointOffsetWorld.y() / zoomRectangleWorld.height());
414434

415-
// Continue to next point if the point is outside the screen
416-
if (!screenRectangle.contains(pointOffsetScreen))
417-
continue;
435+
// Convert it to screen space
436+
const auto pointOffsetScreen = QPoint(pointOffsetWorldNormalized.x() * screenRectangle.width(), screenRectangle.height() - pointOffsetWorldNormalized.y() * screenRectangle.height());
418437

419-
// If the corresponding pixel is not transparent, add the point to the selection
420-
if (selectionAreaImage.pixelColor(pointOffsetScreen).alpha() > 0)
421-
targetSelectionIndices.push_back(localGlobalIndices[localPointIndex]);
438+
// Continue to next point if the point is outside the screen
439+
if (!screenRectangle.contains(pointOffsetScreen))
440+
continue;
441+
442+
// If the corresponding pixel is not transparent, add the point to the selection
443+
if (selectionAreaImage.pixelColor(pointOffsetScreen).alpha() > 0) {
444+
targetSelectionIndices.push_back(localGlobalIndices[localPointIndex]);
445+
446+
boundaries[0] = std::min(boundaries[0], point.x);
447+
boundaries[1] = std::max(boundaries[1], point.x);
448+
boundaries[2] = std::min(boundaries[2], point.y);
449+
boundaries[3] = std::max(boundaries[3], point.y);
450+
}
422451
}
423452

453+
_selectionBoundaries = QRectF(boundaries[0], boundaries[2], boundaries[1] - boundaries[0], boundaries[3] - boundaries[2]);
454+
424455
switch (const auto selectionModifier = pixelSelectionTool.isAborted() ? PixelSelectionModifierType::Subtract : pixelSelectionTool.getModifier())
425456
{
426457
case PixelSelectionModifierType::Replace:
@@ -467,7 +498,9 @@ void ScatterplotPlugin::selectPoints()
467498
}
468499
}
469500

470-
_scatterPlotWidget->getPointRendererNavigator().getNavigationAction().getZoomSelectionAction().setEnabled(!targetSelectionIndices.empty());
501+
auto& navigationAction = _scatterPlotWidget->getPointRendererNavigator().getNavigationAction();
502+
503+
navigationAction.getZoomSelectionAction().setEnabled(!targetSelectionIndices.empty() && !navigationAction.getFreezeNavigation().isChecked());
471504

472505
_positionDataset->setSelectionIndices(targetSelectionIndices);
473506

src/ScatterplotPlugin.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,13 @@ class ScatterplotPlugin : public ViewPlugin
111111
private:
112112
mv::gui::DropWidget* _dropWidget; /** Widget for dropping datasets */
113113
ScatterplotWidget* _scatterPlotWidget; /** The visualization widget */
114-
115114
Dataset<Points> _positionDataset; /** Smart pointer to points dataset for point position */
116115
Dataset<Points> _positionSourceDataset; /** Smart pointer to source of the points dataset for point position (if any) */
117116
std::vector<mv::Vector2f> _positions; /** Point positions */
118117
unsigned int _numPoints; /** Number of point positions */
119-
120118
SettingsAction _settingsAction; /** Group action for all settings */
121119
HorizontalToolbarAction _primaryToolbarAction; /** Horizontal toolbar for primary content */
120+
QRectF _selectionBoundaries; /** Boundaries of the selection */
122121

123122
static const std::int32_t LAZY_UPDATE_INTERVAL = 2;
124123

src/ScatterplotWidget.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,24 @@ void ScatterplotWidget::setRenderMode(const RenderMode& renderMode)
205205
switch (_renderMode)
206206
{
207207
case ScatterplotWidget::SCATTERPLOT:
208-
break;
208+
{
209+
getPointRendererNavigator().setEnabled(true);
210+
getDensityRendererNavigator().setEnabled(false);
211+
212+
break;
213+
}
209214

210215
case ScatterplotWidget::DENSITY:
211-
computeDensity();
212-
break;
213-
214216
case ScatterplotWidget::LANDSCAPE:
215-
computeDensity();
216-
break;
217+
{
218+
getPointRendererNavigator().setEnabled(false);
219+
getDensityRendererNavigator().setEnabled(true);
217220

218-
default:
219-
break;
221+
computeDensity();
222+
_densityRenderer.getNavigator().resetView();
223+
224+
break;
225+
}
220226
}
221227

222228
update();

src/SelectionAction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#include <util/PixelSelectionTool.h>
66

7-
#include <QHBoxLayout>
8-
#include <QPushButton>
9-
107
using namespace mv::gui;
118

129
SelectionAction::SelectionAction(QObject* parent, const QString& title) :
@@ -79,6 +76,8 @@ void SelectionAction::initialize(ScatterplotPlugin* scatterplotPlugin)
7976
PixelSelectionType::Sample
8077
});
8178

79+
_samplerPixelSelectionAction.setShortcutsEnabled(false);
80+
8281
_displayModeAction.setCurrentIndex(static_cast<std::int32_t>(scatterplotPlugin->getScatterplotWidget().getSelectionDisplayMode()));
8382
_outlineScaleAction.setValue(100.0f * scatterplotPlugin->getScatterplotWidget().getSelectionOutlineScale());
8483
_outlineOpacityAction.setValue(100.0f * scatterplotPlugin->getScatterplotWidget().getSelectionOutlineOpacity());

0 commit comments

Comments
 (0)