ocmath_init_baseline_by_connect_ends

 

Description

Init baseline depending on two end points of the curve.

Syntax

int ocmath_init_baseline_by_connect_ends( UINT lSize, const double * px, const double * py, UINT lBaselinePoints, double * pbx, double * pby )

Parameters

lSize
[input] size of px, py
px
[input] it contains curve's X coordinate's datas
py
[input] it contains curve's Y coordinate's datas
lBaselinePoints
[input] size of pxb, pyb
pbx
[output] X coordinate's datas of baseline
pby
[output] Y coordinate's datas of baseline

Return

Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.

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 get the baseline.
//The result is output in a new worksheet and the baseline will plot in the original 
//data plot.
void ocmath_init_baseline_by_connect_ends_ex1()
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        return;
    }
 
    //get data from the first dataplot
    DataPlot dp = gl.DataPlots(0);        
    DataRange dr;
    vector vxData, vyData;
    if(dp.GetDataRange(dr))
    {
        DWORD dwPlotID;
        if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vyData, &vxData) < 0)
        {
            printf("get_plot_data failed GetData");
            return;
        }
    }
 
    uint nDataSize = vxData.GetSize();
    vector vxb, vyb;
    vxb.SetSize(nDataSize);
    vyb.SetSize(nDataSize);
    int nRet = ocmath_init_baseline_by_connect_ends(nDataSize, vxData, vyData, nDataSize, vxb, vyb);
    if( nRet < OE_NOERROR )
    {
        printf("error code: %d\n", nRet);
        return;
    }
    
    //new a worksheet to output the result
    WorksheetPage wksPage;
    wksPage.Create();
    Worksheet wksResult = wksPage.Layers(0);
    //wksResult.AddCol("Indices");
    int nXCol, nYCol;
    nXCol = wksResult.AddCol("X");
    nYCol = wksResult.AddCol("Y");
    //wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(1).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Y);
    
    DataRange drOut;
    drOut.Add("X", wksResult, 0, nXCol, -1, nXCol);
    drOut.Add("Y", wksResult, 0, nYCol, -1, nYCol);
    drOut.SetData(&vyb, &vxb);
    
    //plot the baseline
    gl.AddPlot(drOut, IDM_PLOT_LINE);
}

Remark

Init baseline depending on two end points of the curve.

First, get the two end points from px, py; Second, use the function

Data to construct baseline's x(independent variable) value, and then

loop ii and use formula vby[ii] = y1 + (y2-y1) * (vbx[ii] - x1)/(x2-x1)

((x1, y1) and (x2, y2) are the two end points) to calculate baseline's

y(depend variable) value.

See Also

ocmath_create_baseline_by_masking_peaks

header to Include

origin.h

Reference