Skip to content

Commit 29f99aa

Browse files
authored
Merge branch 'release/core_bican_bg/bican_bg' into master
2 parents 81b78ea + f335565 commit 29f99aa

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

src/ScatterplotPlugin.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <ClusterData/ClusterData.h>
1414
#include <ColorData/ColorData.h>
1515
#include <PointData/PointData.h>
16+
#include <SelectionGroup.h>
1617

1718
#include <graphics/Vector3f.h>
1819

@@ -64,6 +65,17 @@ Q_PLUGIN_METADATA(IID "studio.manivault.ScatterplotPlugin")
6465
using namespace mv;
6566
using namespace mv::util;
6667

68+
namespace
69+
{
70+
Dataset<DatasetImpl> getTopDataset(const Dataset<DatasetImpl> dataset)
71+
{
72+
Dataset<DatasetImpl> topDataset = dataset;
73+
while (topDataset->getParent().isValid())
74+
topDataset = topDataset->getParent();
75+
return topDataset;
76+
}
77+
}
78+
6779
ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
6880
ViewPlugin(factory),
6981
_dropWidget(nullptr),
@@ -250,7 +262,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
250262

251263
// Only allow user to color by clusters when there is a positions dataset loaded
252264
if (_positionDataset.isValid()) {
253-
254265
if (_settingsAction->getColoringAction().hasColorDataset(candidateDataset)) {
255266

256267
// The clusters dataset is already loaded
@@ -935,6 +946,44 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
935946
if (!clusters.isValid() || !_positionDataset.isValid())
936947
return;
937948

949+
// First check if cross-dataset metadata coloring is possible
950+
std::vector<KeyBasedSelectionGroup>& selectionGroups = events().getSelectionGroups();
951+
for (int i = 0; i < selectionGroups.size(); i++)
952+
{
953+
KeyBasedSelectionGroup& selectionGroup = selectionGroups[i];
954+
if (selectionGroup.areDatasetsPartOfGroup(getTopDataset(_positionDataset), getTopDataset(clusters)))
955+
{
956+
const auto& clusterVec = clusters->getClusters();
957+
std::vector<Vector3f> localColors(_numPoints, Vector3f(1, 0, 1));
958+
959+
// If the clusters belong to the same dataset as we're dropping them on, then skip to other path
960+
if (clusters->getParent() == _positionDataset)
961+
continue;
962+
963+
std::vector<int> mappedIndices = selectionGroup.getMappingBetweenDatasets(getTopDataset(clusters), _positionDataset);
964+
965+
for (int j = 0; j < mappedIndices.size(); j++)
966+
{
967+
int localIndex = mappedIndices[j];
968+
if (localIndex == -1) continue;
969+
for (const auto& cluster : clusterVec)
970+
{
971+
if (std::find(cluster.getIndices().begin(), cluster.getIndices().end(), j) != cluster.getIndices().end())
972+
{
973+
const auto color = cluster.getColor();
974+
localColors[localIndex] = Vector3f(color.redF(), color.greenF(), color.blueF());
975+
}
976+
}
977+
}
978+
// Apply colors to scatter plot widget without modification
979+
_scatterPlotWidget->setColors(localColors);
980+
981+
// Render
982+
getWidget().update();
983+
return;
984+
}
985+
}
986+
938987
// Get global indices from the position dataset
939988
const std::uint64_t totalNumPoints = numTotalPoints();
940989

0 commit comments

Comments
 (0)