Persistence 1D incl. Reconstruct1D  1.3
Finding extrema in one dimensional data, filtering them by persistence and reconstructing smooth functions
Macros | Functions
persistence1d_driver.cpp File Reference

Use this program to run Persistence1D on data in text files. More...

#include "persistence1d.hpp"
#include <fstream>
#include <string>
#include <cstring>

Go to the source code of this file.

Macros

#define MATLAB   "-MATLAB"
 

Functions

bool ReadFileToVector (char *filename, vector< float > &data)
 Tries to open the input file and read its contents to a float vector. More...
 
void WriteExtremaToFile (char *filename, vector< TPairedExtrema > pairs, const int idxGlobalMin)
 Writes indices of extrema features to file, sorted according to their persistence. More...
 
bool ParseCmdLine (int argc, char *argv[], float &threshold, bool &matlabIndexing)
 Parses user command line. More...
 
int main (int argc, char *argv[])
 Main function - reads a file specified as a command line argument. More...
 

Detailed Description

Use this program to run Persistence1D on data in text files.

This file contains a sample code for using Persistence1D on data in text files, and can be used to directly run Persistence1D on data in a single text file.

Command line: persistence1d_driver.exe <filename> [threshold] [-MATLAB]

Definition in file persistence1d_driver.cpp.

Macro Definition Documentation

◆ MATLAB

#define MATLAB   "-MATLAB"

Definition at line 30 of file persistence1d_driver.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function - reads a file specified as a command line argument.

runs persistence, writes the indices of extrema to a file called inputfilename_res.txt.

Overwrites files with the same name.

Input file name is assumed to end with a three letter extension.

Definition at line 76 of file persistence1d_driver.cpp.

◆ ParseCmdLine()

bool ParseCmdLine ( int  argc,
char *  argv[],
float &  threshold,
bool &  matlabIndexing 
)

Parses user command line.

Checks if the user set a threshold value or wants MATLAB indexing.

Definition at line 167 of file persistence1d_driver.cpp.

◆ ReadFileToVector()

bool ReadFileToVector ( char *  filename,
vector< float > &  data 
)

Tries to open the input file and read its contents to a float vector.

Input is assumed to be formatted as one number per line, in float compatible notation.

Ignores any lines which do not conform to this assumption.

Number of data entries is assumed to be smaller than vector's class maximum size - this is not checked!

Parameters
[in]filenameName of input file with float data.
[out]dataData is written to this vector.

Definition at line 122 of file persistence1d_driver.cpp.

◆ WriteExtremaToFile()

void WriteExtremaToFile ( char *  filename,
vector< TPairedExtrema pairs,
const int  idxGlobalMin 
)

Writes indices of extrema features to file, sorted according to their persistence.

If no features were found, writes an empty file.

Overwrites any existing file with the same name.

Parameters
[in]filenameName of output file.
[in]pairsPairs of extrema to write.
[in]idxGlobalMinIndex of the global minimum.

Definition at line 146 of file persistence1d_driver.cpp.