2.1.22.4.3 ocmath_adjave_smooth
Description
This function performs adjacent averaging smoothing on the curve.
The parameter nOption specifies the methods to handle the boundary of the data.
Syntax
int ocmath_adjave_smooth( const double * pYData, double * pYSmoothData, uint nSize, int nLeftRightPts, int nOption = EDGEPAD_NONE, bool bWeight = FALSE )
Parameters
- pYData
- [input] Pointer to data of type double to smooth
- pYSmoothData
- [output] Pointer to data of type double to receive results
- nSize
- [input] Size of dataset
- nLeftRightPts
- [input] Number of points to one side of symmetric window(left or right) of given point.
- Zero leaves the data unchanged.
- nOption
- [input] the methods to handle the boundary of data. It can take the following values:
- EDGEPAD_ZERO pad with zeros
- EDGEPAD_REFLECT pad reflect, end points are repeated such that on the left, [-1] = [0], [-2] = [1], [-3] = [2] and etc
- EDGEPAD_REPEAT pad with [0] values the left and with [nSize-1] on the right
- EDGEPAD_EXTRAPOLATE linear extrapolation
- EDGEPAD_PERIODIC pad periodic, [-1] = [nSize -1], [-2] = [nSize - 2]
- bWeight
- [input] weight smooth or not. default is not(FALSE)
Return
return OE_NOERROR for success, otherwise return OE_SMOOTHPTS_LT_ZERO
Examples
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
}
Remark
See Also
ocmath_savitsky_golay
Header to Include
origin.h
Reference
|