Demonstrates how to run the C++ code and visualize the results using Matplotlib.
Contents
This example demonstrates how to:
- Read data from a file,
- Use Persistence1D class to extract extrema
- Filter results according to persistence values.
- Visualize results using Matplotlib scripts.
Results Visualization
- Run visualize.py
Matplotlib Plot of Results
Matplotlib Plot of Results
Code Documentation
#include "..\..\persistence1d\persistence1d.hpp"
#include <fstream>
using namespace std;
{
float currdata;
ifstream datafile;
ofstream outfile;
char * filename = "data.txt";
char * outfilename = "res.txt";
vector<int> min, max;
int globalMinIndex;
datafile.open(filename);
if (!datafile)
{
cout << "Cannot open data file for reading: " << filename << endl;
return -1;
}
while(datafile >> currdata)
{
data.push_back(currdata);
}
datafile.close();
{
cout << "ERROR" << endl;
}
float filterThreshold = 1.0;
outfile.open(outfilename);
if (!outfile)
return -2;
for (unsigned int i = 0; i < min.size() && i < max.size(); i++)
{
outfile << min[i] << endl;
outfile << max[i] << endl;
}
outfile << globalMinIndex << endl;
outfile.close();
return 0;
}