-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMappingUtils.h
More file actions
59 lines (45 loc) · 3.02 KB
/
MappingUtils.h
File metadata and controls
59 lines (45 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <Dataset.h>
#include <LinkedData.h>
#include <PointData/PointData.h>
#include <Set.h>
#include <cstdint>
#include <functional>
#include <utility>
// This only checks the immedeate parent and is deliberately not recursive
// We might consider the latter in the future, but might need to cover edge cases
inline bool parentHasSameNumPoints(const mv::Dataset<mv::DatasetImpl> data, const mv::Dataset<Points>& other) {
if (!data->isDerivedData())
return false;
const auto parent = data->getParent();
if (parent->getDataType() != PointType)
return false;
const auto parentPoints = mv::Dataset<Points>(parent);
return parentPoints->getNumPoints() == other->getNumPoints();
}
// Is the data derived and does it's full source data have same number of points as the other data
inline bool fullSourceHasSameNumPoints(const mv::Dataset<mv::DatasetImpl> data, const mv::Dataset<Points>& other) {
if (!data->isDerivedData())
return false;
return data->getSourceDataset<Points>()->getFullDataset<Points>()->getNumPoints() == other->getNumPoints();
}
using LinkedDataCondition = std::function<bool(const mv::LinkedData& linkedData, const mv::Dataset<Points>& target)>;
/* Returns a mapping (linked data) from source that fulfils a given condition based on target, e.g.
auto checkMapping = [](const mv::LinkedData& linkedData, const mv::Dataset<Points>& target) -> bool {
return linkedData.getTargetDataset() == target;
};
This function will return the first match of the condition
*/
std::pair<const mv::LinkedData*, std::uint64_t> getSelectionMapping(const mv::Dataset<Points>& source, const mv::Dataset<Points>& target, LinkedDataCondition checkMapping);
// Returns a mapping (linked data) from colors whose target is positions or whose target's parent has the same number of points as positions
std::pair<const mv::LinkedData*, std::uint64_t> getSelectionMappingColorsToPositions(const mv::Dataset<Points>& colors, const mv::Dataset<Points>& positions);
// Returns a mapping (linked data) from positions whose target is colors or
// a mapping from positions' parent whose target is colors if the number of data points match
std::pair<const mv::LinkedData*, std::uint64_t> getSelectionMappingPositionsToColors(const mv::Dataset<Points>& positions, const mv::Dataset<Points>& colors);
// Returns a mapping (linked data) from positions' source data whose target is colors
std::pair<const mv::LinkedData*, std::uint64_t> getSelectionMappingPositionSourceToColors(const mv::Dataset<Points>& positions, const mv::Dataset<Points>& colors);
// Check if the mapping is surjective, i.e. hits all elements in the target
bool checkSurjectiveMapping(const mv::LinkedData& linkedData, const std::uint32_t numPointsInTarget);
// returns whether there is a selection map from colors to positions or positions to colors (or respective parents)
// checks whether the mapping covers all elements in the target
bool checkSelectionMapping(const mv::Dataset<Points>& colors, const mv::Dataset<Points>& positions);