diff --git a/src/ColoringAction.cpp b/src/ColoringAction.cpp index 18e04e8..c3fca1f 100644 --- a/src/ColoringAction.cpp +++ b/src/ColoringAction.cpp @@ -127,24 +127,29 @@ ColoringAction::ColoringAction(QObject* parent, const QString& title) : connect(&_scatterplotPlugin->getPositionDataset(), &Dataset::childAdded, this, &ColoringAction::updateColorByActionOptions); connect(&_scatterplotPlugin->getPositionDataset(), &Dataset::childRemoved, this, &ColoringAction::updateColorByActionOptions); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateScatterPlotWidgetColors); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateScatterPlotWidgetColors); + connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, [this](const ScatterplotWidget::ColoringMode& coloringMode) { + updateScatterPlotWidgetColors(); + updateColorMapActionsReadOnly(); + }); + + connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, [this](const ScatterplotWidget::RenderMode& renderMode) { + updateScatterPlotWidgetColors(); + updateColorMapActionsReadOnly(); + }); - connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, &ColoringAction::updateScatterPlotWidgetColors); - connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, &ColoringAction::updateColorMapActionScalarRange); + connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, [this](const int32_t& currentDimensionIndex) { + updateScatterPlotWidgetColors(); + updateColorMapActionsReadOnly(); + updateColorMapActionScalarRange(); + }); connect(&_constantColorAction, &ColorAction::colorChanged, this, &ColoringAction::updateScatterplotWidgetColorMap); connect(&_colorMap1DAction, &ColorMapAction::imageChanged, this, &ColoringAction::updateScatterplotWidgetColorMap); connect(&_colorMap2DAction, &ColorMapAction::imageChanged, this, &ColoringAction::updateScatterplotWidgetColorMap); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateScatterplotWidgetColorMap); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateScatterplotWidgetColorMap); connect(&_colorMap1DAction.getRangeAction(ColorMapAction::Axis::X), &DecimalRangeAction::rangeChanged, this, &ColoringAction::updateScatterPlotWidgetColorMapRange); connect(&_colorMap2DAction.getRangeAction(ColorMapAction::Axis::X), &DecimalRangeAction::rangeChanged, this, &ColoringAction::updateScatterPlotWidgetColorMapRange); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateColorMapActionsReadOnly); - connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateColorMapActionsReadOnly); - const auto updateReadOnly = [this]() { setEnabled(_scatterplotPlugin->getPositionDataset().isValid() && _scatterplotPlugin->getScatterplotWidget().getRenderMode() == ScatterplotWidget::SCATTERPLOT); }; @@ -276,7 +281,8 @@ void ColoringAction::updateScatterplotWidgetColorMap() { case ScatterplotWidget::SCATTERPLOT: { - if (_colorByAction.getCurrentIndex() == 0) { + const int32_t currentIndex = _colorByAction.getCurrentIndex(); + if (currentIndex == 0) { QPixmap colorPixmap(1, 1); colorPixmap.fill(_constantColorAction.getColor()); @@ -285,7 +291,7 @@ void ColoringAction::updateScatterplotWidgetColorMap() scatterplotWidget.setScalarEffect(PointEffect::Color); scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Constant); } - else if (_colorByAction.getCurrentIndex() == 1) { + else if (currentIndex == 1) { scatterplotWidget.setColorMap(_colorMap2DAction.getColorMapImage()); scatterplotWidget.setScalarEffect(PointEffect::Color2D); scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Scatter); diff --git a/src/ScatterplotPlugin.cpp b/src/ScatterplotPlugin.cpp index 0429892..05ddec0 100644 --- a/src/ScatterplotPlugin.cpp +++ b/src/ScatterplotPlugin.cpp @@ -797,9 +797,6 @@ void ScatterplotPlugin::loadColors(const Dataset& clusters) if (!clusters.isValid() || !_positionDataset.isValid()) return; - // Mapping from local to global indices - std::vector globalIndices; - // Get global indices from the position dataset int totalNumPoints = 0; if (_positionDataset->isDerivedData()) @@ -807,15 +804,17 @@ void ScatterplotPlugin::loadColors(const Dataset& clusters) else totalNumPoints = _positionDataset->getFullDataset()->getNumPoints(); + // Mapping from local to global indices + std::vector globalIndices; _positionDataset->getGlobalIndices(globalIndices); // Generate color buffer for global and local colors std::vector globalColors(totalNumPoints); - std::vector localColors(_positions.size()); + std::vector localColors(_numPoints); const auto& clusterVec = clusters->getClusters(); - if (totalNumPoints == _positions.size() && clusterVec.size() == totalNumPoints) + if (totalNumPoints == _numPoints && clusterVec.size() == totalNumPoints) { for (size_t i = 0; i < static_cast(clusterVec.size()); i++) { @@ -826,14 +825,15 @@ void ScatterplotPlugin::loadColors(const Dataset& clusters) } } - else + else if(globalIndices.size() == _numPoints) { // Loop over all clusters and populate global colors for (const auto& cluster : clusterVec) { - const auto color = cluster.getColor(); + const auto color = cluster.getColor(); + const auto colVec = Vector3f(color.redF(), color.greenF(), color.blueF()); for (const auto& index : cluster.getIndices()) - globalColors[index] = Vector3f(color.redF(), color.greenF(), color.blueF()); + globalColors[index] = colVec; } diff --git a/src/ScatterplotWidget.cpp b/src/ScatterplotWidget.cpp index 535c985..ff6f6f8 100644 --- a/src/ScatterplotWidget.cpp +++ b/src/ScatterplotWidget.cpp @@ -41,6 +41,7 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) : _pointRenderer(this), _isInitialized(false), _renderMode(SCATTERPLOT), + _scalarEffect(PointEffect::Color), _backgroundColor(255, 255, 255, 255), _coloringMode(ColoringMode::Constant), _dataRectangleAction(this, "Data rectangle"), @@ -334,7 +335,7 @@ void ScatterplotWidget::setScalars(const std::vector& scalars) void ScatterplotWidget::setColors(const std::vector& colors) { _pointRenderer.setColors(colors); - _pointRenderer.setScalarEffect(None); + setScalarEffect(PointEffect::None); update(); } @@ -367,6 +368,7 @@ void ScatterplotWidget::setPointScaling(mv::gui::PointScaling scalingMode) void ScatterplotWidget::setScalarEffect(PointEffect effect) { _pointRenderer.setScalarEffect(effect); + _scalarEffect = effect; update(); } @@ -621,7 +623,7 @@ void ScatterplotWidget::initializeGL() _densityRenderer.init(); // Set a default color map for both renderers - _pointRenderer.setScalarEffect(PointEffect::Color); + _pointRenderer.setScalarEffect(_scalarEffect); _pointRenderer.setPointScaling(Absolute); _pointRenderer.setSelectionOutlineColor(Vector3f(1, 0, 0)); diff --git a/src/ScatterplotWidget.h b/src/ScatterplotWidget.h index cf0618a..9e73b49 100644 --- a/src/ScatterplotWidget.h +++ b/src/ScatterplotWidget.h @@ -296,6 +296,7 @@ private slots: private: bool _isInitialized; /** Boolean determining whether the widget it properly initialized or not */ RenderMode _renderMode; /** Current render mode */ + PointEffect _scalarEffect; /** Current scalar effect */ QColor _backgroundColor; /** Background color */ ColoringMode _coloringMode; /** Type of point/density coloring */ DecimalRectangleAction _dataRectangleAction; /** Rectangle action for the bounds of the loaded data */