Skip to content

Commit c6e0fe8

Browse files
committed
WIP: map means to HSNE embedding
1 parent c376c60 commit c6e0fe8

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/MappingUtils.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ std::pair<const mv::LinkedData*, unsigned int> getSelectionMappingPositionsToCol
6868

6969
return { mapping, numTargetPoints };
7070
}
71+
72+
std::pair<const mv::LinkedData*, unsigned int> getSelectionMappingPositionSourceToColors(const mv::Dataset<Points>& positions, const mv::Dataset<Points>& colors) {
73+
if (!positions->isDerivedData())
74+
return { nullptr, 0 };
75+
76+
const auto fullSourceData = positions->getSourceDataset<Points>()->getFullDataset<Points>();
77+
78+
if(!fullSourceData.isValid())
79+
return { nullptr, 0 };
80+
81+
return getSelectionMappingPositionsToColors(fullSourceData, colors);
7182
}
7283

7384
bool checkSurjectiveMapping(const mv::LinkedData& linkedData, const std::uint32_t numPointsInTarget) {
@@ -93,16 +104,17 @@ bool checkSurjectiveMapping(const mv::LinkedData& linkedData, const std::uint32_
93104

94105
bool checkSelectionMapping(const mv::Dataset<Points>& colors, const mv::Dataset<Points>& positions) {
95106

96-
// Check if there is a mapping
97-
auto mapping = getSelectionMappingColorsToPositions(colors, positions);
98-
auto numTargetPoints = positions->getNumPoints();
107+
printLinkedDataNames(colors);
108+
printLinkedDataNames(positions);
99109

100110
// Check if there is a mapping
101111
auto [mapping, numTargetPoints] = getSelectionMappingColorsToPositions(colors, positions);
102112

103113
if (!mapping)
104114
std::tie(mapping, numTargetPoints) = getSelectionMappingPositionsToColors(positions, colors);
105115

116+
if (!mapping)
117+
std::tie(mapping, numTargetPoints) = getSelectionMappingPositionSourceToColors(positions, colors);
106118

107119
if (!mapping)
108120
return false;

src/MappingUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ std::pair<const mv::LinkedData*, unsigned int> getSelectionMappingColorsToPositi
3939

4040
std::pair<const mv::LinkedData*, unsigned int> getSelectionMappingPositionsToColors(const mv::Dataset<Points>& positions, const mv::Dataset<Points>& colors);
4141

42+
std::pair<const mv::LinkedData*, unsigned int> getSelectionMappingPositionSourceToColors(const mv::Dataset<Points>& positions, const mv::Dataset<Points>& colors);
43+
4244
// Check if the mapping is surjective, i.e. hits all elements in the target
4345
bool checkSurjectiveMapping(const mv::LinkedData& linkedData, const std::uint32_t numPointsInTarget);
4446

src/ScatterplotPlugin.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,33 @@ void ScatterplotPlugin::loadColors(const Dataset<Points>& pointsColor, const std
723723
}
724724
}
725725

726+
}
727+
else if ( // mapping from position data set to color data set
728+
const auto [selectionMapping, numPointsTarget] = getSelectionMappingPositionSourceToColors(_positionDataset, pointsColor);
729+
/* check if valid */ selectionMapping != nullptr // && numPointsTarget == _numPoints
730+
)
731+
{ // THIS DOES NOT WORK YET
732+
733+
// selectionMapping is from full source data (scVI) to pointsColor (means)
734+
// we need to use both the global indices and linked data mapping
735+
736+
const mv::SelectionMap::Map& linkedMap = selectionMapping->getMapping().getMap();
737+
738+
std::vector<std::uint32_t> globalIndices;
739+
_positionDataset->getGlobalIndices(globalIndices);
740+
741+
for (std::int32_t localColorIndex = 0; localColorIndex < globalIndices.size(); localColorIndex++) {
742+
743+
const auto& mappedIndices = linkedMap.at(globalIndices[localColorIndex]); // from full source (parent) to means
744+
745+
for (const auto& mappedIndex : mappedIndices) {
746+
if (mappedScalars[mappedIndex] != std::numeric_limits<float>::lowest())
747+
continue;
748+
749+
mappedScalars[localColorIndex] = scalars[mappedIndex];
750+
}
751+
}
752+
726753
}
727754
else {
728755
qWarning("Number of points used for coloring does not match number of points in data, aborting attempt to color plot");

0 commit comments

Comments
 (0)