【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.23.2.17 ocmath_xy_remove_duplicates
Contents
Description
This function remove duplicated points and replace duplicated points by nMethod, where 0 means replace with mean, 1=median, 2=min, 3=max, 4=sum
Syntax
int ocmath_xy_remove_duplicates(double * px, double * py, UINT nSize, int nMethod = Replace_With_Mean, double dPrecision = 1.0e-8, bool bSort = TRUE, double * duppx = NULL, double * pCounts = NULL, int * pnSizeDuppx = NULL )
Parameters
- px
- [modify] on input, it contains X coordinate's datas; on output, contains X coordinate's datas removed duplicates
- py
- [modify] on input, it contains Y coordinate's datas; on output, contains Y coordinate's datas removed duplicates
- nSize
- [input] size of px, py
- nMethod
- [input] replace duplicates methods, where 0 means replace with mean, 1=median, 2=min, 3=max, 4=sum
- dPrecision
- [input] precision to determine whether two points are duplicated or not
- bSort
- [input] if TRUE, will sort px, then reorder py by px's index.
- duppx
- [output] An array to hold the duplicate x values. Before calling, need alloc enough memory for it.
- pCounts
- [output] An array to hold the number of each duplicate x values. Before calling, need alloc enough memory for it.
- pnSizeDuppx
- [output] the count of dupplicate
Return
Return number of points in px, py after removed duplicates if succeed, otherwise, negative error code is returned.
Examples
EX1
//Before running, make sure the active layer is a graph with dataplot containing curve's X/Y data void ocmath_xy_remove_duplicates_ex1() { GraphLayer gl = Project.ActiveLayer(); if (!gl) { return; } 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(); int nMethod = Replace_With_Mean; double dPrecision = 1.0e-8; int nRet; nDataSize = ocmath_xy_remove_duplicates(vxData, vyData, nDataSize, nMethod, dPrecision); if( nDataSize < OE_NOERROR ) { printf("error code: %d\n", nRet); return; } vxData.SetSize(nDataSize); vyData.SetSize(nDataSize); 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(nXCol).SetType(OKDATAOBJ_DESIGNATION_X); wksResult.Columns(nYCol).SetType(OKDATAOBJ_DESIGNATION_Y); DataRange drOut; drOut.Add("X", wksResult, 0, nXCol, -1, nXCol); drOut.Add("Y", wksResult, 0, nYCol, -1, nYCol); drOut.SetData(&vyData, &vxData); gl.AddPlot(drOut, IDM_PLOT_SCATTER, GAP_ALLOW_DUPLICATE_COL | GAP_USE_TEMPLATE); }
Remark
See Also
Header to Include
origin.h