This function performs adjacent averaging smoothing on the curve. The parameter nOption specifies the methods to handle the boundary of the data.
int ocmath_adjave_smooth( const double * pYData, double * pYSmoothData, uint nSize, int nLeftRightPts, int nOption = EDGEPAD_NONE, bool bWeight = FALSE )
return OE_NOERROR for success, otherwise return OE_SMOOTHPTS_LT_ZERO
EX1
//Assume in the current graph, curve's XY data is in the first data plot. This piece //of code get the XY data of the curve from the first data plot and smooth on it. //The result is output in a new worksheet and the curve after smoothing will plot //in the original data plot with color red. void ocmath_adjave_smooth_ex1() { GraphLayer gl = Project.ActiveLayer(); if (!gl) { out_str("Active layer is not a graph."); return; } //get XY data from the first dataplot DataPlot dp = gl.DataPlots(0); DataRange dr; vector vx, vy; if(dp.GetDataRange(dr)) { DWORD dwPlotID; if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vy, &vx) < 0) { printf("get data failed GetData"); return; } } vector vSmooth; vSmooth.SetSize(vy.GetSize()); ocmath_adjave_smooth(vy, vSmooth, vy.GetSize(),3); // Total of seven points considered : 3 + 1 + 3 //new a worksheet to output the result Worksheet wks; wks.Create("Smooth"); wks.SetSize(-1, 2); wks.SetColDesignations("XY"); DataRange drOut; drOut.Add("X", wks, 0, 0, -1, 0); drOut.Add("Y", wks, 0, 1, -1, 1); drOut.SetData(&vSmooth, &vx); //plot the curve after smoothing int nPlot = gl.AddPlot(drOut, IDM_PLOT_LINE); dp = gl.DataPlots(nPlot); dp.SetColor(1);//set color to red }
origin.h