Skip to content

Commit 4330db4

Browse files
authored
Merge pull request #217 from ManiVaultStudio/master
Merge master into release/core_bican_bg
2 parents 9db7226 + f3e7e43 commit 4330db4

File tree

5 files changed

+74
-29
lines changed

5 files changed

+74
-29
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
};
@@ -299,7 +304,8 @@ void ColoringAction::updateScatterplotWidgetColorMap()
299304
{
300305
case ScatterplotWidget::SCATTERPLOT:
301306
{
302-
if (_colorByAction.getCurrentIndex() == 0) {
307+
const int32_t currentIndex = _colorByAction.getCurrentIndex();
308+
if (currentIndex == 0) {
303309
QPixmap colorPixmap(1, 1);
304310

305311
colorPixmap.fill(_constantColorAction.getColor());
@@ -308,7 +314,7 @@ void ColoringAction::updateScatterplotWidgetColorMap()
308314
scatterplotWidget.setScalarEffect(PointEffect::Color);
309315
scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Constant);
310316
}
311-
else if (_colorByAction.getCurrentIndex() == 1) {
317+
else if (currentIndex == 1) {
312318
scatterplotWidget.setColorMap(_colorMap2DAction.getColorMapImage());
313319
scatterplotWidget.setScalarEffect(PointEffect::Color2D);
314320
scatterplotWidget.setColoringMode(ScatterplotWidget::ColoringMode::Scatter);

src/ScatterplotPlugin.cpp

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,30 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
238238
});
239239
}
240240
else {
241-
242-
// Use the clusters set for points color
243-
dropRegions << new DropWidget::DropRegion(this, "Color", description, "palette", true, [this, candidateDataset]() {
244-
_settingsAction.getColoringAction().addColorDataset(candidateDataset);
245-
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset);
246-
});
241+
if (candidateDataset.isValid())
242+
{
243+
// Check to set whether the number of data points comprised throughout all clusters is the same number
244+
// as the number of data points in the dataset we are trying to color
245+
int totalNumIndices = 0;
246+
for (const Cluster& cluster : candidateDataset->getClusters())
247+
{
248+
totalNumIndices += cluster.getIndices().size();
249+
}
250+
251+
if (totalNumIndices == _positionDataset->getNumPoints())
252+
{
253+
// Use the clusters set for points color
254+
dropRegions << new DropWidget::DropRegion(this, "Color", description, "palette", true, [this, candidateDataset]() {
255+
_settingsAction.getColoringAction().addColorDataset(candidateDataset);
256+
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset);
257+
});
258+
}
259+
else
260+
{
261+
// Number of indices in clusters doesn't match point dataset
262+
dropRegions << new DropWidget::DropRegion(this, "Incompatible data", "Cluster data does not match number of data points", "exclamation-circle", false);
263+
}
264+
}
247265
}
248266
}
249267
else {
@@ -264,8 +282,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
264282
getLearningCenterAction().addVideos(QStringList({ "Practitioner", "Developer" }));
265283

266284
setOverlayActionsTargetWidget(_scatterPlotWidget);
267-
268-
269285
}
270286

271287
ScatterplotPlugin::~ScatterplotPlugin()
@@ -397,6 +413,10 @@ void ScatterplotPlugin::init()
397413
connect(&_settingsAction.getColoringAction().getColorByAction(), &OptionAction::currentIndexChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
398414
connect(&_settingsAction.getPlotAction().getPointPlotAction().getSizeAction(), &ScalarAction::sourceDataChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
399415
connect(&_settingsAction.getPlotAction().getPointPlotAction().getOpacityAction(), &ScalarAction::sourceDataChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
416+
417+
updateHeadsUpDisplayTextColor();
418+
419+
connect(&_settingsAction.getMiscellaneousAction().getBackgroundColorAction(), &ColorAction::colorChanged, this, &ScatterplotPlugin::updateHeadsUpDisplayTextColor);
400420
}
401421

402422
void ScatterplotPlugin::loadData(const Datasets& datasets)
@@ -816,25 +836,24 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
816836
if (!clusters.isValid() || !_positionDataset.isValid())
817837
return;
818838

819-
// Mapping from local to global indices
820-
std::vector<std::uint32_t> globalIndices;
821-
822839
// Get global indices from the position dataset
823840
int totalNumPoints = 0;
824841
if (_positionDataset->isDerivedData())
825842
totalNumPoints = _positionSourceDataset->getFullDataset<Points>()->getNumPoints();
826843
else
827844
totalNumPoints = _positionDataset->getFullDataset<Points>()->getNumPoints();
828845

846+
// Mapping from local to global indices
847+
std::vector<std::uint32_t> globalIndices;
829848
_positionDataset->getGlobalIndices(globalIndices);
830849

831850
// Generate color buffer for global and local colors
832851
std::vector<Vector3f> globalColors(totalNumPoints);
833-
std::vector<Vector3f> localColors(_positions.size());
852+
std::vector<Vector3f> localColors(_numPoints);
834853

835854
const auto& clusterVec = clusters->getClusters();
836855

837-
if (totalNumPoints == _positions.size() && clusterVec.size() == totalNumPoints)
856+
if (totalNumPoints == _numPoints && clusterVec.size() == totalNumPoints)
838857
{
839858
for (size_t i = 0; i < static_cast<size_t>(clusterVec.size()); i++)
840859
{
@@ -845,14 +864,15 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
845864
}
846865

847866
}
848-
else
867+
else if(globalIndices.size() == _numPoints)
849868
{
850869
// Loop over all clusters and populate global colors
851870
for (const auto& cluster : clusterVec)
852871
{
853-
const auto color = cluster.getColor();
872+
const auto color = cluster.getColor();
873+
const auto colVec = Vector3f(color.redF(), color.greenF(), color.blueF());
854874
for (const auto& index : cluster.getIndices())
855-
globalColors[index] = Vector3f(color.redF(), color.greenF(), color.blueF());
875+
globalColors[index] = colVec;
856876

857877
}
858878

@@ -1017,6 +1037,19 @@ void ScatterplotPlugin::updateHeadsUpDisplay()
10171037
}
10181038
}
10191039

1040+
void ScatterplotPlugin::updateHeadsUpDisplayTextColor()
1041+
{
1042+
if (auto headsUpDisplayWidget = getWidget().findChild<QWidget*>("HeadsUpDisplayWidget")) {
1043+
if (auto headsUpDisplayWidgetTreeView = headsUpDisplayWidget->findChild<QTreeView*>("TreeView")) {
1044+
QPalette palette = headsUpDisplayWidgetTreeView->palette();
1045+
1046+
palette.setColor(QPalette::Text, _settingsAction.getMiscellaneousAction().getBackgroundColorAction().getColor().lightnessF() > .5f ? Qt::black : Qt::white);
1047+
1048+
headsUpDisplayWidgetTreeView->setPalette(palette);
1049+
}
1050+
}
1051+
}
1052+
10201053
void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)
10211054
{
10221055
ViewPlugin::fromVariantMap(variantMap);
@@ -1038,6 +1071,8 @@ void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)
10381071

10391072
_scatterPlotWidget->update();
10401073
}
1074+
1075+
updateHeadsUpDisplayTextColor();
10411076
}
10421077

10431078
QVariantMap ScatterplotPlugin::toVariantMap() const

src/ScatterplotPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ScatterplotPlugin : public ViewPlugin
9595
void updateSelection();
9696

9797
void updateHeadsUpDisplay();
98+
void updateHeadsUpDisplayTextColor();
9899

99100
public: // Serialization
100101

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)