Persistence 1D incl. Reconstruct1D  1.3
Finding extrema in one dimensional data, filtering them by persistence and reconstructing smooth functions
SimpleDataVector.cpp
Go to the documentation of this file.
1 /*! \file SimpleDataVector.cpp
2  Basic example which demonstrates how to use the Persistence1D class for finding extrema features.
3 */
4 /*! \example SimpleDataVector.cpp
5 
6  Basic example which demonstrates how to use the Persistence1D class for finding extrema features.
7 
8  # Contents
9  This example demonstrates how to:
10  -# Create a data vector.
11  -# Run persistence on data vector.
12  -# Filter extrema by a persistence threshold.
13  -# Print the filtered extrema.
14 
15  # Expected Output
16  Output reference file: [persistence_base_dir]\\src\\examples\\SimpleDataVector\\SimpleDataVectorRes.ref
17  with contents:
18  \include SimpleDataVectorRes.ref
19 
20  # Code Documentation
21 */
22 
23 #include "..\..\persistence1d\persistence1d.hpp"
24 
25 using namespace std;
26 using namespace p1d;
27 
28 int main()
29 {
30  //Create some data
31  vector< float > data;
32  data.push_back(2.0); data.push_back(5.0); data.push_back(7.0);
33  data.push_back(-12.0); data.push_back(-13.0); data.push_back(-7.0);
34  data.push_back(10.0); data.push_back(18.0); data.push_back(6.0);
35  data.push_back(8.0); data.push_back(7.0); data.push_back(4.0);
36 
37  //Run persistence on data - this is the main call.
38  Persistence1D p;
40 
41  //Get all extrema with a persistence larger than 10.
42  vector< TPairedExtrema > Extrema;
43  p.GetPairedExtrema(Extrema, 10);
44 
45  //Print all found pairs - pairs are sorted ascending wrt. persistence.
46  for(vector< TPairedExtrema >::iterator it = Extrema.begin(); it != Extrema.end(); it++)
47  {
48  cout << "Persistence: " << (*it).Persistence
49  << " minimum index: " << (*it).MinIndex
50  << " maximum index: " << (*it).MaxIndex
51  << std::endl;
52  }
53 
54  //Also, print the global minimum.
55  cout << "Global minimum index: " << p.GetGlobalMinimumIndex()
56  << " Global minimum value: " << p.GetGlobalMinimumValue() << endl;
57 
58  /*
59  Note that filtering and printing can also be done with one single function call:
60  p.PrintResults(10);
61  */
62 
63  return 0;
64 }
int main()
int GetGlobalMinimumIndex(const bool matlabIndexing=false) const
Returns the index of the global minimum.
bool RunPersistence(const std::vector< float > &InputData)
Call this function with a vector of one dimensional data to find extrema features in the data.
Finds extrema and their persistence in one-dimensional data.
bool GetPairedExtrema(std::vector< TPairedExtrema > &pairs, const float threshold=0, const bool matlabIndexing=false) const
Use this method to get the results of RunPersistence.
float GetGlobalMinimumValue() const
Returns the value of the global minimum.