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

Main Matlab-C++ Interface file. More...

#include <matrix.h>
#include <mex.h>
#include <algorithm>
#include <vector>
#include "..\src\persistence1d\persistence1d.hpp"

Go to the source code of this file.

Macros

#define NUM_INPUT_VARIABLES   1
 
#define NUM_OUTPUT_VARIABLES   5
 
#define MATLAB_INDEXING   true
 
#define NO_FILTERING   0.0
 

Functions

bool MxFloatArrayToFloatVector (const mxArray *input, std::vector< float > &data)
 Fills a given float data vector with values from float mxArray. More...
 
mxArray * VectorToMxSingleArray (const std::vector< float > data)
 Copies vector<float> data to 1-d MATLAB matrix. More...
 
mxArray * VectorToMxSingleArray (const std::vector< int > data)
 Copies vector<int> data to 1-d Single-type MATLAB matrix. More...
 
mxArray * VectorToMxSingleArray (const std::vector< TPairedExtrema > data)
 Creates a 1-d Single-Type MATLAB matrix with the persistence values from a vector of TPairedExtrema. More...
 
mxArray * ScalarToMxSingleArray (const float data)
 Creates a 1x1 Single Type Matlab matrix from a single float value. More...
 
mxArray * ScalarToMxSingleArray (const int data)
 
bool CheckInput (const int nOuts, mxArray *outs[], const int nIns, const mxArray *ins[])
 Validates the following for the input: More...
 
void WriteVectorToMexOutput (const std::vector< float > data)
 Displays float-vector content in Matlab output window. More...
 
void WriteInputToVector (const mxArray *inputs[], std::vector< float > &data)
 Assumption - first input argument is a vector of 1-d data,. More...
 
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 Main MATLAB interface. More...
 

Detailed Description

Main Matlab-C++ Interface file.

Compile with MEX to use as MATLAB interface for Persistence1D class. Tested on 32-bits only, MATLAB 2011b and above.

Usage: [MinIndices MaxIndices Persistence GlobalMinIdx GlobalMinVal] = run_persistence1d(single(data))

Supports input in single format. Output is INT32 and SINGLE.

To see output messages in Matlab, uncomment line 38 before compilation.

Parameters
[in]dataA vector of data, sorted according to coordinates. This should contain only data values to be sorted. Assumes the data is one dimensional.
[out]MinIndicesVector of (Matlab compatible) indices of local maxima.
[out]MaxIndicesVector of (Matlab compatible) indices of local minima.
[out]PersistenceVector of persistence of the paired extrema whose indices live in MinIndices and MaxIndices
[out]GlobalMinIdxIndex (Matlab compatible) of global minimum.
[out]GlobalMinValValue of global minimum.

Definition in file run_persistence1d.cpp.

Macro Definition Documentation

◆ MATLAB_INDEXING

#define MATLAB_INDEXING   true

Definition at line 35 of file run_persistence1d.cpp.

◆ NO_FILTERING

#define NO_FILTERING   0.0

Definition at line 36 of file run_persistence1d.cpp.

◆ NUM_INPUT_VARIABLES

#define NUM_INPUT_VARIABLES   1

Definition at line 33 of file run_persistence1d.cpp.

◆ NUM_OUTPUT_VARIABLES

#define NUM_OUTPUT_VARIABLES   5

Definition at line 34 of file run_persistence1d.cpp.

Function Documentation

◆ CheckInput()

bool CheckInput ( const int  nOuts,
mxArray *  outs[],
const int  nIns,
const mxArray *  ins[] 
)

Validates the following for the input:

  • Total number of arguments = 1
  • The only arguments should be data, in a 1-d matrix
  • Matrix data type is single (AKA float)
  • No complex data
  • No char data

Validates the following for the output:

  • There are three output variables
Parameters
[in]nOutsNumber of output variables.
[in]outsArray of pointers to output matrices.
[in]nInsNumber of input variables.
[in]insArray of pointers in input matrices.

Definition at line 233 of file run_persistence1d.cpp.

◆ mexFunction()

void mexFunction ( int  nlhs,
mxArray *  plhs[],
int  nrhs,
const mxArray *  prhs[] 
)

Main MATLAB interface.

Parameters
[in,out]nlhsNumber of left hand (output) matrices.
[in,out]plhsPointers to left hand (output) matrices.
[in]nrhsNumber of right hand (input) matrices.
[in]prhsPointers to right hand (input) matrices.

Definition at line 63 of file run_persistence1d.cpp.

◆ MxFloatArrayToFloatVector()

bool MxFloatArrayToFloatVector ( const mxArray *  input,
std::vector< float > &  data 
)

Fills a given float data vector with values from float mxArray.

Warning - does not check if mxArray format is single.

Definition at line 128 of file run_persistence1d.cpp.

◆ ScalarToMxSingleArray() [1/2]

mxArray * ScalarToMxSingleArray ( const float  data)

Creates a 1x1 Single Type Matlab matrix from a single float value.

Definition at line 152 of file run_persistence1d.cpp.

◆ ScalarToMxSingleArray() [2/2]

mxArray * ScalarToMxSingleArray ( const int  data)

Definition at line 160 of file run_persistence1d.cpp.

◆ VectorToMxSingleArray() [1/3]

mxArray * VectorToMxSingleArray ( const std::vector< float >  data)

Copies vector<float> data to 1-d MATLAB matrix.

Parameters
[in]dataA vector of float to copy.

Definition at line 170 of file run_persistence1d.cpp.

◆ VectorToMxSingleArray() [2/3]

mxArray * VectorToMxSingleArray ( const std::vector< int >  data)

Copies vector<int> data to 1-d Single-type MATLAB matrix.

Parameters
[in]datadata to be copied to Matlab.

Definition at line 188 of file run_persistence1d.cpp.

◆ VectorToMxSingleArray() [3/3]

mxArray * VectorToMxSingleArray ( const std::vector< TPairedExtrema data)

Creates a 1-d Single-Type MATLAB matrix with the persistence values from a vector of TPairedExtrema.

Parameters
[in]dataVector of paired extrema

Definition at line 205 of file run_persistence1d.cpp.

◆ WriteInputToVector()

void WriteInputToVector ( const mxArray *  inputs[],
std::vector< float > &  data 
)

Assumption - first input argument is a vector of 1-d data,.

Copies the content of mxArray to a vector.

Parameters
[in]inputsArray of MATLAB matrix data, as received by mexFunction (MATLAB entrance point)
[out]dataVector which contain data for Persistence

Definition at line 293 of file run_persistence1d.cpp.

◆ WriteVectorToMexOutput()

void WriteVectorToMexOutput ( const std::vector< float >  data)

Displays float-vector content in Matlab output window.

Parameters
[in]dataFloat vector to write

Definition at line 276 of file run_persistence1d.cpp.