TTK
Loading...
Searching...
No Matches
PersistenceCurve.cpp
Go to the documentation of this file.
1#include <Geometry.h>
2#include <PersistenceCurve.h>
3
5 setDebugMsgPrefix("PersistenceCurve");
6}
7
8int ttk::PersistenceCurve::execute(std::array<PlotType, 4> &plots,
9 const DiagramType &diagram) const {
10
11 const auto epsilon{Geometry::powIntTen(-REAL_SIGNIFICANT_DIGITS)};
12
13 // copy input diagram and sort the copy by pair persistence
14 auto sortedDiagram{diagram};
15
16 TTK_PSORT(this->threadNumber_, sortedDiagram.begin(), sortedDiagram.end(),
17 [](const PersistencePair &a, const PersistencePair &b) {
18 return a.persistence() < b.persistence();
19 });
20
21 for(const auto &pair : sortedDiagram) {
22 // per dimension
23 plots[pair.dim].emplace_back(
24 std::max(pair.persistence(), epsilon), plots[pair.dim].size());
25 // all pairs
26 plots[3].emplace_back(
27 std::max(pair.persistence(), epsilon), plots[3].size());
28 }
29
30 for(auto &plot : plots) {
31 for(auto &el : plot) {
32 el.second = plot.size() - el.second;
33 }
34 }
35
36 // look at the first finite pair of dimension 1
37 const auto firstPairDim1 = std::find_if(
38 diagram.begin(), diagram.end(),
39 [](const PersistencePair &p) { return p.dim == 1 && p.isFinite; });
40
41 // if critical type of death is maximum, the diagram was computed on
42 // a 2D dataset
43 const auto datasetIs2D
44 = firstPairDim1 != diagram.end()
45 && firstPairDim1->death.type == ttk::CriticalType::Local_maximum;
46
47 // enforce plots[2] is for saddle-max pairs
48 if(datasetIs2D) {
49 plots[2] = std::move(plots[1]);
50 }
51
52 return 0;
53}
#define TTK_PSORT(NTHREADS,...)
Parallel sort macro.
Definition: OpenMP.h:46
#define REAL_SIGNIFICANT_DIGITS
Definition: Os.h:46
void setDebugMsgPrefix(const std::string &prefix)
Definition: Debug.h:364
int execute(std::array< PlotType, 4 > &plots, const DiagramType &diagram) const
Compute the Persistence Curve from the input Diagram.
T powIntTen(const int n)
Compute the nth power of ten.
Definition: Geometry.h:360
std::vector< PersistencePair > DiagramType
Persistence Diagram type as a vector of Persistence pairs.