|
13 | 13 | #include <ClusterData/ClusterData.h> |
14 | 14 | #include <ColorData/ColorData.h> |
15 | 15 | #include <PointData/PointData.h> |
| 16 | +#include <SelectionGroup.h> |
16 | 17 |
|
17 | 18 | #include <graphics/Vector3f.h> |
18 | 19 |
|
@@ -64,6 +65,17 @@ Q_PLUGIN_METADATA(IID "studio.manivault.ScatterplotPlugin") |
64 | 65 | using namespace mv; |
65 | 66 | using namespace mv::util; |
66 | 67 |
|
| 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 | + |
67 | 79 | ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) : |
68 | 80 | ViewPlugin(factory), |
69 | 81 | _dropWidget(nullptr), |
@@ -250,7 +262,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) : |
250 | 262 |
|
251 | 263 | // Only allow user to color by clusters when there is a positions dataset loaded |
252 | 264 | if (_positionDataset.isValid()) { |
253 | | - |
254 | 265 | if (_settingsAction->getColoringAction().hasColorDataset(candidateDataset)) { |
255 | 266 |
|
256 | 267 | // The clusters dataset is already loaded |
@@ -935,6 +946,44 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters) |
935 | 946 | if (!clusters.isValid() || !_positionDataset.isValid()) |
936 | 947 | return; |
937 | 948 |
|
| 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 | + |
938 | 987 | // Get global indices from the position dataset |
939 | 988 | const std::uint64_t totalNumPoints = numTotalPoints(); |
940 | 989 |
|
|
0 commit comments