Skip to content
Merged
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
32 changes: 29 additions & 3 deletions src/ColoringAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,33 @@ ColoringAction::ColoringAction(QObject* parent, const QString& title) :

const auto currentColorDataset = getCurrentColorDataset();

if (currentColorDataset.isValid()) {
const auto currentColorDatasetTypeIsPointType = currentColorDataset->getDataType() == PointType;
if (_currentColorPointsDataset.isValid()) {
disconnect(&_currentColorPointsDataset, &Dataset<Points>::dataDimensionsChanged, this, nullptr);
}

_currentColorPointsDataset = Dataset<Points>();

_dimensionAction.setPointsDataset(currentColorDatasetTypeIsPointType ? Dataset<Points>(currentColorDataset) : Dataset<Points>());
if (currentColorDataset.isValid()) {
if (currentColorDataset->getDataType() == PointType) {
_currentColorPointsDataset = currentColorDataset.get<Points>();

if (_currentColorPointsDataset.isValid()) {
connect(&_currentColorPointsDataset, &Dataset<Points>::dataDimensionsChanged, this, [this]() {
if (_currentColorPointsDataset.isValid()) {
_dimensionAction.setPointsDataset(_currentColorPointsDataset);
updateScatterPlotWidgetColors();
}
});

_dimensionAction.setPointsDataset(_currentColorPointsDataset);
}
else {
_dimensionAction.setPointsDataset(Dataset<Points>());
}
}
else {
_dimensionAction.setPointsDataset(Dataset<Points>());
}
//_dimensionAction.setVisible(currentColorDatasetTypeIsPointType);

emit currentColorDatasetChanged(currentColorDataset);
Expand Down Expand Up @@ -179,6 +202,9 @@ Dataset<DatasetImpl> ColoringAction::getCurrentColorDataset() const

void ColoringAction::setCurrentColorDataset(const Dataset<DatasetImpl>& colorDataset)
{
if (!colorDataset.isValid())
return;

addColorDataset(colorDataset);

const auto colorDatasetRowIndex = _colorByModel.rowIndex(colorDataset);
Expand Down
15 changes: 8 additions & 7 deletions src/ColoringAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ class ColoringAction : public VerticalGroupAction
void currentColorDatasetChanged(Dataset<DatasetImpl> currentColorDataset);

private:
ScatterplotPlugin* _scatterplotPlugin; /** Pointer to scatter plot plugin */
ColorSourceModel _colorByModel; /** Color by model (model input for the color by action) */
OptionAction _colorByAction; /** Action for picking the coloring type */
ColorAction _constantColorAction; /** Action for picking the constant color */
DimensionPickerAction _dimensionAction; /** Dimension picker action */
ColorMap1DAction _colorMap1DAction; /** One-dimensional color map action */
ColorMap2DAction _colorMap2DAction; /** Two-dimensional color map action */
ScatterplotPlugin* _scatterplotPlugin; /** Pointer to scatter plot plugin */
ColorSourceModel _colorByModel; /** Color by model (model input for the color by action) */
OptionAction _colorByAction; /** Action for picking the coloring type */
ColorAction _constantColorAction; /** Action for picking the constant color */
DimensionPickerAction _dimensionAction; /** Dimension picker action */
ColorMap1DAction _colorMap1DAction; /** One-dimensional color map action */
ColorMap2DAction _colorMap2DAction; /** Two-dimensional color map action */
Dataset<Points> _currentColorPointsDataset; /** Current color dataset */

/** Default constant color */
static const QColor DEFAULT_CONSTANT_COLOR;
Expand Down
18 changes: 18 additions & 0 deletions src/PointPlotAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ void PointPlotAction::addPointOpacityDataset(const Dataset<DatasetImpl>& pointOp
_opacityAction.addDataset(pointOpacityDataset);
}

void PointPlotAction::setCurrentPointSizeDataset(const Dataset<DatasetImpl>& pointSizeDataset)
{
if (!pointSizeDataset.isValid())
return;

addPointSizeDataset(pointSizeDataset);
_sizeAction.setCurrentDataset(pointSizeDataset);
}

void PointPlotAction::setCurrentPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset)
{
if (!pointOpacityDataset.isValid())
return;

addPointOpacityDataset(pointOpacityDataset);
_opacityAction.setCurrentDataset(pointOpacityDataset);
}

void PointPlotAction::updateDefaultDatasets()
{
if (_scatterplotPlugin == nullptr)
Expand Down
12 changes: 12 additions & 0 deletions src/PointPlotAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class PointPlotAction : public VerticalGroupAction
*/
void addPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset);

/**
* Set the current point size dataset
* @param pointSizeDataset Smart pointer to point size dataset
*/
void setCurrentPointSizeDataset(const Dataset<DatasetImpl>& pointSizeDataset);

/**
* Set the current opacity size dataset
* @param pointOpacityDataset Smart pointer to opacity size dataset
*/
void setCurrentPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset);

protected:

/** Update default datasets (candidates are children of points type and with matching number of points) */
Expand Down
3 changes: 3 additions & 0 deletions src/ScalarAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void ScalarAction::addDataset(const Dataset<DatasetImpl>& dataset)
{
auto& sourceModel = _sourceAction.getModel();

if (sourceModel.hasDataset(dataset))
return;

sourceModel.addDataset(dataset);

connect(&sourceModel.getDatasets().last(), &Dataset<DatasetImpl>::dataChanged, this, [this, dataset]() {
Expand Down
9 changes: 8 additions & 1 deletion src/ScalarSourceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ QVariant ScalarSourceModel::data(const QModelIndex& index, int role) const
if (row == DefaultRow::Selection)
return "Selection";
}

break;
}

default:
Expand All @@ -86,7 +88,7 @@ QVariant ScalarSourceModel::data(const QModelIndex& index, int role) const
void ScalarSourceModel::addDataset(const Dataset<DatasetImpl>& dataset)
{
// Avoid duplicates
if (rowIndex(dataset) >= DefaultRow::DatasetStart)
if (hasDataset(dataset))
return;

// Insert row into model
Expand Down Expand Up @@ -127,6 +129,11 @@ void ScalarSourceModel::addDataset(const Dataset<DatasetImpl>& dataset)
});
}

bool ScalarSourceModel::hasDataset(const Dataset<DatasetImpl>& dataset) const
{
return rowIndex(dataset) >= DefaultRow::DatasetStart;
}

void ScalarSourceModel::removeDataset(const Dataset<DatasetImpl>& dataset)
{
// Get row index of the dataset
Expand Down
7 changes: 7 additions & 0 deletions src/ScalarSourceModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class ScalarSourceModel : public QAbstractListModel
*/
void addDataset(const Dataset<DatasetImpl>& dataset);

/**
* Determines whether a given dataset is already loaded
* @param dataset Smart pointer to dataset
* @return whether the dataset is already loaded
*/
bool hasDataset(const Dataset<DatasetImpl>& dataset) const;

/**
* Remove a dataset
* @param dataset Smart pointer to dataset
Expand Down
78 changes: 57 additions & 21 deletions src/ScatterplotPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <widgets/ViewPluginLearningCenterOverlayWidget.h>

#include <actions/PluginTriggerAction.h>
#include <actions/ViewPluginSamplerAction.h>

#include <DatasetsMimeData.h>

Expand All @@ -29,9 +30,8 @@
#include <QtCore>

#include <algorithm>
#include <functional>
#include <cassert>
#include <vector>
#include <actions/ViewPluginSamplerAction.h>

#define VIEW_SAMPLING_HTML
//#define VIEW_SAMPLING_WIDGET
Expand Down Expand Up @@ -172,24 +172,33 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
});
}

if (candidateDataset->getNumPoints() == _positionDataset->getNumPoints()) {

// The number of points is equal, so offer the option to use the points dataset as source for points colors
// Accept both data with the same number if points and data which is derived from
// a parent that has the same number of points (e.g. for HSNE embeddings)
const auto numPointsCandidate = candidateDataset->getNumPoints();
const auto numPointsPosition = _positionDataset->getNumPoints();
const bool sameNumPoints = numPointsPosition == numPointsCandidate;
const bool sameNumPointsAsFull =
/*if*/ _positionDataset->isDerivedData() ?
/*then*/ _positionDataset->getSourceDataset<Points>()->getFullDataset<Points>()->getNumPoints() == numPointsCandidate :
/*else*/ false;

if (sameNumPoints || sameNumPointsAsFull) {
// Offer the option to use the points dataset as source for points colors
dropRegions << new DropWidget::DropRegion(this, "Point color", QString("Colorize %1 points with %2").arg(_positionDataset->text(), candidateDataset->text()), "palette", true, [this, candidateDataset]() {
_settingsAction.getColoringAction().addColorDataset(candidateDataset);
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset);
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset); // calls addColorDataset internally
});

// The number of points is equal, so offer the option to use the points dataset as source for points size
}

if (sameNumPoints) {
// Offer the option to use the points dataset as source for points size
dropRegions << new DropWidget::DropRegion(this, "Point size", QString("Size %1 points with %2").arg(_positionDataset->text(), candidateDataset->text()), "ruler-horizontal", true, [this, candidateDataset]() {
_settingsAction.getPlotAction().getPointPlotAction().addPointSizeDataset(candidateDataset);
_settingsAction.getPlotAction().getPointPlotAction().getSizeAction().setCurrentDataset(candidateDataset);
_settingsAction.getPlotAction().getPointPlotAction().setCurrentPointSizeDataset(candidateDataset);
});

// The number of points is equal, so offer the option to use the points dataset as source for points opacity
// Offer the option to use the points dataset as source for points opacity
dropRegions << new DropWidget::DropRegion(this, "Point opacity", QString("Set %1 points opacity with %2").arg(_positionDataset->text(), candidateDataset->text()), "brush", true, [this, candidateDataset]() {
_settingsAction.getPlotAction().getPointPlotAction().addPointOpacityDataset(candidateDataset);
_settingsAction.getPlotAction().getPointPlotAction().getOpacityAction().setCurrentDataset(candidateDataset);
_settingsAction.getPlotAction().getPointPlotAction().setCurrentPointOpacityDataset(candidateDataset);
});
}
}
Expand Down Expand Up @@ -647,14 +656,37 @@ void ScatterplotPlugin::loadColors(const Dataset<Points>& points, const std::uin
// Generate point scalars for color mapping
std::vector<float> scalars;

if (_positionDataset->getNumPoints() != _numPoints)
{
qWarning("Number of points used for coloring does not match number of points in data, aborting attempt to color plot");
return;
points->extractDataForDimension(scalars, dimensionIndex);

const auto numColorPoints = points->getNumPoints();


if (numColorPoints != _numPoints) {

const bool sameNumPointsAsFull =
/*if*/ _positionDataset->isDerivedData() ?
/*then*/ _positionSourceDataset->getFullDataset<Points>()->getNumPoints() == numColorPoints :
/*else*/ false;

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

std::vector<float> localScalars(_numPoints, 0);
std::int32_t localColorIndex = 0;

for (const auto& globalIndex : globalIndices)
localScalars[localColorIndex++] = scalars[globalIndex];

std::swap(localScalars, scalars);
}
else {
qWarning("Number of points used for coloring does not match number of points in data, aborting attempt to color plot");
return;
}
}

// Populate point scalars
points->extractDataForDimension(scalars, dimensionIndex);
assert(scalars.size() == _numPoints);

// Assign scalars and scalar effect
_scatterPlotWidget->setScalars(scalars);
Expand Down Expand Up @@ -853,14 +885,18 @@ void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)

variantMapMustContain(variantMap, "Settings");

auto& pointRenderer = const_cast<PointRenderer&>(_scatterPlotWidget->getPointRenderer());

pointRenderer.getNavigator().resetView(true);

_primaryToolbarAction.fromParentVariantMap(variantMap);
_settingsAction.fromParentVariantMap(variantMap);

auto& pointRenderer = const_cast<PointRenderer&>(_scatterPlotWidget->getPointRenderer());


if (pointRenderer.getNavigator().getNavigationAction().getSerializationCountFrom() == 0) {
qDebug() << "Resetting view";
pointRenderer.getNavigator().resetView(true);


_scatterPlotWidget->update();
}
Expand Down