TTK
Loading...
Searching...
No Matches
MergeTreePrincipalGeodesicsUtils.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace ttk {
6 template <class dataType>
8 std::vector<dataType> &distances) {
9 dataType variance = 0.0;
10 for(auto distance : distances)
11 variance += distance * distance;
12 return variance / distances.size();
13 }
14
15 template <class dataType>
17 ftm::MergeTree<dataType> &barycenter,
18 std::vector<ftm::MergeTree<dataType>> &trees,
19 std::vector<std::vector<double>> &v,
20 std::vector<std::vector<double>> &v2,
21 std::vector<double> &ts,
22 bool globalVariance) {
23
24 std::vector<ftm::MergeTree<dataType>> allInterpolated(trees.size());
25 ftm::MergeTree<dataType> barycenterInterpolated;
26 if(not globalVariance) {
27 for(unsigned int i = 0; i < trees.size(); ++i)
28 getInterpolation<dataType>(
29 barycenter, v, v2, ts[i], allInterpolated[i]);
30 computeOneBarycenter<dataType>(allInterpolated, barycenterInterpolated);
31 }
32
33 std::vector<dataType> distances(trees.size());
34#ifdef TTK_ENABLE_OPENMP
35#pragma omp parallel for schedule(dynamic) \
36 num_threads(this->threadNumber_) if(parallelize_)
37#endif
38 for(unsigned int i = 0; i < trees.size(); ++i) {
39 if(globalVariance) {
40 computeOneDistance(barycenter, trees[i], distances[i], true);
41 } else {
43 barycenterInterpolated, allInterpolated[i], distances[i], true);
44 }
45 }
46 return computeVarianceFromDistances(distances);
47 }
48
49 template <class dataType>
51 ftm::MergeTree<dataType> &barycenter,
52 std::vector<ftm::MergeTree<dataType>> &trees) {
53 std::vector<double> ts;
54 std::vector<std::vector<double>> v, v2;
55 return computeExplainedVariance<dataType>(
56 barycenter, trees, v, v2, ts, true);
57 }
58
59 template <class dataType>
61 ftm::MergeTree<dataType> &barycenter,
62 std::vector<ftm::MergeTree<dataType>> &trees,
63 std::vector<std::vector<std::vector<double>>> &vS,
64 std::vector<std::vector<std::vector<double>>> &v2s,
65 std::vector<std::vector<double>> &ts) {
66 std::vector<ftm::MergeTree<dataType>> allInterpolated(trees.size());
67 ftm::MergeTree<dataType> barycenterInterpolated;
68 for(unsigned int i = 0; i < trees.size(); ++i) {
69 std::vector<double> treeTs(ts.size());
70 for(unsigned int j = 0; j < ts.size(); ++j)
71 treeTs[j] = ts[j][i];
72 getMultiInterpolation<dataType>(
73 barycenter, vS, v2s, treeTs, allInterpolated[i]);
74 }
75 computeOneBarycenter<dataType>(allInterpolated, barycenterInterpolated);
76
77 std::vector<dataType> distances(trees.size());
78#ifdef TTK_ENABLE_OPENMP
79#pragma omp parallel for schedule(dynamic) \
80 num_threads(this->threadNumber_) if(parallelize_)
81#endif
82 for(unsigned int i = 0; i < trees.size(); ++i) {
84 barycenterInterpolated, allInterpolated[i], distances[i], true);
85 }
86 return computeVarianceFromDistances(distances);
87 }
88
89 template <class dataType>
91 ftm::MergeTree<dataType> &barycenter,
92 std::vector<std::vector<double>> &v,
93 std::vector<std::vector<double>> &v2,
94 std::vector<double> &ts,
95 std::vector<double> &distances,
96 bool useDoubleInput,
97 bool isFirstInput) {
98 ftm::MergeTree<dataType> extremity1, extremity2;
99 getInterpolation(barycenter, v, v2, 0.0, extremity1);
100 getInterpolation(barycenter, v, v2, 1.0, extremity2);
101 dataType distance;
102 computeOneDistance<dataType>(
103 extremity1, extremity2, distance, false, useDoubleInput, isFirstInput);
104
105 double tBarycenter = 0.0;
106 for(auto t : ts)
107 tBarycenter += t / ts.size();
108
109 distances.resize(ts.size());
110 for(unsigned int i = 0; i < ts.size(); ++i)
111 distances[i] = (ts[i] - tBarycenter) * distance;
112 }
113
114 template <class dataType>
116 ftm::MergeTree<dataType> &barycenter,
117 std::vector<std::vector<double>> &v,
118 std::vector<std::vector<double>> &v2,
119 std::vector<double> &ts) {
120 std::vector<double> distances;
121 computeProjectionDistances(barycenter, v, v2, ts, distances);
122 return computeVarianceFromDistances(distances);
123 }
124
125 template <class dataType>
127 ftm::MergeTree<dataType> &barycenter,
128 std::vector<std::vector<double>> &v,
129 std::vector<std::vector<double>> &v2,
130 ftm::MergeTree<dataType> &barycenter2,
131 std::vector<std::vector<double>> &trees2V,
132 std::vector<std::vector<double>> &trees2V2,
133 std::vector<double> &ts) {
134 std::vector<double> distances, distances2;
135 computeProjectionDistances(barycenter, v, v2, ts, distances, true);
137 barycenter2, trees2V, trees2V2, ts, distances2, true, false);
138 for(unsigned int i = 0; i < distances.size(); ++i)
139 distances[i] = mixDistances(distances[i], distances2[i]);
140 return computeVarianceFromDistances(distances);
141 }
142} // namespace ttk
void computeOneDistance(ftm::MergeTree< dataType > &tree1, ftm::MergeTree< dataType > &tree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &matching, dataType &distance, bool isCalled=false, bool useDoubleInput=false, bool isFirstInput=true)
double mixDistances(dataType distance1, dataType distance2)
void getInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< double * > &v, std::vector< double * > &v2, size_t vSize, double t, ftm::MergeTree< dataType > &interpolated, bool transposeVector=true)
void computeProjectionDistances(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts, std::vector< double > &distances, bool useDoubleInput=false, bool isFirstInput=true)
double computeExplainedVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts, bool computeGlobalVariance=false)
dataType computeVarianceFromDistances(std::vector< dataType > &distances)
double computeSurfaceExplainedVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< std::vector< double > > &ts)
double computeExplainedVarianceT(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts)
double computeGlobalVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees)
The Topology ToolKit.