Skip to content

Commit 31132c6

Browse files
Temp commit
1 parent e1bac5f commit 31132c6

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

src/ScatterplotPlugin.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ClusterData/ClusterData.h>
1313
#include <ColorData/ColorData.h>
1414
#include <PointData/PointData.h>
15+
#include <SelectionGroup.h>
1516

1617
#include <graphics/Vector3f.h>
1718

@@ -231,7 +232,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
231232

232233
// Only allow user to color by clusters when there is a positions dataset loaded
233234
if (_positionDataset.isValid()) {
234-
235235
if (_settingsAction->getColoringAction().hasColorDataset(candidateDataset)) {
236236

237237
// The clusters dataset is already loaded
@@ -242,6 +242,22 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
242242
else {
243243
if (candidateDataset.isValid())
244244
{
245+
bool foundGroup = false;
246+
// First check if cross-dataset metadata coloring is possible
247+
std::vector<KeyBasedSelectionGroup>& selectionGroups = events().getSelectionGroups();
248+
for (int i = 0; i < selectionGroups.size(); i++)
249+
{
250+
KeyBasedSelectionGroup& selectionGroup = selectionGroups[i];
251+
if (selectionGroup.areDatasetsPartOfGroup(_positionDataset->getParent(), candidateDataset->getParent()))
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+
foundGroup = true;
259+
}
260+
}
245261
// Check to set whether the number of data points comprised throughout all clusters is the same number
246262
// as the number of data points in the dataset we are trying to color
247263
int totalNumIndices = 0;
@@ -255,8 +271,12 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
255271
totalNumPoints = _positionSourceDataset->getFullDataset<Points>()->getNumPoints();
256272
else
257273
totalNumPoints = _positionDataset->getFullDataset<Points>()->getNumPoints();
274+
qDebug() << "Found group" << foundGroup << candidateDataset->getGuiName() << candidateDataset->getParent()->getGuiName();
275+
if (foundGroup)
276+
{
258277

259-
if (totalNumIndices == totalNumPoints)
278+
}
279+
else if (totalNumIndices == totalNumPoints)
260280
{
261281
// Use the clusters set for points color
262282
dropRegions << new DropWidget::DropRegion(this, "Color", description, "palette", true, [this, candidateDataset]() {
@@ -845,6 +865,40 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
845865
if (!clusters.isValid() || !_positionDataset.isValid())
846866
return;
847867

868+
// First check if cross-dataset metadata coloring is possible
869+
std::vector<KeyBasedSelectionGroup>& selectionGroups = events().getSelectionGroups();
870+
for (int i = 0; i < selectionGroups.size(); i++)
871+
{
872+
KeyBasedSelectionGroup& selectionGroup = selectionGroups[i];
873+
if (selectionGroup.areDatasetsPartOfGroup(_positionDataset->getParent(), clusters->getParent()))
874+
{
875+
const auto& clusterVec = clusters->getClusters();
876+
std::vector<Vector3f> localColors(_numPoints, Vector3f(1, 0, 1));
877+
878+
std::vector<int> mappedIndices = selectionGroup.getMappingBetweenDatasets(clusters->getParent(), _positionDataset->getParent());
879+
880+
for (int j = 0; j < mappedIndices.size(); j++)
881+
{
882+
int localIndex = mappedIndices[j];
883+
if (localIndex == -1) continue;
884+
for (const auto& cluster : clusterVec)
885+
{
886+
if (std::find(cluster.getIndices().begin(), cluster.getIndices().end(), j) != cluster.getIndices().end())
887+
{
888+
const auto color = cluster.getColor();
889+
localColors[localIndex] = Vector3f(color.redF(), color.greenF(), color.blueF());
890+
}
891+
}
892+
}
893+
// Apply colors to scatter plot widget without modification
894+
_scatterPlotWidget->setColors(localColors);
895+
896+
// Render
897+
getWidget().update();
898+
return;
899+
}
900+
}
901+
848902
// Get global indices from the position dataset
849903
int totalNumPoints = 0;
850904
if (_positionDataset->isDerivedData())

0 commit comments

Comments
 (0)