TTK
Loading...
Searching...
No Matches
TrackingFromCriticalPoints.h
Go to the documentation of this file.
1
10
11#pragma once
12
13// base code includes
14#include <DataTypes.h>
16#include <Triangulation.h>
17
18namespace ttk {
19
20 using trackingTuple = std::tuple<int, int, std::vector<SimplexId>>;
21
22 class TrackingFromCriticalPoints : virtual public Debug {
23
24 private:
25 double relativeEpsilon_{10e-1};
26 double meshDiameter_{1};
27 double tolerance_{10e-3};
28 int assignmentMethod_{0};
29 double assignmentPrecision{0.01};
30 double xWeight_{1};
31 double yWeight_{1};
32 double zWeight_{1};
33 double fWeight_{0};
34
35 public:
37 this->setDebugMsgPrefix("TrackingFromCriticalPoint");
38 }
39
40 void setMeshDiameter(double r) {
41 meshDiameter_ = r;
42 }
43
44 void setEpsilon(double e) {
45 relativeEpsilon_ = e;
46 }
47
48 void setTolerance(double t) {
49 tolerance_ = t;
50 }
51
52 void setAssignmentPrecision(double p) {
53 assignmentPrecision = p;
54 }
55
56 void setAssignmentMethod(int a) {
57 if(a == 0 || a == 1) {
58 assignmentMethod_ = a;
59 }
60 }
61
62 void setWeights(double PX, double PY, double PZ, double PF) {
63 xWeight_ = PX;
64 yWeight_ = PY;
65 zWeight_ = PZ;
66 fWeight_ = PF;
67 }
68
70 const DiagramType &d2) {
71 double maxScalar = d1[0].birth.sfValue;
72 double minScalar = d1[0].birth.sfValue;
73
74 for(unsigned int i = 0; i < d1.size(); i++) {
75 maxScalar = std::max(maxScalar, d1[i].birth.sfValue);
76 maxScalar = std::max(maxScalar, d1[i].death.sfValue);
77 minScalar = std::min(minScalar, d1[i].birth.sfValue);
78 minScalar = std::min(minScalar, d1[i].death.sfValue);
79 }
80
81 for(unsigned int i = 0; i < d2.size(); i++) {
82 maxScalar = std::max(maxScalar, d2[i].birth.sfValue);
83 maxScalar = std::max(maxScalar, d2[i].death.sfValue);
84 minScalar = std::min(minScalar, d2[i].birth.sfValue);
85 minScalar = std::min(minScalar, d2[i].death.sfValue);
86 }
87
88 return std::sqrt(std::pow(meshDiameter_, 2)
89 + fWeight_ * std::pow(maxScalar - minScalar, 2));
90 }
91
92 void
93 performMatchings(const std::vector<DiagramType> &persistenceDiagrams,
94 std::vector<std::vector<MatchingType>> &maximaMatchings,
95 std::vector<std::vector<MatchingType>> &sad_1_Matchings,
96 std::vector<std::vector<MatchingType>> &sad_2_Matchings,
97 std::vector<std::vector<MatchingType>> &minimaMatchings,
98 std::vector<std::vector<SimplexId>> &maxMap,
99 std::vector<std::vector<SimplexId>> &sad_1Map,
100 std::vector<std::vector<SimplexId>> &sad_2Map,
101 std::vector<std::vector<SimplexId>> &minMap);
102 void performTrackings(
103 const std::vector<DiagramType> &persistenceDiagrams,
104 const std::vector<std::vector<MatchingType>> &maximaMatchings,
105 const std::vector<std::vector<MatchingType>> &sad_1_Matchings,
106 const std::vector<std::vector<MatchingType>> &sad_2_Matchings,
107 const std::vector<std::vector<MatchingType>> &minimaMatchings,
108 const std::vector<std::vector<SimplexId>> &maxMap,
109 const std::vector<std::vector<SimplexId>> &sad_1Map,
110 const std::vector<std::vector<SimplexId>> &sad_2Map,
111 const std::vector<std::vector<SimplexId>> &minMap,
112 std::vector<trackingTuple> &allTrackings,
113 std::vector<std::vector<double>> &allTrackingsCost,
114 std::vector<std::vector<double>> &allTrackingsInstantPersistences,
115 unsigned int (&typesArrayLimits)[3]);
116
117 private:
118 double computeRelevantPersistence(const DiagramType &d1,
119 const DiagramType &d2) {
120 const auto sp = this->tolerance_;
121 const double s = sp > 0.0 && sp < 100.0 ? sp / 100.0 : 0;
122
123 std::vector<double> toSort(d1.size() + d2.size());
124 for(size_t i = 0; i < d1.size(); ++i) {
125 const auto &t = d1[i];
126 toSort[i] = std::abs(t.persistence());
127 }
128 for(size_t i = 0; i < d2.size(); ++i) {
129 const auto &t = d2[i];
130 toSort[d1.size() + i] = std::abs(t.persistence());
131 }
132
133 const auto minVal = *std::min_element(toSort.begin(), toSort.end());
134 const auto maxVal = *std::max_element(toSort.begin(), toSort.end());
135 return s * (maxVal - minVal);
136 }
137
138 // Compute L_p distance betweem (p,f(p)) and (q,f(q)) where p and q are
139 // critical points
140
141 double criticalPointDistance(const std::array<float, 3> &coords_p1,
142 const double &sfValue_p1,
143 const std::array<float, 3> &coords_p2,
144 const double &sfValue_p2,
145 const int &p);
146
147 // Sort the critical points by types
148
149 void sortCriticalPoint(const DiagramType &d,
150 const double minimumRelevantPersistence,
151 std::vector<std::array<float, 3>> &maxCoords,
152 std::vector<std::array<float, 3>> &sad_1Coords,
153 std::vector<std::array<float, 3>> &sad_2Coords,
154 std::vector<std::array<float, 3>> &minCoords,
155 std::vector<double> &maxScalar,
156 std::vector<double> &sad1Scalar,
157 std::vector<double> &sad_2Scalar,
158 std::vector<double> &minScalar,
159 std::vector<SimplexId> &mapMax,
160 std::vector<SimplexId> &mapSad_1,
161 std::vector<SimplexId> &mapSad_2,
162 std::vector<SimplexId> &mapMin);
163
164 void buildCostMatrix(const std::vector<std::array<float, 3>> &coords_1,
165 const std::vector<double> &sfValues_1,
166 const std::vector<std::array<float, 3>> &coords_2,
167 const std::vector<double> &sfValues_2,
168 const float &costDeathBirth,
169 std::vector<std::vector<double>> &matrix);
170
171 void localToGlobalMatching(const std::vector<int> &startMap,
172 const std::vector<int> &endMap,
173 const std::vector<double> &startPersistence,
174 const std::vector<double> &endPersistence,
175 std::vector<MatchingType> &matchings,
176 std::vector<MatchingType> &matchingsPersistence);
177
178 void assignmentSolver(std::vector<std::vector<double>> &costMatrix,
179 std::vector<ttk::MatchingType> &matching);
180
181 int computeGlobalId(const DiagramType &persistenceDiagram,
182 const CriticalType &type,
183 const SimplexId &id);
184
185 void performTrackingForOneType(
186 const std::vector<DiagramType> &persistenceDiagrams,
187 const std::vector<std::vector<MatchingType>> &matching,
188 const std::vector<std::vector<SimplexId>> &map,
189 const CriticalType &currentType,
190 std::vector<trackingTuple> &tracking,
191 std::vector<std::vector<double>> &trackingCosts,
192 std::vector<std::vector<double>> &trackingsInstantPersistences);
193 };
194} // namespace ttk
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
void setWeights(double PX, double PY, double PZ, double PF)
void performMatchings(const std::vector< DiagramType > &persistenceDiagrams, std::vector< std::vector< MatchingType > > &maximaMatchings, std::vector< std::vector< MatchingType > > &sad_1_Matchings, std::vector< std::vector< MatchingType > > &sad_2_Matchings, std::vector< std::vector< MatchingType > > &minimaMatchings, std::vector< std::vector< SimplexId > > &maxMap, std::vector< std::vector< SimplexId > > &sad_1Map, std::vector< std::vector< SimplexId > > &sad_2Map, std::vector< std::vector< SimplexId > > &minMap)
void performTrackings(const std::vector< DiagramType > &persistenceDiagrams, const std::vector< std::vector< MatchingType > > &maximaMatchings, const std::vector< std::vector< MatchingType > > &sad_1_Matchings, const std::vector< std::vector< MatchingType > > &sad_2_Matchings, const std::vector< std::vector< MatchingType > > &minimaMatchings, const std::vector< std::vector< SimplexId > > &maxMap, const std::vector< std::vector< SimplexId > > &sad_1Map, const std::vector< std::vector< SimplexId > > &sad_2Map, const std::vector< std::vector< SimplexId > > &minMap, std::vector< trackingTuple > &allTrackings, std::vector< std::vector< double > > &allTrackingsCost, std::vector< std::vector< double > > &allTrackingsInstantPersistences, unsigned int(&typesArrayLimits)[3])
double computeBoundingBoxRadius(const DiagramType &d1, const DiagramType &d2)
TTK base package defining the standard types.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
CriticalType
default value for critical index
Definition DataTypes.h:88
std::tuple< int, int, std::vector< SimplexId > > trackingTuple
std::vector< PersistencePair > DiagramType
Persistence Diagram type as a vector of Persistence pairs.