Average multiple curves with interpolation by length parameter.
int ocmath_ave_multiple_curves_by_length_parameter( UINT nSize, const OneCurveData * pCurves, int * pnAveSize, double * pAveX, double * pAveY, double * pAveErr = NULL, int nErrType = AVMC_SE, int * pAveCount = NULL, int nMethod = INTERP_TYPE_LINEAR, double* pAveMin = NULL, double* pAveMax = NULL, int iOption = OPTION_EXTRAPOLATE )
Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.
EX1
//This example assume the active window is a graph. void ocmath_ave_multicurves_by_length_parameter_ex1() { GraphLayer gl = Project.ActiveLayer(); if (!gl) { return; } int nPlots = gl.DataPlots.Count(); OneCurveData* multiCurveData = (OneCurveData*) malloc(sizeof(OneCurveData)*nPlots); double* xx; double* yy; int nAveSize = 0; for(int ii = 0; ii < nPlots; ii++) { DataPlot dp = gl.DataPlots(ii); DataRange dr; vector vDatax, vDatay; if(dp.GetDataRange(dr)) { DWORD dwPlotID; if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vDatay, &vDatax) < 0) { printf("get_plot_data failed GetData"); return; } } int nSize = vDatay.GetSize(); xx = (double*) malloc (sizeof(double) * nSize); yy = (double*) malloc (sizeof(double) * nSize); memcpy(xx, vDatax, sizeof(double)*nSize); memcpy(yy, vDatay, sizeof(double)*nSize); multiCurveData[ii].nSize = nSize; multiCurveData[ii].pX = xx; multiCurveData[ii].pY = yy; nAveSize += nSize; } vector vxAve(nAveSize); vector vyAve(nAveSize); vector vErr(nAveSize); vector<int> vCount(nAveSize); int nRet = ocmath_ave_multiple_curves_by_length_parameter (nPlots, multiCurveData, &nAveSize, vxAve, vyAve, vErr, AVMC_SE, vCount); if( nRet!=OE_NOERROR ) { printf("error code: %d\n", nRet); return; } vxAve.SetSize(nAveSize); vyAve.SetSize(nAveSize); vErr.SetSize(nAveSize); vCount.SetSize(nAveSize); for (ii = 0; ii < nPlots; ii++) { free(multiCurveData[ii].pX); free(multiCurveData[ii].pY); } free(multiCurveData); WorksheetPage wksPage; wksPage.Create(); Worksheet wksAve = wksPage.Layers(0); wksAve.SetSize(-1, 2); wksAve.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X); wksAve.Columns(1).SetType(OKDATAOBJ_DESIGNATION_Y); DataRange drOut; drOut.Add("X", wksAve, 0, 0, -1, 0); drOut.Add("Y", wksAve, 0, 1, -1, 1); drOut.SetData(&vyAve, &vxAve); gl.AddPlot(drOut, IDM_PLOT_SCATTER); }
This function averages multiple curves with interpolation by length parameter.
if number of curve = 1, if memory enough pAveX will be curve's X value and pAveY will be curve's Y value, else return non-zero error code.
If number of curve > 1, it assumes that all curves's X value are not monotonic but consistent, so before average please check curves order by ocmath_check_order_multiple_curves.
origin.h