Skip to content

Commit f3e7e43

Browse files
authored
Merge pull request #216 from ManiVaultStudio/feature/FixLoadClusterColorsFromMinimized
Fix loading colors from cluster in minimized scatterplot in project
2 parents 741494d + b402206 commit f3e7e43

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/ColoringAction.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,29 @@ ColoringAction::ColoringAction(QObject* parent, const QString& title) :
127127
connect(&_scatterplotPlugin->getPositionDataset(), &Dataset<Points>::childAdded, this, &ColoringAction::updateColorByActionOptions);
128128
connect(&_scatterplotPlugin->getPositionDataset(), &Dataset<Points>::childRemoved, this, &ColoringAction::updateColorByActionOptions);
129129

130-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateScatterPlotWidgetColors);
131-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateScatterPlotWidgetColors);
130+
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, [this](const ScatterplotWidget::ColoringMode& coloringMode) {
131+
updateScatterPlotWidgetColors();
132+
updateColorMapActionsReadOnly();
133+
});
134+
135+
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, [this](const ScatterplotWidget::RenderMode& renderMode) {
136+
updateScatterPlotWidgetColors();
137+
updateColorMapActionsReadOnly();
138+
});
132139

133-
connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, &ColoringAction::updateScatterPlotWidgetColors);
134-
connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, &ColoringAction::updateColorMapActionScalarRange);
140+
connect(&_dimensionAction, &DimensionPickerAction::currentDimensionIndexChanged, this, [this](const int32_t& currentDimensionIndex) {
141+
updateScatterPlotWidgetColors();
142+
updateColorMapActionsReadOnly();
143+
updateColorMapActionScalarRange();
144+
});
135145

136146
connect(&_constantColorAction, &ColorAction::colorChanged, this, &ColoringAction::updateScatterplotWidgetColorMap);
137147
connect(&_colorMap1DAction, &ColorMapAction::imageChanged, this, &ColoringAction::updateScatterplotWidgetColorMap);
138148
connect(&_colorMap2DAction, &ColorMapAction::imageChanged, this, &ColoringAction::updateScatterplotWidgetColorMap);
139-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateScatterplotWidgetColorMap);
140-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateScatterplotWidgetColorMap);
141149

142150
connect(&_colorMap1DAction.getRangeAction(ColorMapAction::Axis::X), &DecimalRangeAction::rangeChanged, this, &ColoringAction::updateScatterPlotWidgetColorMapRange);
143151
connect(&_colorMap2DAction.getRangeAction(ColorMapAction::Axis::X), &DecimalRangeAction::rangeChanged, this, &ColoringAction::updateScatterPlotWidgetColorMapRange);
144152

145-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::coloringModeChanged, this, &ColoringAction::updateColorMapActionsReadOnly);
146-
connect(&_scatterplotPlugin->getScatterplotWidget(), &ScatterplotWidget::renderModeChanged, this, &ColoringAction::updateColorMapActionsReadOnly);
147-
148153
const auto updateReadOnly = [this]() {
149154
setEnabled(_scatterplotPlugin->getPositionDataset().isValid() && _scatterplotPlugin->getScatterplotWidget().getRenderMode() == ScatterplotWidget::SCATTERPLOT);
150155
};
@@ -276,7 +281,8 @@ void ColoringAction::updateScatterplotWidgetColorMap()
276281
{
277282
case ScatterplotWidget::SCATTERPLOT:
278283
{
279-
if (_colorByAction.getCurrentIndex() == 0) {
284+
const int32_t currentIndex = _colorByAction.getCurrentIndex();
285+
if (currentIndex == 0) {
280286
QPixmap colorPixmap(1, 1);
281287

282288
colorPixmap.fill(_constantColorAction.getColor());
@@ -285,7 +291,7 @@ void ColoringAction::updateScatterplotWidgetColorMap()
285291
scatterplotWidget.setScalarEffect(PointEffect::Color);
286292
scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Constant);
287293
}
288-
else if (_colorByAction.getCurrentIndex() == 1) {
294+
else if (currentIndex == 1) {
289295
scatterplotWidget.setColorMap(_colorMap2DAction.getColorMapImage());
290296
scatterplotWidget.setScalarEffect(PointEffect::Color2D);
291297
scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Scatter);

src/ScatterplotPlugin.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -815,25 +815,24 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
815815
if (!clusters.isValid() || !_positionDataset.isValid())
816816
return;
817817

818-
// Mapping from local to global indices
819-
std::vector<std::uint32_t> globalIndices;
820-
821818
// Get global indices from the position dataset
822819
int totalNumPoints = 0;
823820
if (_positionDataset->isDerivedData())
824821
totalNumPoints = _positionSourceDataset->getFullDataset<Points>()->getNumPoints();
825822
else
826823
totalNumPoints = _positionDataset->getFullDataset<Points>()->getNumPoints();
827824

825+
// Mapping from local to global indices
826+
std::vector<std::uint32_t> globalIndices;
828827
_positionDataset->getGlobalIndices(globalIndices);
829828

830829
// Generate color buffer for global and local colors
831830
std::vector<Vector3f> globalColors(totalNumPoints);
832-
std::vector<Vector3f> localColors(_positions.size());
831+
std::vector<Vector3f> localColors(_numPoints);
833832

834833
const auto& clusterVec = clusters->getClusters();
835834

836-
if (totalNumPoints == _positions.size() && clusterVec.size() == totalNumPoints)
835+
if (totalNumPoints == _numPoints && clusterVec.size() == totalNumPoints)
837836
{
838837
for (size_t i = 0; i < static_cast<size_t>(clusterVec.size()); i++)
839838
{
@@ -844,14 +843,15 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
844843
}
845844

846845
}
847-
else
846+
else if(globalIndices.size() == _numPoints)
848847
{
849848
// Loop over all clusters and populate global colors
850849
for (const auto& cluster : clusterVec)
851850
{
852-
const auto color = cluster.getColor();
851+
const auto color = cluster.getColor();
852+
const auto colVec = Vector3f(color.redF(), color.greenF(), color.blueF());
853853
for (const auto& index : cluster.getIndices())
854-
globalColors[index] = Vector3f(color.redF(), color.greenF(), color.blueF());
854+
globalColors[index] = colVec;
855855

856856
}
857857

src/ScatterplotWidget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
4141
_pointRenderer(this),
4242
_isInitialized(false),
4343
_renderMode(SCATTERPLOT),
44+
_scalarEffect(PointEffect::Color),
4445
_backgroundColor(255, 255, 255, 255),
4546
_coloringMode(ColoringMode::Constant),
4647
_dataRectangleAction(this, "Data rectangle"),
@@ -334,7 +335,7 @@ void ScatterplotWidget::setScalars(const std::vector<float>& scalars)
334335
void ScatterplotWidget::setColors(const std::vector<Vector3f>& colors)
335336
{
336337
_pointRenderer.setColors(colors);
337-
_pointRenderer.setScalarEffect(None);
338+
setScalarEffect(PointEffect::None);
338339

339340
update();
340341
}
@@ -367,6 +368,7 @@ void ScatterplotWidget::setPointScaling(mv::gui::PointScaling scalingMode)
367368
void ScatterplotWidget::setScalarEffect(PointEffect effect)
368369
{
369370
_pointRenderer.setScalarEffect(effect);
371+
_scalarEffect = effect;
370372

371373
update();
372374
}
@@ -621,7 +623,7 @@ void ScatterplotWidget::initializeGL()
621623
_densityRenderer.init();
622624

623625
// Set a default color map for both renderers
624-
_pointRenderer.setScalarEffect(PointEffect::Color);
626+
_pointRenderer.setScalarEffect(_scalarEffect);
625627

626628
_pointRenderer.setPointScaling(Absolute);
627629
_pointRenderer.setSelectionOutlineColor(Vector3f(1, 0, 0));

src/ScatterplotWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ private slots:
296296
private:
297297
bool _isInitialized; /** Boolean determining whether the widget it properly initialized or not */
298298
RenderMode _renderMode; /** Current render mode */
299+
PointEffect _scalarEffect; /** Current scalar effect */
299300
QColor _backgroundColor; /** Background color */
300301
ColoringMode _coloringMode; /** Type of point/density coloring */
301302
DecimalRectangleAction _dataRectangleAction; /** Rectangle action for the bounds of the loaded data */

0 commit comments

Comments
 (0)