Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ set(Actions
src/ScalarSourceAction.cpp
src/SelectionAction.h
src/SelectionAction.cpp
src/SelectionRestrictionAction.h
src/SelectionRestrictionAction.cpp
src/SettingsAction.h
src/SettingsAction.cpp
src/SubsetAction.h
src/SubsetAction.cpp
src/ZOrderingAction.h
src/ZOrderingAction.cpp
src/ExportAction.h
src/ExportAction.cpp
src/DatasetsAction.h
Expand Down
17 changes: 2 additions & 15 deletions src/MiscellaneousAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ const QColor MiscellaneousAction::DEFAULT_BACKGROUND_COLOR = qRgb(255, 255, 255)
MiscellaneousAction::MiscellaneousAction(QObject* parent, const QString& title) :
VerticalGroupAction(parent, title),
_scatterplotPlugin(dynamic_cast<ScatterplotPlugin*>(parent->parent())),
_backgroundColorAction(this, "Background color"),
_randomizedDepthAction(this, "Randomized depth", true)
_backgroundColorAction(this, "Background color")
{
setIconByName("cog");
setLabelSizingType(LabelSizingType::Auto);
setConfigurationFlag(WidgetAction::ConfigurationFlag::ForceCollapsedInGroup);

addAction(&_backgroundColorAction);
addAction(&_randomizedDepthAction);

_backgroundColorAction.setColor(DEFAULT_BACKGROUND_COLOR);

Expand All @@ -32,15 +30,6 @@ MiscellaneousAction::MiscellaneousAction(QObject* parent, const QString& title)

updateBackgroundColor();

const auto updateRandomizedDepth = [this]() -> void {
_scatterplotPlugin->getScatterplotWidget().setRandomizedDepthEnabled(_randomizedDepthAction.isChecked());
};

connect(&_randomizedDepthAction, &ToggleAction::toggled, this, [this, updateRandomizedDepth](bool toggled) {
updateRandomizedDepth();
});

updateRandomizedDepth();
}

QMenu* MiscellaneousAction::getContextMenu()
Expand Down Expand Up @@ -85,15 +74,13 @@ void MiscellaneousAction::fromVariantMap(const QVariantMap& variantMap)
GroupAction::fromVariantMap(variantMap);

_backgroundColorAction.fromParentVariantMap(variantMap);
_randomizedDepthAction.fromParentVariantMap(variantMap);
}

QVariantMap MiscellaneousAction::toVariantMap() const
{
auto variantMap = GroupAction::toVariantMap();

_backgroundColorAction.insertIntoVariantMap(variantMap);
_randomizedDepthAction.insertIntoVariantMap(variantMap);

return variantMap;
}
}
5 changes: 1 addition & 4 deletions src/MiscellaneousAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <actions/VerticalGroupAction.h>
#include <actions/ColorAction.h>
#include <actions/ToggleAction.h>

using namespace mv::gui;

Expand Down Expand Up @@ -66,12 +65,10 @@ class MiscellaneousAction : public VerticalGroupAction
public: // Action getters

ColorAction& getBackgroundColorAction() { return _backgroundColorAction; }
ToggleAction& getRandomizedDepthAction() { return _randomizedDepthAction; }

private:
ScatterplotPlugin* _scatterplotPlugin; /** Pointer to scatter plot plugin */
ColorAction _backgroundColorAction; /** Color action for setting the background color action */
ToggleAction _randomizedDepthAction; /** whether the z-order of each point is to be randomized or not */

static const QColor DEFAULT_BACKGROUND_COLOR;

Expand All @@ -80,4 +77,4 @@ class MiscellaneousAction : public VerticalGroupAction

Q_DECLARE_METATYPE(MiscellaneousAction)

inline const auto miscellaneousActionMetaTypeId = qRegisterMetaType<MiscellaneousAction*>("MiscellaneousAction");
inline const auto miscellaneousActionMetaTypeId = qRegisterMetaType<MiscellaneousAction*>("MiscellaneousAction");
103 changes: 100 additions & 3 deletions src/ScatterplotPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
_primaryToolbarAction->addAction(&_settingsAction->getDatasetsAction());
_primaryToolbarAction->addAction(&_settingsAction->getRenderModeAction(), 3, GroupAction::Horizontal);
_primaryToolbarAction->addAction(&_settingsAction->getPositionAction(), 1, GroupAction::Horizontal);
_primaryToolbarAction->addAction(&_settingsAction->getZOrderingAction(), 1, GroupAction::Horizontal);
_primaryToolbarAction->addAction(&_settingsAction->getPlotAction(), 2, GroupAction::Horizontal);
_primaryToolbarAction->addAction(&_settingsAction->getColoringAction());
_primaryToolbarAction->addAction(&_settingsAction->getSubsetAction());
Expand Down Expand Up @@ -457,6 +458,78 @@ void ScatterplotPlugin::createSubset(const bool& fromSourceData /*= false*/, con
subset->getDataHierarchyItem().select();
}

void ScatterplotPlugin::selectAllEligiblePoints()
{
if (!_positionDataset.isValid())
return;

std::vector<std::uint32_t> globalIndices;
_positionDataset->getGlobalIndices(globalIndices);

std::vector<std::uint32_t> eligibleIndices;
eligibleIndices.reserve(globalIndices.size());

for (std::uint32_t localIndex = 0; localIndex < globalIndices.size(); ++localIndex) {
if (!_scatterPlotWidget->isSelectionExcluded(localIndex))
eligibleIndices.push_back(globalIndices[localIndex]);
}

_positionDataset->setSelectionIndices(eligibleIndices);
events().notifyDatasetDataSelectionChanged(_positionDataset->getSourceDataset<Points>());
}

void ScatterplotPlugin::invertEligiblePointSelection()
{
if (!_positionDataset.isValid())
return;

const auto selection = _positionDataset->getSelection<Points>();

std::vector<bool> selected;
_positionDataset->selectedLocalIndices(selection->indices, selected);

std::vector<std::uint32_t> globalIndices;
_positionDataset->getGlobalIndices(globalIndices);

std::vector<std::uint32_t> invertedIndices;
invertedIndices.reserve(globalIndices.size());

for (std::uint32_t localIndex = 0; localIndex < globalIndices.size(); ++localIndex) {
if (!_scatterPlotWidget->isSelectionExcluded(localIndex) && (localIndex >= selected.size() || !selected[localIndex]))
invertedIndices.push_back(globalIndices[localIndex]);
}

_positionDataset->setSelectionIndices(invertedIndices);
events().notifyDatasetDataSelectionChanged(_positionDataset->getSourceDataset<Points>());
}

void ScatterplotPlugin::filterSelectionExcludedIndices(std::vector<std::uint32_t>& globalIndices) const
{
if (!_positionDataset.isValid()) {
globalIndices.clear();
return;
}

std::vector<bool> selected;
_positionDataset->selectedLocalIndices(globalIndices, selected);

std::vector<std::uint32_t> localGlobalIndices;
_positionDataset->getGlobalIndices(localGlobalIndices);

globalIndices.clear();
globalIndices.reserve(localGlobalIndices.size());

for (std::uint32_t localIndex = 0; localIndex < localGlobalIndices.size(); ++localIndex) {
if (localIndex < selected.size() && selected[localIndex] && !_scatterPlotWidget->isSelectionExcluded(localIndex))
globalIndices.push_back(localGlobalIndices[localIndex]);
}
}

void ScatterplotPlugin::refreshSelection()
{
updateSelection();
}

void ScatterplotPlugin::selectPoints()
{
if (getSettingsAction().getSelectionAction().getFreezeSelectionAction().isChecked())
Expand Down Expand Up @@ -494,6 +567,9 @@ void ScatterplotPlugin::selectPoints()

// Go over all points in the dataset to see if they are selected
for (std::uint32_t localPointIndex = 0; localPointIndex < _positions.size(); localPointIndex++) {
if (_scatterPlotWidget->isSelectionExcluded(localPointIndex))
continue;

const auto& point = _positions[localPointIndex];

// Compute the offset of the point in the world space
Expand Down Expand Up @@ -568,6 +644,8 @@ void ScatterplotPlugin::selectPoints()
}
}

filterSelectionExcludedIndices(targetSelectionIndices);

auto& navigationAction = navigator.getNavigationAction();

navigationAction.getZoomSelectionAction().setEnabled(!targetSelectionIndices.empty() && navigationAction.isNavigationActive());
Expand Down Expand Up @@ -608,6 +686,9 @@ void ScatterplotPlugin::samplePoints()
// Go over all points in the dataset to see if they should be sampled
for (std::uint32_t localPointIndex = 0; localPointIndex < _positions.size(); localPointIndex++) {

if (_scatterPlotWidget->isSelectionExcluded(localPointIndex))
continue;

// Compute the offset of the point in the world space
const auto pointOffsetWorld = QPointF(_positions[localPointIndex].x - zoomRectangleWorld.left(), _positions[localPointIndex].y - zoomRectangleWorld.top());

Expand Down Expand Up @@ -989,13 +1070,15 @@ void ScatterplotPlugin::updateData()

// Pass the 2D points to the scatter plot widget
_scatterPlotWidget->setData(&_positions);
_settingsAction->getZOrderingAction().updateScatterplotWidget();

updateSelection();
}
else {
_numPoints = 0;
_positions.clear();
_scatterPlotWidget->setData(&_positions);
_settingsAction->getZOrderingAction().updateScatterplotWidget();
}
}

Expand Down Expand Up @@ -1029,14 +1112,16 @@ void ScatterplotPlugin::updateSelection()

sampledPoints.reserve(_positions.size());

for (auto selectionIndex : selection->indices)
sampledPoints.push_back(selectionIndex);
for (std::uint32_t localIndex = 0; localIndex < selected.size(); ++localIndex) {
if (selected[localIndex] && !_scatterPlotWidget->isSelectionExcluded(localIndex))
sampledPoints.push_back(localIndex);
}

std::int32_t numberOfPoints = 0;

QVariantList localPointIndices, globalPointIndices;

const auto numberOfSelectedPoints = selection->indices.size();
const auto numberOfSelectedPoints = sampledPoints.size();

localPointIndices.reserve(static_cast<std::int32_t>(numberOfSelectedPoints));
globalPointIndices.reserve(static_cast<std::int32_t>(numberOfSelectedPoints));
Expand Down Expand Up @@ -1072,6 +1157,8 @@ void ScatterplotPlugin::updateSelection()
{ "RenderMode", _settingsAction->getRenderModeAction().getCurrentText() }
});
}

updateHeadsUpDisplay();
}

void ScatterplotPlugin::updateHeadsUpDisplay()
Expand Down Expand Up @@ -1101,6 +1188,16 @@ void ScatterplotPlugin::updateHeadsUpDisplay()
//qDebug() << "ScatterplotPlugin::updateHeadsUpDisplay: point size dataset: " << pointPlotAction.getSizeAction().getCurrentDataset().isValid() << ", opacity dataset: " << pointPlotAction.getOpacityAction().getCurrentDataset().isValid();
addMetaDataToHeadsUpDisplay("Size", pointPlotAction.getSizeAction().getCurrentDataset(), datasetsItem);
addMetaDataToHeadsUpDisplay("Opacity", pointPlotAction.getOpacityAction().getCurrentDataset(), datasetsItem);

const auto selectionItem = getHeadsUpDisplayAction().addHeadsUpDisplayItem("Selection", "", "");
const auto numberOfSelectedPoints = _scatterPlotWidget->getNumberOfEffectivelySelectedPoints();
const auto numberOfSelectablePoints = _scatterPlotWidget->getNumberOfSelectablePoints();

getHeadsUpDisplayAction().addHeadsUpDisplayItem(
"Selected:",
QString("%1 of %2 selectable points").arg(numberOfSelectedPoints).arg(numberOfSelectablePoints),
"",
selectionItem);
} else {
getHeadsUpDisplayAction().addHeadsUpDisplayItem("No datasets loaded", "", "");
}
Expand Down
6 changes: 5 additions & 1 deletion src/ScatterplotPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ScatterplotPlugin : public ViewPlugin

public:
void createSubset(const bool& fromSourceData = false, const QString& name = "");
void selectAllEligiblePoints();
void invertEligiblePointSelection();
void refreshSelection();

public: // Dimension picking
void setXDimension(const std::int32_t& dimensionIndex);
Expand Down Expand Up @@ -111,6 +114,7 @@ class ScatterplotPlugin : public ViewPlugin
void updateData();
void updateSelection();
void updateHeadsUpDisplayTextColor();
void filterSelectionExcludedIndices(std::vector<std::uint32_t>& globalIndices) const;

public:

Expand Down Expand Up @@ -184,4 +188,4 @@ class ScatterplotPluginFactory : public ViewPluginFactory
* @return URL of the GitHub repository (or readme markdown URL if set)
*/
QUrl getRepositoryUrl() const override;
};
};
Loading
Loading